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); }