mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2026-01-23 06:44:38 +01:00
clang-format root
This commit is contained in:
committed by
Hielke Morsink
parent
9c022606f1
commit
c57bbca827
@@ -7,33 +7,33 @@
|
||||
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||
*****************************************************************************/
|
||||
|
||||
#include "FileClassifier.h"
|
||||
|
||||
#include "core/Console.hpp"
|
||||
#include "core/FileStream.hpp"
|
||||
#include "core/Path.hpp"
|
||||
#include "FileClassifier.h"
|
||||
#include "rct12/SawyerChunkReader.h"
|
||||
|
||||
#include "scenario/Scenario.h"
|
||||
#include "util/SawyerCoding.h"
|
||||
|
||||
static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result);
|
||||
static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result);
|
||||
static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result);
|
||||
static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result);
|
||||
static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result);
|
||||
|
||||
bool TryClassifyFile(const std::string &path, ClassifiedFileInfo * result)
|
||||
bool TryClassifyFile(const std::string& path, ClassifiedFileInfo* result)
|
||||
{
|
||||
try
|
||||
{
|
||||
auto fs = FileStream(path, FILE_MODE_OPEN);
|
||||
return TryClassifyFile(&fs, result);
|
||||
}
|
||||
catch (const std::exception &)
|
||||
catch (const std::exception&)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result)
|
||||
bool TryClassifyFile(IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
// TODO Currently track designs get classified as SC4s because they use the
|
||||
// same checksum algorithm. The only way after to tell the difference
|
||||
@@ -61,7 +61,7 @@ bool TryClassifyFile(IStream * stream, ClassifiedFileInfo * result)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
|
||||
static bool TryClassifyAsS6(IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
@@ -80,7 +80,7 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
|
||||
result->Version = s6Header.version;
|
||||
success = true;
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
// Exceptions are likely to occur if file is not S6 format
|
||||
log_verbose(e.what());
|
||||
@@ -89,14 +89,14 @@ static bool TryClassifyAsS6(IStream * stream, ClassifiedFileInfo * result)
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
|
||||
static bool TryClassifyAsS4(IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
try
|
||||
{
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
auto deleter_lambda = [dataLength](uint8_t * ptr) { Memory::FreeArray(ptr, dataLength); };
|
||||
auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); };
|
||||
std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda);
|
||||
stream->SetPosition(originalPosition);
|
||||
int32_t fileTypeVersion = sawyercoding_detect_file_type(data.get(), dataLength);
|
||||
@@ -117,7 +117,7 @@ static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
catch (const std::exception &e)
|
||||
catch (const std::exception& e)
|
||||
{
|
||||
Console::Error::WriteLine(e.what());
|
||||
}
|
||||
@@ -126,20 +126,21 @@ static bool TryClassifyAsS4(IStream * stream, ClassifiedFileInfo * result)
|
||||
return success;
|
||||
}
|
||||
|
||||
static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result)
|
||||
static bool TryClassifyAsTD4_TD6(IStream* stream, ClassifiedFileInfo* result)
|
||||
{
|
||||
bool success = false;
|
||||
uint64_t originalPosition = stream->GetPosition();
|
||||
try
|
||||
{
|
||||
size_t dataLength = (size_t)stream->GetLength();
|
||||
auto deleter_lambda = [dataLength](uint8_t * ptr) { Memory::FreeArray(ptr, dataLength); };
|
||||
auto deleter_lambda = [dataLength](uint8_t* ptr) { Memory::FreeArray(ptr, dataLength); };
|
||||
std::unique_ptr<uint8_t, decltype(deleter_lambda)> data(stream->ReadArray<uint8_t>(dataLength), deleter_lambda);
|
||||
stream->SetPosition(originalPosition);
|
||||
|
||||
if (sawyercoding_validate_track_checksum(data.get(), dataLength))
|
||||
{
|
||||
std::unique_ptr<uint8_t, decltype(&Memory::Free<uint8_t>)> td6data(Memory::Allocate<uint8_t>(0x10000), &Memory::Free<uint8_t>);
|
||||
std::unique_ptr<uint8_t, decltype(&Memory::Free<uint8_t>)> td6data(
|
||||
Memory::Allocate<uint8_t>(0x10000), &Memory::Free<uint8_t>);
|
||||
size_t td6len = sawyercoding_decode_td6(data.get(), td6data.get(), dataLength);
|
||||
if (td6data != nullptr && td6len >= 8)
|
||||
{
|
||||
@@ -161,16 +162,22 @@ static bool TryClassifyAsTD4_TD6(IStream * stream, ClassifiedFileInfo * result)
|
||||
return success;
|
||||
}
|
||||
|
||||
uint32_t get_file_extension_type(const utf8 * path)
|
||||
uint32_t get_file_extension_type(const utf8* path)
|
||||
{
|
||||
auto extension = Path::GetExtension(path);
|
||||
if (String::Equals(extension, ".dat", true)) return FILE_EXTENSION_DAT;
|
||||
if (String::Equals(extension, ".sc4", true)) return FILE_EXTENSION_SC4;
|
||||
if (String::Equals(extension, ".sv4", true)) return FILE_EXTENSION_SV4;
|
||||
if (String::Equals(extension, ".td4", true)) return FILE_EXTENSION_TD4;
|
||||
if (String::Equals(extension, ".sc6", true)) return FILE_EXTENSION_SC6;
|
||||
if (String::Equals(extension, ".sv6", true)) return FILE_EXTENSION_SV6;
|
||||
if (String::Equals(extension, ".td6", true)) return FILE_EXTENSION_TD6;
|
||||
if (String::Equals(extension, ".dat", true))
|
||||
return FILE_EXTENSION_DAT;
|
||||
if (String::Equals(extension, ".sc4", true))
|
||||
return FILE_EXTENSION_SC4;
|
||||
if (String::Equals(extension, ".sv4", true))
|
||||
return FILE_EXTENSION_SV4;
|
||||
if (String::Equals(extension, ".td4", true))
|
||||
return FILE_EXTENSION_TD4;
|
||||
if (String::Equals(extension, ".sc6", true))
|
||||
return FILE_EXTENSION_SC6;
|
||||
if (String::Equals(extension, ".sv6", true))
|
||||
return FILE_EXTENSION_SV6;
|
||||
if (String::Equals(extension, ".td6", true))
|
||||
return FILE_EXTENSION_TD6;
|
||||
return FILE_EXTENSION_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user