Revive bsatool
parent
17e406e58c
commit
3adf3f5121
@ -0,0 +1,26 @@
|
||||
set(BSATOOL
|
||||
bsatool.cpp
|
||||
bsatool_cmd.c
|
||||
bsatool_cmd.h
|
||||
)
|
||||
source_group(apps\\bsatool FILES ${BSATOOL})
|
||||
|
||||
# Main executable
|
||||
add_executable(bsatool
|
||||
${BSATOOL}
|
||||
)
|
||||
|
||||
target_link_libraries(bsatool
|
||||
${Boost_LIBRARIES}
|
||||
components
|
||||
)
|
||||
|
||||
#if (APPLE)
|
||||
# find_library(CARBON_FRAMEWORK Carbon)
|
||||
# target_link_libraries(openmw ${CARBON_FRAMEWORK})
|
||||
#endif (APPLE)
|
||||
|
||||
if (BUILD_WITH_CODE_COVERAGE)
|
||||
add_definitions (--coverage)
|
||||
target_link_libraries(bsatool gcov)
|
||||
endif()
|
@ -0,0 +1,86 @@
|
||||
#include <components/bsa/bsa_file.hpp>
|
||||
|
||||
#include "bsatool_cmd.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
gengetopt_args_info info;
|
||||
|
||||
if(cmdline_parser(argc, argv, &info) != 0)
|
||||
return 1;
|
||||
|
||||
if(info.inputs_num != 1)
|
||||
{
|
||||
if(info.inputs_num == 0)
|
||||
std::cout << "ERROR: missing BSA file\n\n";
|
||||
else
|
||||
std::cout << "ERROR: more than one BSA file specified\n\n";
|
||||
cmdline_parser_print_help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Open file
|
||||
Bsa::BSAFile bsa;
|
||||
char *arcname = info.inputs[0];
|
||||
try { bsa.open(arcname); }
|
||||
catch(std::exception &e)
|
||||
{
|
||||
std::cout << "ERROR reading BSA archive '" << arcname
|
||||
<< "'\nDetails:\n" << e.what() << std::endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(info.extract_given)
|
||||
{
|
||||
char *file = info.extract_arg;
|
||||
|
||||
if(!bsa.exists(file))
|
||||
{
|
||||
std::cout << "ERROR: file '" << file << "' not found\n";
|
||||
std::cout << "In archive: " << arcname << std::endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Find the base name of the file
|
||||
int pos = strlen(file);
|
||||
while(pos > 0 && file[pos] != '\\') pos--;
|
||||
char *base = file+pos+1;
|
||||
|
||||
// TODO: We might add full directory name extraction later. We
|
||||
// could also allow automatic conversion from / to \ in
|
||||
// parameter file names.
|
||||
|
||||
// Load the file into a memory buffer
|
||||
Ogre::DataStreamPtr data = bsa.getFile(file);
|
||||
|
||||
// Write the file to disk
|
||||
std::ofstream out(base, std::ios::binary);
|
||||
out.write(data->getAsString().c_str(), data->size());
|
||||
out.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List all files
|
||||
const Bsa::BSAFile::FileList &files = bsa.getList();
|
||||
for(int i=0; i<files.size(); i++)
|
||||
{
|
||||
if(info.long_given)
|
||||
{
|
||||
// Long format
|
||||
std::cout << std::setw(50) << std::left << files[i].name;
|
||||
std::cout << std::setw(8) << std::left << std::dec << files[i].fileSize;
|
||||
std::cout << "@ 0x" << std::hex << files[i].offset << std::endl;
|
||||
}
|
||||
else
|
||||
std::cout << files[i].name << std::endl;
|
||||
}
|
||||
|
||||
// Done!
|
||||
return 0;
|
||||
}
|
@ -1,92 +0,0 @@
|
||||
#include "../bsa_file.hpp"
|
||||
|
||||
#include "bsatool_cmd.h"
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <fstream>
|
||||
#include <exception>
|
||||
|
||||
#include "../../mangle/stream/filters/buffer_stream.hpp"
|
||||
|
||||
using namespace std;
|
||||
using namespace Mangle::Stream;
|
||||
using namespace Bsa;
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
gengetopt_args_info info;
|
||||
|
||||
if(cmdline_parser(argc, argv, &info) != 0)
|
||||
return 1;
|
||||
|
||||
if(info.inputs_num != 1)
|
||||
{
|
||||
if(info.inputs_num == 0)
|
||||
cout << "ERROR: missing BSA file\n\n";
|
||||
else
|
||||
cout << "ERROR: more than one BSA file specified\n\n";
|
||||
cmdline_parser_print_help();
|
||||
return 1;
|
||||
}
|
||||
|
||||
// Open file
|
||||
BSAFile bsa;
|
||||
char *arcname = info.inputs[0];
|
||||
try { bsa.open(arcname); }
|
||||
catch(exception &e)
|
||||
{
|
||||
cout << "ERROR reading BSA archive '" << arcname
|
||||
<< "'\nDetails:\n" << e.what() << endl;
|
||||
return 2;
|
||||
}
|
||||
|
||||
if(info.extract_given)
|
||||
{
|
||||
char *file = info.extract_arg;
|
||||
|
||||
if(!bsa.exists(file))
|
||||
{
|
||||
cout << "ERROR: file '" << file << "' not found\n";
|
||||
cout << "In archive: " << arcname << endl;
|
||||
return 3;
|
||||
}
|
||||
|
||||
// Find the base name of the file
|
||||
int pos = strlen(file);
|
||||
while(pos > 0 && file[pos] != '\\') pos--;
|
||||
char *base = file+pos+1;
|
||||
|
||||
// TODO: We might add full directory name extraction later. We
|
||||
// could also allow automatic conversion from / to \ in
|
||||
// parameter file names.
|
||||
|
||||
// Load the file into a memory buffer
|
||||
BufferStream data(bsa.getFile(file));
|
||||
|
||||
// Write the file to disk
|
||||
ofstream out(base, ios::binary);
|
||||
out.write((char*)data.getPtr(), data.size());
|
||||
out.close();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// List all files
|
||||
const BSAFile::FileList &files = bsa.getList();
|
||||
for(int i=0; i<files.size(); i++)
|
||||
{
|
||||
if(info.long_given)
|
||||
{
|
||||
// Long format
|
||||
cout << setw(50) << left << files[i].name;
|
||||
cout << setw(8) << left << dec << files[i].fileSize;
|
||||
cout << "@ 0x" << hex << files[i].offset << endl;
|
||||
}
|
||||
else
|
||||
cout << files[i].name << endl;
|
||||
}
|
||||
|
||||
// Done!
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue