mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 23:46:59 +00:00
add specify a config file as argument
This commit is contained in:
parent
000af36510
commit
e485d457a6
@ -98,9 +98,9 @@ class ShutdownException : public std::runtime_error {
|
||||
};
|
||||
|
||||
struct UIData {
|
||||
static inline std::string GamePath, ProfilePath, CachePath, Build, PublicKey, UserRole, Username, GameVer;
|
||||
static inline bool LoginAuth{false}, Console{false};
|
||||
static inline std::string GamePath, ProfilePath, CachePath, Build, PublicKey, UserRole, Username, GameVer, ConfigPath;
|
||||
static inline bool LoginAuth{false}, Console{false}, UI;
|
||||
};
|
||||
|
||||
void UpdateKey(const std::string& newKey);
|
||||
void entry();
|
||||
int entry();
|
||||
|
@ -8,8 +8,8 @@
|
||||
#include "Logger.h"
|
||||
|
||||
void Launcher::LoadConfig() {
|
||||
if (fs::exists("Launcher.toml")) {
|
||||
toml::parse_result config = toml::parse_file("Launcher.toml");
|
||||
if (fs::exists(UIData::ConfigPath)) {
|
||||
toml::parse_result config = toml::parse_file(UIData::ConfigPath);
|
||||
auto ui = config["UI"];
|
||||
auto build = config["Build"];
|
||||
auto GamePath = config["GamePath"];
|
||||
@ -26,24 +26,24 @@ void Launcher::LoadConfig() {
|
||||
} else LOG(ERROR) << "Failed to get 'Build' string from config";
|
||||
|
||||
if (GamePath.is_string()) {
|
||||
if(!GamePath.as_string()->get().empty()) {
|
||||
if (!GamePath.as_string()->get().empty()) {
|
||||
BeamRoot = GamePath.as_string()->get();
|
||||
} else throw ShutdownException("GamePath cannot be empty");
|
||||
}
|
||||
else LOG(ERROR) << "Failed to get 'GamePath' string from config";
|
||||
} else LOG(ERROR) << "Failed to get 'GamePath' string from config";
|
||||
|
||||
if (ProfilePath.is_string()) {
|
||||
auto GameVer = VersionParser(UIData::GameVer).split;
|
||||
if (!UIData::GameVer.empty()) {
|
||||
auto GameVer = VersionParser(UIData::GameVer).split;
|
||||
|
||||
if (!ProfilePath.as_string()->get().empty()) {
|
||||
BeamUserPath = fs::path(ProfilePath.as_string()->get())/(GameVer[0] + '.' + GameVer[1]);
|
||||
MPUserPath = BeamUserPath/"mods"/"multiplayer";
|
||||
} else throw ShutdownException("ProfilePath cannot be empty");
|
||||
}
|
||||
else LOG(ERROR) << "Failed to get 'ProfilePath' string from config";
|
||||
if (!ProfilePath.as_string()->get().empty()) {
|
||||
BeamUserPath = fs::path(ProfilePath.as_string()->get()) / (GameVer[0] + '.' + GameVer[1]);
|
||||
MPUserPath = BeamUserPath / "mods" / "multiplayer";
|
||||
} else throw ShutdownException("ProfilePath cannot be empty");
|
||||
} else throw ShutdownException ("Check game path in config");
|
||||
} else LOG(ERROR) << "Failed to get 'ProfilePath' string from config";
|
||||
|
||||
if (CachePath.is_string()) {
|
||||
if(!CachePath.as_string()->get().empty()) {
|
||||
if (!CachePath.as_string()->get().empty()) {
|
||||
LauncherCache = CachePath.as_string()->get();
|
||||
} else throw ShutdownException("CachePath cannot be empty");
|
||||
} else LOG(ERROR) << "Failed to get 'CachePath' string from config";
|
||||
|
@ -198,11 +198,11 @@ void MySettingsFrame::UpdateCacheDirectory(const std::string& path) {
|
||||
/////////// UpdateConfig Function ///////////
|
||||
template<typename ValueType>
|
||||
void UpdateConfig(const std::string& key, ValueType&& value) {
|
||||
if (fs::exists("Launcher.toml")) {
|
||||
toml::parse_result config = toml::parse_file("Launcher.toml");
|
||||
if (fs::exists(UIData::ConfigPath)) {
|
||||
toml::parse_result config = toml::parse_file(UIData::ConfigPath);
|
||||
config.insert_or_assign(key, value);
|
||||
|
||||
std::ofstream tml("Launcher.toml");
|
||||
std::ofstream tml(UIData::ConfigPath);
|
||||
if (tml.is_open()) {
|
||||
tml << config;
|
||||
tml.close();
|
||||
@ -272,9 +272,9 @@ std::string ResetCache() {
|
||||
|
||||
/////////// Load Config Function ///////////
|
||||
void LoadConfig() {
|
||||
if (fs::exists("Launcher.toml")) {
|
||||
toml::parse_result config = toml::parse_file("Launcher.toml");
|
||||
auto ui = config["UI"];
|
||||
if (fs::exists(UIData::ConfigPath)) {
|
||||
toml::parse_result config = toml::parse_file(UIData::ConfigPath);
|
||||
auto UI = config["UI"];
|
||||
auto Build = config["Build"];
|
||||
auto GamePath = config["GamePath"];
|
||||
auto ProfilePath = config["ProfilePath"];
|
||||
@ -301,8 +301,12 @@ void LoadConfig() {
|
||||
UIData::Build = Build.as_string()->get();
|
||||
} else wxMessageBox("Unable to retrieve build state!", "Error");
|
||||
|
||||
if (UI.is_boolean()) {
|
||||
UIData::UI = UI.as_boolean()->get();
|
||||
} else wxMessageBox("Unable to retrieve UI state!", "Error");
|
||||
|
||||
} else {
|
||||
std::ofstream tml("Launcher.toml");
|
||||
std::ofstream tml(UIData::ConfigPath);
|
||||
if (tml.is_open()) {
|
||||
tml << "UI = true\n"
|
||||
"Build = 'Default'\n"
|
||||
@ -415,8 +419,6 @@ bool MyApp::OnInit() {
|
||||
}
|
||||
}
|
||||
|
||||
Log::Init();
|
||||
LoadConfig();
|
||||
CheckKey();
|
||||
|
||||
WindowsConsole(UIData::Console);
|
||||
@ -963,20 +965,34 @@ void MySettingsFrame::OnResetCache(wxCommandEvent& event) {
|
||||
|
||||
/////////// MAIN FUNCTION ///////////
|
||||
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) {
|
||||
std::string ConfigPath(lpCmdLine);
|
||||
if (!ConfigPath.empty()) {
|
||||
UIData::ConfigPath = ConfigPath;
|
||||
} else UIData::ConfigPath = "Launcher.toml";
|
||||
wxDisableAsserts();
|
||||
wxLog::SetLogLevel(wxLOG_Info);
|
||||
int result = 0;
|
||||
try {
|
||||
new MyApp();
|
||||
result = wxEntry(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
||||
if (Launcher::EntryThread.joinable())
|
||||
Launcher::EntryThread.join();
|
||||
if (MyMainFrame::UpdateThread.joinable())
|
||||
MyMainFrame::UpdateThread.join();
|
||||
} catch (const ShutdownException& e) {
|
||||
LOG(INFO) << "Launcher shutting down with reason: " << e.what();
|
||||
} catch (const std::exception& e) {
|
||||
LOG(FATAL) << e.what();
|
||||
Log::Init();
|
||||
LoadConfig();
|
||||
UIData::GameVer = jsonRead();
|
||||
|
||||
if (UIData::UI) {
|
||||
int result = 0;
|
||||
try {
|
||||
new MyApp();
|
||||
result = wxEntry(hInstance, hPrevInstance, lpCmdLine, nShowCmd);
|
||||
if (Launcher::EntryThread.joinable())
|
||||
Launcher::EntryThread.join();
|
||||
if (MyMainFrame::UpdateThread.joinable())
|
||||
MyMainFrame::UpdateThread.join();
|
||||
} catch (const ShutdownException& e) {
|
||||
LOG(INFO) << "Launcher shutting down with reason: " << e.what();
|
||||
} catch (const std::exception& e) {
|
||||
LOG(FATAL) << e.what();
|
||||
}
|
||||
return result;
|
||||
} else {
|
||||
WindowsConsole(true);
|
||||
Log::ConsoleOutput(true);
|
||||
return entry();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
@ -6,8 +6,7 @@
|
||||
#include "Launcher.h"
|
||||
#include "Logger.h"
|
||||
|
||||
void entry() {
|
||||
|
||||
int entry() {
|
||||
try {
|
||||
Launcher launcher;
|
||||
launcher.RunDiscordRPC();
|
||||
@ -25,5 +24,5 @@ void entry() {
|
||||
}
|
||||
std::this_thread::sleep_for(std::chrono::seconds(2));
|
||||
Launcher::setExit(true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user