mirror of
https://github.com/OpenRCT2/OpenRCT2
synced 2025-12-23 15:52:55 +01:00
Move Csg path related functions into their own header (#22004)
This commit is contained in:
@@ -37,6 +37,7 @@
|
|||||||
#include <openrct2/localisation/LocalisationService.h>
|
#include <openrct2/localisation/LocalisationService.h>
|
||||||
#include <openrct2/network/network.h>
|
#include <openrct2/network/network.h>
|
||||||
#include <openrct2/platform/Platform.h>
|
#include <openrct2/platform/Platform.h>
|
||||||
|
#include <openrct2/rct1/Csg.h>
|
||||||
#include <openrct2/ride/RideAudio.h>
|
#include <openrct2/ride/RideAudio.h>
|
||||||
#include <openrct2/scenario/Scenario.h>
|
#include <openrct2/scenario/Scenario.h>
|
||||||
#include <openrct2/scenes/title/TitleScene.h>
|
#include <openrct2/scenes/title/TitleScene.h>
|
||||||
@@ -45,7 +46,9 @@
|
|||||||
#include <openrct2/ui/UiContext.h>
|
#include <openrct2/ui/UiContext.h>
|
||||||
#include <openrct2/util/Util.h>
|
#include <openrct2/util/Util.h>
|
||||||
|
|
||||||
|
using namespace OpenRCT2;
|
||||||
using namespace OpenRCT2::Audio;
|
using namespace OpenRCT2::Audio;
|
||||||
|
|
||||||
namespace OpenRCT2::Ui::Windows
|
namespace OpenRCT2::Ui::Windows
|
||||||
{
|
{
|
||||||
// clang-format off
|
// clang-format off
|
||||||
|
|||||||
@@ -26,7 +26,7 @@
|
|||||||
#include "../network/network.h"
|
#include "../network/network.h"
|
||||||
#include "../paint/VirtualFloor.h"
|
#include "../paint/VirtualFloor.h"
|
||||||
#include "../platform/Platform.h"
|
#include "../platform/Platform.h"
|
||||||
#include "../rct1/Limits.h"
|
#include "../rct1/Csg.h"
|
||||||
#include "../scenario/Scenario.h"
|
#include "../scenario/Scenario.h"
|
||||||
#include "../ui/UiContext.h"
|
#include "../ui/UiContext.h"
|
||||||
#include "../util/Util.h"
|
#include "../util/Util.h"
|
||||||
@@ -944,78 +944,3 @@ bool ConfigFindOrBrowseInstallDirectory()
|
|||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FindCsg1datAtLocation(u8string_view path)
|
|
||||||
{
|
|
||||||
auto checkPath1 = Path::Combine(path, u8"Data", u8"CSG1.DAT");
|
|
||||||
auto checkPath2 = Path::Combine(path, u8"Data", u8"CSG1.1");
|
|
||||||
|
|
||||||
// Since Linux is case sensitive (and macOS sometimes too), make sure we handle case properly.
|
|
||||||
std::string path1result = Path::ResolveCasing(checkPath1);
|
|
||||||
if (!path1result.empty())
|
|
||||||
{
|
|
||||||
return path1result;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string path2result = Path::ResolveCasing(checkPath2);
|
|
||||||
return path2result;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Csg1datPresentAtLocation(u8string_view path)
|
|
||||||
{
|
|
||||||
auto location = FindCsg1datAtLocation(path);
|
|
||||||
return !location.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
u8string FindCsg1idatAtLocation(u8string_view path)
|
|
||||||
{
|
|
||||||
auto result1 = Path::ResolveCasing(Path::Combine(path, u8"Data", u8"CSG1I.DAT"));
|
|
||||||
if (!result1.empty())
|
|
||||||
{
|
|
||||||
return result1;
|
|
||||||
}
|
|
||||||
auto result2 = Path::ResolveCasing(Path::Combine(path, u8"RCTdeluxe_install", u8"Data", u8"CSG1I.DAT"));
|
|
||||||
return result2;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool Csg1idatPresentAtLocation(u8string_view path)
|
|
||||||
{
|
|
||||||
std::string location = FindCsg1idatAtLocation(path);
|
|
||||||
return !location.empty();
|
|
||||||
}
|
|
||||||
|
|
||||||
bool RCT1DataPresentAtLocation(u8string_view path)
|
|
||||||
{
|
|
||||||
return Csg1datPresentAtLocation(path) && Csg1idatPresentAtLocation(path) && CsgAtLocationIsUsable(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CsgIsUsable(const Gx& csg)
|
|
||||||
{
|
|
||||||
return csg.header.total_size == RCT1::Limits::LL_CSG1_DAT_FileSize
|
|
||||||
&& csg.header.num_entries == RCT1::Limits::Num_LL_CSG_Entries;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool CsgAtLocationIsUsable(u8string_view path)
|
|
||||||
{
|
|
||||||
auto csg1HeaderPath = FindCsg1idatAtLocation(path);
|
|
||||||
if (csg1HeaderPath.empty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto csg1DataPath = FindCsg1datAtLocation(path);
|
|
||||||
if (csg1DataPath.empty())
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto fileHeader = FileStream(csg1HeaderPath, FILE_MODE_OPEN);
|
|
||||||
auto fileData = FileStream(csg1DataPath, FILE_MODE_OPEN);
|
|
||||||
size_t fileHeaderSize = fileHeader.GetLength();
|
|
||||||
size_t fileDataSize = fileData.GetLength();
|
|
||||||
|
|
||||||
Gx csg = {};
|
|
||||||
csg.header.num_entries = static_cast<uint32_t>(fileHeaderSize / sizeof(RCTG1Element));
|
|
||||||
csg.header.total_size = static_cast<uint32_t>(fileDataSize);
|
|
||||||
return CsgIsUsable(csg);
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -14,9 +14,6 @@
|
|||||||
#include "ConfigTypes.h"
|
#include "ConfigTypes.h"
|
||||||
|
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <string>
|
|
||||||
|
|
||||||
struct Gx;
|
|
||||||
|
|
||||||
struct GeneralConfiguration
|
struct GeneralConfiguration
|
||||||
{
|
{
|
||||||
@@ -229,11 +226,3 @@ u8string ConfigGetDefaultPath();
|
|||||||
void ConfigSetDefaults();
|
void ConfigSetDefaults();
|
||||||
bool ConfigSaveDefault();
|
bool ConfigSaveDefault();
|
||||||
bool ConfigFindOrBrowseInstallDirectory();
|
bool ConfigFindOrBrowseInstallDirectory();
|
||||||
|
|
||||||
bool RCT1DataPresentAtLocation(u8string_view path);
|
|
||||||
std::string FindCsg1datAtLocation(u8string_view path);
|
|
||||||
bool Csg1datPresentAtLocation(u8string_view path);
|
|
||||||
std::string FindCsg1idatAtLocation(u8string_view path);
|
|
||||||
bool Csg1idatPresentAtLocation(u8string_view path);
|
|
||||||
bool CsgIsUsable(const Gx& csg);
|
|
||||||
bool CsgAtLocationIsUsable(u8string_view path);
|
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
#include "../core/MemoryStream.h"
|
#include "../core/MemoryStream.h"
|
||||||
#include "../core/Path.hpp"
|
#include "../core/Path.hpp"
|
||||||
#include "../platform/Platform.h"
|
#include "../platform/Platform.h"
|
||||||
|
#include "../rct1/Csg.h"
|
||||||
#include "../sprites.h"
|
#include "../sprites.h"
|
||||||
#include "../ui/UiContext.h"
|
#include "../ui/UiContext.h"
|
||||||
#include "../util/Util.h"
|
#include "../util/Util.h"
|
||||||
|
|||||||
@@ -387,6 +387,7 @@
|
|||||||
<ClInclude Include="rct12\SawyerChunk.h" />
|
<ClInclude Include="rct12\SawyerChunk.h" />
|
||||||
<ClInclude Include="rct12\SawyerChunkReader.h" />
|
<ClInclude Include="rct12\SawyerChunkReader.h" />
|
||||||
<ClInclude Include="rct12\SawyerChunkWriter.h" />
|
<ClInclude Include="rct12\SawyerChunkWriter.h" />
|
||||||
|
<ClInclude Include="rct1\Csg.h" />
|
||||||
<ClInclude Include="rct1\Limits.h" />
|
<ClInclude Include="rct1\Limits.h" />
|
||||||
<ClInclude Include="rct1\RCT1.h" />
|
<ClInclude Include="rct1\RCT1.h" />
|
||||||
<ClInclude Include="rct1\Tables.h" />
|
<ClInclude Include="rct1\Tables.h" />
|
||||||
@@ -896,6 +897,7 @@
|
|||||||
<ClCompile Include="rct12\SawyerChunk.cpp" />
|
<ClCompile Include="rct12\SawyerChunk.cpp" />
|
||||||
<ClCompile Include="rct12\SawyerChunkReader.cpp" />
|
<ClCompile Include="rct12\SawyerChunkReader.cpp" />
|
||||||
<ClCompile Include="rct12\SawyerChunkWriter.cpp" />
|
<ClCompile Include="rct12\SawyerChunkWriter.cpp" />
|
||||||
|
<ClCompile Include="rct1\Csg.cpp" />
|
||||||
<ClCompile Include="rct1\S4Importer.cpp" />
|
<ClCompile Include="rct1\S4Importer.cpp" />
|
||||||
<ClCompile Include="rct1\T4Importer.cpp" />
|
<ClCompile Include="rct1\T4Importer.cpp" />
|
||||||
<ClCompile Include="rct1\Tables.cpp" />
|
<ClCompile Include="rct1\Tables.cpp" />
|
||||||
|
|||||||
92
src/openrct2/rct1/Csg.cpp
Normal file
92
src/openrct2/rct1/Csg.cpp
Normal file
@@ -0,0 +1,92 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
||||||
|
*
|
||||||
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#include "Csg.h"
|
||||||
|
|
||||||
|
#include "../core/FileStream.h"
|
||||||
|
#include "../core/Path.hpp"
|
||||||
|
#include "../drawing/Drawing.h"
|
||||||
|
#include "../rct1/Limits.h"
|
||||||
|
|
||||||
|
using namespace OpenRCT2;
|
||||||
|
|
||||||
|
std::string FindCsg1datAtLocation(u8string_view path)
|
||||||
|
{
|
||||||
|
auto checkPath1 = Path::Combine(path, u8"Data", u8"CSG1.DAT");
|
||||||
|
auto checkPath2 = Path::Combine(path, u8"Data", u8"CSG1.1");
|
||||||
|
|
||||||
|
// Since Linux is case sensitive (and macOS sometimes too), make sure we handle case properly.
|
||||||
|
std::string path1result = Path::ResolveCasing(checkPath1);
|
||||||
|
if (!path1result.empty())
|
||||||
|
{
|
||||||
|
return path1result;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string path2result = Path::ResolveCasing(checkPath2);
|
||||||
|
return path2result;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Csg1datPresentAtLocation(u8string_view path)
|
||||||
|
{
|
||||||
|
auto location = FindCsg1datAtLocation(path);
|
||||||
|
return !location.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
u8string FindCsg1idatAtLocation(u8string_view path)
|
||||||
|
{
|
||||||
|
auto result1 = Path::ResolveCasing(Path::Combine(path, u8"Data", u8"CSG1I.DAT"));
|
||||||
|
if (!result1.empty())
|
||||||
|
{
|
||||||
|
return result1;
|
||||||
|
}
|
||||||
|
auto result2 = Path::ResolveCasing(Path::Combine(path, u8"RCTdeluxe_install", u8"Data", u8"CSG1I.DAT"));
|
||||||
|
return result2;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Csg1idatPresentAtLocation(u8string_view path)
|
||||||
|
{
|
||||||
|
std::string location = FindCsg1idatAtLocation(path);
|
||||||
|
return !location.empty();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool RCT1DataPresentAtLocation(u8string_view path)
|
||||||
|
{
|
||||||
|
return Csg1datPresentAtLocation(path) && Csg1idatPresentAtLocation(path) && CsgAtLocationIsUsable(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CsgIsUsable(const Gx& csg)
|
||||||
|
{
|
||||||
|
return csg.header.total_size == RCT1::Limits::LL_CSG1_DAT_FileSize
|
||||||
|
&& csg.header.num_entries == RCT1::Limits::Num_LL_CSG_Entries;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CsgAtLocationIsUsable(u8string_view path)
|
||||||
|
{
|
||||||
|
auto csg1HeaderPath = FindCsg1idatAtLocation(path);
|
||||||
|
if (csg1HeaderPath.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto csg1DataPath = FindCsg1datAtLocation(path);
|
||||||
|
if (csg1DataPath.empty())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fileHeader = FileStream(csg1HeaderPath, FILE_MODE_OPEN);
|
||||||
|
auto fileData = FileStream(csg1DataPath, FILE_MODE_OPEN);
|
||||||
|
size_t fileHeaderSize = fileHeader.GetLength();
|
||||||
|
size_t fileDataSize = fileData.GetLength();
|
||||||
|
|
||||||
|
Gx csg = {};
|
||||||
|
csg.header.num_entries = static_cast<uint32_t>(fileHeaderSize / sizeof(RCTG1Element));
|
||||||
|
csg.header.total_size = static_cast<uint32_t>(fileDataSize);
|
||||||
|
return CsgIsUsable(csg);
|
||||||
|
}
|
||||||
24
src/openrct2/rct1/Csg.h
Normal file
24
src/openrct2/rct1/Csg.h
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
/*****************************************************************************
|
||||||
|
* Copyright (c) 2014-2024 OpenRCT2 developers
|
||||||
|
*
|
||||||
|
* For a complete list of all authors, please refer to contributors.md
|
||||||
|
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
|
||||||
|
*
|
||||||
|
* OpenRCT2 is licensed under the GNU General Public License version 3.
|
||||||
|
*****************************************************************************/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "../core/String.hpp"
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
struct Gx;
|
||||||
|
|
||||||
|
bool RCT1DataPresentAtLocation(u8string_view path);
|
||||||
|
std::string FindCsg1datAtLocation(u8string_view path);
|
||||||
|
bool Csg1datPresentAtLocation(u8string_view path);
|
||||||
|
std::string FindCsg1idatAtLocation(u8string_view path);
|
||||||
|
bool Csg1idatPresentAtLocation(u8string_view path);
|
||||||
|
bool CsgIsUsable(const Gx& csg);
|
||||||
|
bool CsgAtLocationIsUsable(u8string_view path);
|
||||||
Reference in New Issue
Block a user