Commander_X wrote: ↑Tue Jun 27, 2023 11:05 pm
EDIT: It also creates GNUstep and Logs folders in the current directory.
Hmm, this is the behaviour before the attempted fix. Are you sure you are using the file I posted?
It seems the call
Code: Select all
GetCurrentDirectory(MAX_PATH_LEN - 1, currentWorkingDir);
in
SDL/main.m to prepare the
GNUSTEP_* environment variables is the culprit. It should be replaced with retrieving the folder where the exe file resides.
Correct and this is what the posted exe was trying to do. It seems though that I indeed messed up something somewhere, because when I run my posted exe on my Win10 work computer, it failed to start as well. I think I may have posted an executable without the final fix embedded, so let's try this one more time, if that's OK with you. Here is an executable that works for me:
https://we.tl/t-GQIWWUGoT1
And just to be on the safe side, here is the source code diff showing what this exe is exactly supposed to do. It does 3 things: 1. Gets the directory oolite.exe is being run from, 2. sets this directory as the very first element of the PATH environment variable and 3. changes internally to that folder to ensure that GNUstep can see the expected and correct file/folder structure. Here is the patch if you want to build it yourself:
Code: Select all
diff --git a/GNUmakefile b/GNUmakefile
index e41d1c32..42316f54 100755
--- a/GNUmakefile
+++ b/GNUmakefile
@@ -31,9 +31,9 @@ ifeq ($(GNUSTEP_HOST_OS),mingw32)
ADDITIONAL_INCLUDE_DIRS = -I$(WIN_DEPS_DIR)/include -I$(JS_INC_DIR) -Isrc/SDL -Isrc/Core -Isrc/BSDCompat -Isrc/Core/Scripting -Isrc/Core/Materials -Isrc/Core/Entities -Isrc/Core/OXPVerifier -Isrc/Core/Debug -Isrc/Core/Tables -Isrc/Core/MiniZip
ADDITIONAL_OBJC_LIBS = -L$(WIN_DEPS_DIR)/lib -lglu32 -lopengl32 -lopenal32.dll -lpng14.dll -lmingw32 -lSDLmain -lSDL -lvorbisfile.dll -lvorbis.dll -lz -lgnustep-base -l$(JS_IMPORT_LIBRARY) -lwinmm -mwindows
- ADDITIONAL_CFLAGS = -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` -mtune=generic -DWINVER=0x0601
+ ADDITIONAL_CFLAGS = -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` -mtune=generic -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
# note the vpath stuff above isn't working for me, so adding src/SDL and src/Core explicitly
- ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DWIN32 -DXP_WIN -Wno-import -std=gnu99 `sdl-config --cflags` -mtune=generic -DWINVER=0x0601
+ ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DWIN32 -DXP_WIN -Wno-import -std=gnu99 `sdl-config --cflags` -mtune=generic -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
ifneq ($(HOST_ARCH),x86_64)
ADDITIONAL_LDFLAGS += -Wl,--large-address-aware
# else
diff --git a/src/SDL/main.m b/src/SDL/main.m
index ca066a52..3b8f53e0 100644
--- a/src/SDL/main.m
+++ b/src/SDL/main.m
@@ -65,7 +65,18 @@ int main(int argc, char *argv[])
#define MAX_PATH_LEN 256
char currentWorkingDir[MAX_PATH_LEN];
char envVarString[2 * MAX_PATH_LEN];
- GetCurrentDirectory(MAX_PATH_LEN - 1, currentWorkingDir);
+ DWORD bufferSize = MAX_PATH_LEN;
+ QueryFullProcessImageName(GetCurrentProcess(), 0, currentWorkingDir, &bufferSize);
+ char *probeString = strrchr(currentWorkingDir, '\\');
+ if (probeString) *probeString = '\0';
+
+ // Prepend the system's PATH env vraiable with our own executable's path
+ // this way we can once again launch from the command line and batch files like we used to
+ char finalPath[16 * MAX_PATH_LEN];
+ char *systemPath = SDL_getenv("PATH");
+ strcpy(finalPath, currentWorkingDir);
+ strcat(finalPath, ";");
+ strcat(finalPath, systemPath);
#define SETENVVAR(var, value) do {\
sprintf(envVarString, "%s=%s", (var), (value));\
@@ -73,11 +84,14 @@ int main(int argc, char *argv[])
} while (0);
SETENVVAR("GNUSTEP_PATH_HANDLING", "windows");
+ SETENVVAR("PATH", finalPath);
SETENVVAR("GNUSTEP_SYSTEM_ROOT", currentWorkingDir);
SETENVVAR("GNUSTEP_LOCAL_ROOT", currentWorkingDir);
SETENVVAR("GNUSTEP_NETWORK_ROOT", currentWorkingDir);
SETENVVAR("GNUSTEP_USERS_ROOT", currentWorkingDir);
SETENVVAR("HOMEPATH", currentWorkingDir);
+
+ SetCurrentDirectory(currentWorkingDir);
/* Windows amibtiously starts apps with the C library locale set to the
system locale rather than the "C" locale as per spec. Fixing here so
Hope it works this time.