From e981acded2a94d202ffa79c8f4c86f4c77b1b6d3 Mon Sep 17 00:00:00 2001 From: onpon4 Date: Wed, 1 Feb 2017 16:10:48 -0500 Subject: [PATCH] Made the minimal changes to allow Starfighter to be compiled on Windows. It's not perfect, but I honestly just can't be arsed to figure out how to use the Windows API to do the same thing that pwd.h does. At the very least, Starfighter can now be successfully compiled for Windows with MinGW simply by defining the "SF_WINDOWS" environment variable to 1 (or any other non-empty value). The only downside is that it uses the current working directory to decide where .config/starfighter should go, meaning it can't be installed into restricted directories like Program Files. --- configure.ac | 4 ++++ src/engine.cpp | 24 ++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 8ca82cc..b4d7c1e 100644 --- a/configure.ac +++ b/configure.ac @@ -31,12 +31,16 @@ PKG_CHECK_EXISTS([SDL2_mixer], [ AC_ARG_VAR([SF_SCREEN_WIDTH], [The width of the game window in pixels]) AC_ARG_VAR([SF_SCREEN_HEIGHT], [The height of the game window in pixels]) +AC_ARG_VAR([SF_WINDOWS], [Set to "1" to indicate that the build is for Windows]) AS_IF([test -n "$SF_SCREEN_WIDTH"], [ STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DSCREEN_WIDTH=$SF_SCREEN_WIDTH" ]) AS_IF([test -n "$SF_SCREEN_HEIGHT"], [ STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DSCREEN_HEIGHT=$SF_SCREEN_HEIGHT" ]) +AS_IF([test -n "$SF_WINDOWS"], [ + STARFIGHTER_CFLAGS="$STARFIGHTER_CFLAGS -DWINDOWS" +]) AC_SUBST([STARFIGHTER_CFLAGS]) diff --git a/src/engine.cpp b/src/engine.cpp index d83a6bf..711d4ff 100644 --- a/src/engine.cpp +++ b/src/engine.cpp @@ -18,11 +18,14 @@ along with this program. If not, see . */ #include -#include #include #include #include +#ifndef WINDOWS +#include +#endif + #include "SDL.h" #ifndef NOSOUND @@ -157,20 +160,37 @@ This gets the user's home directory, then creates the config directory. void engine_setupConfigDirectory() { const char *userHome; + char dir[PATH_MAX]; +#ifdef WINDOWS + // XXX: This is a bad design, but I just can't be bothered to learn + // the Windows API so I can do this properly. If anyone wants to + // make this point to the proper directory, be my guest! + userHome = "."; +#else if ((userHome = getenv("HOME")) == NULL) userHome = getpwuid(getuid())->pw_dir; +#endif - char dir[PATH_MAX]; strcpy(dir, ""); sprintf(dir, "%s/.config", userHome); + +#ifdef WINDOWS + if ((mkdir(dir) != 0) && (errno != EEXIST)) + engine_showError(2, dir); + + sprintf(dir, "%s/.config/starfighter", userHome); + if ((mkdir(dir) != 0) && (errno != EEXIST)) + engine_showError(2, dir); +#else if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) engine_showError(2, dir); sprintf(dir, "%s/.config/starfighter", userHome); if ((mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0) && (errno != EEXIST)) engine_showError(2, dir); +#endif sprintf(engine.configDirectory, "%s/.config/starfighter/", userHome); }