2018-10-24 23:31:26 +11:00
|
|
|
#include "File.h"
|
|
|
|
|
|
|
|
#include <fstream>
|
|
|
|
|
2020-02-10 14:05:04 +11:00
|
|
|
namespace xiv::dat
|
|
|
|
{
|
|
|
|
|
|
|
|
File::File() :
|
|
|
|
_type( FileType::empty )
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
FileType File::get_type() const
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
const std::vector< std::vector< char>>& File::get_data_sections() const
|
|
|
|
{
|
|
|
|
return _data_sections;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::vector< char>>& File::access_data_sections()
|
|
|
|
{
|
|
|
|
return _data_sections;
|
|
|
|
}
|
|
|
|
|
|
|
|
void File::exportToFile( const std::filesystem::path& i_path ) const
|
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
std::ofstream ofs( i_path, std::ios::binary | std::ios::out );
|
|
|
|
|
|
|
|
if( !ofs )
|
2020-02-10 14:05:04 +11:00
|
|
|
{
|
2023-04-26 13:58:41 +02:00
|
|
|
throw std::runtime_error( "Failed to open the output file: " + i_path.string() );
|
2020-02-10 14:05:04 +11:00
|
|
|
}
|
2023-04-26 13:58:41 +02:00
|
|
|
|
|
|
|
for( const auto& data_section : _data_sections )
|
|
|
|
{
|
|
|
|
ofs.write( reinterpret_cast< const char* >( data_section.data() ), static_cast< std::streamsize >( data_section.size() ) );
|
|
|
|
}
|
|
|
|
|
|
|
|
// The file stream will be closed automatically when the ofstream object goes out of scope
|
|
|
|
// ofs.close();
|
2020-02-10 14:05:04 +11:00
|
|
|
}
|
2018-10-24 23:31:26 +11:00
|
|
|
|
|
|
|
}
|