mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-15 19:13:07 +01:00
add missing exception handling.
Every TryClassifyAsX()-method now has exceptionhandling.
This commit is contained in:
committed by
Richard Jenkins
parent
a5ae503f0a
commit
51bbfb084f
@@ -95,57 +95,71 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
|
||||
|
||||
static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64 originalPosition = stream->GetPosition();
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
uint8 * data = stream->ReadArray<uint8>(dataLength);
|
||||
try
|
||||
{
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
uint8 * data = stream->ReadArray<uint8>(dataLength);
|
||||
stream->SetPosition(originalPosition);
|
||||
sint32 fileTypeVersion = sawyercoding_detect_file_type(data, dataLength);
|
||||
Memory::Free(data);
|
||||
|
||||
sint32 type = fileTypeVersion & FILE_TYPE_MASK;
|
||||
sint32 version = fileTypeVersion & FILE_VERSION_MASK;
|
||||
|
||||
if (type == FILE_TYPE_SV4)
|
||||
{
|
||||
result->Type = FILE_TYPE::SAVED_GAME;
|
||||
result->Version = version;
|
||||
success = true;
|
||||
}
|
||||
else if (type == FILE_TYPE_SC4)
|
||||
{
|
||||
result->Type = FILE_TYPE::SCENARIO;
|
||||
result->Version = version;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
|
||||
stream->SetPosition(originalPosition);
|
||||
sint32 fileTypeVersion = sawyercoding_detect_file_type(data, dataLength);
|
||||
Memory::Free(data);
|
||||
|
||||
sint32 type = fileTypeVersion & FILE_TYPE_MASK;
|
||||
sint32 version = fileTypeVersion & FILE_VERSION_MASK;
|
||||
|
||||
if (type == FILE_TYPE_SV4)
|
||||
{
|
||||
result->Type = FILE_TYPE::SAVED_GAME;
|
||||
result->Version = version;
|
||||
return true;
|
||||
}
|
||||
else if (type == FILE_TYPE_SC4)
|
||||
{
|
||||
result->Type = FILE_TYPE::SCENARIO;
|
||||
result->Version = version;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64 originalPosition = stream->GetPosition();
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
uint8 * data = stream->ReadArray<uint8>(dataLength);
|
||||
stream->SetPosition(originalPosition);
|
||||
|
||||
if (sawyercoding_validate_track_checksum(data, dataLength))
|
||||
try
|
||||
{
|
||||
uint8 * td6data = Memory::Allocate<uint8>(0x10000);
|
||||
size_t td6len = sawyercoding_decode_td6(data, td6data, dataLength);
|
||||
if (td6data != nullptr && td6len >= 8)
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
uint8 * data = stream->ReadArray<uint8>(dataLength);
|
||||
stream->SetPosition(originalPosition);
|
||||
|
||||
if (sawyercoding_validate_track_checksum(data, dataLength))
|
||||
{
|
||||
uint8 version = (td6data[7] >> 2) & 3;
|
||||
if (version <= 2)
|
||||
uint8 * td6data = Memory::Allocate<uint8>(0x10000);
|
||||
size_t td6len = sawyercoding_decode_td6(data, td6data, dataLength);
|
||||
if (td6data != nullptr && td6len >= 8)
|
||||
{
|
||||
result->Type = FILE_TYPE::TRACK_DESIGN;
|
||||
result->Version = version;
|
||||
success = true;
|
||||
uint8 version = (td6data[7] >> 2) & 3;
|
||||
if (version <= 2)
|
||||
{
|
||||
result->Type = FILE_TYPE::TRACK_DESIGN;
|
||||
result->Version = version;
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
Memory::Free(td6data);
|
||||
}
|
||||
Memory::Free(td6data);
|
||||
Memory::Free(data);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
Memory::Free(data);
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user