1
0
Fork 0
mirror of https://github.com/OpenMW/openmw.git synced 2025-02-28 17:09:41 +00:00

Make niftest exceptions more informative

This commit is contained in:
Alexei Kotov 2023-11-28 21:50:40 +03:00
parent 99024d3826
commit b96600a7fb

View file

@ -72,9 +72,10 @@ std::unique_ptr<VFS::Archive> makeArchive(const std::filesystem::path& path)
void readNIF( void readNIF(
const std::filesystem::path& source, const std::filesystem::path& path, const VFS::Manager* vfs, bool quiet) const std::filesystem::path& source, const std::filesystem::path& path, const VFS::Manager* vfs, bool quiet)
{ {
const std::string pathStr = Files::pathToUnicodeString(path);
if (!quiet) if (!quiet)
{ {
std::cout << "Reading NIF file '" << Files::pathToUnicodeString(path) << "'"; std::cout << "Reading NIF file '" << pathStr << "'";
if (!source.empty()) if (!source.empty())
std::cout << " from '" << Files::pathToUnicodeString(isBSA(source) ? source.filename() : source) << "'"; std::cout << " from '" << Files::pathToUnicodeString(isBSA(source) ? source.filename() : source) << "'";
std::cout << std::endl; std::cout << std::endl;
@ -85,13 +86,13 @@ void readNIF(
Nif::NIFFile file(fullPath); Nif::NIFFile file(fullPath);
Nif::Reader reader(file); Nif::Reader reader(file);
if (vfs != nullptr) if (vfs != nullptr)
reader.parse(vfs->get(Files::pathToUnicodeString(path))); reader.parse(vfs->get(pathStr));
else else
reader.parse(Files::openConstrainedFileStream(fullPath)); reader.parse(Files::openConstrainedFileStream(fullPath));
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << "Error, an exception has occurred: " << e.what() << std::endl; std::cerr << "Failed to read '" << pathStr << "':" << std::endl << e.what() << std::endl;
} }
} }
@ -204,20 +205,20 @@ int main(int argc, char** argv)
vfs = std::make_unique<VFS::Manager>(); vfs = std::make_unique<VFS::Manager>();
for (const std::filesystem::path& path : sources) for (const std::filesystem::path& path : sources)
{ {
const std::string pathStr = Files::pathToUnicodeString(path);
if (!quiet) if (!quiet)
std::cout << "Adding data source '" << Files::pathToUnicodeString(path) << "'" << std::endl; std::cout << "Adding data source '" << pathStr << "'" << std::endl;
try try
{ {
if (auto archive = makeArchive(path)) if (auto archive = makeArchive(path))
vfs->addArchive(std::move(archive)); vfs->addArchive(std::move(archive));
else else
std::cerr << "Error: '" << Files::pathToUnicodeString(path) << "' is not an archive or directory" std::cerr << "Error: '" << pathStr << "' is not an archive or directory" << std::endl;
<< std::endl;
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << "Error, an exception has occurred: " << e.what() << std::endl; std::cerr << "Failed to add data source '" << pathStr << "': " << e.what() << std::endl;
} }
} }
@ -226,6 +227,7 @@ int main(int argc, char** argv)
for (const auto& path : files) for (const auto& path : files)
{ {
const std::string pathStr = Files::pathToUnicodeString(path);
try try
{ {
if (isNIF(path)) if (isNIF(path))
@ -238,13 +240,12 @@ int main(int argc, char** argv)
} }
else else
{ {
std::cerr << "Error: '" << Files::pathToUnicodeString(path) std::cerr << "Error: '" << pathStr << "' is not a NIF file, BSA/BA2 archive, or directory" << std::endl;
<< "' is not a NIF file, BSA/BA2 archive, or directory" << std::endl;
} }
} }
catch (std::exception& e) catch (std::exception& e)
{ {
std::cerr << "Error, an exception has occurred: " << e.what() << std::endl; std::cerr << "Failed to read '" << pathStr << "': " << e.what() << std::endl;
} }
} }
return 0; return 0;