Erase and recreate lua directories on import

This commit is contained in:
MysterD 2023-04-10 15:28:47 -07:00
parent c1c12feb8f
commit 69703ac29b
1 changed files with 21 additions and 0 deletions

View File

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