mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2026-06-19 23:20:57 +00:00
- always check latest profile
This commit is contained in:
+3
-1
@@ -53,7 +53,8 @@ class Launcher {
|
|||||||
|
|
||||||
private: // functions
|
private: // functions
|
||||||
void HandleIPC(const std::string& Data);
|
void HandleIPC(const std::string& Data);
|
||||||
fs::path GetBeamNGProfile();
|
std::string GetProfileVersion();
|
||||||
|
fs::path GetProfileRoot();
|
||||||
void UpdatePresence();
|
void UpdatePresence();
|
||||||
void RichPresence();
|
void RichPresence();
|
||||||
void WindowsInit();
|
void WindowsInit();
|
||||||
@@ -71,6 +72,7 @@ class Launcher {
|
|||||||
uint32_t GamePID{0};
|
uint32_t GamePID{0};
|
||||||
fs::path MPUserPath{};
|
fs::path MPUserPath{};
|
||||||
fs::path BeamUserPath{};
|
fs::path BeamUserPath{};
|
||||||
|
fs::path BeamProfilePath{};
|
||||||
fs::path LauncherCache{"Resources"};
|
fs::path LauncherCache{"Resources"};
|
||||||
int64_t DiscordTime{};
|
int64_t DiscordTime{};
|
||||||
bool LoginAuth = false;
|
bool LoginAuth = false;
|
||||||
|
|||||||
+14
-9
@@ -30,10 +30,11 @@ void Launcher::LoadConfig(const fs::path& conf) { // check if json (issue)
|
|||||||
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||||
|
|
||||||
if (ProfilePath.is_string() && !ProfilePath.as_string()->get().empty()) {
|
if (ProfilePath.is_string() && !ProfilePath.as_string()->get().empty()) {
|
||||||
BeamUserPath = fs::path(ProfilePath.as_string()->get());
|
BeamProfilePath = fs::path(ProfilePath.as_string()->get());
|
||||||
|
BeamUserPath = BeamProfilePath/GetProfileVersion();
|
||||||
} else {
|
} else {
|
||||||
LOG(ERROR) << "'ProfilePath' string from config is empty defaulting";
|
LOG(ERROR) << "'ProfilePath' string from config is empty defaulting";
|
||||||
BeamUserPath = GetBeamNGProfile();
|
BeamUserPath = GetProfileRoot()/GetProfileVersion();
|
||||||
}
|
}
|
||||||
MPUserPath = BeamUserPath / "mods" / "multiplayer";
|
MPUserPath = BeamUserPath / "mods" / "multiplayer";
|
||||||
|
|
||||||
@@ -44,7 +45,7 @@ void Launcher::LoadConfig(const fs::path& conf) { // check if json (issue)
|
|||||||
} else LOG(ERROR) << "Failed to get 'CachePath' string from config";
|
} else LOG(ERROR) << "Failed to get 'CachePath' string from config";
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
auto GameProfile = GetBeamNGProfile();
|
auto GameProfile = GetProfileRoot();
|
||||||
std::ofstream tml(conf);
|
std::ofstream tml(conf);
|
||||||
if (tml.is_open()) {
|
if (tml.is_open()) {
|
||||||
tml << "Build = 'Default'\n"
|
tml << "Build = 'Default'\n"
|
||||||
@@ -58,7 +59,7 @@ void Launcher::LoadConfig(const fs::path& conf) { // check if json (issue)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fs::path Launcher::GetBeamNGProfile() {
|
fs::path Launcher::GetProfileRoot() {
|
||||||
|
|
||||||
HKEY BeamNG;
|
HKEY BeamNG;
|
||||||
fs::path ProfilePath;
|
fs::path ProfilePath;
|
||||||
@@ -82,8 +83,12 @@ fs::path Launcher::GetBeamNGProfile() {
|
|||||||
CoTaskMemFree(folderPath);
|
CoTaskMemFree(folderPath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
BeamProfilePath = ProfilePath;
|
||||||
|
return BeamProfilePath;
|
||||||
|
}
|
||||||
|
|
||||||
/////Load latest link
|
std::string Launcher::GetProfileVersion() {
|
||||||
|
//load latest.lnk from profile
|
||||||
|
|
||||||
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) != S_OK) {
|
if (CoInitializeEx(nullptr, COINIT_MULTITHREADED) != S_OK) {
|
||||||
throw ShutdownException("Failed to read link: CoInitializeEx");
|
throw ShutdownException("Failed to read link: CoInitializeEx");
|
||||||
@@ -107,10 +112,10 @@ fs::path Launcher::GetBeamNGProfile() {
|
|||||||
throw ShutdownException("Failed to read link: QueryInterface(IID_IPersistFile)");
|
throw ShutdownException("Failed to read link: QueryInterface(IID_IPersistFile)");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = iPersistFile->Load((ProfilePath/"latest.lnk").wstring().c_str(), STGM_READ);
|
rc = iPersistFile->Load((BeamProfilePath/"latest.lnk").wstring().c_str(), STGM_READ);
|
||||||
|
|
||||||
if (FAILED(rc)) {
|
if (FAILED(rc)) {
|
||||||
throw ShutdownException("Failed to read link: iPersistFile->Load()");
|
throw ShutdownException("Failed to read link: Please launch the game at least once, check ProfilePath in Launcher.toml");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = iShellLink->Resolve(nullptr, 0);
|
rc = iShellLink->Resolve(nullptr, 0);
|
||||||
@@ -132,6 +137,6 @@ fs::path Launcher::GetBeamNGProfile() {
|
|||||||
iShellLink->Release();
|
iShellLink->Release();
|
||||||
|
|
||||||
BeamVersion = std::filesystem::path(linkTarget).filename().string();
|
BeamVersion = std::filesystem::path(linkTarget).filename().string();
|
||||||
LOG(INFO) << "Found BeamNG profile " << BeamVersion;
|
LOG(INFO) << "Found profile for BeamNG " << BeamVersion;
|
||||||
return ProfilePath/BeamVersion;
|
return BeamVersion;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user