MCPcopy Create free account
hub / github.com/HertzDevil/0CC-FamiTracker / ValidateFile

Method ValidateFile

Source/DocumentFile.cpp:180–208  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

178}
179
180void CDocumentFile::ValidateFile()
181{
182 // Checks if loaded file is valid
183
184 // Check ident string
185 char Buffer[FILE_HEADER_ID.size()] = { };
186 Read(reinterpret_cast<unsigned char *>(Buffer), FILE_HEADER_ID.size()); // // //
187
188 if (array_view<char> {Buffer} != FILE_HEADER_ID)
189 RaiseModuleException("File is not a FamiTracker module");
190
191 // Read file version
192 unsigned char VerBuffer[4] = { }; // // //
193 Read(VerBuffer, std::size(VerBuffer));
194 m_iFileVersion = (VerBuffer[3] << 24) | (VerBuffer[2] << 16) | (VerBuffer[1] << 8) | VerBuffer[0];
195
196 // // // Older file version
197 if (GetFileVersion() < COMPATIBLE_VER)
198 throw CModuleException::WithMessage("FamiTracker module version too old (0x" + conv::from_int_hex(GetFileVersion()) +
199 "), expected 0x" + conv::from_int_hex(COMPATIBLE_VER) + " or above");
200
201 // // // File version is too new
202 if (GetFileVersion() > 0x450u /*FILE_VER*/) // // // 050B
203 throw CModuleException::WithMessage("FamiTracker module version too new (0x" + conv::from_int_hex(GetFileVersion()) +
204 "), expected 0x" + conv::from_int_hex(0x450u) + " or below");
205
206 m_bFileDone = false;
207 m_bIncomplete = false;
208}
209
210unsigned int CDocumentFile::GetFileVersion() const
211{

Callers 1

OpenDocumentMethod · 0.80

Calls 4

sizeFunction · 0.85
GetFileVersionFunction · 0.85
from_int_hexFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected