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