|  |  |  | @ -40,58 +40,79 @@ import com.eclipsesource.json.JsonArray; | 
		
	
		
			
				|  |  |  |  | import com.eclipsesource.json.JsonObject; | 
		
	
		
			
				|  |  |  |  | import com.eclipsesource.json.JsonValue; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | import javafx.application.Platform; | 
		
	
		
			
				|  |  |  |  | import kellerkinder.HomeFlix.application.Main; | 
		
	
		
			
				|  |  |  |  | import kellerkinder.HomeFlix.application.SettingsView; | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | public class UpdateController implements Runnable { | 
		
	
		
			
				|  |  |  |  | public class UpdateController { | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	private SettingsView settingsViewController; | 
		
	
		
			
				|  |  |  |  | 	private int updateBuildNumber; // tag_name from gitea | 
		
	
		
			
				|  |  |  |  | 	private String apiOutput; | 
		
	
		
			
				|  |  |  |  | 	private static int updateBuildNumber; // tag_name from gitea | 
		
	
		
			
				|  |  |  |  | 	@SuppressWarnings("unused") | 
		
	
		
			
				|  |  |  |  | 	private String updateName; | 
		
	
		
			
				|  |  |  |  | 	private static String updateName; | 
		
	
		
			
				|  |  |  |  | 	@SuppressWarnings("unused") | 
		
	
		
			
				|  |  |  |  | 	private String updateChanges; | 
		
	
		
			
				|  |  |  |  | 	private String browserDownloadUrl; // update download link	 | 
		
	
		
			
				|  |  |  |  | 	private String giteaApiRelease = "https://git.mosad.xyz/api/v1/repos/Seil0/Project-HomeFlix/releases"; | 
		
	
		
			
				|  |  |  |  | 	private URL giteaApiUrl; | 
		
	
		
			
				|  |  |  |  | 	private static String updateChanges; | 
		
	
		
			
				|  |  |  |  | 	private static String browserDownloadUrl; // update download link	 | 
		
	
		
			
				|  |  |  |  | 	private static final String giteaApiRelease = "https://git.mosad.xyz/api/v1/repos/Seil0/Project-HomeFlix/releases"; | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  | 	private static final Logger LOGGER = LogManager.getLogger(UpdateController.class.getName()); | 
		
	
		
			
				|  |  |  |  |  | 
		
	
		
			
				|  |  |  |  | 	/** | 
		
	
		
			
				|  |  |  |  | 	 * updater for Project HomeFlix based on cemu_UIs, checks for Updates and download it | 
		
	
		
			
				|  |  |  |  | 	 * @param mwc			the MainWindowController object | 
		
	
		
			
				|  |  |  |  | 	 * @param buildNumber	the buildNumber of the used HomeFlix version | 
		
	
		
			
				|  |  |  |  | 	 * @param useBeta		if the updater should query the beta channel | 
		
	
		
			
				|  |  |  |  | 	 */ | 
		
	
		
			
				|  |  |  |  | 	public UpdateController(SettingsView svc) { | 
		
	
		
			
				|  |  |  |  | 		settingsViewController = svc; | 
		
	
		
			
				|  |  |  |  | 	public UpdateController() { | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  | 	@Override | 
		
	
		
			
				|  |  |  |  | 	public void run() { | 
		
	
		
			
				|  |  |  |  | 	public static void update() { | 
		
	
		
			
				|  |  |  |  | 		if (browserDownloadUrl != null) { | 
		
	
		
			
				|  |  |  |  | 			LOGGER.info("download link: " + browserDownloadUrl); | 
		
	
		
			
				|  |  |  |  | 			 | 
		
	
		
			
				|  |  |  |  | 			Runnable run = () -> { | 
		
	
		
			
				|  |  |  |  | 				try { | 
		
	
		
			
				|  |  |  |  | 					// open new HTTP connection, ProgressMonitorInputStream for downloading the data | 
		
	
		
			
				|  |  |  |  | 					// FIXME the download progress dialog is not showing! | 
		
	
		
			
				|  |  |  |  | 					HttpURLConnection connection = (HttpURLConnection) new URL(browserDownloadUrl).openConnection(); | 
		
	
		
			
				|  |  |  |  | 					ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", connection.getInputStream()); | 
		
	
		
			
				|  |  |  |  | 					ProgressMonitor pm = pmis.getProgressMonitor(); | 
		
	
		
			
				|  |  |  |  | 					pm.setMillisToDecideToPopup(0); | 
		
	
		
			
				|  |  |  |  | 					pm.setMillisToPopup(0); | 
		
	
		
			
				|  |  |  |  | 					pm.setMinimum(0);// set beginning of the progress bar to 0 | 
		
	
		
			
				|  |  |  |  | 					pm.setMaximum(connection.getContentLength());// set the end to the file length | 
		
	
		
			
				|  |  |  |  | 					FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); // download update | 
		
	
		
			
				|  |  |  |  | 					LOGGER.info("update download successful, restarting ..."); | 
		
	
		
			
				|  |  |  |  | 					org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar")); | 
		
	
		
			
				|  |  |  |  | 					org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); // delete update | 
		
	
		
			
				|  |  |  |  | 					new ProcessBuilder("java", "-jar", "ProjectHomeFlix.jar").start(); // start the new application | 
		
	
		
			
				|  |  |  |  | 					System.exit(0); // close the current application | 
		
	
		
			
				|  |  |  |  | 				} catch (IOException e) { | 
		
	
		
			
				|  |  |  |  | 					LOGGER.info("could not download update files", e); | 
		
	
		
			
				|  |  |  |  | 				} | 
		
	
		
			
				|  |  |  |  | 			}; | 
		
	
		
			
				|  |  |  |  | 			 | 
		
	
		
			
				|  |  |  |  | 			Thread t = new Thread(run); | 
		
	
		
			
				|  |  |  |  | 			t.start(); | 
		
	
		
			
				|  |  |  |  | 			 | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  | 	 | 
		
	
		
			
				|  |  |  |  | 	public static boolean isUpdateAvailable() { | 
		
	
		
			
				|  |  |  |  | 		LOGGER.info("beta:" + XMLController.isUseBeta() + "; checking for updates ..."); | 
		
	
		
			
				|  |  |  |  | 		Platform.runLater(() -> { | 
		
	
		
			
				|  |  |  |  | 			settingsViewController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnChecking")); | 
		
	
		
			
				|  |  |  |  | 		}); | 
		
	
		
			
				|  |  |  |  | 		String apiOutput = ""; | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 		try { | 
		
	
		
			
				|  |  |  |  | 			giteaApiUrl = new URL(giteaApiRelease); | 
		
	
		
			
				|  |  |  |  | 			URL giteaApiUrl = new URL(giteaApiRelease); | 
		
	
		
			
				|  |  |  |  | 			 | 
		
	
		
			
				|  |  |  |  | 			BufferedReader ina = new BufferedReader(new InputStreamReader(giteaApiUrl.openStream())); | 
		
	
		
			
				|  |  |  |  | 			apiOutput = ina.readLine(); | 
		
	
		
			
				|  |  |  |  | 			ina.close(); | 
		
	
		
			
				|  |  |  |  | 		} catch (Exception e) { | 
		
	
		
			
				|  |  |  |  | 			Platform.runLater(() -> { | 
		
	
		
			
				|  |  |  |  | 				LOGGER.error("could not check update version", e); | 
		
	
		
			
				|  |  |  |  | 			}); | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 		JsonArray objectArray = Json.parse("{\"items\": " + apiOutput + "}").asObject().get("items").asArray(); | 
		
	
		
			
				|  |  |  |  | 		JsonValue object = objectArray.get(0).asObject(); // set to the latest release as default | 
		
	
		
			
				|  |  |  |  | 		JsonObject objectAsset = object.asObject().get("assets").asArray().get(0).asObject(); | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 		// TODO rework stream() | 
		
	
		
			
				|  |  |  |  | 		for(JsonValue objectIt : objectArray) { | 
		
	
		
			
				|  |  |  |  | 			if(objectIt.asObject().getBoolean("prerelease", false) == XMLController.isUseBeta()) { | 
		
	
		
			
				|  |  |  |  | 				// we found the needed release either beta or not | 
		
	
	
		
			
				
					
					|  |  |  | @ -104,46 +125,11 @@ public class UpdateController implements Runnable { | 
		
	
		
			
				|  |  |  |  | 		updateBuildNumber = Integer.parseInt(object.asObject().getString("tag_name", "")); | 
		
	
		
			
				|  |  |  |  | 		updateName = object.asObject().getString("name", ""); | 
		
	
		
			
				|  |  |  |  | 		updateChanges = object.asObject().getString("body", ""); | 
		
	
		
			
				|  |  |  |  | 		browserDownloadUrl = objectAsset.getString("browser_download_url", ""); | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 		LOGGER.info("Build: " + Main.buildNumber + ", Update: " + updateBuildNumber); | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 		/** | 
		
	
		
			
				|  |  |  |  | 		 * Compare the program BuildNumber with the current BuildNumber | 
		
	
		
			
				|  |  |  |  | 		 * if buildNumber < updateBuildNumber then perform a update | 
		
	
		
			
				|  |  |  |  | 		 */ | 
		
	
		
			
				|  |  |  |  | 		if (Integer.parseInt(Main.buildNumber) >= updateBuildNumber) { | 
		
	
		
			
				|  |  |  |  | 			Platform.runLater(() -> { | 
		
	
		
			
				|  |  |  |  | 				settingsViewController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnNoUpdateAvailable")); | 
		
	
		
			
				|  |  |  |  | 			}); | 
		
	
		
			
				|  |  |  |  | 			LOGGER.info("no update available"); | 
		
	
		
			
				|  |  |  |  | 		} else { | 
		
	
		
			
				|  |  |  |  | 			Platform.runLater(() -> { | 
		
	
		
			
				|  |  |  |  | 				settingsViewController.getUpdateBtn().setText(XMLController.getLocalBundle().getString("updateBtnUpdateAvailable")); | 
		
	
		
			
				|  |  |  |  | 			}); | 
		
	
		
			
				|  |  |  |  | 			LOGGER.info("update available"); | 
		
	
		
			
				|  |  |  |  | 			browserDownloadUrl = objectAsset.getString("browser_download_url", ""); | 
		
	
		
			
				|  |  |  |  | 			LOGGER.info("download link: " + browserDownloadUrl); | 
		
	
		
			
				|  |  |  |  | 			try { | 
		
	
		
			
				|  |  |  |  | 				// open new HTTP connection, ProgressMonitorInputStream for downloading the data | 
		
	
		
			
				|  |  |  |  | 				// FIXME the download progress dialog is not showing! | 
		
	
		
			
				|  |  |  |  | 				HttpURLConnection connection = (HttpURLConnection) new URL(browserDownloadUrl).openConnection(); | 
		
	
		
			
				|  |  |  |  | 				ProgressMonitorInputStream pmis = new ProgressMonitorInputStream(null, "Downloading...", connection.getInputStream()); | 
		
	
		
			
				|  |  |  |  | 				ProgressMonitor pm = pmis.getProgressMonitor(); | 
		
	
		
			
				|  |  |  |  | 				pm.setMillisToDecideToPopup(0); | 
		
	
		
			
				|  |  |  |  | 				pm.setMillisToPopup(0); | 
		
	
		
			
				|  |  |  |  | 				pm.setMinimum(0);// set beginning of the progress bar to 0 | 
		
	
		
			
				|  |  |  |  | 				pm.setMaximum(connection.getContentLength());// set the end to the file length | 
		
	
		
			
				|  |  |  |  | 				FileUtils.copyInputStreamToFile(pmis, new File("ProjectHomeFlix_update.jar")); // download update | 
		
	
		
			
				|  |  |  |  | 				LOGGER.info("update download successful, restarting ..."); | 
		
	
		
			
				|  |  |  |  | 				org.apache.commons.io.FileUtils.copyFile(new File("ProjectHomeFlix_update.jar"), new File("ProjectHomeFlix.jar")); | 
		
	
		
			
				|  |  |  |  | 				org.apache.commons.io.FileUtils.deleteQuietly(new File("ProjectHomeFlix_update.jar")); // delete update | 
		
	
		
			
				|  |  |  |  | 				new ProcessBuilder("java", "-jar", "ProjectHomeFlix.jar").start(); // start the new application | 
		
	
		
			
				|  |  |  |  | 				System.exit(0); // close the current application | 
		
	
		
			
				|  |  |  |  | 			} catch (IOException e) { | 
		
	
		
			
				|  |  |  |  | 				Platform.runLater(() -> { | 
		
	
		
			
				|  |  |  |  | 					LOGGER.info("could not download update files", e); | 
		
	
		
			
				|  |  |  |  | 				}); | 
		
	
		
			
				|  |  |  |  | 			} | 
		
	
		
			
				|  |  |  |  | 		} | 
		
	
		
			
				|  |  |  |  | 		return Integer.parseInt(Main.buildNumber) < updateBuildNumber; | 
		
	
		
			
				|  |  |  |  | 		 | 
		
	
		
			
				|  |  |  |  | 	} | 
		
	
		
			
				|  |  |  |  | } | 
		
	
	
		
			
				
					
					| 
							
							
							
						 |  |  | 
 |