local appdata for standalone version
This commit is contained in:
parent
531077d703
commit
30f089aee2
|
@ -26,7 +26,7 @@ LUA_LFLAGS=$(shell pkg-config --libs lua5.1)
|
|||
SDL_CFLAGS=$(shell sdl-config --cflags)
|
||||
SDL_LFLAGS=$(shell sdl-config --libs) -lSDL_ttf -lSDL_mixer -lSDL_image
|
||||
|
||||
CFLAGS += -g -Wall -D_HAVE_ICONV -Dunix -D_USE_UNPACK
|
||||
CFLAGS += -g -Wall -D_HAVE_ICONV -Dunix -D_USE_UNPACK -D_LOCAL_APPDATA
|
||||
|
||||
INSTALLD=echo "Do not install standalone version!"
|
||||
INSTALLB=echo "Do not install standalone version!"
|
||||
|
|
|
@ -21,7 +21,7 @@ LUA_LFLAGS=-llua5.1 -L../windows/
|
|||
SDL_CFLAGS=-I../windows/SDL
|
||||
SDL_LFLAGS=-lSDL -lSDLmain -lSDL_ttf -lSDL_mixer -lSDL_image -L../windows/SDL
|
||||
|
||||
CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE
|
||||
CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA
|
||||
LDFLAGS += -liconv
|
||||
|
||||
CC=i486-mingw32-gcc
|
||||
|
|
|
@ -19,7 +19,7 @@ LUA_LFLAGS=-llua5.1
|
|||
SDL_CFLAGS=-IC:\MinGW\include\SDL
|
||||
SDL_LFLAGS=-lSDL -lSDLmain -lSDL_ttf -lSDL_mixer -lSDL_image
|
||||
|
||||
CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE
|
||||
CFLAGS += -Wall -mwindows -D_HAVE_ICONV -D_USE_UNPACK -D_USE_BROWSE -D_LOCAL_APPDATA
|
||||
LDFLAGS += -liconv
|
||||
|
||||
CC=gcc
|
||||
|
|
|
@ -18,7 +18,7 @@ extern int window_sw;
|
|||
extern int nopause_sw;
|
||||
extern int game_own_theme; /* current game has own theme */
|
||||
extern char *err_msg; /* last error message */
|
||||
extern char game_cwd[]; /* current game cwd */
|
||||
extern char game_cwd[PATH_MAX]; /* current game cwd */
|
||||
extern char *curgame_dir;
|
||||
|
||||
extern char *game_local_games_path(int cr);
|
||||
|
|
|
@ -53,6 +53,7 @@ int main(int argc, char **argv)
|
|||
gtk_init(&argc, &argv);
|
||||
#endif
|
||||
putenv("SDL_MOUSE_RELATIVE=0"); /* test this! */
|
||||
getcwd(game_cwd, sizeof(game_cwd));
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i],"-alsa"))
|
||||
alsa_sw = 1;
|
||||
|
|
|
@ -145,34 +145,53 @@ char *open_file_dialog(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
char *game_local_games_path(int cr)
|
||||
char *appdir(void)
|
||||
{
|
||||
static char dir[PATH_MAX];
|
||||
struct passwd *pw;
|
||||
#ifdef _LOCAL_APPDATA
|
||||
strcpy(dir, game_cwd);
|
||||
strcat(dir, "/appdata");
|
||||
if (!access(dir, W_OK))
|
||||
return dir;
|
||||
#endif
|
||||
pw = getpwuid(getuid());
|
||||
if (!pw)
|
||||
return NULL;
|
||||
snprintf(local_games_path, sizeof(local_games_path) - 1 , "%s/.instead", pw->pw_dir);
|
||||
if (mkdir(local_games_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
snprintf(dir, sizeof(dir) - 1 , "%s/.instead", pw->pw_dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
char *game_local_games_path(int cr)
|
||||
{
|
||||
char *app = appdir();
|
||||
if (!app)
|
||||
return NULL;
|
||||
strcpy(local_games_path, app);
|
||||
if (cr) {
|
||||
if (mkdir(local_games_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
}
|
||||
strcat(local_games_path,"/games");
|
||||
if (mkdir(local_games_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
if (cr) {
|
||||
if (mkdir(local_games_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
}
|
||||
return local_games_path;
|
||||
}
|
||||
|
||||
char *game_local_themes_path(void)
|
||||
{
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
if (!pw)
|
||||
char *app = appdir();
|
||||
if (!app)
|
||||
return NULL;
|
||||
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/.instead/themes/", pw->pw_dir);
|
||||
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/themes", app);
|
||||
return local_themes_path;
|
||||
|
||||
}
|
||||
|
||||
char *game_cfg_path(void)
|
||||
{
|
||||
char *app = appdir();
|
||||
struct passwd *pw;
|
||||
pw = getpwuid(getuid());
|
||||
if (!pw)
|
||||
|
@ -181,16 +200,19 @@ char *game_cfg_path(void)
|
|||
if (!access(save_path, R_OK))
|
||||
return save_path;
|
||||
/* no at home? Try in dir */
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/.instead/", pw->pw_dir);
|
||||
if (mkdir(save_path, S_IRWXU) && errno != EEXIST)
|
||||
if (app)
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/", app);
|
||||
if (!app || (mkdir(save_path, S_IRWXU) && errno != EEXIST))
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/.insteadrc", pw->pw_dir); /* fallback to home */
|
||||
else
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/.instead/insteadrc", pw->pw_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/insteadrc", app);
|
||||
return save_path;
|
||||
}
|
||||
|
||||
char *game_save_path(int cr, int nr)
|
||||
{
|
||||
struct passwd *pw;
|
||||
char *app = appdir();
|
||||
|
||||
if (!curgame_dir)
|
||||
return NULL;
|
||||
|
||||
|
@ -200,24 +222,22 @@ char *game_save_path(int cr, int nr)
|
|||
else
|
||||
snprintf(save_path, sizeof(save_path) - 1, "saves/autosave");
|
||||
return save_path;
|
||||
}
|
||||
|
||||
pw = getpwuid(getuid());
|
||||
if (!pw)
|
||||
}
|
||||
if (!app)
|
||||
return NULL;
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/.instead/", pw->pw_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/", app);
|
||||
if (cr && mkdir(save_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/.instead/saves", pw->pw_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/saves", app);
|
||||
if (cr && mkdir(save_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/.instead/saves/%s/", pw->pw_dir, curgame_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s/", app, curgame_dir);
|
||||
if (cr && mkdir(save_path, S_IRWXU) && errno != EEXIST)
|
||||
return NULL;
|
||||
if (nr)
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/.instead/saves/%s/save%d", pw->pw_dir, curgame_dir, nr);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s/save%d", app, curgame_dir, nr);
|
||||
else
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/.instead/saves/%s/autosave", pw->pw_dir, curgame_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s/autosave", app, curgame_dir);
|
||||
return save_path;
|
||||
}
|
||||
|
||||
|
|
|
@ -110,18 +110,25 @@ char *game_tmp_path(void)
|
|||
|
||||
char *game_local_games_path(int cr)
|
||||
{
|
||||
snprintf(local_games_path, sizeof(local_games_path) - 1 , "%s/instead", app_dir());
|
||||
if (mkdir(local_games_path) && errno != EEXIST)
|
||||
char *app = app_dir();
|
||||
if (!app)
|
||||
return NULL;
|
||||
snprintf(local_games_path, sizeof(local_games_path) - 1 , "%s/", app);
|
||||
if (cr) {
|
||||
if (mkdir(local_games_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
}
|
||||
strcat(local_games_path,"/games");
|
||||
if (mkdir(local_games_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
if (cr) {
|
||||
if (mkdir(local_games_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
}
|
||||
return local_games_path;
|
||||
}
|
||||
|
||||
char *game_local_themes_path(void)
|
||||
{
|
||||
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/instead/themes/", app_dir());
|
||||
snprintf(local_themes_path, sizeof(local_themes_path) - 1 , "%s/themes", app_dir());
|
||||
return local_themes_path;
|
||||
}
|
||||
#if 0
|
||||
|
@ -140,32 +147,46 @@ char *home_dir( void )
|
|||
char *app_dir( void )
|
||||
{
|
||||
static char appdir[PATH_MAX]="";
|
||||
#ifdef _LOCAL_APPDATA
|
||||
strcpy(appdir, game_cwd);
|
||||
strcat(appdir, "/appdata");
|
||||
if (!access(appdir, W_OK))
|
||||
return appdir;
|
||||
#endif
|
||||
|
||||
SHGetFolderPath( NULL,
|
||||
CSIDL_FLAG_CREATE | CSIDL_LOCAL_APPDATA,
|
||||
NULL,
|
||||
0,
|
||||
(LPTSTR)appdir );
|
||||
unix_path(appdir);
|
||||
strcat(appdir, "/instead");
|
||||
return appdir;
|
||||
}
|
||||
|
||||
char *game_cfg_path( void )
|
||||
{
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s\\insteadrc", app_dir());
|
||||
char *p = app_dir();
|
||||
if (!p)
|
||||
return NULL;
|
||||
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%src", p); /* appdir/insteadrc ;) */
|
||||
if (!access(save_path, R_OK))
|
||||
return save_path;
|
||||
return save_path;
|
||||
/* no at home? Try in dir */
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s\\instead", app_dir());
|
||||
if (mkdir(save_path) && errno != EEXIST)
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s\\insteadrc", app_dir()); /* fallback to home */
|
||||
else
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s\\instead\\insteadrc", app_dir());
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s", p);
|
||||
if (mkdir(save_path) && errno != EEXIST) {
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%src", p); /* appdir/insteadrc ;) */
|
||||
return save_path;
|
||||
}
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/insteadrc", p);
|
||||
return save_path;
|
||||
}
|
||||
|
||||
char *game_save_path( int cr, int nr )
|
||||
{
|
||||
char appdir[PATH_MAX];
|
||||
char *p = app_dir();
|
||||
|
||||
if (!curgame_dir)
|
||||
return NULL;
|
||||
|
@ -177,22 +198,27 @@ char *game_save_path( int cr, int nr )
|
|||
snprintf(save_path, sizeof(save_path) - 1, "saves/autosave");
|
||||
return save_path;
|
||||
}
|
||||
if (!p)
|
||||
return NULL;
|
||||
strcpy( appdir, p );
|
||||
|
||||
strcpy( appdir, app_dir() );
|
||||
if (cr && mkdir(save_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/saves", appdir);
|
||||
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/instead", appdir);
|
||||
if (cr && mkdir(save_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
snprintf(save_path, sizeof(save_path) - 1 , "%s/instead/saves", appdir);
|
||||
if (cr && mkdir(save_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/instead/saves/%s", appdir, curgame_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s", appdir, curgame_dir);
|
||||
|
||||
if (cr && mkdir(save_path) && errno != EEXIST)
|
||||
return NULL;
|
||||
|
||||
if (nr)
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/instead/saves/%s/save%d", appdir, curgame_dir, nr);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s/save%d", appdir, curgame_dir, nr);
|
||||
else
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/instead/saves/%s/autosave", appdir, curgame_dir);
|
||||
snprintf(save_path, sizeof(save_path) - 1, "%s/saves/%s/autosave", appdir, curgame_dir);
|
||||
|
||||
return save_path;
|
||||
}
|
||||
|
||||
|
|
Reference in a new issue