mirror of
				https://github.com/TES3MP/openmw-tes3mp.git
				synced 2025-10-31 13:56:45 +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. On linux/mac you can use "xargs --arg-file=nifs.txt ./niftest" to give it a list of files to check.
This commit is contained in:
		
							parent
							
								
									d024c1a93f
								
							
						
					
					
						commit
						cdfa24e15d
					
				
					 9 changed files with 136 additions and 5859 deletions
				
			
		
							
								
								
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										1
									
								
								.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -37,6 +37,7 @@ resources | |||
| /omwlauncher | ||||
| /openmw | ||||
| /opencs | ||||
| /niftest | ||||
| 
 | ||||
| ## generated objects | ||||
| apps/openmw/config.hpp | ||||
|  |  | |||
|  | @ -77,6 +77,7 @@ option(BUILD_MWINIIMPORTER "build MWiniImporter" ON) | |||
| option(BUILD_OPENCS "build OpenMW Construction Set" ON) | ||||
| option(BUILD_WITH_CODE_COVERAGE "Enable code coverage with gconv" OFF) | ||||
| option(BUILD_UNITTESTS "Enable Unittests with Google C++ Unittest ang GMock frameworks" OFF) | ||||
| option(BUILD_NIFTEST "build nif file tester" ON) | ||||
| 
 | ||||
| # OS X deployment | ||||
| option(OPENMW_OSX_DEPLOYMENT OFF) | ||||
|  | @ -396,6 +397,9 @@ IF(NOT WIN32 AND NOT APPLE) | |||
|     IF(BUILD_OPENCS) | ||||
|         INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/opencs" DESTINATION "${BINDIR}" ) | ||||
|     ENDIF(BUILD_OPENCS) | ||||
|     IF(BUILD_NIFTEST) | ||||
|         INSTALL(PROGRAMS "${OpenMW_BINARY_DIR}/niftest" DESTINATION "${BINDIR}" ) | ||||
|     ENDIF(BUILD_NIFTEST) | ||||
| 
 | ||||
|     # Install licenses | ||||
|     INSTALL(FILES "docs/license/DejaVu Font License.txt" DESTINATION "${LICDIR}" ) | ||||
|  | @ -512,6 +516,11 @@ add_subdirectory (extern/sdl4ogre) | |||
| # Components | ||||
| add_subdirectory (components) | ||||
| 
 | ||||
| #Testing | ||||
| if (BUILD_NIFTEST) | ||||
|   add_subdirectory(components/nif/tests/) | ||||
| endif(BUILD_NIFTEST) | ||||
| 
 | ||||
| # Apps and tools | ||||
| add_subdirectory( apps/openmw ) | ||||
| 
 | ||||
|  |  | |||
							
								
								
									
										6
									
								
								components/nif/tests/.gitignore
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										6
									
								
								components/nif/tests/.gitignore
									
									
									
									
										vendored
									
									
								
							|  | @ -1,5 +1 @@ | |||
| niftool | ||||
| *_test | ||||
| *.nif | ||||
| *.kf | ||||
| output.txt | ||||
| *.log | ||||
|  |  | |||
							
								
								
									
										19
									
								
								components/nif/tests/CMakeLists.txt
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										19
									
								
								components/nif/tests/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_LIBRARIES} | ||||
|   components | ||||
| ) | ||||
| 
 | ||||
| if (BUILD_WITH_CODE_COVERAGE) | ||||
|   add_definitions (--coverage) | ||||
|   target_link_libraries(niftest gcov) | ||||
| endif() | ||||
|  | @ -1,12 +0,0 @@ | |||
| GCC=g++ | ||||
| 
 | ||||
| all: niftool nif_bsa_test | ||||
| 
 | ||||
| niftool: niftool.cpp ../nif_file.hpp ../nif_file.cpp ../record.hpp | ||||
| 	$(GCC) $< ../nif_file.cpp ../../tools/stringops.cpp -o $@ | ||||
| 
 | ||||
| nif_bsa_test: nif_bsa_test.cpp ../nif_file.cpp ../../bsa/bsa_file.cpp ../../tools/stringops.cpp | ||||
| 	$(GCC) $^ -o $@ | ||||
| 
 | ||||
| clean: | ||||
| 	rm niftool *_test | ||||
|  | @ -1,30 +0,0 @@ | |||
| /*
 | ||||
|   Runs NIFFile through all the NIFs in Morrowind.bsa. | ||||
|  */ | ||||
| 
 | ||||
| #include "../nif_file.hpp" | ||||
| #include "../../bsa/bsa_file.hpp" | ||||
| #include "../../tools/stringops.hpp" | ||||
| #include <iostream> | ||||
| 
 | ||||
| using namespace Mangle::Stream; | ||||
| using namespace std; | ||||
| using namespace Nif; | ||||
| 
 | ||||
| int main(int argc, char **args) | ||||
| { | ||||
|   BSAFile bsa; | ||||
|   cout << "Reading Morrowind.bsa\n"; | ||||
|   bsa.open("../../data/Morrowind.bsa"); | ||||
| 
 | ||||
|   const BSAFile::FileList &files = bsa.getList(); | ||||
| 
 | ||||
|   for(int i=0; i<files.size(); i++) | ||||
|     { | ||||
|       const char *n = files[i].name; | ||||
|       if(!ends(n, ".nif")) continue; | ||||
| 
 | ||||
|       cout << "Decoding " << n << endl; | ||||
|       NIFFile nif(bsa.getFile(n), n); | ||||
|     } | ||||
| } | ||||
							
								
								
									
										96
									
								
								components/nif/tests/niftest.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										96
									
								
								components/nif/tests/niftest.cpp
									
									
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,96 @@ | |||
| ///Program to test .nif files both on the FileSystem and in BSA archives.
 | ||||
| 
 | ||||
| #include "../niffile.hpp" | ||||
| #include "../../bsa/bsa_file.hpp" | ||||
| #include "../../bsa/bsa_archive.hpp" | ||||
| #include <OgreRoot.h> | ||||
| #include <OgreResourceGroupManager.h> | ||||
| #include <iostream> | ||||
| #include <algorithm> | ||||
| #include <exception> | ||||
| 
 | ||||
| ///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) | ||||
| { | ||||
|     Bsa::BSAFile bsa; | ||||
|     bsa.open(filename.c_str()); | ||||
| 
 | ||||
|     const Bsa::BSAFile::FileList &files = bsa.getList(); | ||||
|     Bsa::addBSA(filename,"Bsa Files"); | ||||
| 
 | ||||
|     for(unsigned int i=0; i<files.size(); i++) | ||||
|     { | ||||
|       std::string name = files[i].name; | ||||
|       if(isNIF(name)) | ||||
|       { | ||||
|           //std::cout << "Decoding " << name << std::endl;
 | ||||
|           Nif::NIFFile temp_nif(name); | ||||
|       } | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| int main(int argc, char **argv) | ||||
| { | ||||
| 
 | ||||
|     //Need this for Ogre's getSingleton
 | ||||
|     new Ogre::Root("", "", "niftest.log"); | ||||
|     Ogre::ResourceGroupManager::getSingleton ().createResourceGroup ("Bsa Files"); | ||||
|     //Needed to read files from file system
 | ||||
|     Ogre::ResourceGroupManager::getSingleton().addResourceLocation("/", "FileSystem"); | ||||
|     // Initialize the resource groups:
 | ||||
|     Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); | ||||
| 
 | ||||
|     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(name); | ||||
|              } | ||||
|              else if(isBSA(name)) | ||||
|              { | ||||
|                 std::cout << "Reading " << 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 occured" << e.what() << std::endl; | ||||
|         } | ||||
|      } | ||||
|      return 0; | ||||
| } | ||||
										
											
												File diff suppressed because it is too large
												Load diff
											
										
									
								
							|  | @ -1,18 +1,15 @@ | |||
| #!/bin/bash | ||||
| 
 | ||||
| make || exit | ||||
| #Script to test all nif files (both loose, and in BSA archives) in data files directory | ||||
| 
 | ||||
| mkdir -p output | ||||
| DATAFILESDIR="$1" | ||||
| 
 | ||||
| PROGS=*_test | ||||
| find "$DATAFILESDIR" -iname *bsa > nifs.txt | ||||
| find "$DATAFILESDIR" -iname *nif >> nifs.txt | ||||
| 
 | ||||
| for a in $PROGS; do | ||||
|     if [ -f "output/$a.out" ]; then | ||||
|         echo "Running $a:" | ||||
|         ./$a | diff output/$a.out - | ||||
|     else | ||||
|         echo "Creating $a.out" | ||||
|         ./$a > "output/$a.out" | ||||
|         git add "output/$a.out" | ||||
|     fi | ||||
| done | ||||
| sed -e 's/.*/\"&\"/' nifs.txt > quoted_nifs.txt | ||||
| 
 | ||||
| xargs --arg-file=quoted_nifs.txt ../../../niftest | ||||
| 
 | ||||
| rm nifs.txt | ||||
| rm quoted_nifs.txt | ||||
|  |  | |||
		Loading…
	
		Reference in a new issue