Skip to content

Commit d2a28b1

Browse files
author
AnotherCommander
committed
Fixed inability to launch Oolite properly from within the Windows command console.
1 parent 818ac32 commit d2a28b1

File tree

2 files changed

+18
-3
lines changed

2 files changed

+18
-3
lines changed

GNUmakefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ ifeq ($(GNUSTEP_HOST_OS),mingw32)
3131

3232
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
3333
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
34-
ADDITIONAL_CFLAGS = -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` -mtune=generic -DWINVER=0x0601
34+
ADDITIONAL_CFLAGS = -DWIN32 -DNEED_STRLCPY `sdl-config --cflags` -mtune=generic -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
3535
# note the vpath stuff above isn't working for me, so adding src/SDL and src/Core explicitly
36-
ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DWIN32 -DXP_WIN -Wno-import -std=gnu99 `sdl-config --cflags` -mtune=generic -DWINVER=0x0601
36+
ADDITIONAL_OBJCFLAGS = -DLOADSAVEGUI -DWIN32 -DXP_WIN -Wno-import -std=gnu99 `sdl-config --cflags` -mtune=generic -DWINVER=0x0601 -D_WIN32_WINNT=0x0601
3737
ifneq ($(HOST_ARCH),x86_64)
3838
ADDITIONAL_LDFLAGS += -Wl,--large-address-aware
3939
# else

src/SDL/main.m

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,19 +65,34 @@ int main(int argc, char *argv[])
6565
#define MAX_PATH_LEN 256
6666
char currentWorkingDir[MAX_PATH_LEN];
6767
char envVarString[2 * MAX_PATH_LEN];
68-
GetCurrentDirectory(MAX_PATH_LEN - 1, currentWorkingDir);
68+
DWORD bufferSize = MAX_PATH_LEN;
69+
70+
QueryFullProcessImageName(GetCurrentProcess(), 0, currentWorkingDir, &bufferSize);
71+
// Strip the exe filenameb (from last backslash onwards), leave just the path
72+
char *probeString = strrchr(currentWorkingDir, '\\');
73+
if (probeString) *probeString = '\0'; // currentWorkingDir now contains the path we need
74+
75+
// Prepend system PATH env variable with our own executable's path
76+
char finalPath[16 * MAX_PATH_LEN];
77+
char *systemPath = SDL_getenv("PATH");
78+
strcpy(finalPath, currentWorkingDir);
79+
strcat(finalPath, ";");
80+
strcat(finalPath, systemPath);
6981

7082
#define SETENVVAR(var, value) do {\
7183
sprintf(envVarString, "%s=%s", (var), (value));\
7284
SDL_putenv (envVarString);\
7385
} while (0);
7486

7587
SETENVVAR("GNUSTEP_PATH_HANDLING", "windows");
88+
SETENVVAR("PATH", finalPath);
7689
SETENVVAR("GNUSTEP_SYSTEM_ROOT", currentWorkingDir);
7790
SETENVVAR("GNUSTEP_LOCAL_ROOT", currentWorkingDir);
7891
SETENVVAR("GNUSTEP_NETWORK_ROOT", currentWorkingDir);
7992
SETENVVAR("GNUSTEP_USERS_ROOT", currentWorkingDir);
8093
SETENVVAR("HOMEPATH", currentWorkingDir);
94+
95+
SetCurrentDirectory(currentWorkingDir);
8196

8297
/* Windows amibtiously starts apps with the C library locale set to the
8398
system locale rather than the "C" locale as per spec. Fixing here so

0 commit comments

Comments
 (0)