Skip to content

Commit

Permalink
exception safety when extracting packs
Browse files Browse the repository at this point in the history
user can know why it breaks
  • Loading branch information
poco0317 committed Jun 20, 2024
1 parent 25322fe commit 0e25e78
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions src/Etterna/Singletons/SongManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,16 @@ SongManager::InitAll(LoadingWindow* ld)
bool
SongManager::InstallSmzip(const std::string& sZipFile)
{
miniz_cpp::zip_file fi(sZipFile);
miniz_cpp::zip_file fi;
try {
fi.load(sZipFile);
} catch (std::runtime_error& e) {
Locator::getLogger()->error("Exception when trying to extract {} - Zip "
"may not exist or is bad : {}",
sZipFile,
e.what());
return false;
}
// no ext
auto zipfilename =
sZipFile.substr(sZipFile.find_last_of('/') + 1, sZipFile.length() - 4);
Expand Down Expand Up @@ -182,10 +191,15 @@ SongManager::InstallSmzip(const std::string& sZipFile)
auto filecnt = 0;
for (auto& member : names) {
if (member.starts_with(doot + "/")) {
fi.extract(member,
FILEMAN->ResolveSongFolder(
extractTo, downloadPacksToAdditionalSongs));
filecnt++;
try {
fi.extract(member,
FILEMAN->ResolveSongFolder(
extractTo, downloadPacksToAdditionalSongs));
filecnt++;
} catch (std::runtime_error& ex) {
Locator::getLogger()->error(
"Failed to extract file {} : {}", member, ex.what());
}
}
}

Expand Down

0 comments on commit 0e25e78

Please sign in to comment.