From 02931280d0955ffad5a68a120147d33d9077f2e4 Mon Sep 17 00:00:00 2001 From: LoRd_MuldeR Date: Sun, 29 Sep 2024 14:06:21 +0200 Subject: [PATCH] Added runtime option for *not* setting the current working directory to the executable directory. --- LICENSE.txt | 2 +- README.md | 15 ++++++++++----- res/common.rc | 1 + src/head.c | 6 +++--- src/resource.h | 9 +++++---- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/LICENSE.txt b/LICENSE.txt index 5ff3ae3..02577cf 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,4 +1,4 @@ -Copyright 2023 LoRd_MuldeR +Copyright 2024 LoRd_MuldeR Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/README.md b/README.md index c6e23d4..939be06 100644 --- a/README.md +++ b/README.md @@ -147,7 +147,12 @@ Some options can be configured via the launcher executable's [STRINGTABLE](https (If `ID_STR_HEAPMIN` is specified too, then this value **must** be greater than or equal to `ID_STR_HEAPMIN`). -* **`ID_STR_JAVAMIN` (0x8)** +* **`ID_STR_NSETCWD` (0x8)** + If set to a non-zero value, do ***not*** change the current working directory. + + (By default, the current working directory is set to the directory where the executable file is located) + +* **`ID_STR_JAVAMIN` (0x9)** Specifies the ***minimum*** supported JRE version, in the **`w.x.y.z`** format (e.g. `11.0.0.0`). This values is *inclusive*, i.e. the specified JRE version or any newer JRE version will be accepted. If not specified, then the *default* minimum supported JRE version `8.0.0.0` applies. @@ -156,7 +161,7 @@ Some options can be configured via the launcher executable's [STRINGTABLE](https (This option only applies to the “registry” variant of Launch5j) -* **`ID_STR_JAVAMAX` (0x9)** +* **`ID_STR_JAVAMAX` (0xA)** Specifies the ***maximum*** supported JRE version, in the **`w.x.y.z`** format (e.g. `12.0.0.0`). This values is *exclusive*, i.e. only JRE versions *older* than the specified JRE version will be accepted. If not specified, then there is **no** upper limit on the supported JRE version. @@ -165,13 +170,13 @@ Some options can be configured via the launcher executable's [STRINGTABLE](https (This option only applies to the “registry” variant of Launch5j) -* **`ID_STR_BITNESS` (0xA)** +* **`ID_STR_BITNESS` (0xB)** Specifies the required ***bitness*** of the JRE. This can be either **`32`** (x86, aka i586) or **`64`** (x86-64). If not specified, then 32-Bit *and* 64-Bit JREs are accepted, with a preference to 64-Bit. (This option only applies to the “registry” variant of Launch5j) -* **`ID_STR_JAVAURL` (0xB)** +* **`ID_STR_JAVAURL` (0xC)** The Java download URL that will ne suggested, if **no** suitable JRE could be detected on the machine. If not specified, wes suggest downloading OpenJDK, as provided by the [Eclipse Adoptium](https://adoptium.net/) project. @@ -296,7 +301,7 @@ This project is partly inspired by the “Launch4j” project, even though it ha This work has been released under the MIT license: - Copyright 2023 LoRd_MuldeR + Copyright 2024 LoRd_MuldeR Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/res/common.rc b/res/common.rc index 8502e26..0a41baa 100644 --- a/res/common.rc +++ b/res/common.rc @@ -44,6 +44,7 @@ BEGIN ID_STR_MUTEXID L"?" /*single instance mutex ID*/ ID_STR_HEAPMIN L"?" /*min. heap size, in percent of phys. memory*/ ID_STR_HEAPMAX L"?" /*max. heap size, in percent of phys. memory*/ + ID_STR_NSETCWD L"?" /*do not set current working directory*/ END ///////////////////////////////////////////////////////////////////////////// diff --git a/src/head.c b/src/head.c index ab9f71c..3aa61c5 100644 --- a/src/head.c +++ b/src/head.c @@ -1615,7 +1615,7 @@ static int launch5j_main(const HINSTANCE hinstance, const wchar_t *const cmd_lin DWORD java_required_bitness = 0U, jvm_heap_percent_min = 0U, jvm_heap_percent_max = 0U, jvm_bitness = 0U; ULONGLONG java_required_ver_min = 0ULL, java_required_ver_max = 0ULL, jvm_version = 0ULL; HGDIOBJ splash_image = NULL; - BOOL have_screen_created = FALSE; + BOOL have_screen_created = FALSE, set_current_directory_enabled = TRUE; PROCESS_INFORMATION process_info; STARTUPINFOW startup_info; @@ -1693,7 +1693,7 @@ static int launch5j_main(const HINSTANCE hinstance, const wchar_t *const cmd_lin } // Set the current directory - if (_wcsicmp(executable_directory, L".") != 0) + if (set_current_directory_enabled = (!BOOLIFY(load_uint32(hinstance, ID_STR_NSETCWD, 0U)))) { set_current_directory(executable_directory); } @@ -1770,7 +1770,7 @@ static int launch5j_main(const HINSTANCE hinstance, const wchar_t *const cmd_lin #endif // Now actually start the process! - if (!CreateProcessW(NULL, (LPWSTR)command_line, NULL, NULL, FALSE, 0U, NULL, executable_directory, &startup_info, &process_info)) + if (!CreateProcessW(NULL, (LPWSTR)command_line, NULL, NULL, FALSE, 0U, NULL, set_current_directory_enabled ? executable_directory : NULL, &startup_info, &process_info)) { const wchar_t *const error_text = describe_system_error(GetLastError()); if (error_text) diff --git a/src/resource.h b/src/resource.h index f00bbc4..893b372 100644 --- a/src/resource.h +++ b/src/resource.h @@ -38,9 +38,10 @@ #define ID_STR_MUTEXID 0x5 #define ID_STR_HEAPMIN 0x6 #define ID_STR_HEAPMAX 0x7 -#define ID_STR_JAVAMIN 0x8 -#define ID_STR_JAVAMAX 0x9 -#define ID_STR_BITNESS 0xA -#define ID_STR_JAVAURL 0xB +#define ID_STR_NSETCWD 0x8 +#define ID_STR_JAVAMIN 0x9 +#define ID_STR_JAVAMAX 0xA +#define ID_STR_BITNESS 0xB +#define ID_STR_JAVAURL 0xC #endif