tools: Create destination directory if it does not exist when extracting

This commit is contained in:
Vsevolod Kremianskii 2021-04-22 13:05:29 +07:00
parent 00b082a253
commit 2b7fd07b8d
3 changed files with 21 additions and 3 deletions

View file

@ -59,7 +59,13 @@ void ErfTool::list(const ErfReader &erf) {
}
void ErfTool::extract(ErfReader &erf, const fs::path &destPath) {
if (!fs::is_directory(destPath) || !fs::exists(destPath)) return;
if (!fs::exists(destPath)) {
// Create destination directory if it does not exist
fs::create_directory(destPath);
} else if (!fs::is_directory(destPath)) {
// Return if destination exists, but is not a directory
return;
}
for (size_t i = 0; i < erf.keys().size(); ++i) {
const ErfReader::Key &key = erf.keys()[i];

View file

@ -85,7 +85,13 @@ void KeyBifTool::listBIF(const KeyReader &key, const BifReader &bif, int bifIdx)
}
void KeyBifTool::extractBIF(const KeyReader &key, BifReader &bif, int bifIdx, const fs::path &destPath) {
if (!fs::is_directory(destPath) || !fs::exists(destPath)) return;
if (!fs::exists(destPath)) {
// Create destination directory if it does not exist
fs::create_directory(destPath);
} else if (!fs::is_directory(destPath)) {
// Return if destination exists, but is not a directory
return;
}
for (auto &keyEntry : key.keys()) {
if (keyEntry.bifIdx != bifIdx) continue;

View file

@ -60,7 +60,13 @@ void RimTool::list(const RimReader &rim) {
}
void RimTool::extract(RimReader &rim, const fs::path &destPath) {
if (!fs::is_directory(destPath) || !fs::exists(destPath)) return;
if (!fs::exists(destPath)) {
// Create destination directory if it does not exist
fs::create_directory(destPath);
} else if (!fs::is_directory(destPath)) {
// Return if destination exists, but is not a directory
return;
}
for (size_t i = 0; i < rim.resources().size(); ++i) {
const RimReader::Resource &resEntry = rim.resources()[i];