Properly use utf8 strings where expected

This commit is contained in:
Hielke Morsink 2022-02-12 21:42:55 +01:00
parent 1f83fa417c
commit 55c71b0c74
No known key found for this signature in database
GPG Key ID: FE0B343DF883E7F2
4 changed files with 18 additions and 17 deletions

View File

@ -344,34 +344,34 @@ static void WindowLoadsaveResize(rct_window* w)
static u8string Browse(bool isSave)
{
OpenRCT2::Ui::FileDialogDesc desc = {};
u8string extension = "";
u8string extension{};
auto fileType = FileExtension::Unknown;
rct_string_id title = STR_NONE;
switch (_type & 0x0E)
{
case LOADSAVETYPE_GAME:
extension = ".park";
extension = u8".park";
fileType = FileExtension::PARK;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_GAME : STR_FILE_DIALOG_TITLE_LOAD_GAME;
desc.Filters.emplace_back(language_get_string(STR_OPENRCT2_SAVED_GAME), GetFilterPatternByType(_type, isSave));
break;
case LOADSAVETYPE_LANDSCAPE:
extension = ".park";
extension = u8".park";
fileType = FileExtension::PARK;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_LANDSCAPE : STR_FILE_DIALOG_TITLE_LOAD_LANDSCAPE;
desc.Filters.emplace_back(language_get_string(STR_OPENRCT2_LANDSCAPE_FILE), GetFilterPatternByType(_type, isSave));
break;
case LOADSAVETYPE_SCENARIO:
extension = ".park";
extension = u8".park";
fileType = FileExtension::PARK;
title = STR_FILE_DIALOG_TITLE_SAVE_SCENARIO;
desc.Filters.emplace_back(language_get_string(STR_OPENRCT2_SCENARIO_FILE), GetFilterPatternByType(_type, isSave));
break;
case LOADSAVETYPE_TRACK:
extension = ".td6";
extension = u8".td6";
fileType = FileExtension::TD6;
title = isSave ? STR_FILE_DIALOG_TITLE_SAVE_TRACK : STR_FILE_DIALOG_TITLE_INSTALL_NEW_TRACK_DESIGN;
desc.Filters.emplace_back(

View File

@ -20,7 +20,7 @@ using namespace OpenRCT2;
class PlatformEnvironment final : public IPlatformEnvironment
{
private:
std::string _basePath[DIRBASE_COUNT];
u8string _basePath[DIRBASE_COUNT];
public:
explicit PlatformEnvironment(DIRBASE_VALUES basePaths)
@ -31,12 +31,12 @@ public:
}
}
std::string GetDirectoryPath(DIRBASE base) const override
u8string GetDirectoryPath(DIRBASE base) const override
{
return _basePath[static_cast<size_t>(base)];
}
std::string GetDirectoryPath(DIRBASE base, DIRID did) const override
u8string GetDirectoryPath(DIRBASE base, DIRID did) const override
{
auto basePath = GetDirectoryPath(base);
const utf8* directoryName;
@ -57,7 +57,7 @@ public:
return Path::Combine(basePath, directoryName);
}
std::string GetFilePath(PATHID pathid) const override
u8string GetFilePath(PATHID pathid) const override
{
auto dirbase = GetDefaultBaseDirectory(pathid);
auto basePath = GetDirectoryPath(dirbase);
@ -65,7 +65,7 @@ public:
return Path::Combine(basePath, fileName);
}
void SetBasePath(DIRBASE base, const std::string& path) override
void SetBasePath(DIRBASE base, u8string_view path) override
{
_basePath[static_cast<size_t>(base)] = path;
}

View File

@ -10,6 +10,7 @@
#pragma once
#include "common.h"
#include "core/String.hpp"
#include <memory>
#include <string>
@ -27,7 +28,7 @@ namespace OpenRCT2
DOCUMENTATION, // Base directory for OpenRCT2 doc files.
};
constexpr size_t DIRBASE_COUNT = 7;
using DIRBASE_VALUES = std::string[DIRBASE_COUNT];
using DIRBASE_VALUES = u8string[DIRBASE_COUNT];
enum class DIRID
{
@ -78,10 +79,10 @@ namespace OpenRCT2
{
virtual ~IPlatformEnvironment() = default;
virtual std::string GetDirectoryPath(DIRBASE base) const abstract;
virtual std::string GetDirectoryPath(DIRBASE base, DIRID did) const abstract;
virtual std::string GetFilePath(PATHID pathid) const abstract;
virtual void SetBasePath(DIRBASE base, const std::string& path) abstract;
virtual u8string GetDirectoryPath(DIRBASE base) const abstract;
virtual u8string GetDirectoryPath(DIRBASE base, DIRID did) const abstract;
virtual u8string GetFilePath(PATHID pathid) const abstract;
virtual void SetBasePath(DIRBASE base, u8string_view path) abstract;
};
[[nodiscard]] std::unique_ptr<IPlatformEnvironment> CreatePlatformEnvironment(DIRBASE_VALUES basePaths);

View File

@ -937,7 +937,7 @@ void NetworkBase::SaveGroups()
if (GetMode() == NETWORK_MODE_SERVER)
{
auto env = GetContext().GetPlatformEnvironment();
auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::USER), "groups.json");
auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::USER), u8"groups.json");
json_t jsonGroups = json_t::array();
for (auto& group : group_list)
@ -997,7 +997,7 @@ void NetworkBase::LoadGroups()
group_list.clear();
auto env = GetContext().GetPlatformEnvironment();
auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::USER), "groups.json");
auto path = Path::Combine(env->GetDirectoryPath(DIRBASE::USER), u8"groups.json");
json_t jsonGroupConfig;
if (File::Exists(path))