From 69703ac29b6d290020a9346193d09f199a3e0bc2 Mon Sep 17 00:00:00 2001 From: MysterD Date: Mon, 10 Apr 2023 15:28:47 -0700 Subject: [PATCH] Erase and recreate lua directories on import --- src/pc/mods/mod_import.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/pc/mods/mod_import.c b/src/pc/mods/mod_import.c index 2831d4c2..e57097da 100644 --- a/src/pc/mods/mod_import.c +++ b/src/pc/mods/mod_import.c @@ -56,6 +56,7 @@ static bool mod_import_lua(char* src) { static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { LOG_INFO("Importing zip mod: %s", path); + char luaPath[SYS_MAX_PATH] = { 0 }; mz_zip_archive zip_archive = { 0 }; mz_bool status = mz_zip_reader_init_file(&zip_archive, path, 0); if (!status) { @@ -75,6 +76,7 @@ static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { } if (str_ends_with(file_stat.m_filename, ".lua")) { + path_get_folder(file_stat.m_filename, luaPath); *isLua = true; break; } else if (str_ends_with(file_stat.m_filename, ".tex")) { @@ -102,10 +104,29 @@ static bool mod_import_zip(char* path, bool* isLua, bool* isDynos) { mz_zip_reader_end(&zip_archive); return false; } + + // create mod/dynos path if it doesn't exist if (!fs_sys_dir_exists(dstDirectory)) { fs_sys_mkdir(dstDirectory); } + // erase and create lua path + if (*isLua && strlen(luaPath) > 0) { + if (!concat_path(dst, dstDirectory, luaPath)) { + LOG_ERROR("Failed to concat path for base lua directory"); + mz_zip_reader_end(&zip_archive); + return false; + } + if (fs_sys_dir_exists(dst)) { + mods_delete_folder(dst); + } + if (!fs_sys_mkdir(dst)) { + LOG_ERROR("Failed to mkdir for base lua directory"); + mz_zip_reader_end(&zip_archive); + return false; + } + } + // Extract the archive for (int i = 0; i < (int)mz_zip_reader_get_num_files(&zip_archive); i++) { mz_zip_archive_file_stat file_stat;