Skip to content

Commit 9b171c2

Browse files
author
G_Moris
committed
Mini refactor
1 parent 9f3ebd3 commit 9b171c2

File tree

7 files changed

+39
-13
lines changed

7 files changed

+39
-13
lines changed

Client/core/CCore.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,13 @@ static HMODULE WINAPI SkipDirectPlay_LoadLibraryA(LPCSTR fileName)
6060
const fs::path inLaunchDir = fs::path{FromUTF8(GetLaunchPath())} / "enbseries" / "enbhelper.dll";
6161

6262
if (fs::is_regular_file(inLaunchDir, ec))
63-
return Win32LoadLibraryA(ToUTF8(inLaunchDir.wstring()).c_str());
63+
return Win32LoadLibraryA(PathToUtf8(inLaunchDir).c_str());
6464

6565
// Try to load enbhelper.dll from the GTA install directory second.
6666
const fs::path inGTADir = g_gtaDirectory / "enbseries" / "enbhelper.dll";
6767

6868
if (fs::is_regular_file(inGTADir, ec))
69-
return Win32LoadLibraryA(ToUTF8(inGTADir.wstring()).c_str());
69+
return Win32LoadLibraryA(PathToUtf8(inGTADir).c_str());
7070

7171
return nullptr;
7272
}

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 = ToUTF8(g_gtaDirectory.wstring());
83+
ModuleRootDirOut = PathToUtf8(g_gtaDirectory);
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" + ToUTF8(targetPath.wstring());
658+
strMessage += "\n\n" + PathToUtf8(targetPath);
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" + ToUTF8(sourcePath.wstring());
664+
strMessage += "\n\n" + PathToUtf8(sourcePath);
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" + ToUTF8(patchBasePath.wstring());
696+
strMessage += "\n\n" + PathToUtf8(patchBasePath);
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" + ToUTF8(patchDiffPath.wstring());
704+
strMessage += "\n\n" + PathToUtf8(patchDiffPath);
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" + ToUTF8(dependecyPath.wstring());
774+
strMessage += "\n\n" + PathToUtf8(dependecyPath);
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" + ToUTF8(gtaExePath.wstring());
829+
strMessage += "\n\n" + PathToUtf8(gtaExePath);
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" + ToUTF8(gtaExePath.wstring());
854+
strMessage += "\n\n" + PathToUtf8(gtaExePath);
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" + ToUTF8(gtaExePath.wstring());
877+
strMessage += "\n\n" + PathToUtf8(gtaExePath);
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
@@ -1115,7 +1115,7 @@ int LaunchGame(SString strCmdLine)
11151115
const SString strGTAPath = GetGTAPath();
11161116
const SString strMTASAPath = GetMTASAPath();
11171117
SString strMtaDir = PathJoin(strMTASAPath, "mta");
1118-
SString strGTAEXEPath = ToUTF8(GetGameExecutablePath().wstring());
1118+
SString strGTAEXEPath = PathToUtf8(GetGameExecutablePath());
11191119

11201120
SetDllDirectory(strMtaDir);
11211121
if (!CheckService(CHECK_SERVICE_PRE_CREATE) && !IsUserAdmin())

Shared/sdk/SharedUtil.File.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,26 @@
77
* Multi Theft Auto is available from https://multitheftauto.com/
88
*
99
*****************************************************************************/
10+
1011
#pragma once
1112

1213
#include <vector>
1314
#include "SharedUtil.IntTypes.h"
1415
#include "SString.h"
1516
#include "WString.h"
1617

18+
// C++20?
19+
#if __cplusplus >= 202002L
20+
// Forward declaration of std::filesystem::path to avoid including the <filesystem>
21+
namespace std
22+
{
23+
namespace filesystem
24+
{
25+
class path;
26+
}
27+
}
28+
#endif
29+
1730
namespace SharedUtil
1831
{
1932
//
@@ -101,6 +114,11 @@ namespace SharedUtil
101114
std::wstring FromUTF8(const std::string& strPath);
102115
std::string ToUTF8(const std::wstring& wstrPath);
103116

117+
// C++20?
118+
#if __cplusplus >= 202002L
119+
std::string PathToUtf8(const std::filesystem::path& path);
120+
#endif
121+
104122
std::vector<std::string> ListDir(const char* szPath) noexcept;
105123

106124
namespace File

Shared/sdk/SharedUtil.File.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -642,6 +642,14 @@ std::string SharedUtil::ToUTF8(const std::wstring& wstrPath)
642642
#endif
643643
}
644644

645+
// C++20?
646+
#if __cplusplus >= 202002L
647+
std::string SharedUtil::PathToUtf8(const std::filesystem::path& path)
648+
{
649+
return ToUTF8(path.wstring());
650+
}
651+
#endif
652+
645653
#ifdef _WIN32
646654
///////////////////////////////////////////////////////////////
647655
//

Shared/sdk/SharedUtil.Win32Utf8FileHooks.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ namespace SharedUtil
107107
{
108108
#ifdef UTF8_FILE_HOOKS_PERSONALITY_Core
109109
static SString gtaDirCP = ToACP(g_gtaDirectory);
110-
static SString gtaDirUTF8 = ToUTF8(g_gtaDirectory.wstring());
110+
static SString gtaDirUTF8 = PathToUtf8(g_gtaDirectory);
111111
if (strOriginal.BeginsWithI(gtaDirCP))
112112
{
113113
SString tail = strOriginal.SubStr(gtaDirCP.length());

0 commit comments

Comments
 (0)