MCPcopy Create free account
hub / github.com/Panzerschrek/Chasm-Reverse / Vfs

Method Vfs

PanzerChasm/vfs.cpp:68–108  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68Vfs::Vfs(
69 const char* archive_file_name,
70 const char* const addon_path )
71 : archive_file_( std::fopen( archive_file_name, "rb" ) )
72 , addon_path_( PrepareAddonPath( addon_path ) )
73{
74 if( archive_file_ == nullptr )
75 {
76 Log::FatalError( "Could not open file \"", archive_file_name, "\"" );
77 return;
78 }
79
80 char header[4];
81 FileRead( archive_file_, header, sizeof(header) );
82 if( std::strncmp( header, "CSid", sizeof(header) ) != 0 )
83 {
84 Log::FatalError( "File \"", archive_file_name, "\" is not \"Chasm: The Rift\" archive" );
85 return;
86 }
87
88 unsigned short files_in_archive_count;
89 FileRead( archive_file_, &files_in_archive_count, sizeof(files_in_archive_count) );
90
91 std::vector<FileInfoPacked> files_info_packed( files_in_archive_count );
92 FileRead( archive_file_, files_info_packed.data(), files_info_packed.size() * sizeof(FileInfoPacked ) );
93
94 virtual_files_.reserve( files_in_archive_count );
95
96 for( const FileInfoPacked& file_info_packed : files_info_packed )
97 {
98 virtual_files_.emplace_back();
99 VirtualFile& file= virtual_files_.back();
100
101 std::memcpy( file.name, file_info_packed.name, file_info_packed.name_length );
102 if( file_info_packed.name_length < sizeof(file.name) )
103 file.name[ file_info_packed.name_length ]= '\0';
104
105 std::memcpy( &file.size , &file_info_packed.size , sizeof(unsigned int) );
106 std::memcpy( &file.offset, &file_info_packed.offset, sizeof(unsigned int) );
107 }
108}
109
110Vfs::~Vfs()
111{

Callers

nothing calls this directly

Calls 2

PrepareAddonPathFunction · 0.85
FileReadFunction · 0.85

Tested by

no test coverage detected