1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-22 14:24:33 +01:00

Move RCT2 file copy into rct2.c

This commit is contained in:
Ted John
2016-12-11 12:10:35 +00:00
parent 0019827d6c
commit cef2587119
3 changed files with 71 additions and 70 deletions

View File

@@ -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;
}

View File

@@ -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");
}

View File

@@ -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
}