diff --git a/Makefile b/Makefile index 83b1519..d0c49b4 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,7 @@ -CC=gcc -EXEEXT= +CC = gcc +EXEEXT = + +SEARCHPATH += src/plat/unix +OBJS += unixInit.o include common.mk diff --git a/Makefile.win32 b/Makefile.win32 index b7aae0e..a12a627 100644 --- a/Makefile.win32 +++ b/Makefile.win32 @@ -1,4 +1,7 @@ -EXEEXT=.exe -CC=x86_64-w64-mingw32-gcc +EXEEXT = .exe +CC = x86_64-w64-mingw32-gcc + +SEARCHPATH += src/plat/win32 +OBJS += win32Init.o include common.mk diff --git a/common.mk b/common.mk index 385a771..1c386c9 100644 --- a/common.mk +++ b/common.mk @@ -1,6 +1,6 @@ PROG = tbftss -TARGET=$(PROG)$(EXEEXT) +TARGET = $(PROG)$(EXEEXT) VERSION = 0.4 REVISION = $(shell date +"%y%m%d") diff --git a/src/plat/unix/unixInit.c b/src/plat/unix/unixInit.c new file mode 100644 index 0000000..3b712d0 --- /dev/null +++ b/src/plat/unix/unixInit.c @@ -0,0 +1,46 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "unixInit.h" + +void createSaveFolder(void) +{ + char *userHome; + char dir[MAX_FILENAME_LENGTH]; + + userHome = getenv("HOME"); + + if (!userHome) + { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir."); + return; + } + + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome); + + sprintf(dir, "%s/.local/share/tbftss", userHome); + if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST) + { + SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir); + return; + } + + STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH); +} diff --git a/src/plat/unix/unixInit.h b/src/plat/unix/unixInit.h new file mode 100644 index 0000000..08a6559 --- /dev/null +++ b/src/plat/unix/unixInit.h @@ -0,0 +1,31 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include +#include +#include +#include + +#include "SDL2/SDL.h" + +#include "../../defs.h" +#include "../../structs.h" + +extern App app; diff --git a/src/plat/win32/win32Init.c b/src/plat/win32/win32Init.c new file mode 100644 index 0000000..c2cfc91 --- /dev/null +++ b/src/plat/win32/win32Init.c @@ -0,0 +1,25 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "win32Init.h" + +void createSaveFolder(void) +{ +} diff --git a/src/plat/win32/win32Init.h b/src/plat/win32/win32Init.h new file mode 100644 index 0000000..c21a68c --- /dev/null +++ b/src/plat/win32/win32Init.h @@ -0,0 +1,19 @@ +/* +Copyright (C) 2015 Parallel Realities + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +See the GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ diff --git a/src/system/init.c b/src/system/init.c index b1aa5ea..8354416 100644 --- a/src/system/init.c +++ b/src/system/init.c @@ -20,14 +20,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "init.h" -#ifndef _WIN32 -#define UNIX 1 -#endif - - -#if UNIX -static void createSaveFolder(void); -#endif static void loadConfig(void); void saveConfig(void); static void initColor(SDL_Color *c, int r, int g, int b); @@ -39,9 +31,8 @@ void initSDL(void) /* do this here, so we don't destroy the save dir stored in app */ memset(&app, 0, sizeof(App)); - #if UNIX + /* done in src/plat/ */ createSaveFolder(); - #endif rendererFlags = SDL_RENDERER_ACCELERATED; windowFlags = 0; @@ -101,33 +92,6 @@ void initSDL(void) SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "Game scale factor: %.2f,%.2f\n", app.scaleX, app.scaleY); } -#ifdef UNIX -static void createSaveFolder(void) -{ - char *userHome; - char dir[MAX_FILENAME_LENGTH]; - - userHome = getenv("HOME"); - - if (!userHome) - { - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Unable to determine user save folder. Will save to current dir."); - return; - } - - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_INFO, "User home = %s", userHome); - - sprintf(dir, "%s/.local/share/tbftss", userHome); - if (mkdir(dir, S_IRWXU|S_IRWXG|S_IROTH|S_IXOTH) != 0 && errno != EEXIST) - { - SDL_LogMessage(SDL_LOG_CATEGORY_APPLICATION, SDL_LOG_PRIORITY_WARN, "Failed to create save dir '%s'. Will save to current dir.", dir); - return; - } - - STRNCPY(app.saveDir, dir, MAX_FILENAME_LENGTH); -} -#endif - void initGameSystem(void) { initColor(&colors.red, 255, 0, 0); diff --git a/src/system/init.h b/src/system/init.h index 5927a0c..95cfc1c 100644 --- a/src/system/init.h +++ b/src/system/init.h @@ -27,13 +27,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "../structs.h" #include "../json/cJSON.h" -#if UNIX - #include - #include - #include - #include -#endif - extern int fileExists(char *filename); extern char *readFile(char *filename); extern int writeFile(char *filename, char *data); @@ -62,6 +55,7 @@ extern void destroyGalacticMap(void); extern void destroyWidgets(void); extern void expireTexts(void); extern void initInput(void); +extern void createSaveFolder(void); extern App app; extern Colors colors;