|
|
|
@ -33,18 +33,48 @@ bool hasExtension(const std::filesystem::path& filename, const std::string& exte
|
|
|
|
|
/// See if the file has the "nif" extension.
|
|
|
|
|
bool isNIF(const std::filesystem::path& filename)
|
|
|
|
|
{
|
|
|
|
|
return hasExtension(filename, "nif");
|
|
|
|
|
return hasExtension(filename, ".nif");
|
|
|
|
|
}
|
|
|
|
|
/// See if the file has the "bsa" extension.
|
|
|
|
|
bool isBSA(const std::filesystem::path& filename)
|
|
|
|
|
{
|
|
|
|
|
return hasExtension(filename, "bsa");
|
|
|
|
|
return hasExtension(filename, ".bsa");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<VFS::Archive> makeBsaArchive(const std::filesystem::path& path)
|
|
|
|
|
{
|
|
|
|
|
switch (Bsa::CompressedBSAFile::detectVersion(path))
|
|
|
|
|
{
|
|
|
|
|
case Bsa::BSAVER_UNKNOWN:
|
|
|
|
|
std::cerr << '"' << path << "\" is unknown BSA archive" << std::endl;
|
|
|
|
|
return nullptr;
|
|
|
|
|
case Bsa::BSAVER_UNCOMPRESSED:
|
|
|
|
|
return std::make_unique<VFS::BsaArchive>(path);
|
|
|
|
|
case Bsa::BSAVER_COMPRESSED:
|
|
|
|
|
return std::make_unique<VFS::CompressedBsaArchive>(path);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::cerr << '"' << path << "\" is unsupported BSA archive" << std::endl;
|
|
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<VFS::Archive> makeArchive(const std::filesystem::path& path)
|
|
|
|
|
{
|
|
|
|
|
if (isBSA(path))
|
|
|
|
|
return makeBsaArchive(path);
|
|
|
|
|
if (std::filesystem::is_directory(path))
|
|
|
|
|
return std::make_unique<VFS::FileSystemArchive>(path);
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// Check all the nif files in a given VFS::Archive
|
|
|
|
|
/// \note Can not read a bsa file inside of a bsa file.
|
|
|
|
|
void readVFS(std::unique_ptr<VFS::Archive>&& anArchive, const std::filesystem::path& archivePath = {})
|
|
|
|
|
{
|
|
|
|
|
if (anArchive == nullptr)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
VFS::Manager myManager(true);
|
|
|
|
|
myManager.addArchive(std::move(anArchive));
|
|
|
|
|
myManager.buildIndex();
|
|
|
|
@ -65,7 +95,7 @@ void readVFS(std::unique_ptr<VFS::Archive>&& anArchive, const std::filesystem::p
|
|
|
|
|
if (!archivePath.empty() && !isBSA(archivePath))
|
|
|
|
|
{
|
|
|
|
|
// std::cout << "Reading BSA File: " << name << std::endl;
|
|
|
|
|
readVFS(std::make_unique<VFS::BsaArchive>(archivePath / name), archivePath / name);
|
|
|
|
|
readVFS(makeBsaArchive(archivePath / name), archivePath / name);
|
|
|
|
|
// std::cout << "Done with BSA File: " << name << std::endl;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -77,7 +107,8 @@ void readVFS(std::unique_ptr<VFS::Archive>&& anArchive, const std::filesystem::p
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool parseOptions(int argc, char** argv, std::vector<Files::MaybeQuotedPath>& files)
|
|
|
|
|
bool parseOptions(int argc, char** argv, std::vector<Files::MaybeQuotedPath>& files, bool& writeDebugLog,
|
|
|
|
|
std::vector<Files::MaybeQuotedPath>& archives)
|
|
|
|
|
{
|
|
|
|
|
bpo::options_description desc(R"(Ensure that OpenMW can use the provided NIF and BSA files
|
|
|
|
|
|
|
|
|
@ -88,6 +119,8 @@ Usages:
|
|
|
|
|
Allowed options)");
|
|
|
|
|
auto addOption = desc.add_options();
|
|
|
|
|
addOption("help,h", "print help message.");
|
|
|
|
|
addOption("write-debug-log,v", "write debug log for unsupported nif files");
|
|
|
|
|
addOption("archives", bpo::value<Files::MaybeQuotedPathContainer>(), "path to archive files to provide files");
|
|
|
|
|
addOption("input-file", bpo::value<Files::MaybeQuotedPathContainer>(), "input file");
|
|
|
|
|
|
|
|
|
|
// Default option if none provided
|
|
|
|
@ -105,9 +138,12 @@ Allowed options)");
|
|
|
|
|
std::cout << desc << std::endl;
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
writeDebugLog = variables.count("write-debug-log") > 0;
|
|
|
|
|
if (variables.count("input-file"))
|
|
|
|
|
{
|
|
|
|
|
files = variables["input-file"].as<Files::MaybeQuotedPathContainer>();
|
|
|
|
|
if (const auto it = variables.find("archives"); it != variables.end())
|
|
|
|
|
archives = it->second.as<Files::MaybeQuotedPathContainer>();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
@ -125,10 +161,26 @@ Allowed options)");
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
|
{
|
|
|
|
|
std::vector<Files::MaybeQuotedPath> files;
|
|
|
|
|
if (!parseOptions(argc, argv, files))
|
|
|
|
|
bool writeDebugLog = false;
|
|
|
|
|
std::vector<Files::MaybeQuotedPath> archives;
|
|
|
|
|
if (!parseOptions(argc, argv, files, writeDebugLog, archives))
|
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
|
|
Nif::Reader::setLoadUnsupportedFiles(true);
|
|
|
|
|
Nif::Reader::setWriteNifDebugLog(writeDebugLog);
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<VFS::Manager> vfs;
|
|
|
|
|
if (!archives.empty())
|
|
|
|
|
{
|
|
|
|
|
vfs = std::make_unique<VFS::Manager>(true);
|
|
|
|
|
for (const std::filesystem::path& path : archives)
|
|
|
|
|
if (auto archive = makeArchive(path))
|
|
|
|
|
vfs->addArchive(std::move(archive));
|
|
|
|
|
else
|
|
|
|
|
std::cerr << '"' << path << "\" is unsupported archive" << std::endl;
|
|
|
|
|
vfs->buildIndex();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// std::cout << "Reading Files" << std::endl;
|
|
|
|
|
for (const auto& path : files)
|
|
|
|
|
{
|
|
|
|
@ -139,17 +191,14 @@ int main(int argc, char** argv)
|
|
|
|
|
// std::cout << "Decoding: " << name << std::endl;
|
|
|
|
|
Nif::NIFFile file(path);
|
|
|
|
|
Nif::Reader reader(file);
|
|
|
|
|
reader.parse(Files::openConstrainedFileStream(path));
|
|
|
|
|
}
|
|
|
|
|
else if (isBSA(path))
|
|
|
|
|
{
|
|
|
|
|
// std::cout << "Reading BSA File: " << name << std::endl;
|
|
|
|
|
readVFS(std::make_unique<VFS::BsaArchive>(path));
|
|
|
|
|
if (vfs != nullptr)
|
|
|
|
|
reader.parse(vfs->get(Files::pathToUnicodeString(path)));
|
|
|
|
|
else
|
|
|
|
|
reader.parse(Files::openConstrainedFileStream(path));
|
|
|
|
|
}
|
|
|
|
|
else if (std::filesystem::is_directory(path))
|
|
|
|
|
else if (auto archive = makeArchive(path))
|
|
|
|
|
{
|
|
|
|
|
// std::cout << "Reading All Files in: " << name << std::endl;
|
|
|
|
|
readVFS(std::make_unique<VFS::FileSystemArchive>(path), path);
|
|
|
|
|
readVFS(std::move(archive), path);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|