From 6bca308262eeca7ada5565e342f6567d50911234 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 16:35:21 +0100 Subject: [PATCH 1/6] started tackling restart on status --- head_src/consolehead/consolehead.c | 5 +++-- head_src/jniconsolehead_BETA/jniconsolehead.c | 5 +++-- head_src/resource.h | 1 + src/net/sf/launch4j/RcBuilder.java | 2 ++ src/net/sf/launch4j/config/Config.java | 11 +++++++++++ 5 files changed, 20 insertions(+), 4 deletions(-) diff --git a/head_src/consolehead/consolehead.c b/head_src/consolehead/consolehead.c index 1846a56..4d12d83 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); // atoi is returning 0 if not an int DWORD dwExitCode; do @@ -85,11 +86,11 @@ int main(int argc, char* argv[]) break; } - if (restartOnCrash && dwExitCode != 0) + if ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while (restartOnCrash && dwExitCode != 0); + } while ((restartOnCrash && dwExitCode != 0) || 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..7feb400 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); // atoi is returning 0 if not an int DWORD dwExitCode; do @@ -87,11 +88,11 @@ int main(int argc, char* argv[]) break; } - if (restartOnCrash && dwExitCode != 0) + if ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while (restartOnCrash && dwExitCode != 0); + } while ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); diff --git a/head_src/resource.h b/head_src/resource.h index 829923d..3a6801a 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..060a11e 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 Integer 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 Integer getRestartOnStatus() { + return restartOnStatus; + } + + public void setRestartOnStatus(Integer 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; From 10bdc78da05a19c29df38e351cc9551b98257bc6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 17:33:16 +0100 Subject: [PATCH 2/6] fixing restart statement --- head_src/consolehead/consolehead.c | 4 ++-- head_src/jniconsolehead_BETA/jniconsolehead.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/head_src/consolehead/consolehead.c b/head_src/consolehead/consolehead.c index 4d12d83..5c48c87 100644 --- a/head_src/consolehead/consolehead.c +++ b/head_src/consolehead/consolehead.c @@ -86,11 +86,11 @@ int main(int argc, char* argv[]) break; } - if ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus) + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus); + } 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 7feb400..08662e3 100644 --- a/head_src/jniconsolehead_BETA/jniconsolehead.c +++ b/head_src/jniconsolehead_BETA/jniconsolehead.c @@ -88,11 +88,11 @@ int main(int argc, char* argv[]) break; } - if ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus) + if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) { debug("Exit code:\t%d, restarting the application!\n", dwExitCode); } - } while ((restartOnCrash && dwExitCode != 0) || dwExitCode == restartOnStatus); + } while (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)); debug("Exit code:\t%d\n", dwExitCode); closeLogFile(); From e5272aaf66701846c1b08bb9c8b0c6f90c83e4af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 17:34:55 +0100 Subject: [PATCH 3/6] Integer -> int in Config.java --- src/net/sf/launch4j/config/Config.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/net/sf/launch4j/config/Config.java b/src/net/sf/launch4j/config/Config.java index 060a11e..10621c3 100644 --- a/src/net/sf/launch4j/config/Config.java +++ b/src/net/sf/launch4j/config/Config.java @@ -95,7 +95,7 @@ public class Config implements IValidatable { private String supportUrl; private boolean stayAlive; private boolean restartOnCrash; - private Integer restartOnStatus; + private int restartOnStatus; private File manifest; private File icon; private List variables; @@ -359,11 +359,11 @@ public void setRestartOnCrash(boolean restartOnCrash) { } /** Restart the application whenever the java application returns the status given here **/ - public Integer getRestartOnStatus() { + public int getRestartOnStatus() { return restartOnStatus; } - public void setRestartOnStatus(Integer status) { + public void setRestartOnStatus(int status) { if(status < 5 && status > 255) throw new NumberFormatException("Restart-Status needs to be between 5 and 255!"); restartOnStatus = status; } From 26ade1b74738a546572eddce77119d0feb50a8b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 17:37:47 +0100 Subject: [PATCH 4/6] using tab instead of spaces in resources --- head_src/resource.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/head_src/resource.h b/head_src/resource.h index 3a6801a..470594f 100644 --- a/head_src/resource.h +++ b/head_src/resource.h @@ -67,7 +67,7 @@ #define RUNTIME_BITS 30 #define RESTART_ON_CRASH 31 #define BUNDLED_JRE_AS_FALLBACK 32 -#define RESTART_ON_STATUS 33 +#define RESTART_ON_STATUS 33 #define STARTUP_ERR 101 #define BUNDLED_JRE_ERR 102 From be8a563385b5ec87b7d1e5bf5764a2658cef6343 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 17:47:35 +0100 Subject: [PATCH 5/6] removing coment, handling gui cases --- head_src/consolehead/consolehead.c | 2 +- head_src/guihead/guihead.c | 8 +++++--- head_src/jniconsolehead_BETA/jniconsolehead.c | 2 +- head_src/jniguihead_BETA/jniguihead.c | 8 +++++--- 4 files changed, 12 insertions(+), 8 deletions(-) diff --git a/head_src/consolehead/consolehead.c b/head_src/consolehead/consolehead.c index 5c48c87..1efbd5b 100644 --- a/head_src/consolehead/consolehead.c +++ b/head_src/consolehead/consolehead.c @@ -73,7 +73,7 @@ int main(int argc, char* argv[]) } restartOnCrash = loadBool(RESTART_ON_CRASH); - int restartOnStatus = loadInt(RESTART_ON_STATUS); // atoi is returning 0 if not an int + int restartOnStatus = loadInt(RESTART_ON_STATUS); DWORD dwExitCode; do diff --git a/head_src/guihead/guihead.c b/head_src/guihead/guihead.c index 6d165a2..d84e581 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 08662e3..9dd598c 100644 --- a/head_src/jniconsolehead_BETA/jniconsolehead.c +++ b/head_src/jniconsolehead_BETA/jniconsolehead.c @@ -74,7 +74,7 @@ int main(int argc, char* argv[]) } restartOnCrash = loadBool(RESTART_ON_CRASH); - int restartOnStatus = loadInt(RESTART_ON_STATUS); // atoi is returning 0 if not an int + int restartOnStatus = loadInt(RESTART_ON_STATUS); DWORD dwExitCode; do 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(); From 897ca4ae988cedb71b714bf4cde5a2eeda31c842 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andre=CC=81=20Tietz?= Date: Mon, 2 Nov 2020 17:50:21 +0100 Subject: [PATCH 6/6] replaced spaces with tabs --- head_src/guihead/guihead.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/head_src/guihead/guihead.c b/head_src/guihead/guihead.c index d84e581..26a0000 100644 --- a/head_src/guihead/guihead.c +++ b/head_src/guihead/guihead.c @@ -149,7 +149,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, DispatchMessage(&msg); } - int restartOnStatus = loadInt(RESTART_ON_STATUS); + int restartOnStatus = loadInt(RESTART_ON_STATUS); if (dwExitCode != 0 && (restartOnCrash || dwExitCode == restartOnStatus)) {