From: Holger Schemel Date: Sun, 30 Jul 2006 20:11:57 +0000 (+0200) Subject: rnd-20060730-2-src X-Git-Tag: 3.2.1^2~29 X-Git-Url: https://git.artsoft.org/?a=commitdiff_plain;h=8e17da8cdff134bfa0e766a50f408a3c06428f54;p=rocksndiamonds.git rnd-20060730-2-src * changed user data directory for Mac OS X from Unix style to new place --- diff --git a/ChangeLog b/ChangeLog index e9752cd3..d90c4d41 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2006-07-30 * improved down-scaling of images for better level and preview graphics + * changed user data directory for Mac OS X from Unix style to new place 2006-07-26 * improved level number selection in main menu and player selection in diff --git a/src/conftime.h b/src/conftime.h index fcaa9e27..529c2b1d 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "[2006-07-30 12:51]" +#define COMPILE_DATE_STRING "[2006-07-30 22:09]" diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 9125a4e1..ea5ed01a 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -450,38 +450,6 @@ char *getRealName() return real_name; } -char *getHomeDir() -{ - static char *dir = NULL; - -#if defined(PLATFORM_WIN32) - if (dir == NULL) - { - dir = checked_malloc(MAX_PATH + 1); - - if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, dir))) - strcpy(dir, "."); - } -#elif defined(PLATFORM_UNIX) - if (dir == NULL) - { - if ((dir = getenv("HOME")) == NULL) - { - struct passwd *pwd; - - if ((pwd = getpwuid(getuid())) != NULL) - dir = getStringCopy(pwd->pw_dir); - else - dir = "."; - } - } -#else - dir = "."; -#endif - - return dir; -} - /* ------------------------------------------------------------------------- */ /* path manipulation functions */ @@ -2799,7 +2767,7 @@ void FreeCustomArtworkLists(struct ArtworkListInfo *artwork_info) char *getErrorFilename(char *basename) { - return getPath2(getUserDataDir(), basename); + return getPath2(getUserGameDataDir(), basename); } void openErrorFile() diff --git a/src/libgame/misc.h b/src/libgame/misc.h index 9fb4f65b..7c84c94b 100644 --- a/src/libgame/misc.h +++ b/src/libgame/misc.h @@ -93,7 +93,6 @@ unsigned int get_random_number(int, int); char *getLoginName(void); char *getRealName(void); -char *getHomeDir(void); char *getBasePath(char *); char *getBaseName(char *); diff --git a/src/libgame/setup.c b/src/libgame/setup.c index a004bc82..c7cc92f0 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -17,6 +17,13 @@ #include #include +#include "platform.h" + +#if !defined(PLATFORM_WIN32) +#include +#include +#endif + #include "setup.h" #include "joystick.h" #include "text.h" @@ -100,7 +107,7 @@ static char *getLevelClassDescription(TreeInfo *ldi) static char *getUserLevelDir(char *level_subdir) { static char *userlevel_dir = NULL; - char *data_dir = getUserDataDir(); + char *data_dir = getUserGameDataDir(); char *userlevel_subdir = LEVELS_DIRECTORY; checked_free(userlevel_dir); @@ -132,7 +139,7 @@ static char *getScoreDir(char *level_subdir) static char *getLevelSetupDir(char *level_subdir) { static char *levelsetup_dir = NULL; - char *data_dir = getUserDataDir(); + char *data_dir = getUserGameDataDir(); char *levelsetup_subdir = LEVELSETUP_DIRECTORY; checked_free(levelsetup_dir); @@ -168,7 +175,7 @@ char *getCurrentLevelDir() static char *getTapeDir(char *level_subdir) { static char *tape_dir = NULL; - char *data_dir = getUserDataDir(); + char *data_dir = getUserGameDataDir(); char *tape_subdir = TAPES_DIRECTORY; checked_free(tape_dir); @@ -258,7 +265,7 @@ static char *getUserGraphicsDir() static char *usergraphics_dir = NULL; if (usergraphics_dir == NULL) - usergraphics_dir = getPath2(getUserDataDir(), GRAPHICS_DIRECTORY); + usergraphics_dir = getPath2(getUserGameDataDir(), GRAPHICS_DIRECTORY); return usergraphics_dir; } @@ -268,7 +275,7 @@ static char *getUserSoundsDir() static char *usersounds_dir = NULL; if (usersounds_dir == NULL) - usersounds_dir = getPath2(getUserDataDir(), SOUNDS_DIRECTORY); + usersounds_dir = getPath2(getUserGameDataDir(), SOUNDS_DIRECTORY); return usersounds_dir; } @@ -278,7 +285,7 @@ static char *getUserMusicDir() static char *usermusic_dir = NULL; if (usermusic_dir == NULL) - usermusic_dir = getPath2(getUserDataDir(), MUSIC_DIRECTORY); + usermusic_dir = getPath2(getUserGameDataDir(), MUSIC_DIRECTORY); return usermusic_dir; } @@ -764,7 +771,7 @@ char *getCustomMusicDirectory(void) void InitTapeDirectory(char *level_subdir) { - createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); + createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); createDirectory(getTapeDir(NULL), "main tape", PERMS_PRIVATE); createDirectory(getTapeDir(level_subdir), "level tape", PERMS_PRIVATE); } @@ -782,7 +789,7 @@ void InitUserLevelDirectory(char *level_subdir) { if (!fileExists(getUserLevelDir(level_subdir))) { - createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); + createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); createDirectory(getUserLevelDir(NULL), "main user level", PERMS_PRIVATE); createDirectory(getUserLevelDir(level_subdir), "user level",PERMS_PRIVATE); @@ -792,7 +799,7 @@ void InitUserLevelDirectory(char *level_subdir) void InitLevelSetupDirectory(char *level_subdir) { - createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); + createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); createDirectory(getLevelSetupDir(NULL), "main level setup", PERMS_PRIVATE); createDirectory(getLevelSetupDir(level_subdir), "level setup",PERMS_PRIVATE); } @@ -1108,14 +1115,36 @@ void sortTreeInfo(TreeInfo **node_first, #define FILE_PERMS_PRIVATE (MODE_R_ALL | MODE_W_PRIVATE) #define FILE_PERMS_PUBLIC (MODE_R_ALL | MODE_W_PUBLIC) -char *getUserDataDir(void) +char *getHomeDir() { - static char *userdata_dir = NULL; + static char *dir = NULL; + +#if defined(PLATFORM_WIN32) + if (dir == NULL) + { + dir = checked_malloc(MAX_PATH + 1); - if (userdata_dir == NULL) - userdata_dir = getPath2(getHomeDir(), program.userdata_directory); + if (!SUCCEEDED(SHGetFolderPath(NULL, CSIDL_PERSONAL, NULL, 0, dir))) + strcpy(dir, "."); + } +#elif defined(PLATFORM_UNIX) + if (dir == NULL) + { + if ((dir = getenv("HOME")) == NULL) + { + struct passwd *pwd; - return userdata_dir; + if ((pwd = getpwuid(getuid())) != NULL) + dir = getStringCopy(pwd->pw_dir); + else + dir = "."; + } + } +#else + dir = "."; +#endif + + return dir; } char *getCommonDataDir(void) @@ -1141,9 +1170,58 @@ char *getCommonDataDir(void) return common_data_dir; } +char *getPersonalDataDir(void) +{ + static char *personal_data_dir = NULL; + +#if defined(PLATFORM_MACOSX) + if (personal_data_dir == NULL) + personal_data_dir = getPath2(getHomeDir(), "Documents"); +#else + if (personal_data_dir == NULL) + personal_data_dir = getHomeDir(); +#endif + + return personal_data_dir; +} + +char *getUserGameDataDir(void) +{ + if (program.userdata_path == NULL) + program.userdata_path = getPath2(getPersonalDataDir(), + program.userdata_subdir); + + return program.userdata_path; +} + +void fixUserGameDataDir() +{ +#if defined(PLATFORM_MACOSX) + char *userdata_dir_old = getPath2(getHomeDir(), program.userdata_subdir_unix); + char *userdata_dir_new = getUserGameDataDir(); + + /* convert old Unix style game data directory to Mac OS X style, if needed */ + if (fileExists(userdata_dir_old) && !fileExists(userdata_dir_new)) + { + if (rename(userdata_dir_old, userdata_dir_new) != 0) + { + Error(ERR_WARN, "cannot move game data directory '%s' to '%s'", + userdata_dir_old, userdata_dir_new); + + /* continue using Unix style data directory -- this should not happen */ + program.userdata_path = getPath2(getPersonalDataDir(), + program.userdata_subdir_unix); + } + } + + free(userdata_dir_old); + free(userdata_dir_new); +#endif +} + char *getSetupDir() { - return getUserDataDir(); + return getUserGameDataDir(); } static mode_t posix_umask(mode_t mask) @@ -1183,7 +1261,7 @@ void createDirectory(char *dir, char *text, int permission_class) void InitUserDataDirectory() { - createDirectory(getUserDataDir(), "user data", PERMS_PRIVATE); + createDirectory(getUserGameDataDir(), "user data", PERMS_PRIVATE); } void SetFilePermissions(char *filename, int permission_class) diff --git a/src/libgame/setup.h b/src/libgame/setup.h index ab465276..87cb4cba 100644 --- a/src/libgame/setup.h +++ b/src/libgame/setup.h @@ -248,11 +248,15 @@ void dumpTreeInfo(TreeInfo *, int); void sortTreeInfo(TreeInfo **, int (*compare_function)(const void *, const void *)); -char *getUserDataDir(void); +char *getHomeDir(void); char *getCommonDataDir(void); +char *getPersonalDataDir(void); +char *getUserGameDataDir(void); char *getSetupDir(void); char *getCurrentLevelDir(void); +void fixUserGameDataDir(void); + void createDirectory(char *, char *, int); void InitUserDataDirectory(void); void SetFilePermissions(char *, int); diff --git a/src/libgame/system.c b/src/libgame/system.c index 4f8ef0fb..551f3824 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -69,8 +69,8 @@ int FrameCounter = 0; /* ========================================================================= */ void InitProgramInfo(char *argv0, - char *userdata_directory, char *program_title, - char *window_title, char *icon_title, + char *userdata_subdir, char *userdata_subdir_unix, + char *program_title, char *window_title, char *icon_title, char *x11_icon_filename, char *x11_iconmask_filename, char *msdos_cursor_filename, char *cookie_prefix, char *filename_prefix, @@ -79,10 +79,14 @@ void InitProgramInfo(char *argv0, program.command_basepath = getBasePath(argv0); program.command_basename = getBaseName(argv0); - program.userdata_directory = userdata_directory; + program.userdata_subdir = userdata_subdir; + program.userdata_subdir_unix = userdata_subdir_unix; + program.userdata_path = getUserGameDataDir(); + program.program_title = program_title; program.window_title = window_title; program.icon_title = icon_title; + program.x11_icon_filename = x11_icon_filename; program.x11_iconmask_filename = x11_iconmask_filename; program.msdos_cursor_filename = msdos_cursor_filename; @@ -118,7 +122,11 @@ void InitPlatformDependentStuff(void) _fmode = O_BINARY; #endif -#if defined(PLATFORM_WIN32) || defined(PLATFORM_MSDOS) +#if defined(PLATFORM_MACOSX) + fixUserGameDataDir(); +#endif + +#if !defined(PLATFORM_UNIX) || defined(PLATFORM_MACOSX) openErrorFile(); #endif diff --git a/src/libgame/system.h b/src/libgame/system.h index c175d59f..74917b21 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -526,7 +526,10 @@ struct ProgramInfo { char *command_basepath; /* directory that contains the program */ char *command_basename; /* base filename of the program binary */ - char *userdata_directory; /* personal user data directory */ + + char *userdata_subdir; /* personal user game data directory */ + char *userdata_subdir_unix; /* personal user game data directory (Unix) */ + char *userdata_path; /* resulting full path to game data directory */ char *program_title; char *window_title; @@ -990,7 +993,7 @@ extern int FrameCounter; /* function definitions */ void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, - char *, char *, char *, int); + char *, char *, char *, char *, int); void InitExitFunction(void (*exit_function)(int)); void InitPlatformDependentStuff(void); diff --git a/src/main.c b/src/main.c index 4506c8e3..a663bbcf 100644 --- a/src/main.c +++ b/src/main.c @@ -4688,7 +4688,7 @@ static void print_usage() int main(int argc, char *argv[]) { - InitProgramInfo(argv[0], USERDATA_DIRECTORY, + InitProgramInfo(argv[0], USERDATA_DIRECTORY, USERDATA_DIRECTORY_UNIX, PROGRAM_TITLE_STRING, getWindowTitleString(), ICON_TITLE_STRING, X11_ICON_FILENAME, X11_ICONMASK_FILENAME, MSDOS_POINTER_FILENAME, diff --git a/src/main.h b/src/main.h index 354c023b..b7ad953f 100644 --- a/src/main.h +++ b/src/main.h @@ -1725,12 +1725,19 @@ #define COOKIE_PREFIX "ROCKSNDIAMONDS" #define FILENAME_PREFIX "Rocks" -#if defined(PLATFORM_UNIX) -#define USERDATA_DIRECTORY ".rocksndiamonds" -#elif defined(PLATFORM_WIN32) -#define USERDATA_DIRECTORY PROGRAM_TITLE_STRING +#define USERDATA_DIRECTORY_WIN32 PROGRAM_TITLE_STRING +#define USERDATA_DIRECTORY_MACOSX PROGRAM_TITLE_STRING +#define USERDATA_DIRECTORY_UNIX ".rocksndiamonds" +#define USERDATA_DIRECTORY_DOS "userdata" + +#if defined(PLATFORM_WIN32) +#define USERDATA_DIRECTORY USERDATA_DIRECTORY_WIN32 +#elif defined(PLATFORM_MACOSX) +#define USERDATA_DIRECTORY USERDATA_DIRECTORY_MACOSX +#elif defined(PLATFORM_UNIX) +#define USERDATA_DIRECTORY USERDATA_DIRECTORY_UNIX #else -#define USERDATA_DIRECTORY "userdata" +#define USERDATA_DIRECTORY USERDATA_DIRECTORY_DOS #endif #define X11_ICON_FILENAME "rocks_icon.xbm"