Skip to content

Commit

Permalink
Fixed inability to launch Oolite properly from within the Windows com…
Browse files Browse the repository at this point in the history
…mand console.
  • Loading branch information
AnotherCommander committed Jun 28, 2023
1 parent 818ac32 commit d2a28b1
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 2 additions & 2 deletions GNUmakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 16 additions & 1 deletion src/SDL/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,34 @@ 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);
// Strip the exe filenameb (from last backslash onwards), leave just the path
char *probeString = strrchr(currentWorkingDir, '\\');
if (probeString) *probeString = '\0'; // currentWorkingDir now contains the path we need

// Prepend system PATH env variable with our own executable's path
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));\
SDL_putenv (envVarString);\
} 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
Expand Down

0 comments on commit d2a28b1

Please sign in to comment.