From cef258711939b36e4f0cbaabb3c3ed91786035b1 Mon Sep 17 00:00:00 2001 From: Ted John Date: Sun, 11 Dec 2016 12:10:35 +0000 Subject: [PATCH] Move RCT2 file copy into rct2.c --- src/openrct2.c | 71 +------------------------------------------------- src/rct2.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++ src/rct2.h | 1 + 3 files changed, 71 insertions(+), 70 deletions(-) diff --git a/src/openrct2.c b/src/openrct2.c index baac5b623c..5a8cf1ac93 100644 --- a/src/openrct2.c +++ b/src/openrct2.c @@ -93,81 +93,12 @@ void openrct2_write_full_version_info(utf8 *buffer, size_t bufferSize) #endif } -static void openrct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension) -{ - utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH]; - int fileEnumHandle; - file_info fileInfo; - - if (!platform_ensure_directory_exists(newDirectory)) { - log_error("Could not create directory %s.", newDirectory); - return; - } - - // Create filter path - safe_strcpy(filter, originalDirectory, sizeof(filter)); - ch = strchr(filter, '*'); - if (ch != NULL) - *ch = 0; - safe_strcat_path(filter, "*", sizeof(filter)); - path_append_extension(filter, extension, sizeof(filter)); - - fileEnumHandle = platform_enumerate_files_begin(filter); - while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { - safe_strcpy(newPath, newDirectory, sizeof(newPath)); - safe_strcat_path(newPath, fileInfo.path, sizeof(newPath)); - - safe_strcpy(oldPath, originalDirectory, sizeof(oldPath)); - ch = strchr(oldPath, '*'); - if (ch != NULL) - *ch = 0; - safe_strcat_path(oldPath, fileInfo.path, sizeof(oldPath)); - - if (!platform_file_exists(newPath)) - platform_file_copy(oldPath, newPath, false); - } - platform_enumerate_files_end(fileEnumHandle); - - fileEnumHandle = platform_enumerate_directories_begin(originalDirectory); - while (platform_enumerate_directories_next(fileEnumHandle, filter)) { - safe_strcpy(newPath, newDirectory, sizeof(newPath)); - safe_strcat_path(newPath, filter, sizeof(newPath)); - - safe_strcpy(oldPath, originalDirectory, MAX_PATH); - ch = strchr(oldPath, '*'); - if (ch != NULL) - *ch = 0; - safe_strcat_path(oldPath, filter, sizeof(oldPath)); - - if (!platform_ensure_directory_exists(newPath)) { - log_error("Could not create directory %s.", newPath); - return; - } - openrct2_copy_files_over(oldPath, newPath, extension); - } - platform_enumerate_directories_end(fileEnumHandle); -} - static void openrct2_set_exe_path() { platform_get_exe_path(gExePath, sizeof(gExePath)); log_verbose("Setting exe path to %s", gExePath); } -/** - * Copy saved games and landscapes to user directory - */ -static void openrct2_copy_original_user_files_over() -{ - utf8 path[MAX_PATH]; - - platform_get_user_directory(path, "save", sizeof(path)); - openrct2_copy_files_over((utf8*)gRCT2AddressSavedGamesPath, path, ".sv6"); - - platform_get_user_directory(path, "landscape", sizeof(path)); - openrct2_copy_files_over((utf8*)gRCT2AddressLandscapesPath, path, ".sc6"); -} - bool openrct2_initialise() { utf8 userPath[MAX_PATH]; @@ -251,7 +182,7 @@ bool openrct2_initialise() chat_init(); - openrct2_copy_original_user_files_over(); + rct2_copy_original_user_files_over(); return true; } diff --git a/src/rct2.c b/src/rct2.c index ea8bbb4119..afb697f26c 100644 --- a/src/rct2.c +++ b/src/rct2.c @@ -499,3 +499,72 @@ uint32 get_file_extension_type(const utf8 *path) if (strcicmp(extension, ".td6") == 0) return FILE_EXTENSION_TD6; return FILE_EXTENSION_UNKNOWN; } + +static void rct2_copy_files_over(const utf8 *originalDirectory, const utf8 *newDirectory, const utf8 *extension) +{ + utf8 *ch, filter[MAX_PATH], oldPath[MAX_PATH], newPath[MAX_PATH]; + int fileEnumHandle; + file_info fileInfo; + + if (!platform_ensure_directory_exists(newDirectory)) { + log_error("Could not create directory %s.", newDirectory); + return; + } + + // Create filter path + safe_strcpy(filter, originalDirectory, sizeof(filter)); + ch = strchr(filter, '*'); + if (ch != NULL) + *ch = 0; + safe_strcat_path(filter, "*", sizeof(filter)); + path_append_extension(filter, extension, sizeof(filter)); + + fileEnumHandle = platform_enumerate_files_begin(filter); + while (platform_enumerate_files_next(fileEnumHandle, &fileInfo)) { + safe_strcpy(newPath, newDirectory, sizeof(newPath)); + safe_strcat_path(newPath, fileInfo.path, sizeof(newPath)); + + safe_strcpy(oldPath, originalDirectory, sizeof(oldPath)); + ch = strchr(oldPath, '*'); + if (ch != NULL) + *ch = 0; + safe_strcat_path(oldPath, fileInfo.path, sizeof(oldPath)); + + if (!platform_file_exists(newPath)) + platform_file_copy(oldPath, newPath, false); + } + platform_enumerate_files_end(fileEnumHandle); + + fileEnumHandle = platform_enumerate_directories_begin(originalDirectory); + while (platform_enumerate_directories_next(fileEnumHandle, filter)) { + safe_strcpy(newPath, newDirectory, sizeof(newPath)); + safe_strcat_path(newPath, filter, sizeof(newPath)); + + safe_strcpy(oldPath, originalDirectory, MAX_PATH); + ch = strchr(oldPath, '*'); + if (ch != NULL) + *ch = 0; + safe_strcat_path(oldPath, filter, sizeof(oldPath)); + + if (!platform_ensure_directory_exists(newPath)) { + log_error("Could not create directory %s.", newPath); + return; + } + rct2_copy_files_over(oldPath, newPath, extension); + } + platform_enumerate_directories_end(fileEnumHandle); +} + +/** + * Copy saved games and landscapes to user directory + */ +void rct2_copy_original_user_files_over() +{ + utf8 path[MAX_PATH]; + + platform_get_user_directory(path, "save", sizeof(path)); + rct2_copy_files_over((utf8*)gRCT2AddressSavedGamesPath, path, ".sv6"); + + platform_get_user_directory(path, "landscape", sizeof(path)); + rct2_copy_files_over((utf8*)gRCT2AddressLandscapesPath, path, ".sc6"); +} diff --git a/src/rct2.h b/src/rct2.h index 3f450067e3..71435ff079 100644 --- a/src/rct2.h +++ b/src/rct2.h @@ -145,6 +145,7 @@ void rct2_quit(); bool rct2_open_file(const char *path); uint32 get_file_extension_type(const utf8 *path); +void rct2_copy_original_user_files_over(); #ifdef __cplusplus }