mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-08-16 08:16:20 +00:00
Change to canonical paths for executable paths
This commit is contained in:
parent
b6b0e4ba3e
commit
7a4b24d616
@ -13,6 +13,7 @@
|
||||
|
||||
void InitLauncher();
|
||||
beammp_fs_string GetEP(const beammp_fs_char* P = nullptr);
|
||||
std::filesystem::path GetBP(const beammp_fs_char* P = nullptr);
|
||||
std::filesystem::path GetGamePath();
|
||||
std::string GetVer();
|
||||
std::string GetPatch();
|
||||
|
@ -14,7 +14,10 @@
|
||||
#if defined(_WIN32)
|
||||
#elif defined(__linux__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#elif defined (__APPLE__)
|
||||
#include <unistd.h>
|
||||
#include <libproc.h>
|
||||
#endif // __APPLE__
|
||||
#include "Http.h"
|
||||
#include "Logger.h"
|
||||
#include "Network/network.hpp"
|
||||
@ -94,6 +97,34 @@ beammp_fs_string GetEP(const beammp_fs_char* P) {
|
||||
}();
|
||||
return Ret;
|
||||
}
|
||||
|
||||
beammp_fs_string GetBP(const beammp_fs_char* P) {
|
||||
fs::path fspath = {};
|
||||
#if defined(_WIN32)
|
||||
beammp_fs_char path[256];
|
||||
GetModuleFileNameW(nullptr, path, sizeof(path));
|
||||
fspath = path;
|
||||
#elif defined(__linux__)
|
||||
fspath = fs::canonical("/proc/self/exe");
|
||||
#elif defined(__APPLE__)
|
||||
pid_t pid = getpid();
|
||||
char path[PROC_PIDPATHINFO_MAXSIZE];
|
||||
// While this is fine for a raw executable,
|
||||
// an application bundle is read-only and these files
|
||||
// should instead be placed in Application Support.
|
||||
proc_pidpath(pid, path, sizeof(path));
|
||||
fspath = std::string(path);
|
||||
#else
|
||||
fspath = beammp_fs_string(P);
|
||||
#endif
|
||||
fspath = fs::weakly_canonical(fspath.string() + "/..");
|
||||
#if defined(_WIN32)
|
||||
return fspath.wstring();
|
||||
#else
|
||||
return fspath.string();
|
||||
#endif
|
||||
}
|
||||
|
||||
#if defined(_WIN32)
|
||||
void ReLaunch() {
|
||||
std::wstring Arg;
|
||||
@ -103,7 +134,7 @@ void ReLaunch() {
|
||||
}
|
||||
info("Relaunch!");
|
||||
system("cls");
|
||||
ShellExecuteW(nullptr, L"runas", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||
ShellExecuteW(nullptr, L"runas", (GetBP() / GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(), 0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
exit(1);
|
||||
@ -114,7 +145,7 @@ void URelaunch() {
|
||||
Arg += Utils::ToWString(options.argv[c - 1]);
|
||||
Arg += L" ";
|
||||
}
|
||||
ShellExecuteW(nullptr, L"open", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||
ShellExecuteW(nullptr, L"open", (GetBP() / GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
|
||||
ShowWindow(GetConsoleWindow(), 0);
|
||||
std::this_thread::sleep_for(std::chrono::seconds(1));
|
||||
exit(1);
|
||||
@ -128,7 +159,7 @@ void ReLaunch() {
|
||||
}
|
||||
info("Relaunch!");
|
||||
system("clear");
|
||||
int ret = execv(options.executable_name.c_str(), const_cast<char**>(options.argv));
|
||||
int ret = execv((GetBP() / GetEN()).c_str(), const_cast<char**>(options.argv));
|
||||
if (ret < 0) {
|
||||
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||
exit(1);
|
||||
@ -137,7 +168,7 @@ void ReLaunch() {
|
||||
exit(1);
|
||||
}
|
||||
void URelaunch() {
|
||||
int ret = execv(options.executable_name.c_str(), const_cast<char**>(options.argv));
|
||||
int ret = execv((GetBP() / GetEN()).c_str(), const_cast<char**>(options.argv));
|
||||
if (ret < 0) {
|
||||
error(std::string("execv() failed with: ") + strerror(errno) + ". Failed to relaunch");
|
||||
exit(1);
|
||||
@ -169,7 +200,7 @@ void CheckForUpdates(const std::string& CV) {
|
||||
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||
|
||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||
beammp_fs_string EP(GetEP() + GetEN()), Back(GetEP() + beammp_wide("BeamMP-Launcher.back"));
|
||||
beammp_fs_string BP(GetBP() / GetEN()), Back(GetBP() / beammp_wide("BeamMP-Launcher.back"));
|
||||
|
||||
std::string FileHash = Utils::GetSha256HashReallyFastFile(EP);
|
||||
|
||||
@ -254,8 +285,8 @@ void InitLauncher() {
|
||||
}
|
||||
#endif
|
||||
|
||||
size_t DirCount(const std::filesystem::path& path) {
|
||||
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
||||
size_t DirCount(const fs::path& path) {
|
||||
return (size_t)std::distance(fs::directory_iterator { path }, fs::directory_iterator {});
|
||||
}
|
||||
|
||||
void CheckMP(const beammp_fs_string& Path) {
|
||||
|
@ -39,6 +39,7 @@ int main(int argc, const char** argv) try {
|
||||
curl_global_init(CURL_GLOBAL_ALL);
|
||||
|
||||
GetEP(Utils::ToWString(std::string(argv[0])).c_str());
|
||||
info("BP Path: " + GetBP(Utils::ToWString(std::string(argv[0])).c_str()));
|
||||
|
||||
InitLog();
|
||||
ConfigInit();
|
||||
|
Loading…
x
Reference in New Issue
Block a user