From 042a8484b0d906955aa56c104d85485d55bccac4 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Mon, 28 Sep 2020 18:27:01 +0200 Subject: [PATCH] Added support for loading extra command-line args from the resources. --- README.md | 22 +++++++++++++++++++++- res/common.rc | 1 + src/head.c | 19 ++++++++++++++----- src/resource.h | 1 + 4 files changed, 37 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 88db3a4..4281bae 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,7 @@ There currently are two different ways to use Launch5j with your application cod # Variants -Launch5j executables come in a number of variants, allowing you to pick the most suitable one: +Launch5j executables come in a number of variants, allowing you to pick the most suitable one for you project: * **`wrapped`** Expects that the JAR file and the executable launcher have been combined to a *single* file; default variant expects that a separate JAR file is present in the same directory where the executable launcher resides. @@ -54,6 +54,12 @@ Launch5j executables come in a number of variants, allowing you to pick the most * **`nosplash`** Does **not** display a splash screen while the application is launching; default variant *does* display a splash screen while the application is launching – will be hidden as soon as application window shows up. +## Platforms + +All of the above Launch5j variants are available as `i586` (32-Bit) and `x86-64` (64-Bit) executables. The `i586` (32-Bit) executables can run on *32-Bit* and *64-Bit* versions of Microsoft® Windows™, whereas the `x86-64` (64-Bit) executables necessarily require a *64-Bit* version of Microsoft® Windows™. Consequently, it is generally recommended to distribute the `i586` (32-Bit) launcher executable with your Java application. Please note that this does **not** restrict the “bitness” of the JRE that can be used. Even the `i586` (32-Bit) launcher executable is perfectly able to detect and launch a *64-Bit* JRE – if it is available. + +Launch5j has been tested to work on Windows XP (Service Pack 2), or a compatible newer version. + # Customizations Launch5j comes with a *default* executable icon and a *default* splash screen bitmap. These just server as an example and you probably want to replace them with your own *application-specific* graphics. @@ -62,6 +68,20 @@ It is *not* necessary (though possible) to re-build the executable files for tha ![reshack](etc/reshacker-example.png) +## Additional options + +Some options can be configured via the launcher executable's [STRINGTABLE](https://docs.microsoft.com/en-us/windows/win32/menurc/stringtable-resource) resource: + +* **`ID_STR_JVMARGS` (#1)** + Specifies *additional* options JVM options to be passed, e.g. `-Xmx2g` or `-Dproperty=value`. + See here for a list of available options: + https://docs.oracle.com/javase/7/docs/technotes/tools/windows/java.html + +* **`ID_STR_CMDARGS` (#2)** + Specifies *additional* (fixed) command-line options to be passed to the application. + +*Note:* The default value `"?"` means "nothing" should be passed, because resource strings cannot be empty! + # Build instructions In order to build Launch5j from the sources, it is recommended to use the [*GNU C Compiler* (GCC)](https://gcc.gnu.org/) for Windows, as provided by the [*Mingw-w64*](http://mingw-w64.org/) project. Other C compilers may work, but are **not** officially supported. diff --git a/res/common.rc b/res/common.rc index 5e656ce..9952e45 100644 --- a/res/common.rc +++ b/res/common.rc @@ -38,6 +38,7 @@ ID_ICON_MAIN ICON "assets/icon.ico" STRINGTABLE BEGIN ID_STR_JVMARGS L"?" /*-Xmx512m*/ + ID_STR_CMDARGS L"?" END ///////////////////////////////////////////////////////////////////////////// diff --git a/src/head.c b/src/head.c index 0e1da1e..8bb594f 100644 --- a/src/head.c +++ b/src/head.c @@ -80,6 +80,7 @@ static const ULONGLONG JAVA_MINIMUM_VERSION = ((ULONGLONG)(REQUIRE_JAVA)) << 48; #define STR(S) #S #define NOT_EMPTY(STR) ((STR) && ((STR)[0U])) +#define AVAILABLE(OPT) (NOT_EMPTY(OPT) && (wcscmp((OPT), L"?") != 0)) #define SET_STRING(DST,SRC) do \ { \ @@ -88,6 +89,7 @@ static const ULONGLONG JAVA_MINIMUM_VERSION = ((ULONGLONG)(REQUIRE_JAVA)) << 48; } \ while(0) + static wchar_t *vawprintf(const wchar_t *const fmt, va_list ap) { const int str_len = _vscwprintf(fmt, ap); @@ -866,7 +868,7 @@ static void destroy_window(HWND *const hwnd) int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow) { int result = -1; - const wchar_t *executable_path = NULL, *executable_directory = NULL, *jarfile_path = NULL, *java_runtime_path = NULL, *jvm_extra_args = NULL, *command_line = NULL; + const wchar_t *executable_path = NULL, *executable_directory = NULL, *jarfile_path = NULL, *java_runtime_path = NULL, *jvm_extra_args = NULL, *cmd_extra_args = NULL, *command_line = NULL; HGDIOBJ splash_image = NULL; PROCESS_INFORMATION process_info; STARTUPINFOW startup_info; @@ -946,13 +948,18 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine } #endif - // Load extra JVM args + // Load additional options jvm_extra_args = load_string(hInstance, ID_STR_JVMARGS); + cmd_extra_args = load_string(hInstance, ID_STR_CMDARGS); // Build the command-line - command_line = (NOT_EMPTY(jvm_extra_args) && (wcscmp(jvm_extra_args, L"?") != 0)) - ? awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" %ls -jar \"%ls\" %ls" : L"\"%ls\" %ls -jar \"%ls\"", java_runtime_path, jvm_extra_args, jarfile_path, pCmdLine) - : awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" -jar \"%ls\" %ls" : L"\"%ls\" -jar \"%ls\"", java_runtime_path, jarfile_path, pCmdLine); + command_line = AVAILABLE(cmd_extra_args) + ? (AVAILABLE(jvm_extra_args) + ? awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" %ls -jar \"%ls\" %ls %ls" : L"\"%ls\" %ls -jar \"%ls\" %ls", java_runtime_path, jvm_extra_args, jarfile_path, cmd_extra_args, pCmdLine) + : awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" -jar \"%ls\" %ls %ls" : L"\"%ls\" -jar \"%ls\" %ls", java_runtime_path, jarfile_path, cmd_extra_args, pCmdLine)) + : (AVAILABLE(jvm_extra_args) + ? awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" %ls -jar \"%ls\" %ls" : L"\"%ls\" %ls -jar \"%ls\"", java_runtime_path, jvm_extra_args, jarfile_path, pCmdLine) + : awprintf(NOT_EMPTY(pCmdLine) ? L"\"%ls\" -jar \"%ls\" %ls" : L"\"%ls\" -jar \"%ls\"", java_runtime_path, jarfile_path, pCmdLine)); if (!command_line) { show_message(hwnd, MB_ICONERROR | MB_TOPMOST, L"System Error", L"The Java command-line could not be generated!"); @@ -1011,6 +1018,8 @@ cleanup: destroy_window(&hwnd); delete_object(&splash_image); + free((void*)jvm_extra_args); + free((void*)cmd_extra_args); free((void*)command_line); free((void*)java_runtime_path); free((void*)jarfile_path); diff --git a/src/resource.h b/src/resource.h index 6f36795..9e2ab19 100644 --- a/src/resource.h +++ b/src/resource.h @@ -19,3 +19,4 @@ // STRINGS #define ID_STR_JVMARGS 1 +#define ID_STR_CMDARGS 2