1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2025-12-23 15:52:55 +01:00

Use u8string for custom paths

This commit is contained in:
Michael Steenbeek
2022-01-27 14:21:46 +01:00
committed by GitHub
parent 2c8c940caa
commit 149b164ee8
10 changed files with 45 additions and 54 deletions

View File

@@ -770,7 +770,7 @@ namespace OpenRCT2
std::string GetOrPromptRCT2Path()
{
auto result = std::string();
if (String::IsNullOrEmpty(gCustomRCT2DataPath))
if (gCustomRCT2DataPath.empty())
{
// Check install directory
if (gConfigGeneral.rct2_path.empty() || !Platform::OriginalGameDataExists(gConfigGeneral.rct2_path))
@@ -786,11 +786,11 @@ namespace OpenRCT2
return std::string();
}
}
result = std::string(gConfigGeneral.rct2_path);
result = gConfigGeneral.rct2_path;
}
else
{
result = std::string(gCustomRCT2DataPath);
result = gCustomRCT2DataPath;
}
return result;
}
@@ -906,7 +906,7 @@ namespace OpenRCT2
gNetworkStartAddress = gConfigNetwork.listen_address;
}
if (String::IsNullOrEmpty(gCustomPassword))
if (gCustomPassword.empty())
{
_network.SetPassword(gConfigNetwork.default_password.c_str());
}

View File

@@ -775,7 +775,7 @@ void start_silent_record()
{
OpenRCT2::ReplayRecordInfo info;
replayManager->GetCurrentReplayInfo(info);
safe_strcpy(gSilentRecordingName, info.FilePath.c_str(), MAX_PATH);
gSilentRecordingName = info.FilePath;
const char* logFmt = "Silent replay recording started: (%s) %s\n";
Console::WriteLine(logFmt, info.Name.c_str(), info.FilePath.c_str());

View File

@@ -11,12 +11,12 @@
StartupAction gOpenRCT2StartupAction = StartupAction::Title;
utf8 gOpenRCT2StartupActionPath[512] = { 0 };
utf8 gCustomUserDataPath[MAX_PATH] = { 0 };
utf8 gCustomOpenRCT2DataPath[MAX_PATH] = { 0 };
utf8 gCustomRCT1DataPath[MAX_PATH] = { 0 };
utf8 gCustomRCT2DataPath[MAX_PATH] = { 0 };
utf8 gCustomPassword[MAX_PATH] = { 0 };
utf8 gSilentRecordingName[MAX_PATH] = { 0 };
u8string gCustomUserDataPath = {};
u8string gCustomOpenRCT2DataPath = {};
u8string gCustomRCT1DataPath = {};
u8string gCustomRCT2DataPath = {};
u8string gCustomPassword = {};
u8string gSilentRecordingName = {};
bool gOpenRCT2Headless = false;
bool gOpenRCT2NoGraphics = false;

View File

@@ -39,16 +39,16 @@ enum
extern StartupAction gOpenRCT2StartupAction;
extern utf8 gOpenRCT2StartupActionPath[512];
extern utf8 gCustomUserDataPath[MAX_PATH];
extern utf8 gCustomOpenRCT2DataPath[MAX_PATH];
extern utf8 gCustomRCT1DataPath[MAX_PATH];
extern utf8 gCustomRCT2DataPath[MAX_PATH];
extern utf8 gCustomPassword[MAX_PATH];
extern u8string gCustomUserDataPath;
extern u8string gCustomOpenRCT2DataPath;
extern u8string gCustomRCT1DataPath;
extern u8string gCustomRCT2DataPath;
extern u8string gCustomPassword;
extern bool gOpenRCT2Headless;
extern bool gOpenRCT2NoGraphics;
extern bool gOpenRCT2ShowChangelog;
extern bool gOpenRCT2SilentBreakpad;
extern utf8 gSilentRecordingName[MAX_PATH];
extern u8string gSilentRecordingName;
#ifndef DISABLE_NETWORK
extern int32_t gNetworkStart;

View File

@@ -135,19 +135,19 @@ std::unique_ptr<IPlatformEnvironment> OpenRCT2::CreatePlatformEnvironment()
basePaths[static_cast<size_t>(DIRBASE::DOCUMENTATION)] = Platform::GetDocsPath();
// Override paths that have been specified via the command line
if (!String::IsNullOrEmpty(gCustomRCT1DataPath))
if (!gCustomRCT1DataPath.empty())
{
basePaths[static_cast<size_t>(DIRBASE::RCT1)] = gCustomRCT1DataPath;
}
if (!String::IsNullOrEmpty(gCustomRCT2DataPath))
if (!gCustomRCT2DataPath.empty())
{
basePaths[static_cast<size_t>(DIRBASE::RCT2)] = gCustomRCT2DataPath;
}
if (!String::IsNullOrEmpty(gCustomOpenRCT2DataPath))
if (!gCustomOpenRCT2DataPath.empty())
{
basePaths[static_cast<size_t>(DIRBASE::OPENRCT2)] = gCustomOpenRCT2DataPath;
}
if (!String::IsNullOrEmpty(gCustomUserDataPath))
if (!gCustomUserDataPath.empty())
{
basePaths[static_cast<size_t>(DIRBASE::USER)] = gCustomUserDataPath;
basePaths[static_cast<size_t>(DIRBASE::CONFIG)] = gCustomUserDataPath;
@@ -168,11 +168,11 @@ std::unique_ptr<IPlatformEnvironment> OpenRCT2::CreatePlatformEnvironment()
{
config_save(configPath.c_str());
}
if (String::IsNullOrEmpty(gCustomRCT1DataPath))
if (gCustomRCT1DataPath.empty())
{
env->SetBasePath(DIRBASE::RCT1, String::ToStd(gConfigGeneral.rct1_path));
}
if (String::IsNullOrEmpty(gCustomRCT2DataPath))
if (gCustomRCT2DataPath.empty())
{
env->SetBasePath(DIRBASE::RCT2, gConfigGeneral.rct2_path);
}

View File

@@ -486,7 +486,7 @@ namespace CommandLine
*(static_cast<float*>(option->OutAddress)) = static_cast<float>(atof(valueString));
return true;
case CMDLINE_TYPE_STRING:
*(static_cast<utf8**>(option->OutAddress)) = String::Duplicate(valueString);
*(static_cast<u8string*>(option->OutAddress)) = u8string(valueString);
return true;
default:
Console::Error::WriteLine("Unknown CMDLINE_TYPE for: %s", option->LongName);

View File

@@ -54,11 +54,11 @@ static bool _all = false;
static bool _about = false;
static bool _verbose = false;
static bool _headless = false;
static utf8* _password = nullptr;
static utf8* _userDataPath = nullptr;
static utf8* _openrct2DataPath = nullptr;
static utf8* _rct1DataPath = nullptr;
static utf8* _rct2DataPath = nullptr;
static u8string _password = {};
static u8string _userDataPath = {};
static u8string _openrct2DataPath = {};
static u8string _rct1DataPath = {};
static u8string _rct2DataPath = {};
static bool _silentBreakpad = false;
// clang-format off
@@ -199,36 +199,29 @@ exitcode_t CommandLine::HandleCommandDefault()
gOpenRCT2NoGraphics = _headless;
gOpenRCT2SilentBreakpad = _silentBreakpad || _headless;
if (_userDataPath != nullptr)
if (!_userDataPath.empty())
{
const auto absolutePath = Path::GetAbsolute(_userDataPath);
String::Set(gCustomUserDataPath, std::size(gCustomUserDataPath), absolutePath.c_str());
Memory::Free(_userDataPath);
gCustomUserDataPath = Path::GetAbsolute(_userDataPath);
}
if (_openrct2DataPath != nullptr)
if (!_openrct2DataPath.empty())
{
const auto absolutePath = Path::GetAbsolute(_openrct2DataPath);
String::Set(gCustomOpenRCT2DataPath, std::size(gCustomOpenRCT2DataPath), absolutePath.c_str());
Memory::Free(_openrct2DataPath);
gCustomOpenRCT2DataPath = Path::GetAbsolute(_openrct2DataPath);
}
if (_rct1DataPath != nullptr)
if (!_rct1DataPath.empty())
{
String::Set(gCustomRCT1DataPath, std::size(gCustomRCT1DataPath), _rct1DataPath);
Memory::Free(_rct1DataPath);
gCustomRCT1DataPath = _rct1DataPath;
}
if (_rct2DataPath != nullptr)
if (!_rct2DataPath.empty())
{
String::Set(gCustomRCT2DataPath, std::size(gCustomRCT2DataPath), _rct2DataPath);
Memory::Free(_rct2DataPath);
gCustomRCT2DataPath = _rct2DataPath;
}
if (_password != nullptr)
if (!_password.empty())
{
String::Set(gCustomPassword, std::size(gCustomPassword), _password);
Memory::Free(_password);
gCustomPassword = _password;
}
return result;

View File

@@ -828,9 +828,9 @@ void NetworkBase::KickPlayer(int32_t playerId)
}
}
void NetworkBase::SetPassword(const char* password)
void NetworkBase::SetPassword(u8string_view password)
{
_password = password == nullptr ? "" : password;
_password = password;
}
void NetworkBase::ServerClientDisconnected()
@@ -2170,8 +2170,7 @@ void NetworkBase::Client_Handle_TOKEN(NetworkConnection& connection, NetworkPack
// when process dump gets collected at some point in future.
_key.Unload();
const char* password = String::IsNullOrEmpty(gCustomPassword) ? "" : gCustomPassword;
Client_Send_AUTH(gConfigNetwork.player_name.c_str(), password, pubkey.c_str(), signature);
Client_Send_AUTH(gConfigNetwork.player_name.c_str(), gCustomPassword.c_str(), pubkey.c_str(), signature);
}
void NetworkBase::Server_Handle_REQUEST_GAMESTATE(NetworkConnection& connection, NetworkPacket& packet)

View File

@@ -41,7 +41,7 @@ public: // Common
std::vector<std::unique_ptr<NetworkGroup>>::iterator GetGroupIteratorByID(uint8_t id);
NetworkPlayer* GetPlayerByID(uint8_t id);
NetworkGroup* GetGroupByID(uint8_t id);
void SetPassword(const char* password);
void SetPassword(u8string_view password);
uint8_t GetDefaultGroup();
std::string BeginLog(const std::string& directory, const std::string& midName, const std::string& filenameFormat);
void AppendLog(std::ostream& fs, std::string_view s);

View File

@@ -89,10 +89,9 @@ namespace Platform
std::string GetInstallPath()
{
// 1. Try command line argument
auto path = std::string(gCustomOpenRCT2DataPath);
if (!path.empty())
if (!gCustomOpenRCT2DataPath.empty())
{
return Path::GetAbsolute(path);
return Path::GetAbsolute(gCustomOpenRCT2DataPath);
}
// 2. Try {${exeDir},${cwd},/}/{data,standard system app directories}
// exeDir should come first to allow installing into build dir