Skip to content
Snippets Groups Projects
Commit f6ba683d authored by tobias's avatar tobias
Browse files

Start adding Update Class

parent 3695b705
No related branches found
No related tags found
No related merge requests found
...@@ -54,6 +54,7 @@ import de.tobias.playpad.settings.ProfileReference; ...@@ -54,6 +54,7 @@ import de.tobias.playpad.settings.ProfileReference;
import de.tobias.playpad.tigger.TriggerRegistry; import de.tobias.playpad.tigger.TriggerRegistry;
import de.tobias.playpad.trigger.CartTriggerItemConnect; import de.tobias.playpad.trigger.CartTriggerItemConnect;
import de.tobias.playpad.trigger.VolumeTriggerItemConnect; import de.tobias.playpad.trigger.VolumeTriggerItemConnect;
import de.tobias.playpad.update.PlayPadUpdater;
import de.tobias.playpad.update.Updatable; import de.tobias.playpad.update.Updatable;
import de.tobias.playpad.update.UpdateRegistery; import de.tobias.playpad.update.UpdateRegistery;
import de.tobias.playpad.view.MapperOverviewViewController; import de.tobias.playpad.view.MapperOverviewViewController;
......
package de.tobias.playpad; package de.tobias.playpad.update;
import java.io.IOException; import java.io.IOException;
import java.net.URISyntaxException; import java.net.URISyntaxException;
......
package de.tobias.playpad.update;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import de.tobias.playpad.AppUserInfoStrings;
import de.tobias.utils.application.App;
import de.tobias.utils.application.ApplicationUtils;
import de.tobias.utils.application.NativeLauncher;
import de.tobias.utils.application.container.PathType;
import de.tobias.utils.util.IOUtils;
import de.tobias.utils.util.OS;
import javafx.application.Platform;
public class Updates {
// Ornder im App-Folder wo Updates zwischengespeichert werden sollen.
private static final String CACHE_FOLER = "Updates";
// Name der Updater Datei
private static String JAR_NAME = "Updater.jar";
private static String EXE_NAME = "Updater.exe";
/**
* Sollte in einem Extra Thread gemacht werden, da der Updater gedownloaded wird.
*
* @throws IOException
*/
public static void update() throws IOException {
App app = ApplicationUtils.getApplication();
String downloadPath = app.getPath(PathType.DOWNLOAD, CACHE_FOLER).toString();
String updateParameter = UpdateRegistery.buildParamaterString(downloadPath);
boolean successfulStartUpdate = false;
// Start des Update Prozesses
if (OS.isWindows()) {
successfulStartUpdate = updateWindows(updateParameter, UpdateRegistery.needsAdminPermission());
} else if (OS.isMacOS()) {
successfulStartUpdate = updateMacOS(updateParameter);
}
if (successfulStartUpdate) {
// Kill the program
Platform.exit();
System.exit(0);
}
}
private static boolean updateWindows(String parameter, boolean needAdminPermission) throws IOException {
Path path = searchForFile(EXE_NAME);
if (path == null) {
App app = ApplicationUtils.getApplication();
String updaterURL = app.getInfo().getUserInfo().get(AppUserInfoStrings.UPDATER_PROGRAM) + EXE_NAME;
Path downloadUpdaterFile = ApplicationUtils.getApplication().getPath(PathType.DOWNLOAD, EXE_NAME);
downloadUpdater(updaterURL, downloadUpdaterFile);
}
startExeFile(parameter, path, needAdminPermission);
return false;
}
private static boolean updateMacOS(String parameter) throws IOException {
Path path = searchForFile(JAR_NAME);
if (path == null) {
App app = ApplicationUtils.getApplication();
String updaterURL = app.getInfo().getUserInfo().get(AppUserInfoStrings.UPDATER_PROGRAM) + JAR_NAME;
Path downloadUpdaterFile = ApplicationUtils.getApplication().getPath(PathType.DOWNLOAD, JAR_NAME);
downloadUpdater(updaterURL, downloadUpdaterFile);
}
startJarFile(parameter, path);
return false;
}
private static void downloadUpdater(String updaterURL, Path path) throws IOException, MalformedURLException {
URL url = new URL(updaterURL);
InputStream iStr = url.openStream();
IOUtils.copy(iStr, path);
iStr.close();
}
private static void startExeFile(String parameter, Path fileExe, boolean needAdminPermission) throws IOException {
if (needAdminPermission) {
NativeLauncher.executeAsAdministrator(fileExe.toAbsolutePath().toString(), parameter);
} else {
ProcessBuilder builder = new ProcessBuilder(fileExe.toAbsolutePath().toString(), parameter);
builder.start();
}
System.exit(0);
}
private static Path searchForFile(String name) {
Path file = Paths.get(name);
Path fileFolder = ApplicationUtils.getApplication().getPath(PathType.DOWNLOAD, name);
if (Files.exists(file)) {
return file;
} else if (Files.exists(fileFolder)) {
return fileFolder;
}
return null;
}
private static void startJarFile(String parameter, Path fileJar) throws IOException {
ProcessBuilder builder = new ProcessBuilder("java", "-jar", fileJar.toAbsolutePath().toString(), parameter);
builder.start();
System.exit(0);
}
}
package de.tobias.playpad.viewcontroller.cell; package de.tobias.playpad.viewcontroller.cell;
import de.tobias.playpad.PlayPadUpdater;
import de.tobias.playpad.Strings; import de.tobias.playpad.Strings;
import de.tobias.playpad.update.PlayPadUpdater;
import de.tobias.playpad.update.Updatable; import de.tobias.playpad.update.Updatable;
import de.tobias.utils.util.Localization; import de.tobias.utils.util.Localization;
import javafx.scene.control.ListCell; import javafx.scene.control.ListCell;
......
...@@ -53,7 +53,7 @@ import javafx.stage.Window; ...@@ -53,7 +53,7 @@ import javafx.stage.Window;
public class UpdateTabViewController extends SettingsTabViewController { public class UpdateTabViewController extends SettingsTabViewController {
private static final String DOWNLOAD_FOLDER = "Updates"; @Deprecated private static final String DOWNLOAD_FOLDER = "Updates";
private static final String UPDATER_JAR = "Updater.jar"; private static final String UPDATER_JAR = "Updater.jar";
private static final String UPDATER_EXE = "Updater.exe"; private static final String UPDATER_EXE = "Updater.exe";
...@@ -268,6 +268,7 @@ public class UpdateTabViewController extends SettingsTabViewController { ...@@ -268,6 +268,7 @@ public class UpdateTabViewController extends SettingsTabViewController {
oStr.close(); oStr.close();
} }
@Deprecated
private static void startExeFile(String parameter, Path fileExe, boolean admin) throws IOException { private static void startExeFile(String parameter, Path fileExe, boolean admin) throws IOException {
if (admin) { if (admin) {
NativeLauncher.executeAsAdministrator(fileExe.toAbsolutePath().toString(), parameter); NativeLauncher.executeAsAdministrator(fileExe.toAbsolutePath().toString(), parameter);
...@@ -279,6 +280,7 @@ public class UpdateTabViewController extends SettingsTabViewController { ...@@ -279,6 +280,7 @@ public class UpdateTabViewController extends SettingsTabViewController {
System.exit(0); System.exit(0);
} }
@Deprecated
private static void startJarFile(String parameter, Path fileJar) throws IOException { private static void startJarFile(String parameter, Path fileJar) throws IOException {
ProcessBuilder builder = new ProcessBuilder("java", "-jar", fileJar.toAbsolutePath().toString(), parameter); ProcessBuilder builder = new ProcessBuilder("java", "-jar", fileJar.toAbsolutePath().toString(), parameter);
builder.start(); builder.start();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment