- fix uri now show beammp launcher prompt

This commit is contained in:
Anonymous-275
2023-09-02 00:55:58 +01:00
parent 6e7803357a
commit 5d1aee98a1
5 changed files with 39 additions and 29 deletions
+2 -1
View File
@@ -30,6 +30,7 @@ class Launcher {
public: // available functions public: // available functions
static void StaticAbort(Launcher* Instance = nullptr); static void StaticAbort(Launcher* Instance = nullptr);
std::string Login(const std::string& fields); std::string Login(const std::string& fields);
void UpdateKey(const std::string& newKey);
void SendIPC(const std::string& Data, bool core = true); void SendIPC(const std::string& Data, bool core = true);
void LoadConfig(const fs::path& conf); void LoadConfig(const fs::path& conf);
void RunDiscordRPC(); void RunDiscordRPC();
@@ -76,7 +77,7 @@ class Launcher {
fs::path MPUserPath{}; fs::path MPUserPath{};
fs::path BeamUserPath{}; fs::path BeamUserPath{};
fs::path BeamProfilePath{}; fs::path BeamProfilePath{};
fs::path LauncherCache{"Resources"}; fs::path LauncherCache{};
int64_t DiscordTime{}; int64_t DiscordTime{};
bool LoginAuth = false; bool LoginAuth = false;
bool DebugMode = false; bool DebugMode = false;
+1 -1
View File
@@ -56,7 +56,7 @@ void Launcher::LoadConfig(const fs::path& conf) { // check if json (issue)
tml.close(); tml.close();
LoadConfig(conf); LoadConfig(conf);
} else LOG(ERROR) << "Failed to create config file"; } else LOG(ERROR) << "Failed to create config file " << conf;
} }
} }
+25 -16
View File
@@ -22,7 +22,7 @@ LONG WINAPI CrashHandler(EXCEPTION_POINTERS* p) {
} }
Launcher::Launcher(int argc, char* argv[]) : Launcher::Launcher(int argc, char* argv[]) :
CurrentPath(std::filesystem::current_path()), CurrentPath(fs::current_path()),
DiscordMessage("Just launched") { DiscordMessage("Just launched") {
Log::Init(); Log::Init();
Shutdown.store(false); Shutdown.store(false);
@@ -33,22 +33,31 @@ Launcher::Launcher(int argc, char* argv[]) :
SetUnhandledExceptionFilter(CrashHandler); SetUnhandledExceptionFilter(CrashHandler);
LOG(INFO) << "Starting Launcher v" << FullVersion; LOG(INFO) << "Starting Launcher v" << FullVersion;
fs::path config_path(fs::current_path() / "Launcher.toml"); fs::path config_path(CurrentPath / "Launcher.toml");
if (argc > 1) {
std::string arg(argv[1]); std::string arg, arg2;
if (arg.starts_with('0')) { if(argc > 2) {
LOG(INFO) << "Debug param in effect"; arg = argv[1];
DebugMode = true; arg2 = argv[2];
Memory::DebugMode = true; } else if (argc > 1) {
} else if (arg.starts_with("beammp://")) { arg = argv[1];
if (arg.starts_with("beammp://connect/")) {
ConnectURI = arg.substr(17);
}
} else {
config_path = fs::current_path() / arg;
}
} }
if (arg.starts_with('0')) {
LOG(INFO) << "Debug param in effect";
DebugMode = true;
Memory::DebugMode = true;
} else if (arg2.starts_with("beammp://")) {
CurrentPath = arg;
config_path = CurrentPath / "Launcher.toml";
if (arg2.starts_with("beammp://connect/")) {
ConnectURI = arg2.substr(17);
}
} else if (!arg.empty()) {
config_path = CurrentPath / arg;
}
LoadConfig(config_path); LoadConfig(config_path);
LauncherCache = CurrentPath/"Resources";
} }
void Launcher::Abort() { void Launcher::Abort() {
@@ -105,7 +114,7 @@ void Launcher::WindowsInit() {
signal(SIGBREAK, ShutdownHandler); signal(SIGBREAK, ShutdownHandler);
std::wstring command = L"cmd /c \"cd /D \"" + CurrentPath.wstring() + L"\" && BeamMP-Launcher.exe \"%1\"\""; std::wstring command = L"\"" + (CurrentPath/"BeamMP-Launcher.exe").wstring() + L"\" \"" + CurrentPath.wstring() + L"\" \"%1\"";
std::wstring ICON = L"\"" + (CurrentPath/"BeamMP-Launcher.exe").wstring() + L"\",0"; std::wstring ICON = L"\"" + (CurrentPath/"BeamMP-Launcher.exe").wstring() + L"\",0";
std::wstring URL = L"URL:beammp Protocol"; std::wstring URL = L"URL:beammp Protocol";
HKEY hKey; HKEY hKey;
+7 -7
View File
@@ -8,9 +8,9 @@
#include "Launcher.h" #include "Launcher.h"
#include "Logger.h" #include "Logger.h"
void UpdateKey(const std::string& newKey) { void Launcher::UpdateKey(const std::string& newKey) {
if (!newKey.empty() && std::isalnum(newKey[0])) { if (!newKey.empty() && std::isalnum(newKey[0])) {
std::ofstream Key("key"); std::ofstream Key(CurrentPath/"key");
if (Key.is_open()) { if (Key.is_open()) {
Key << newKey; Key << newKey;
Key.close(); Key.close();
@@ -18,8 +18,8 @@ void UpdateKey(const std::string& newKey) {
LOG(FATAL) << "Cannot write to disk!"; LOG(FATAL) << "Cannot write to disk!";
throw ShutdownException("Fatal Error"); throw ShutdownException("Fatal Error");
} }
} else if (fs::exists("key")) { } else if (fs::exists(CurrentPath/"key")) {
remove("key"); fs::remove(CurrentPath/"key");
} }
} }
@@ -79,10 +79,10 @@ std::string Launcher::Login(const std::string& fields) {
} }
void Launcher::CheckKey() { void Launcher::CheckKey() {
if (fs::exists("key") && fs::file_size("key") < 100) { if (fs::exists(CurrentPath/"key") && fs::file_size(CurrentPath/"key") < 100) {
std::ifstream Key("key"); std::ifstream Key(CurrentPath/"key");
if (Key.is_open()) { if (Key.is_open()) {
auto Size = fs::file_size("key"); auto Size = fs::file_size(CurrentPath/"key");
std::string Buffer(Size, 0); std::string Buffer(Size, 0);
Key.read(&Buffer[0], std::streamsize(Size)); Key.read(&Buffer[0], std::streamsize(Size));
Key.close(); Key.close();
+4 -4
View File
@@ -116,18 +116,18 @@ void Launcher::UpdateCheck() {
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower); transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, "BeamMP-Launcher.exe"); std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, (CurrentPath/"BeamMP-Launcher.exe").string());
if(FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(FullVersion)) { if(FileHash != LatestHash && VersionParser(LatestVersion) > VersionParser(FullVersion)) {
LOG(INFO) << "Launcher update found!"; LOG(INFO) << "Launcher update found!";
fs::remove("BeamMP-Launcher.back"); fs::remove((CurrentPath/"BeamMP-Launcher.back").string());
fs::rename("BeamMP-Launcher.exe", "BeamMP-Launcher.back"); fs::rename((CurrentPath/"BeamMP-Launcher.exe").string(), (CurrentPath/"BeamMP-Launcher.back").string());
LOG(INFO) << "Downloading Launcher update " << LatestHash; LOG(INFO) << "Downloading Launcher update " << LatestHash;
HTTP::Download( HTTP::Download(
"https://backend.beammp.com/builds/launcher?download=true" "https://backend.beammp.com/builds/launcher?download=true"
"&pk=" + "&pk=" +
PublicKey + "&branch=" + TargetBuild, PublicKey + "&branch=" + TargetBuild,
"BeamMP-Launcher.exe"); (CurrentPath/"BeamMP-Launcher.exe").string());
throw ShutdownException("Launcher update"); throw ShutdownException("Launcher update");
} }