mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-16 19:19:56 +00:00
(Re) Wrote a tool to test NIF files in BSAs and on the filesystem.
Just give it a set of files, one file per argument, and it will make sure openmw can read them.
This commit is contained in:
parent
2c1cee38b4
commit
2a653e45fd
4 changed files with 142 additions and 0 deletions
|
@ -72,6 +72,7 @@ option(BUILD_OPENCS "build OpenMW Construction Set" ON)
|
||||||
option(BUILD_WIZARD "build Installation Wizard" ON)
|
option(BUILD_WIZARD "build Installation Wizard" ON)
|
||||||
option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF)
|
option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF)
|
||||||
option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest" OFF)
|
option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest" OFF)
|
||||||
|
option(BUILD_NIFTEST "build nif file tester" OFF)
|
||||||
option(BUILD_MYGUI_PLUGIN "build MyGUI plugin for OpenMW resources, to use with MyGUI tools" ON)
|
option(BUILD_MYGUI_PLUGIN "build MyGUI plugin for OpenMW resources, to use with MyGUI tools" ON)
|
||||||
|
|
||||||
# OS X deployment
|
# OS X deployment
|
||||||
|
@ -396,6 +397,9 @@ IF(NOT WIN32 AND NOT APPLE)
|
||||||
IF(BUILD_ESMTOOL)
|
IF(BUILD_ESMTOOL)
|
||||||
INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/esmtool" DESTINATION "${BINDIR}" )
|
INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/esmtool" DESTINATION "${BINDIR}" )
|
||||||
ENDIF(BUILD_ESMTOOL)
|
ENDIF(BUILD_ESMTOOL)
|
||||||
|
IF(BUILD_NIFTEST)
|
||||||
|
INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/niftest" DESTINATION "${BINDIR}" )
|
||||||
|
ENDIF(BUILD_NIFTEST)
|
||||||
IF(BUILD_MWINIIMPORTER)
|
IF(BUILD_MWINIIMPORTER)
|
||||||
INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/openmw-iniimporter" DESTINATION "${BINDIR}" )
|
INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/openmw-iniimporter" DESTINATION "${BINDIR}" )
|
||||||
ENDIF(BUILD_MWINIIMPORTER)
|
ENDIF(BUILD_MWINIIMPORTER)
|
||||||
|
@ -581,6 +585,10 @@ if (BUILD_WIZARD)
|
||||||
add_subdirectory(apps/wizard)
|
add_subdirectory(apps/wizard)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if (BUILD_NIFTEST)
|
||||||
|
add_subdirectory(apps/niftest)
|
||||||
|
endif(BUILD_NIFTEST)
|
||||||
|
|
||||||
# UnitTests
|
# UnitTests
|
||||||
if (BUILD_UNITTESTS)
|
if (BUILD_UNITTESTS)
|
||||||
add_subdirectory( apps/openmw_test_suite )
|
add_subdirectory( apps/openmw_test_suite )
|
||||||
|
|
19
apps/niftest/CMakeLists.txt
Normal file
19
apps/niftest/CMakeLists.txt
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
set(NIFTEST
|
||||||
|
niftest.cpp
|
||||||
|
)
|
||||||
|
source_group(components\\nif\\tests FILES ${NIFTEST})
|
||||||
|
|
||||||
|
# Main executable
|
||||||
|
add_executable(niftest
|
||||||
|
${NIFTEST}
|
||||||
|
)
|
||||||
|
|
||||||
|
target_link_libraries(niftest
|
||||||
|
${Boost_FILESYSTEM_LIBRARY}
|
||||||
|
components
|
||||||
|
)
|
||||||
|
|
||||||
|
if (BUILD_WITH_CODE_COVERAGE)
|
||||||
|
add_definitions (--coverage)
|
||||||
|
target_link_libraries(niftest gcov)
|
||||||
|
endif()
|
28
apps/niftest/find_bad_nifs.sh
Executable file
28
apps/niftest/find_bad_nifs.sh
Executable file
|
@ -0,0 +1,28 @@
|
||||||
|
#!/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"
|
87
apps/niftest/niftest.cpp
Normal file
87
apps/niftest/niftest.cpp
Normal file
|
@ -0,0 +1,87 @@
|
||||||
|
///Program to test .nif files both on the FileSystem and in BSA archives.
|
||||||
|
|
||||||
|
#include <iostream>
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
|
#include <components/nif/niffile.hpp>
|
||||||
|
#include <components/files/constrainedfilestream.hpp>
|
||||||
|
#include <components/vfs/manager.hpp>
|
||||||
|
#include <components/vfs/bsaarchive.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
///See if the file has the named extension
|
||||||
|
bool hasExtension(std::string filename, std::string extensionToFind)
|
||||||
|
{
|
||||||
|
std::string extension = filename.substr(filename.find_last_of(".")+1);
|
||||||
|
|
||||||
|
//Convert strings to lower case for comparison
|
||||||
|
std::transform(extension.begin(), extension.end(), extension.begin(), ::tolower);
|
||||||
|
std::transform(extensionToFind.begin(), extensionToFind.end(), extensionToFind.begin(), ::tolower);
|
||||||
|
|
||||||
|
if(extension == extensionToFind)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
///See if the file has the "nif" extension.
|
||||||
|
bool isNIF(std::string filename)
|
||||||
|
{
|
||||||
|
return hasExtension(filename,"nif");
|
||||||
|
}
|
||||||
|
///See if the file has the "bsa" extension.
|
||||||
|
bool isBSA(std::string filename)
|
||||||
|
{
|
||||||
|
return hasExtension(filename,"bsa");
|
||||||
|
}
|
||||||
|
|
||||||
|
///Check all the nif files in the given BSA archive
|
||||||
|
void readBSA(std::string filename)
|
||||||
|
{
|
||||||
|
VFS::Manager myManager(false);
|
||||||
|
myManager.addArchive(new VFS::BsaArchive(filename));
|
||||||
|
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;
|
||||||
|
if(isNIF(name))
|
||||||
|
{
|
||||||
|
// std::cout << "Decoding: " << name << std::endl;
|
||||||
|
Nif::NIFFile temp_nif(myManager.get(name),name);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(int argc, char **argv)
|
||||||
|
{
|
||||||
|
|
||||||
|
std::cout << "Reading Files" << std::endl;
|
||||||
|
for(int i = 1; i<argc;i++)
|
||||||
|
{
|
||||||
|
std::string name = argv[i];
|
||||||
|
|
||||||
|
try{
|
||||||
|
if(isNIF(name))
|
||||||
|
{
|
||||||
|
//std::cout << "Decoding: " << name << std::endl;
|
||||||
|
Nif::NIFFile temp_nif(Files::openConstrainedFileStream(name.c_str()),name);
|
||||||
|
}
|
||||||
|
else if(isBSA(name))
|
||||||
|
{
|
||||||
|
std::cout << "Reading BSA File: " << name << std::endl;
|
||||||
|
readBSA(name);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR: \"" << name << "\" is not a nif or bsa file!" << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (std::exception& e)
|
||||||
|
{
|
||||||
|
std::cerr << "ERROR, an exception has occurred: " << e.what() << std::endl;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
Loading…
Reference in a new issue