diff --git a/360/main.c b/360/main.c index aca493adb3..22d1bf79d1 100644 --- a/360/main.c +++ b/360/main.c @@ -190,21 +190,9 @@ static void set_default_settings (void) g_extern.verbose = true; } -static bool file_exists(const char * filename) -{ - unsigned long file_attr; - - file_attr = GetFileAttributes(filename); - - if (0xFFFFFFFF == file_attr) - return false; - - return true; -} - static void init_settings (void) { - if(!file_exists(SYS_CONFIG_FILE)) + if(!filepath_exists(SYS_CONFIG_FILE)) { SSNES_ERR("Config file \"%s\" desn't exist. Creating...\n", "game:\\ssnes.cfg"); FILE * f; @@ -230,7 +218,7 @@ static void init_settings (void) static void save_settings (void) { - if(!file_exists(SYS_CONFIG_FILE)) + if(!filepath_exists(SYS_CONFIG_FILE)) { FILE * f; f = fopen(SYS_CONFIG_FILE, "w"); @@ -374,7 +362,7 @@ begin_loop: goto begin_loop; begin_shutdown: - if(file_exists(SYS_CONFIG_FILE)) + if(filepath_exists(SYS_CONFIG_FILE)) save_settings(); xdk360_video_deinit(); } diff --git a/file.c b/file.c index d9181f45d9..791a9145f3 100644 --- a/file.c +++ b/file.c @@ -938,6 +938,27 @@ void dir_list_free(char **dir_list) free(orig); } +#ifdef SSNES_CONSOLE +bool filepath_exists(const char *path) +{ +#ifdef _WIN32 + DWORD file_attr; + + file_attr = GetFileAttributes(path); + + if (0xFFFFFFFF == file_attr) + return false; + return true; +#elif defined(__CELLOS_LV2__) + CellFsStat file_attr; + if(cellFsStat(path,&file_attr) == CELL_FS_SUCCEEDED) + return true; + else + return false; +#endif +} +#endif + bool path_is_directory(const char *path) { #ifdef _WIN32 diff --git a/file.h b/file.h index c65b12337d..96b411776a 100644 --- a/file.h +++ b/file.h @@ -47,6 +47,10 @@ void dir_list_free(char **dir_list); bool path_is_directory(const char *path); bool path_file_exists(const char *path); +#ifdef SSNES_CONSOLE +bool filepath_exists(const char *path); +#endif + // Path-name operations. // If any of these operation are detected to overflow, the application will be terminated. diff --git a/ps3/main.c b/ps3/main.c index 376f434233..20640acf90 100644 --- a/ps3/main.c +++ b/ps3/main.c @@ -74,15 +74,6 @@ void set_text_message(const char * message, uint32_t speed) SET_TIMER_EXPIRATION(speed); } -static bool file_exists(const char * filename) -{ - CellFsStat sb; - if(cellFsStat(filename,&sb) == CELL_FS_SUCCEEDED) - return true; - else - return false; -} - static void set_default_settings(void) { // g_settings @@ -174,7 +165,7 @@ static void set_default_settings(void) static void init_settings(void) { - if(!file_exists(SYS_CONFIG_FILE)) + if(!filepath_exists(SYS_CONFIG_FILE)) { SSNES_ERR("Config file \"%s\" doesn't exist. Creating...\n", SYS_CONFIG_FILE); FILE * f; @@ -219,7 +210,7 @@ static void init_settings(void) static void save_settings(void) { - if(!file_exists(SYS_CONFIG_FILE)) + if(!filepath_exists(SYS_CONFIG_FILE)) { FILE * f; f = fopen(SYS_CONFIG_FILE, "w"); @@ -436,7 +427,7 @@ begin_loop: goto begin_loop; begin_shutdown: - if(file_exists(SYS_CONFIG_FILE)) + if(filepath_exists(SYS_CONFIG_FILE)) save_settings(); ps3_input_deinit(); ps3_video_deinit();