recover from filesystem exception when dumping

This commit is contained in:
6arelyFuture 2025-01-11 11:20:12 +01:00
parent 5d69473551
commit 315eb76127
Signed by: Future
GPG Key ID: F2000F181A4F7C85
3 changed files with 15 additions and 4 deletions

View File

@ -1,6 +1,7 @@
#include "AssetDumpingContext.h" #include "AssetDumpingContext.h"
#include <filesystem> #include <filesystem>
#include <format>
#include <fstream> #include <fstream>
AssetDumpingContext::AssetDumpingContext() AssetDumpingContext::AssetDumpingContext()
@ -15,13 +16,21 @@ std::unique_ptr<std::ostream> AssetDumpingContext::OpenAssetFile(const std::stri
auto assetFileFolder(assetFilePath); auto assetFileFolder(assetFilePath);
assetFileFolder.replace_filename(""); assetFileFolder.replace_filename("");
create_directories(assetFileFolder);
std::error_code ec;
std::filesystem::create_directories(assetFileFolder, ec);
if (ec)
{
std::cerr << std::format("Failed to create folder '{}'. Asset '{}' won't be dumped\n", assetFilePath.string(), fileName);
return nullptr;
}
auto file = std::make_unique<std::ofstream>(assetFilePath, std::fstream::out | std::fstream::binary); auto file = std::make_unique<std::ofstream>(assetFilePath, std::fstream::out | std::fstream::binary);
if (!file->is_open()) if (!file->is_open())
{ {
std::cout << "Failed to open file '" << assetFilePath.string() << "' to dump asset '" << fileName << "'\n"; std::cerr << std::format("Failed to open file '{}' to dump asset '{}'\n", assetFilePath.string(), fileName);
return nullptr; return nullptr;
} }

View File

@ -1,5 +1,6 @@
#include "AssetDumperRawFile.h" #include "AssetDumperRawFile.h"
#include <format>
#include <stdexcept> #include <stdexcept>
#include <zlib.h> #include <zlib.h>
@ -49,7 +50,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
if (ret < 0) if (ret < 0)
{ {
printf("Inflate failed for dumping rawfile '%s'\n", rawFile->name); std::cerr << std::format("Inflate failed when attempting to dump rawfile '{}'\n", rawFile->name);
inflateEnd(&zs); inflateEnd(&zs);
return; return;
} }

View File

@ -1,5 +1,6 @@
#include "AssetDumperRawFile.h" #include "AssetDumperRawFile.h"
#include <format>
#include <stdexcept> #include <stdexcept>
#include <zlib.h> #include <zlib.h>
@ -49,7 +50,7 @@ void AssetDumperRawFile::DumpAsset(AssetDumpingContext& context, XAssetInfo<RawF
if (ret < 0) if (ret < 0)
{ {
std::cerr << "Inflate failed when attempting to dump rawfile " << rawFile->name << "\n"; std::cerr << std::format("Inflate failed when attempting to dump rawfile '{}'\n", rawFile->name);
inflateEnd(&zs); inflateEnd(&zs);
return; return;
} }