@@ -22,44 +22,6 @@ struct FileInfoPacked
2222};
2323#pragma pack(pop)
2424
25- // Own replacement for nonstandard strncasecmp
26- static bool StringEquals ( const char * const s0, const char * const s1, const unsigned int max_length )
27- {
28- unsigned int i= 0 ;
29- while ( s0[i] != ' \0 ' && s1[i] != ' \0 ' && i < max_length )
30- {
31- if ( std::tolower ( s0[i] ) != std::tolower ( s1[i] ) )
32- return false ;
33- i++;
34- }
35-
36- return i == max_length || s0[i] == s1[i];
37- }
38-
39- static std::string ToUpper ( const std::string& s )
40- {
41- std::string r= s;
42- for ( char & c : r )
43- c= std::toupper (c);
44- return r;
45- }
46-
47- static const char * ExtractFileName ( const char * const file_path )
48- {
49- const char * file_name_pos= file_path;
50-
51- const char * str= file_path;
52- while ( *str != ' \0 ' )
53- {
54- if ( *str == ' /' || *str == ' \\ ' )
55- file_name_pos= str + 1u ;
56-
57- str++;
58- }
59-
60- return file_name_pos;
61- }
62-
6325static std::string PrepareAddonPath ( const char * const addon_path )
6426{
6527 if ( addon_path == nullptr )
@@ -115,36 +77,38 @@ Vfs::Vfs(
11577 : archive_file_( std::fopen( archive_file_name, " rb" ) )
11678 , addon_path_( PrepareAddonPath( addon_path ) )
11779{
118- if ( archive_file_ = = nullptr )
80+ if ( archive_file_ ! = nullptr )
11981 {
120- Log::FatalError ( " Could not open file \" " , archive_file_name, " \" " );
121- return ;
122- }
82+ char header[4 ];
83+ FileRead ( archive_file_, header, sizeof (header) );
84+ if ( std::strncmp ( header, " CSid" , sizeof (header) ) != 0 )
85+ {
86+ Log::FatalError ( " File \" " , archive_file_name, " \" is not \" Chasm: The Rift\" archive" );
87+ return ;
88+ }
12389
124- char header[4 ];
125- FileRead ( archive_file_, header, sizeof (header) );
126- if ( std::strncmp ( header, " CSid" , sizeof (header) ) != 0 )
127- {
128- Log::FatalError ( " File \" " , archive_file_name, " \" is not \" Chasm: The Rift\" archive" );
129- return ;
130- }
90+ unsigned short files_in_archive_count;
91+ FileRead ( archive_file_, &files_in_archive_count, sizeof (files_in_archive_count) );
13192
132- unsigned short files_in_archive_count;
133- FileRead ( archive_file_, &files_in_archive_count, sizeof (files_in_archive_count ) );
93+ std::vector<FileInfoPacked> files_info_packed ( files_in_archive_count ) ;
94+ FileRead ( archive_file_, files_info_packed. data (), files_info_packed. size () * sizeof (FileInfoPacked ) );
13495
135- std::vector<FileInfoPacked> files_info_packed ( files_in_archive_count );
136- FileRead ( archive_file_, files_info_packed.data (), files_info_packed.size () * sizeof (FileInfoPacked ) );
96+ virtual_files_.reserve ( files_in_archive_count );
13797
138- virtual_files_.reserve ( files_in_archive_count );
98+ for ( const FileInfoPacked& file_info_packed : files_info_packed )
99+ {
100+ VirtualFile file;
101+ std::memcpy ( &file.size , &file_info_packed.size , sizeof (unsigned int ) );
102+ std::memcpy ( &file.offset , &file_info_packed.offset , sizeof (unsigned int ) );
139103
140- for ( const FileInfoPacked& file_info_packed : files_info_packed )
104+ virtual_files_[ VirtualFileName ( file_info_packed.name , file_info_packed.name_length ) ]= file;
105+ }
106+ } else if ( addon_path_.empty () )
141107 {
142- VirtualFile file;
143- std::memcpy ( &file.size , &file_info_packed.size , sizeof (unsigned int ) );
144- std::memcpy ( &file.offset , &file_info_packed.offset , sizeof (unsigned int ) );
145-
146- virtual_files_[ VirtualFileName ( file_info_packed.name , file_info_packed.name_length ) ]= file;
108+ Log::FatalError ( " Could not open file \" " , archive_file_name, " \" " );
147109 }
110+
111+ return ;
148112}
149113
150114Vfs::~Vfs ()
0 commit comments