Skip to content

Commit

Permalink
fixing installer
Browse files Browse the repository at this point in the history
fixing restart
  • Loading branch information
Idrinth committed May 13, 2021
1 parent 9e4dd9c commit 7b65e08
Show file tree
Hide file tree
Showing 7 changed files with 73 additions and 42 deletions.
17 changes: 16 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>de.idrinth</groupId>
<artifactId>WARAddonClient</artifactId>
<version>1.10.1</version>
<version>1.10.2</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down Expand Up @@ -208,6 +208,21 @@
</resources>
</configuration>
</execution>
<execution>
<id>copy-conf</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/java/conf</outputDirectory>
<resources>
<resource>
<directory>${java.home}/conf</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
Expand Down
52 changes: 28 additions & 24 deletions src/main/java/de/idrinth/waraddonclient/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,31 +55,35 @@ public static void main(String[] args) {

public static void restart() throws IOException {
try {
StringBuilder cmd = new StringBuilder("\"" + System.getProperty("java.home") + "/bin/java\" ");
ManagementFactory.getRuntimeMXBean().getInputArguments().stream().filter(arg -> (!arg.contains("-agentlib"))).map(arg -> {
cmd.append(arg);
return arg;
}).forEachOrdered(item -> cmd.append(" "));

String[] mainCommand = System.getProperty(SUN_JAVA_COMMAND).split(" ");
cmd.append("-jar " );
cmd.append(new File(mainCommand[0]).getPath());
for (int i = 1; i < mainCommand.length; i++) {
cmd.append(" ");
cmd.append(mainCommand[i]);
}
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
Runtime.getRuntime().exec(cmd.toString());
} catch (IOException e) {
e.printStackTrace();
File jar = new File("WARAddonClient.jar");
File exe = new File("WARAddonClient.exe");
if (exe.exists()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
Runtime.getRuntime().exec(exe.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
}
});
System.exit(0);
} catch (Exception e) {
});
System.exit(0);
} else if (jar.exists()) {
Runtime.getRuntime().addShutdownHook(new Thread() {
@Override
public void run() {
try {
Runtime.getRuntime().exec("java -jar "+jar.getAbsolutePath());
} catch (IOException e) {
e.printStackTrace();
}
}
});
System.exit(0);
}
throw new IOException("Executable not found, did you replace it?");
} catch (IOException e) {
throw new IOException("Error while trying to restart the application", e);
}
}
Expand Down
18 changes: 15 additions & 3 deletions src/main/java/de/idrinth/waraddonclient/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,39 @@

import de.idrinth.waraddonclient.service.FileLogger;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.logging.Level;
import java.util.logging.Logger;

public class Utils {

private Utils() {
}

public static void emptyFolder(File folder) {
public static void emptyFolder(File folder) throws IOException {
if (folder == null || !folder.exists()) {
return;
}
for (File file : folder.listFiles()) {
if (file.isDirectory()) {
emptyFolder(file);
}
file.delete();
Files.deleteIfExists(file.toPath());
}
}

public static void deleteFolder(File folder) throws IOException {
if (folder == null || !folder.exists()) {
return;
}
emptyFolder(folder);
Files.deleteIfExists(folder.toPath());
}
public static void sleep(int duration, FileLogger logger) {
try {
Thread.sleep(duration);
} catch (java.lang.InterruptedException exception) {
} catch (InterruptedException exception) {
logger.info(exception);
}
}
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/de/idrinth/waraddonclient/gui/Window.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.awt.Desktop;
import java.awt.FileDialog;
import java.awt.Toolkit;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.event.HyperlinkEvent;
Expand Down Expand Up @@ -650,25 +652,25 @@ private void RestoreBackupActionPerformed(java.awt.event.ActionEvent evt) {//GEN
try {
Backup.restore(new java.io.File(dialog.getDirectory() + "/" + dialog.getFile()));
JOptionPane.showMessageDialog(this, "Backup restored.");
} catch (ZipException ex) {
} catch (IOException ex) {
logger.error(ex);
JOptionPane.showMessageDialog(this, "Couldn't restore Backup.");
}
}
}//GEN-LAST:event_RestoreBackupActionPerformed

private void QuitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_QuitActionPerformed
this.dispose();
Runtime.getRuntime().exit(0);
}//GEN-LAST:event_QuitActionPerformed

private void RestartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RestartActionPerformed
try {
Main.restart();
} catch (IOException ex) {
logger.error(ex);
JOptionPane.showMessageDialog(this, "Couldn't restart app.");
}
}//GEN-LAST:event_QuitActionPerformed

private void RestartActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RestartActionPerformed
this.dispose();
Runtime.getRuntime().exit(0);
}//GEN-LAST:event_RestartActionPerformed

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,13 +253,9 @@ public void run(boolean redeploy) throws IOException {
Config.setEnabled(name, false);
}

/**
* removes all data of this addon from the harddrive
*/
private void uninstall() {
private void uninstall() throws IOException {
java.io.File addonFolder = new java.io.File(Config.getWARPath() + BASE_PATH + name);
Utils.emptyFolder(addonFolder);
addonFolder.delete();
Utils.deleteFolder(addonFolder);
installed="-";
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/de/idrinth/waraddonclient/service/Backup.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import de.idrinth.waraddonclient.Config;
import de.idrinth.waraddonclient.Utils;
import java.io.IOException;
import net.lingala.zip4j.exception.ZipException;

public class Backup {
private Backup() {
Expand All @@ -21,7 +23,7 @@ public static void create() throws net.lingala.zip4j.exception.ZipException {
zip.addFolder(new java.io.File(warDir+"/Interface"));
}

public static void restore(java.io.File backup) throws net.lingala.zip4j.exception.ZipException {
public static void restore(java.io.File backup) throws ZipException, IOException {
create();
String warDir = Config.getWARPath();
net.lingala.zip4j.ZipFile zip = new net.lingala.zip4j.ZipFile(backup);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ DefaultDirName={autopf}\{#MyAppName}
DisableProgramGroupPage=yes
PrivilegesRequiredOverridesAllowed=dialog
OutputDir={#MyAppBasePath}\output
OutputBaseFilename={#MyAppName}Setup{#MyAppVersion}
OutputBaseFilename={#MyAppName}Setup
SetupIconFile={#MyAppBasePath}\src\main\resources\Images\logo.ico
Compression=lzma
SolidCompression=yes
Expand Down

0 comments on commit 7b65e08

Please sign in to comment.