Adapted utils_create_dir_recursively to general project style

This commit is contained in:
mkrsym1 2023-08-10 01:15:53 +03:00
parent e9d2130105
commit c80635fc71
3 changed files with 6 additions and 9 deletions

View File

@ -7,7 +7,7 @@
int utils_path_exists(const wchar_t *filePath); int utils_path_exists(const wchar_t *filePath);
uint32_t utils_file_crc32c(const wchar_t *filePath); uint32_t utils_file_crc32c(const wchar_t *filePath);
void utils_create_dir_recursively(const wchar_t *path); void utils_create_parent_dirs(const wchar_t *path);
void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length); void utils_save_to_file(const wchar_t *filePath, const void *buf, size_t length);

View File

@ -62,7 +62,7 @@ static void _run_tx(struct game_data *game, wchar_t *txFile) {
void *table = core_perform_tx(game, &tableSize); void *table = core_perform_tx(game, &tableSize);
// Save to file // Save to file
utils_create_dir_recursively(txFile); utils_create_parent_dirs(txFile);
utils_save_to_file(txFile, table, tableSize); utils_save_to_file(txFile, table, tableSize);
// Cleanup // Cleanup

View File

@ -34,21 +34,18 @@ uint32_t utils_file_crc32c(const wchar_t *filePath) {
} }
// https://stackoverflow.com/a/16719260 // https://stackoverflow.com/a/16719260
void utils_create_dir_recursively(const wchar_t *path) { void utils_create_parent_dirs(const wchar_t *path) {
wchar_t dir[MAX_PATH]; wchar_t dir[MAX_PATH];
ZeroMemory(dir, MAX_PATH * sizeof(wchar_t)); ZeroMemory(dir, sizeof(dir));
wchar_t *end = wcschr(path, L'\\'); const wchar_t *end = path - 1;
while(end != NULL) while((end = wcschr(++end, L'\\')) != NULL) {
{
wcsncpy(dir, path, end - path + 1); wcsncpy(dir, path, end - path + 1);
if (!utils_path_exists(dir) && !CreateDirectoryW(dir, NULL)) { if (!utils_path_exists(dir) && !CreateDirectoryW(dir, NULL)) {
msg_err_w(L"Failed to create directory: %ls", dir); msg_err_w(L"Failed to create directory: %ls", dir);
} }
end = wcschr(++end, L'\\');
} }
} }