diff --git a/include/Security/Init.h b/include/Security/Init.h index 7a1d0ea..c6f3db7 100644 --- a/include/Security/Init.h +++ b/include/Security/Init.h @@ -7,7 +7,7 @@ /// #pragma once #include -void PreGame(int argc, char* argv[],const std::string& GamePath); +void PreGame(const std::string& GamePath); std::string CheckVer(const std::string &path); void InitGame(const std::string& Dir); std::string GetGameDir(); diff --git a/include/Startup.h b/include/Startup.h index d0ed404..f2e9d45 100644 --- a/include/Startup.h +++ b/include/Startup.h @@ -9,7 +9,7 @@ #include void InitLauncher(int argc, char* argv[]); void CheckDir(int argc,char* args[]); -std::string GetGamePath(); +std::wstring GetGamePath(); std::string GetVer(); std::string GetEN(); extern bool Dev; \ No newline at end of file diff --git a/src/GameStart.cpp b/src/GameStart.cpp index 1536f5e..c6a69d7 100644 --- a/src/GameStart.cpp +++ b/src/GameStart.cpp @@ -11,12 +11,14 @@ #include #include "Logger.h" #include +#include #include +#include unsigned long GamePID = 0; std::string QueryKey(HKEY hKey,int ID); -std::string GetGamePath(){ - static std::string Path; +std::wstring GetGamePath(){ + static std::wstring Path; if(!Path.empty())return Path; HKEY hKey; @@ -25,7 +27,8 @@ std::string GetGamePath(){ if (openRes != ERROR_SUCCESS){ fatal("Please launch the game at least once"); } - Path = QueryKey(hKey,4); + std::string T = QueryKey(hKey,4); + Path = std::wstring(T.begin(),T.end()); if(Path.empty()){ CoInitialize(nullptr); @@ -33,9 +36,8 @@ std::string GetGamePath(){ SHGetKnownFolderPath(FOLDERID_Documents, KF_FLAG_SIMPLE_IDLIST, nullptr, (PWSTR *)(&path)); CoTaskMemFree(path); std::wstring ws(path); - std::string s(ws.begin(), ws.end()); - Path = s; - Path += "\\BeamNG.drive\\"; + ws += L"\\BeamNG.drive\\"; + return ws; } return Path; diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 7fedca6..cff99be 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -258,10 +258,11 @@ void SyncResources(SOCKET Sock){ UpdateUl(false,std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + a.substr(a.find_last_of('/'))); std::this_thread::sleep_for(std::chrono::milliseconds(50)); try { - if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } - fs::copy_file(a, GetGamePath() + "mods/multiplayer" + a.substr(a.find_last_of('/')), + std::string P = "mods/multiplayer" + a.substr(a.find_last_of('/')); + fs::copy_file(a, GetGamePath() + std::wstring(P.begin(),P.end()), fs::copy_options::overwrite_existing); } catch (std::exception& e) { error("Failed copy to the mods folder! " + std::string(e.what())); @@ -299,10 +300,10 @@ void SyncResources(SOCKET Sock){ }while(fs::file_size(a) != ModSize && !Terminate); if(!Terminate){ - if(!fs::exists(GetGamePath() + "mods/multiplayer")){ - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if(!fs::exists(GetGamePath() + L"mods/multiplayer")){ + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } - fs::copy_file(a,GetGamePath() + "mods/multiplayer" + FName, fs::copy_options::overwrite_existing); + fs::copy_file(a,GetGamePath() + L"mods/multiplayer" + std::wstring(FName.begin(),FName.end()), fs::copy_options::overwrite_existing); } WaitForConfirm(); } diff --git a/src/Startup.cpp b/src/Startup.cpp index 8f93ca8..cbfadb0 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -187,8 +187,14 @@ void InitLauncher(int argc, char* argv[]) { CustomPort(argc, argv); CheckForUpdates(argc, argv, std::string(GetVer()) + GetPatch()); } +inline std::string to_string(const std::wstring& str){ + auto loc = std::locale{}; + std::vector buf(str.size()); + std::use_facet>(loc).narrow(str.data(), str.data() + str.size(), '?', buf.data()); -void PreGame(int argc, char* argv[],const std::string& GamePath){ + return std::string(buf.data(), buf.size()); +} +void PreGame(const std::string& GamePath){ info("Game Version : " + CheckVer(GamePath)); if(!Dev) { @@ -196,16 +202,17 @@ void PreGame(int argc, char* argv[],const std::string& GamePath){ //if(fallback)link = "https://backup1.beammp.com/builds/client"; std::string link = "https://beammp.com/builds/client"; try { - if (!fs::exists(GetGamePath() + "mods")) { - fs::create_directory(GetGamePath() + "mods"); + if (!fs::exists(GetGamePath() + L"mods")) { + fs::create_directory(GetGamePath() + L"mods"); } - if (!fs::exists(GetGamePath() + "mods/multiplayer")) { - fs::create_directory(GetGamePath() + "mods/multiplayer"); + if (!fs::exists(GetGamePath() + L"mods/multiplayer")) { + fs::create_directory(GetGamePath() + L"mods/multiplayer"); } + std::wstring P = GetGamePath() + LR"(mods/multiplayer/BeamMP.zip)"; + Download(link, to_string(P), true); }catch(std::exception&e){ fatal(e.what()); } - Download(link, GetGamePath() + R"(mods/multiplayer/BeamMP.zip)", true); info("Download Complete!"); } diff --git a/src/main.cpp b/src/main.cpp index 0cdf2eb..a6fcbfb 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -27,7 +27,7 @@ int main(int argc, char* argv[]) { InitLauncher(argc,argv); //CheckDir(argc,argv); LegitimacyCheck(); - PreGame(argc,argv,GetGameDir()); + PreGame(GetGameDir()); InitGame(GetGameDir()); CoreNetwork(); }