diff --git a/head_src/consolehead/consolehead.c b/head_src/consolehead/consolehead.c index 1846a56..1efbd5b 100644 --- a/head_src/consolehead/consolehead.c +++ b/head_src/consolehead/consolehead.c @@ -73,6 +73,7 @@ int main(int argc, char* argv[]) } restartOnCrash = loadBool(RESTART_ON_CRASH); + int restartOnStatus = loadInt(RESTART_ON_STATUS); DWORD dwExitCode; do @@ -85,11 +86,11 @@ int main(int argc, char* argv[]) break; } - if (restartOnCrash && dwExitCode != 0) + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while (restartOnCrash && dwExitCode != 0); + } while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); diff --git a/head_src/guihead/guihead.c b/head_src/guihead/guihead.c index 6d165a2..26a0000 100644 --- a/head_src/guihead/guihead.c +++ b/head_src/guihead/guihead.c @@ -148,14 +148,16 @@ int APIENTRY WinMain(HINSTANCE hInstance, TranslateMessage(&msg); DispatchMessage(&msg); } - - if (restartOnCrash && dwExitCode != 0) + + int restartOnStatus = loadInt(RESTART_ON_STATUS); + + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } closeProcessHandles(); - } while (restartOnCrash && dwExitCode != 0); + } while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); diff --git a/head_src/jniconsolehead_BETA/jniconsolehead.c b/head_src/jniconsolehead_BETA/jniconsolehead.c index 0e7f6dd..9dd598c 100644 --- a/head_src/jniconsolehead_BETA/jniconsolehead.c +++ b/head_src/jniconsolehead_BETA/jniconsolehead.c @@ -74,6 +74,7 @@ int main(int argc, char* argv[]) } restartOnCrash = loadBool(RESTART_ON_CRASH); + int restartOnStatus = loadInt(RESTART_ON_STATUS); DWORD dwExitCode; do @@ -87,11 +88,11 @@ int main(int argc, char* argv[]) break; } - if (restartOnCrash && dwExitCode != 0) + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while (restartOnCrash && dwExitCode != 0); + } while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); diff --git a/head_src/jniguihead_BETA/jniguihead.c b/head_src/jniguihead_BETA/jniguihead.c index 0259a27..b15f391 100644 --- a/head_src/jniguihead_BETA/jniguihead.c +++ b/head_src/jniguihead_BETA/jniguihead.c @@ -151,14 +151,16 @@ int APIENTRY WinMain(HINSTANCE hInstance, TranslateMessage(&msg); DispatchMessage(&msg); } - - if (restartOnCrash && dwExitCode != 0) + + int restartOnStatus = loadInt(RESTART_ON_STATUS); + + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } closeProcessHandles(); - } while (restartOnCrash && dwExitCode != 0); + } while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); diff --git a/head_src/resource.h b/head_src/resource.h index 829923d..470594f 100644 --- a/head_src/resource.h +++ b/head_src/resource.h @@ -67,6 +67,7 @@ #define RUNTIME_BITS 30 #define RESTART_ON_CRASH 31 #define BUNDLED_JRE_AS_FALLBACK 32 +#define RESTART_ON_STATUS 33 #define STARTUP_ERR 101 #define BUNDLED_JRE_ERR 102 diff --git a/src/net/sf/launch4j/RcBuilder.java b/src/net/sf/launch4j/RcBuilder.java index 45f2339..7b8c124 100644 --- a/src/net/sf/launch4j/RcBuilder.java +++ b/src/net/sf/launch4j/RcBuilder.java @@ -104,6 +104,7 @@ public class RcBuilder { public static final int RUNTIME_BITS = 30; public static final int RESTART_ON_CRASH = 31; public static final int BUNDLED_JRE_AS_FALLBACK = 32; + public static final int RESTART_ON_STATUS = 33; public static final int STARTUP_ERR = 101; public static final int BUNDLED_JRE_ERR = 102; @@ -139,6 +140,7 @@ public File build(Config c) throws IOException { addText(PRIORITY_CLASS, String.valueOf(c.getPriorityClass())); addTrue(GUI_HEADER_STAYS_ALIVE, c.isStayAlive()); addTrue(RESTART_ON_CRASH, c.isRestartOnCrash()); + addInteger(RESTART_ON_STATUS, c.getRestartOnStatus()); addSplash(c.getSplash()); addMessages(c); diff --git a/src/net/sf/launch4j/config/Config.java b/src/net/sf/launch4j/config/Config.java index da9dd1d..10621c3 100644 --- a/src/net/sf/launch4j/config/Config.java +++ b/src/net/sf/launch4j/config/Config.java @@ -95,6 +95,7 @@ public class Config implements IValidatable { private String supportUrl; private boolean stayAlive; private boolean restartOnCrash; + private int restartOnStatus; private File manifest; private File icon; private List variables; @@ -356,6 +357,16 @@ public boolean isRestartOnCrash() { public void setRestartOnCrash(boolean restartOnCrash) { this.restartOnCrash = restartOnCrash; } + + /** Restart the application whenever the java application returns the status given here **/ + public int getRestartOnStatus() { + return restartOnStatus; + } + + public void setRestartOnStatus(int status) { + if(status < 5 && status > 255) throw new NumberFormatException("Restart-Status needs to be between 5 and 255!"); + restartOnStatus = status; + } public VersionInfo getVersionInfo() { return versionInfo;