static char *getScoreDir(char *level_subdir)
{
static char *score_dir = NULL;
- char *data_dir = options.rw_base_directory;
+ char *data_dir = getCommonDataDir();
char *score_subdir = SCORES_DIRECTORY;
if (score_dir)
{
static char *msdos_filename = NULL;
- if (filename != NULL)
- free(filename);
+ if (msdos_filename != NULL)
+ free(msdos_filename);
- filename = getStringCopy(basename_corrected);
- strncpy(&filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1);
+ msdos_filename = getStringCopy(basename_corrected);
+ strncpy(&msdos_filename[8], &basename[strlen(basename) - 1+3], 1+3 + 1);
}
}
#endif
return basename_corrected;
}
-static boolean fileExists(char *filename)
-{
-#if 0
- printf("checking file '%s'\n", filename);
-#endif
-
- return (access(filename, F_OK) == 0);
-}
-
char *getCustomImageFilename(char *basename)
{
static char *filename = NULL;
void InitScoreDirectory(char *level_subdir)
{
+ createDirectory(getCommonDataDir(), "common data", PERMS_PUBLIC);
createDirectory(getScoreDir(NULL), "main score", PERMS_PUBLIC);
createDirectory(getScoreDir(level_subdir), "level score", PERMS_PUBLIC);
}
{
static char *userdata_dir = NULL;
- if (!userdata_dir)
+ if (userdata_dir == NULL)
+ userdata_dir = getPath2(getHomeDir(), program.userdata_directory);
+
+ return userdata_dir;
+}
+
+char *getCommonDataDir(void)
+{
+ static char *common_data_dir = NULL;
+
+#if defined(PLATFORM_WIN32)
+ if (common_data_dir == NULL)
{
- char *home_dir = getHomeDir();
- char *data_dir = program.userdata_directory;
+ char *dir = checked_malloc(MAX_PATH + 1);
- userdata_dir = getPath2(home_dir, data_dir);
+ if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_COMMON_DOCUMENTS, NULL, 0, dir))
+ && strcmp(dir, "") != 0) /* empty for Windows 95/98 */
+ common_data_dir = getPath2(dir, program.userdata_directory);
+ else
+ common_data_dir = options.rw_base_directory;
}
+#else
+ if (common_data_dir == NULL)
+ common_data_dir = options.rw_base_directory;
+#endif
- return userdata_dir;
+ return common_data_dir;
}
char *getSetupDir()
void freeSetupFileList(struct SetupFileList *setup_file_list)
{
- if (!setup_file_list)
+ if (setup_file_list == NULL)
return;
if (setup_file_list->token)
free(setup_file_list);
}
-static struct SetupFileList *newSetupFileList(char *token, char *value)
+struct SetupFileList *newSetupFileList(char *token, char *value)
{
struct SetupFileList *new = checked_malloc(sizeof(struct SetupFileList));
- new->token = checked_malloc(strlen(token) + 1);
- strcpy(new->token, token);
-
- new->value = checked_malloc(strlen(value) + 1);
- strcpy(new->value, value);
+ new->token = getStringCopy(token);
+ new->value = getStringCopy(value);
new->next = NULL;
char *getTokenValue(struct SetupFileList *setup_file_list, char *token)
{
- if (!setup_file_list)
+ if (setup_file_list == NULL)
return NULL;
if (strcmp(setup_file_list->token, token) == 0)
return getTokenValue(setup_file_list->next, token);
}
-static void setTokenValue(struct SetupFileList *setup_file_list,
- char *token, char *value)
+void setTokenValue(struct SetupFileList *setup_file_list,
+ char *token, char *value)
{
- if (!setup_file_list)
+ if (setup_file_list == NULL)
return;
if (strcmp(setup_file_list->token, token) == 0)
{
- free(setup_file_list->value);
- setup_file_list->value = checked_malloc(strlen(value) + 1);
- strcpy(setup_file_list->value, value);
+ if (setup_file_list->value)
+ free(setup_file_list->value);
+
+ setup_file_list->value = getStringCopy(value);
}
else if (setup_file_list->next == NULL)
setup_file_list->next = newSetupFileList(token, value);
char *token, *value, *line_ptr;
struct SetupFileList *setup_file_list = newSetupFileList("", "");
struct SetupFileList *first_valid_list_entry;
-
FILE *file;
if (!(file = fopen(filename, MODE_READ)))