mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-19 21:53:51 +00:00
Merge remote-tracking branch 'emperorarthur/nif_tester_updates'
This commit is contained in:
commit
be6a85c7aa
2 changed files with 95 additions and 45 deletions
|
@ -1,28 +0,0 @@
|
|||
#!/bin/bash
|
||||
#Script to test all nif files (both loose, and in BSA archives) in data files directory
|
||||
|
||||
#The user input as an absolute path
|
||||
DATAFILESDIR="`readlink -m "$1"`"
|
||||
#Program used to test
|
||||
TEST_PROG="`pwd`/niftest"
|
||||
|
||||
#Make sure our files don't bother anyone
|
||||
NIFTEST_TMP_DIR="/tmp/niftest_$RANDOM/"
|
||||
mkdir "$NIFTEST_TMP_DIR"
|
||||
cd "$NIFTEST_TMP_DIR"
|
||||
|
||||
find "$DATAFILESDIR" -iname *bsa > nifs.txt
|
||||
find "$DATAFILESDIR" -iname *nif >> nifs.txt
|
||||
|
||||
sed -e 's/.*/\"&\"/' nifs.txt > quoted_nifs.txt
|
||||
|
||||
xargs --arg-file=quoted_nifs.txt "$TEST_PROG" 2>&1 | tee nif_out.txt
|
||||
# xargs --arg-file=quoted_nifs.txt "$TEST_PROG" 2> nif_out.txt >/dev/null
|
||||
|
||||
echo "List of bad NIF Files:"
|
||||
cat nif_out.txt|grep File:|cut -d ' ' -f 2-
|
||||
|
||||
rm nifs.txt
|
||||
rm quoted_nifs.txt
|
||||
rm nif_out.txt
|
||||
rmdir "$NIFTEST_TMP_DIR"
|
|
@ -2,12 +2,20 @@
|
|||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <cstdlib>
|
||||
|
||||
#include <components/nif/niffile.hpp>
|
||||
#include <components/files/constrainedfilestream.hpp>
|
||||
#include <components/vfs/manager.hpp>
|
||||
#include <components/vfs/bsaarchive.hpp>
|
||||
#include <components/vfs/filesystemarchive.hpp>
|
||||
|
||||
#include <boost/program_options.hpp>
|
||||
#include <boost/filesystem.hpp>
|
||||
|
||||
// Create local aliases for brevity
|
||||
namespace bpo = boost::program_options;
|
||||
namespace bfs = boost::filesystem;
|
||||
|
||||
///See if the file has the named extension
|
||||
bool hasExtension(std::string filename, std::string extensionToFind)
|
||||
|
@ -35,32 +43,97 @@ bool isBSA(std::string filename)
|
|||
return hasExtension(filename,"bsa");
|
||||
}
|
||||
|
||||
///Check all the nif files in the given BSA archive
|
||||
void readBSA(std::string filename)
|
||||
/// Check all the nif files in a given VFS::Archive
|
||||
/// \note Takes ownership!
|
||||
/// \note Can not read a bsa file inside of a bsa file.
|
||||
void readVFS(VFS::Archive* anArchive,std::string archivePath = "")
|
||||
{
|
||||
VFS::Manager myManager(false);
|
||||
myManager.addArchive(new VFS::BsaArchive(filename));
|
||||
VFS::Manager myManager(true);
|
||||
myManager.addArchive(anArchive);
|
||||
myManager.buildIndex();
|
||||
|
||||
std::map<std::string, VFS::File*> files=myManager.getIndex();
|
||||
for(std::map<std::string, VFS::File*>::const_iterator it=files.begin(); it!=files.end(); ++it)
|
||||
{
|
||||
std::string name = it->first;
|
||||
|
||||
try{
|
||||
if(isNIF(name))
|
||||
{
|
||||
// std::cout << "Decoding: " << name << std::endl;
|
||||
Nif::NIFFile temp_nif(myManager.get(name),name);
|
||||
Nif::NIFFile temp_nif(myManager.get(name),archivePath+name);
|
||||
}
|
||||
else if(isBSA(name))
|
||||
{
|
||||
if(!archivePath.empty() && !isBSA(archivePath))
|
||||
{
|
||||
// std::cout << "Reading BSA File: " << name << std::endl;
|
||||
readVFS(new VFS::BsaArchive(archivePath+name),archivePath+name+"/");
|
||||
// std::cout << "Done with BSA File: " << name << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
{
|
||||
std::cerr << "ERROR, an exception has occurred: " << e.what() << std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> parseOptions (int argc, char** argv)
|
||||
{
|
||||
bpo::options_description desc("Ensure that OpenMW can use the provided NIF and BSA files\n\n"
|
||||
"Usages:\n"
|
||||
" niftool <nif files, BSA files, or directories>\n"
|
||||
" Scan the file or directories for nif errors.\n\n"
|
||||
"Allowed options");
|
||||
desc.add_options()
|
||||
("help,h", "print help message.")
|
||||
("input-file", bpo::value< std::vector<std::string> >(), "input file")
|
||||
;
|
||||
|
||||
//Default option if none provided
|
||||
bpo::positional_options_description p;
|
||||
p.add("input-file", -1);
|
||||
|
||||
bpo::variables_map variables;
|
||||
try
|
||||
{
|
||||
bpo::parsed_options valid_opts = bpo::command_line_parser(argc, argv).
|
||||
options(desc).positional(p).run();
|
||||
bpo::store(valid_opts, variables);
|
||||
}
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout << "ERROR parsing arguments: " << e.what() << "\n\n"
|
||||
<< desc << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
bpo::notify(variables);
|
||||
if (variables.count ("help"))
|
||||
{
|
||||
std::cout << desc << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
if (variables.count("input-file"))
|
||||
{
|
||||
return variables["input-file"].as< std::vector<std::string> >();
|
||||
}
|
||||
|
||||
std::cout << "No input files or directories specified!" << std::endl;
|
||||
std::cout << desc << std::endl;
|
||||
exit(1);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
std::vector<std::string> files = parseOptions (argc, argv);
|
||||
|
||||
std::cout << "Reading Files" << std::endl;
|
||||
for(int i = 1; i<argc;i++)
|
||||
// std::cout << "Reading Files" << std::endl;
|
||||
for(std::vector<std::string>::const_iterator it=files.begin(); it!=files.end(); ++it)
|
||||
{
|
||||
std::string name = argv[i];
|
||||
std::string name = *it;
|
||||
|
||||
try{
|
||||
if(isNIF(name))
|
||||
|
@ -70,12 +143,17 @@ int main(int argc, char **argv)
|
|||
}
|
||||
else if(isBSA(name))
|
||||
{
|
||||
std::cout << "Reading BSA File: " << name << std::endl;
|
||||
readBSA(name);
|
||||
// std::cout << "Reading BSA File: " << name << std::endl;
|
||||
readVFS(new VFS::BsaArchive(name));
|
||||
}
|
||||
else if(bfs::is_directory(bfs::path(name)))
|
||||
{
|
||||
// std::cout << "Reading All Files in: " << name << std::endl;
|
||||
readVFS(new VFS::FileSystemArchive(name),name);
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cerr << "ERROR: \"" << name << "\" is not a nif or bsa file!" << std::endl;
|
||||
std::cerr << "ERROR: \"" << name << "\" is not a nif file, bsa file, or directory!" << std::endl;
|
||||
}
|
||||
}
|
||||
catch (std::exception& e)
|
||||
|
|
Loading…
Reference in a new issue