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.
This commit is contained in:
parent
fd6949120e
commit
e981acded2
|
@ -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])
|
||||
|
||||
|
|
|
@ -18,11 +18,14 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|||
*/
|
||||
|
||||
#include <errno.h>
|
||||
#include <pwd.h>
|
||||
#include <stdio.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#ifndef WINDOWS
|
||||
#include <pwd.h>
|
||||
#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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue