Skip to content

Commit ea663b8

Browse files
committed
Fix remaining UTF-8 issues
Addendum for commit af30d18
1 parent ca04b07 commit ea663b8

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

Client/core/CFilePathTranslator.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ void CFilePathTranslator::GetCurrentWorkingDirectory(std::string& WorkingDirecto
8080

8181
void CFilePathTranslator::GetGTARootDirectory(std::string& ModuleRootDirOut)
8282
{
83-
ModuleRootDirOut = g_gtaDirectory.string();
83+
ModuleRootDirOut = g_gtaDirectory.u8string();
8484
}
8585

8686
void CFilePathTranslator::GetMTASARootDirectory(std::string& InstallRootDirOut)

Client/loader/CInstallManager.cpp

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -655,13 +655,13 @@ SString CInstallManager::_PrepareLaunchLocation()
655655
if (fs::is_regular_file(sourcePath, ec))
656656
{
657657
SString strMessage(_("MTA:SA cannot launch because copying a file failed:"));
658-
strMessage += "\n\n" + targetPath.string();
658+
strMessage += "\n\n" + targetPath.u8string();
659659
BrowseToSolution("copy-files", ASK_GO_ONLINE, strMessage);
660660
}
661661
else
662662
{
663663
SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:"));
664-
strMessage += "\n\n" + sourcePath.string();
664+
strMessage += "\n\n" + sourcePath.u8string();
665665
BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage);
666666
}
667667

@@ -693,15 +693,15 @@ SString CInstallManager::_ProcessGtaPatchCheck()
693693
if (!FileGenerator::IsPatchBase(patchBasePath))
694694
{
695695
SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:"));
696-
strMessage += "\n\n" + patchBasePath.string();
696+
strMessage += "\n\n" + patchBasePath.u8string();
697697
BrowseToSolution("gengta_pakfiles", ASK_GO_ONLINE, strMessage);
698698
return "quit";
699699
}
700700

701701
if (!FileGenerator::IsPatchDiff(patchDiffPath))
702702
{
703703
SString strMessage(_("MTA:SA cannot launch because an MTA:SA file is incorrect or missing:"));
704-
strMessage += "\n\n" + patchDiffPath.string();
704+
strMessage += "\n\n" + patchDiffPath.u8string();
705705
BrowseToSolution("mta-datafiles-missing", ASK_GO_ONLINE, strMessage);
706706
return "quit";
707707
}
@@ -771,7 +771,7 @@ SString CInstallManager::_ProcessGtaDllCheck()
771771
if (isAdmin)
772772
{
773773
SString strMessage(_("MTA:SA cannot launch because a GTA:SA file is incorrect or missing:"));
774-
strMessage += "\n\n" + dependecyPath.string();
774+
strMessage += "\n\n" + dependecyPath.u8string();
775775
BrowseToSolution(SString("gendep_error&name=%s", dependency.fileName), ASK_GO_ONLINE, strMessage);
776776
return "quit";
777777
}
@@ -826,7 +826,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
826826
if (isAdmin)
827827
{
828828
SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is incorrect or missing:"));
829-
strMessage += "\n\n" + gtaExePath.string();
829+
strMessage += "\n\n" + gtaExePath.u8string();
830830
strMessage +=
831831
"\n\n" +
832832
_("Please check your anti-virus for a false-positive detection, try to add an exception for the GTA:SA executable and restart MTA:SA.");
@@ -851,7 +851,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
851851
if (isAdmin)
852852
{
853853
SString strMessage(_("MTA:SA cannot launch because the GTA:SA executable is not loadable:"));
854-
strMessage += "\n\n" + gtaExePath.string();
854+
strMessage += "\n\n" + gtaExePath.u8string();
855855
BrowseToSolution(SString("gengta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage);
856856
return "quit";
857857
}
@@ -874,7 +874,7 @@ SString CInstallManager::_ProcessGtaVersionCheck()
874874
if (isAdmin)
875875
{
876876
SString strMessage(_("MTA:SA cannot launch because patching GTA:SA has failed:"));
877-
strMessage += "\n\n" + gtaExePath.string();
877+
strMessage += "\n\n" + gtaExePath.u8string();
878878
BrowseToSolution(SString("patchgta_error&code=%d", ec.value()), ASK_GO_ONLINE, strMessage);
879879
return "quit";
880880
}

Client/loader/MainFunctions.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1119,7 +1119,7 @@ int LaunchGame(SString strCmdLine)
11191119
const SString strGTAPath = GetGTAPath();
11201120
const SString strMTASAPath = GetMTASAPath();
11211121
SString strMtaDir = PathJoin(strMTASAPath, "mta");
1122-
SString strGTAEXEPath = GetGameExecutablePath().string();
1122+
SString strGTAEXEPath = GetGameExecutablePath().u8string();
11231123

11241124
SetDllDirectory(strMtaDir);
11251125
if (!CheckService(CHECK_SERVICE_PRE_CREATE) && !IsUserAdmin())

Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,22 @@ BUT
5050
#include <filesystem>
5151

5252
extern std::filesystem::path g_gtaDirectory;
53+
54+
/**
55+
* @brief Converts a filesystem path to a string encoded with the active code page.
56+
* @param path Path to convert to a string
57+
*/
58+
auto ToACP(const std::filesystem::path& path) -> std::string
59+
{
60+
if (path.empty())
61+
return {};
62+
63+
const std::wstring widePath = path.wstring();
64+
const int narrowLength = WideCharToMultiByte(CP_ACP, 0, widePath.data(), static_cast<int>(widePath.size()), nullptr, 0, nullptr, nullptr);
65+
std::string narrowPath(narrowLength, 0);
66+
WideCharToMultiByte(CP_ACP, 0, widePath.data(), static_cast<int>(widePath.size()), narrowPath.data(), narrowLength, nullptr, nullptr);
67+
return narrowPath;
68+
}
5369
#endif
5470

5571
namespace SharedUtil
@@ -90,8 +106,8 @@ namespace SharedUtil
90106
SString MakeSurePathIsUTF8(const SString& strOriginal)
91107
{
92108
#ifdef UTF8_FILE_HOOKS_PERSONALITY_Core
93-
static SString gtaDirCP = g_gtaDirectory.string();
94-
static SString gtaDirUTF8 = ToUTF8(g_gtaDirectory.wstring());
109+
static SString gtaDirCP = ToACP(g_gtaDirectory);
110+
static SString gtaDirUTF8 = g_gtaDirectory.u8string();
95111
if (strOriginal.BeginsWithI(gtaDirCP))
96112
{
97113
SString tail = strOriginal.SubStr(gtaDirCP.length());

0 commit comments

Comments
 (0)