mirror of
https://github.com/BeamMP/BeamMP-Launcher.git
synced 2025-07-01 15:36:10 +00:00
Fix wstring for windows and add crossplatform code for fs strings
This commit is contained in:
parent
5e448dc34f
commit
06c741edc5
@ -6,10 +6,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
class HTTP {
|
class HTTP {
|
||||||
public:
|
public:
|
||||||
static bool Download(const std::string& IP, const std::wstring& Path);
|
static bool Download(const std::string& IP, const beammp_fs_string& Path);
|
||||||
static std::string Post(const std::string& IP, const std::string& Fields);
|
static std::string Post(const std::string& IP, const std::string& Fields);
|
||||||
static std::string Get(const std::string& IP);
|
static std::string Get(const std::string& IP);
|
||||||
static bool ProgressBar(size_t c, size_t t);
|
static bool ProgressBar(size_t c, size_t t);
|
||||||
|
@ -6,9 +6,9 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
void PreGame(const std::wstring& GamePath);
|
void PreGame(const beammp_fs_string& GamePath);
|
||||||
std::string CheckVer(const std::wstring& path);
|
std::string CheckVer(const beammp_fs_string& path);
|
||||||
void InitGame(const std::wstring& Dir);
|
void InitGame(const beammp_fs_string& Dir);
|
||||||
std::wstring GetGameDir();
|
beammp_fs_string GetGameDir();
|
||||||
void LegitimacyCheck();
|
void LegitimacyCheck();
|
||||||
void CheckLocalKey();
|
void CheckLocalKey();
|
@ -5,14 +5,16 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <compare>
|
#include <compare>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
void InitLauncher();
|
void InitLauncher();
|
||||||
std::wstring GetEP(const wchar_t* P = nullptr);
|
beammp_fs_string GetEP(const beammp_fs_char* P = nullptr);
|
||||||
std::wstring GetGamePath();
|
beammp_fs_string GetGamePath();
|
||||||
std::string GetVer();
|
std::string GetVer();
|
||||||
std::string GetPatch();
|
std::string GetPatch();
|
||||||
std::wstring GetEN();
|
beammp_fs_string GetEN();
|
||||||
void ConfigInit();
|
void ConfigInit();
|
||||||
|
@ -15,6 +15,16 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
|
#define beammp_fs_string std::wstring
|
||||||
|
#define beammp_fs_char wchar_t
|
||||||
|
#define beammp_wide(str) L##str
|
||||||
|
#else
|
||||||
|
#define beammp_fs_string std::string
|
||||||
|
#define beammp_fs_char char
|
||||||
|
#define beammp_wide(str) str
|
||||||
|
#endif
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
inline std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
inline std::vector<std::string> Split(const std::string& String, const std::string& delimiter) {
|
||||||
@ -120,71 +130,16 @@ namespace Utils {
|
|||||||
inline std::string ToString(const std::wstring& w) {
|
inline std::string ToString(const std::wstring& w) {
|
||||||
return std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>>().to_bytes(w);
|
return std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>>().to_bytes(w);
|
||||||
}
|
}
|
||||||
|
#ifdef _WIN32
|
||||||
inline std::wstring ToWString(const std::string& s) {
|
inline std::wstring ToWString(const std::string& s) {
|
||||||
return std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>>().from_bytes(s);
|
return std::wstring_convert<std::codecvt<wchar_t, char, std::mbstate_t>>().from_bytes(s);
|
||||||
}
|
}
|
||||||
inline std::string GetSha256HashReallyFast(const std::string& filename) {
|
#else
|
||||||
try {
|
inline std::string ToWString(const std::string& s) {
|
||||||
EVP_MD_CTX* mdctx;
|
return s;
|
||||||
const EVP_MD* md;
|
|
||||||
uint8_t sha256_value[EVP_MAX_MD_SIZE];
|
|
||||||
md = EVP_sha256();
|
|
||||||
if (md == nullptr) {
|
|
||||||
throw std::runtime_error("EVP_sha256() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
mdctx = EVP_MD_CTX_new();
|
|
||||||
if (mdctx == nullptr) {
|
|
||||||
throw std::runtime_error("EVP_MD_CTX_new() failed");
|
|
||||||
}
|
|
||||||
if (!EVP_DigestInit_ex2(mdctx, md, NULL)) {
|
|
||||||
EVP_MD_CTX_free(mdctx);
|
|
||||||
throw std::runtime_error("EVP_DigestInit_ex2() failed");
|
|
||||||
}
|
|
||||||
|
|
||||||
std::ifstream stream(filename, std::ios::binary);
|
|
||||||
|
|
||||||
const size_t FileSize = std::filesystem::file_size(filename);
|
|
||||||
size_t Read = 0;
|
|
||||||
std::vector<char> Data;
|
|
||||||
while (Read < FileSize) {
|
|
||||||
Data.resize(size_t(std::min<size_t>(FileSize - Read, 4096)));
|
|
||||||
size_t RealDataSize = Data.size();
|
|
||||||
stream.read(Data.data(), std::streamsize(Data.size()));
|
|
||||||
if (stream.eof() || stream.fail()) {
|
|
||||||
RealDataSize = size_t(stream.gcount());
|
|
||||||
}
|
|
||||||
Data.resize(RealDataSize);
|
|
||||||
if (RealDataSize == 0) {
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
if (RealDataSize > 0 && !EVP_DigestUpdate(mdctx, Data.data(), Data.size())) {
|
|
||||||
EVP_MD_CTX_free(mdctx);
|
|
||||||
throw std::runtime_error("EVP_DigestUpdate() failed");
|
|
||||||
}
|
|
||||||
Read += RealDataSize;
|
|
||||||
}
|
|
||||||
unsigned int sha256_len = 0;
|
|
||||||
if (!EVP_DigestFinal_ex(mdctx, sha256_value, &sha256_len)) {
|
|
||||||
EVP_MD_CTX_free(mdctx);
|
|
||||||
throw std::runtime_error("EVP_DigestFinal_ex() failed");
|
|
||||||
}
|
|
||||||
EVP_MD_CTX_free(mdctx);
|
|
||||||
|
|
||||||
std::string result;
|
|
||||||
for (size_t i = 0; i < sha256_len; i++) {
|
|
||||||
char buf[3];
|
|
||||||
sprintf(buf, "%02x", sha256_value[i]);
|
|
||||||
buf[2] = 0;
|
|
||||||
result += buf;
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
} catch (const std::exception& e) {
|
|
||||||
error("Sha256 hashing of '" + filename + "' failed: " + e.what());
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
inline std::string GetSha256HashReallyFast(const std::wstring& filename) {
|
#endif
|
||||||
|
inline std::string GetSha256HashReallyFast(const beammp_fs_string& filename) {
|
||||||
try {
|
try {
|
||||||
EVP_MD_CTX* mdctx;
|
EVP_MD_CTX* mdctx;
|
||||||
const EVP_MD* md;
|
const EVP_MD* md;
|
||||||
@ -241,7 +196,7 @@ namespace Utils {
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
} catch (const std::exception& e) {
|
} catch (const std::exception& e) {
|
||||||
error(L"Sha256 hashing of '" + filename + L"' failed: " + ToWString(e.what()));
|
error(beammp_wide("Sha256 hashing of '") + filename + beammp_wide("' failed: ") + ToWString(e.what()));
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ void StartGame(std::string Dir) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void InitGame(const std::wstring& Dir) {
|
void InitGame(const beammp_fs_string& Dir) {
|
||||||
if (!options.no_launch) {
|
if (!options.no_launch) {
|
||||||
std::thread Game(StartGame, Dir);
|
std::thread Game(StartGame, Dir);
|
||||||
Game.detach();
|
Game.detach();
|
||||||
|
@ -37,7 +37,7 @@ std::string getDate() {
|
|||||||
}
|
}
|
||||||
void InitLog() {
|
void InitLog() {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + L"Launcher.log");
|
LFS.open(GetEP() + beammp_wide("Launcher.log"));
|
||||||
if (!LFS.is_open()) {
|
if (!LFS.is_open()) {
|
||||||
error("logger file init failed!");
|
error("logger file init failed!");
|
||||||
} else
|
} else
|
||||||
@ -45,13 +45,13 @@ void InitLog() {
|
|||||||
}
|
}
|
||||||
void addToLog(const std::string& Line) {
|
void addToLog(const std::string& Line) {
|
||||||
std::ofstream LFS;
|
std::ofstream LFS;
|
||||||
LFS.open(GetEP() + L"Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + beammp_wide("Launcher.log"), std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
void addToLog(const std::wstring& Line) {
|
void addToLog(const std::wstring& Line) {
|
||||||
std::wofstream LFS;
|
std::wofstream LFS;
|
||||||
LFS.open(GetEP() + L"Launcher.log", std::ios_base::app);
|
LFS.open(GetEP() + beammp_wide("Launcher.log"), std::ios_base::app);
|
||||||
LFS << Line.c_str();
|
LFS << Line.c_str();
|
||||||
LFS.close();
|
LFS.close();
|
||||||
}
|
}
|
||||||
@ -91,6 +91,7 @@ void except(const std::string& toPrint) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef _WIN32
|
||||||
void info(const std::wstring& toPrint) {
|
void info(const std::wstring& toPrint) {
|
||||||
std::wstring Print = Utils::ToWString(getDate()) + L"[INFO] " + toPrint + L"\n";
|
std::wstring Print = Utils::ToWString(getDate()) + L"[INFO] " + toPrint + L"\n";
|
||||||
std::wcout << Print;
|
std::wcout << Print;
|
||||||
@ -124,4 +125,5 @@ void except(const std::wstring& toPrint) {
|
|||||||
std::wstring Print = Utils::ToWString(getDate()) + L"[EXCEP] " + toPrint + L"\n";
|
std::wstring Print = Utils::ToWString(getDate()) + L"[EXCEP] " + toPrint + L"\n";
|
||||||
std::wcout << Print;
|
std::wcout << Print;
|
||||||
addToLog(Print);
|
addToLog(Print);
|
||||||
}
|
}
|
||||||
|
#endif
|
@ -127,7 +127,7 @@ std::string HTTP::Post(const std::string& IP, const std::string& Fields) {
|
|||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool HTTP::Download(const std::string& IP, const std::wstring& Path) {
|
bool HTTP::Download(const std::string& IP, const beammp_fs_string& Path) {
|
||||||
static std::mutex Lock;
|
static std::mutex Lock;
|
||||||
std::scoped_lock Guard(Lock);
|
std::scoped_lock Guard(Lock);
|
||||||
|
|
||||||
@ -145,7 +145,7 @@ bool HTTP::Download(const std::string& IP, const std::wstring& Path) {
|
|||||||
File.close();
|
File.close();
|
||||||
info("Download Complete!");
|
info("Download Complete!");
|
||||||
} else {
|
} else {
|
||||||
error(L"Failed to open file directory: " + Path);
|
error(beammp_wide("Failed to open file directory: ") + Path);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,14 +444,14 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
auto FileName = std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + std::filesystem::path(ModInfoIter->FileName).extension().string();
|
auto FileName = std::filesystem::path(ModInfoIter->FileName).stem().string() + "-" + ModInfoIter->Hash.substr(0, 8) + std::filesystem::path(ModInfoIter->FileName).extension().string();
|
||||||
auto PathToSaveTo = (fs::path(CachingDirectory) / FileName).string();
|
auto PathToSaveTo = (fs::path(CachingDirectory) / FileName);
|
||||||
if (fs::exists(PathToSaveTo) && Utils::GetSha256HashReallyFast(PathToSaveTo) == ModInfoIter->Hash) {
|
if (fs::exists(PathToSaveTo) && Utils::GetSha256HashReallyFast(PathToSaveTo) == ModInfoIter->Hash) {
|
||||||
debug("Mod '" + FileName + "' found in cache");
|
debug("Mod '" + FileName + "' found in cache");
|
||||||
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + L"mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
auto modname = ModInfoIter->FileName;
|
auto modname = ModInfoIter->FileName;
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@ -476,15 +476,15 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
continue;
|
continue;
|
||||||
} else if (auto OldCachedPath = fs::path(CachingDirectory) / std::filesystem::path(ModInfoIter->FileName).filename();
|
} else if (auto OldCachedPath = fs::path(CachingDirectory) / std::filesystem::path(ModInfoIter->FileName).filename();
|
||||||
fs::exists(OldCachedPath) && GetSha256HashReallyFast(OldCachedPath.string()) == ModInfoIter->Hash) {
|
fs::exists(OldCachedPath) && Utils::GetSha256HashReallyFast(OldCachedPath) == ModInfoIter->Hash) {
|
||||||
debug("Mod '" + FileName + "' found in old cache, copying it to the new cache");
|
debug("Mod '" + FileName + "' found in old cache, copying it to the new cache");
|
||||||
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
UpdateUl(false, std::to_string(ModNo) + "/" + std::to_string(TotalMods) + ": " + ModInfoIter->FileName);
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
fs::copy_file(OldCachedPath, PathToSaveTo, fs::copy_options::overwrite_existing);
|
fs::copy_file(OldCachedPath, PathToSaveTo, fs::copy_options::overwrite_existing);
|
||||||
|
|
||||||
if (!fs::exists(GetGamePath() + "mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + "mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
auto modname = ModInfoIter->FileName;
|
auto modname = ModInfoIter->FileName;
|
||||||
@ -525,7 +525,7 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
CheckForDir();
|
CheckForDir();
|
||||||
std::string FName = ModInfoIter->FileName;
|
std::string FName = ModInfoIter->FileName;
|
||||||
do {
|
do {
|
||||||
debug("Loading file '" + FName + "' to '" + PathToSaveTo + "'");
|
debug("Loading file '" + FName + "' to '" + PathToSaveTo.string() + "'");
|
||||||
TCPSend("f" + ModInfoIter->FileName, Sock);
|
TCPSend("f" + ModInfoIter->FileName, Sock);
|
||||||
|
|
||||||
std::string Data = TCPRcv(Sock);
|
std::string Data = TCPRcv(Sock);
|
||||||
@ -558,7 +558,7 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
}
|
}
|
||||||
// 2. verify size and hash
|
// 2. verify size and hash
|
||||||
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
if (std::filesystem::file_size(PathToSaveTo) != DownloadedFile.size()) {
|
||||||
error("Failed to write the entire file '" + PathToSaveTo + "' correctly (file size mismatch)");
|
error("Failed to write the entire file '" + PathToSaveTo.string() + "' correctly (file size mismatch)");
|
||||||
Terminate = true;
|
Terminate = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -568,8 +568,8 @@ void NewSyncResources(SOCKET Sock, const std::string& Mods, const std::vector<Mo
|
|||||||
}
|
}
|
||||||
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
|
} while (fs::file_size(PathToSaveTo) != ModInfoIter->FileSize && !Terminate);
|
||||||
if (!Terminate) {
|
if (!Terminate) {
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + L"mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
@ -667,8 +667,8 @@ void SyncResources(SOCKET Sock) {
|
|||||||
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + PathToSaveTo.substr(PathToSaveTo.find_last_of('/')));
|
UpdateUl(false, std::to_string(Pos) + "/" + std::to_string(Amount) + ": " + PathToSaveTo.substr(PathToSaveTo.find_last_of('/')));
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
std::this_thread::sleep_for(std::chrono::milliseconds(50));
|
||||||
try {
|
try {
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + L"mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
auto modname = PathToSaveTo.substr(PathToSaveTo.find_last_of('/'));
|
auto modname = PathToSaveTo.substr(PathToSaveTo.find_last_of('/'));
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
@ -677,8 +677,8 @@ void SyncResources(SOCKET Sock) {
|
|||||||
c = ::tolower(c);
|
c = ::tolower(c);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
auto name = GetGamePath() + L"mods/multiplayer" + Utils::ToWString(modname);
|
auto name = GetGamePath() + beammp_wide("mods/multiplayer") + Utils::ToWString(modname);
|
||||||
auto tmp_name = name + L".tmp";
|
auto tmp_name = name + beammp_wide(".tmp");
|
||||||
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
|
fs::copy_file(PathToSaveTo, tmp_name, fs::copy_options::overwrite_existing);
|
||||||
fs::rename(tmp_name, name);
|
fs::rename(tmp_name, name);
|
||||||
UpdateModUsage(modname);
|
UpdateModUsage(modname);
|
||||||
@ -725,8 +725,8 @@ void SyncResources(SOCKET Sock) {
|
|||||||
}
|
}
|
||||||
} while (fs::file_size(PathToSaveTo) != std::stoull(*FS) && !Terminate);
|
} while (fs::file_size(PathToSaveTo) != std::stoull(*FS) && !Terminate);
|
||||||
if (!Terminate) {
|
if (!Terminate) {
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + L"mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Linux version of the game doesnt support uppercase letters in mod names
|
// Linux version of the game doesnt support uppercase letters in mod names
|
||||||
@ -736,7 +736,7 @@ void SyncResources(SOCKET Sock) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
fs::copy_file(PathToSaveTo, GetGamePath() + L"mods/multiplayer" + Utils::ToWString(FName), fs::copy_options::overwrite_existing);
|
fs::copy_file(PathToSaveTo, GetGamePath() + beammp_wide("mods/multiplayer") + Utils::ToWString(FName), fs::copy_options::overwrite_existing);
|
||||||
UpdateModUsage(FN->substr(pos));
|
UpdateModUsage(FN->substr(pos));
|
||||||
}
|
}
|
||||||
WaitForConfirm();
|
WaitForConfirm();
|
||||||
|
@ -15,6 +15,8 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#endif
|
#endif
|
||||||
#include "Logger.h"
|
#include "Logger.h"
|
||||||
|
#include "Utils.h"
|
||||||
|
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
@ -23,7 +25,7 @@
|
|||||||
#define MAX_VALUE_NAME 16383
|
#define MAX_VALUE_NAME 16383
|
||||||
|
|
||||||
int TraceBack = 0;
|
int TraceBack = 0;
|
||||||
std::wstring GameDir;
|
beammp_fs_string GameDir;
|
||||||
|
|
||||||
void lowExit(int code) {
|
void lowExit(int code) {
|
||||||
TraceBack = 0;
|
TraceBack = 0;
|
||||||
@ -33,7 +35,7 @@ void lowExit(int code) {
|
|||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetGameDir() {
|
beammp_fs_string GetGameDir() {
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
return GameDir.substr(0, GameDir.find_last_of('\\'));
|
return GameDir.substr(0, GameDir.find_last_of('\\'));
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
@ -231,13 +233,9 @@ void LegitimacyCheck() {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
std::string CheckVer(const std::wstring& dir) {
|
std::string CheckVer(const beammp_fs_string& dir) {
|
||||||
std::string temp;
|
std::string temp;
|
||||||
#if defined(_WIN32)
|
beammp_fs_string Path = dir + beammp_wide("\\integrity.json");
|
||||||
std::wstring Path = dir + L"\\integrity.json";
|
|
||||||
#elif defined(__linux__)
|
|
||||||
std::wstring Path = dir + L"/integrity.json";
|
|
||||||
#endif
|
|
||||||
std::ifstream f(Path.c_str(), std::ios::binary);
|
std::ifstream f(Path.c_str(), std::ios::binary);
|
||||||
int Size = int(std::filesystem::file_size(Path));
|
int Size = int(std::filesystem::file_size(Path));
|
||||||
std::string vec(Size, 0);
|
std::string vec(Size, 0);
|
||||||
|
@ -73,12 +73,8 @@ Version::Version(const std::array<uint8_t, 3>& v)
|
|||||||
: Version(v[0], v[1], v[2]) {
|
: Version(v[0], v[1], v[2]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetEN() {
|
beammp_fs_string GetEN() {
|
||||||
#if defined(_WIN32)
|
return beammp_wide("BeamMP-Launcher.exe");
|
||||||
return L"BeamMP-Launcher.exe";
|
|
||||||
#elif defined(__linux__)
|
|
||||||
return L"BeamMP-Launcher";
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string GetVer() {
|
std::string GetVer() {
|
||||||
@ -88,10 +84,10 @@ std::string GetPatch() {
|
|||||||
return ".1";
|
return ".1";
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring GetEP(const wchar_t* P) {
|
beammp_fs_string GetEP(const beammp_fs_char* P) {
|
||||||
static std::wstring Ret = [&]() {
|
static beammp_fs_string Ret = [&]() {
|
||||||
std::wstring path(P);
|
beammp_fs_string path(P);
|
||||||
return path.substr(0, path.find_last_of(L"\\/") + 1);
|
return path.substr(0, path.find_last_of(beammp_wide("\\/")) + 1);
|
||||||
}();
|
}();
|
||||||
return Ret;
|
return Ret;
|
||||||
}
|
}
|
||||||
@ -152,14 +148,14 @@ void CheckName() {
|
|||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
std::wstring DN = GetEN(), CDir = Utils::ToWString(options.executable_name), FN = CDir.substr(CDir.find_last_of('\\') + 1);
|
std::wstring DN = GetEN(), CDir = Utils::ToWString(options.executable_name), FN = CDir.substr(CDir.find_last_of('\\') + 1);
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
std::wstring DN = GetEN(), CDir = Utils::ToWString(options.executable_name), FN = CDir.substr(CDir.find_last_of('/') + 1);
|
std::string DN = GetEN(), CDir = options.executable_name, FN = CDir.substr(CDir.find_last_of('/') + 1);
|
||||||
#endif
|
#endif
|
||||||
if (FN != DN) {
|
if (FN != DN) {
|
||||||
if (fs::exists(DN))
|
if (fs::exists(DN))
|
||||||
_wremove(DN.c_str());
|
fs::remove(DN.c_str());
|
||||||
if (fs::exists(DN))
|
if (fs::exists(DN))
|
||||||
ReLaunch();
|
ReLaunch();
|
||||||
_wrename(FN.c_str(), DN.c_str());
|
fs::rename(FN.c_str(), DN.c_str());
|
||||||
URelaunch();
|
URelaunch();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -170,7 +166,7 @@ void CheckForUpdates(const std::string& CV) {
|
|||||||
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
"https://backend.beammp.com/version/launcher?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
|
|
||||||
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
transform(LatestHash.begin(), LatestHash.end(), LatestHash.begin(), ::tolower);
|
||||||
std::wstring EP(GetEP() + GetEN()), Back(GetEP() + L"BeamMP-Launcher.back");
|
beammp_fs_string EP(GetEP() + GetEN()), Back(GetEP() + beammp_wide("BeamMP-Launcher.back"));
|
||||||
|
|
||||||
std::string FileHash = Utils::GetSha256HashReallyFast(EP);
|
std::string FileHash = Utils::GetSha256HashReallyFast(EP);
|
||||||
|
|
||||||
@ -252,7 +248,7 @@ size_t DirCount(const std::filesystem::path& path) {
|
|||||||
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
return (size_t)std::distance(std::filesystem::directory_iterator { path }, std::filesystem::directory_iterator {});
|
||||||
}
|
}
|
||||||
|
|
||||||
void CheckMP(const std::wstring& Path) {
|
void CheckMP(const beammp_fs_string& Path) {
|
||||||
if (!fs::exists(Path))
|
if (!fs::exists(Path))
|
||||||
return;
|
return;
|
||||||
size_t c = DirCount(fs::path(Path));
|
size_t c = DirCount(fs::path(Path));
|
||||||
@ -272,7 +268,7 @@ void CheckMP(const std::wstring& Path) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void EnableMP() {
|
void EnableMP() {
|
||||||
std::wstring File(GetGamePath() + L"mods/db.json");
|
beammp_fs_string File(GetGamePath() + beammp_wide("mods/db.json"));
|
||||||
if (!fs::exists(File))
|
if (!fs::exists(File))
|
||||||
return;
|
return;
|
||||||
auto Size = fs::file_size(File);
|
auto Size = fs::file_size(File);
|
||||||
@ -295,18 +291,18 @@ void EnableMP() {
|
|||||||
ofs << d.dump();
|
ofs << d.dump();
|
||||||
ofs.close();
|
ofs.close();
|
||||||
} else {
|
} else {
|
||||||
error(L"Failed to write " + File);
|
error(beammp_wide("Failed to write ") + File);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PreGame(const std::wstring& GamePath) {
|
void PreGame(const beammp_fs_string& GamePath) {
|
||||||
std::string GameVer = CheckVer(GamePath);
|
std::string GameVer = CheckVer(GamePath);
|
||||||
info("Game Version : " + GameVer);
|
info("Game Version : " + GameVer);
|
||||||
|
|
||||||
CheckMP(GetGamePath() + L"mods/multiplayer");
|
CheckMP(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
info(L"Game user path: " + GetGamePath());
|
info(beammp_wide("Game user path: ") + GetGamePath());
|
||||||
|
|
||||||
if (!options.no_download) {
|
if (!options.no_download) {
|
||||||
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
std::string LatestHash = HTTP::Get("https://backend.beammp.com/sha/mod?branch=" + Branch + "&pk=" + PublicKey);
|
||||||
@ -316,8 +312,8 @@ void PreGame(const std::wstring& GamePath) {
|
|||||||
LatestHash.end());
|
LatestHash.end());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (!fs::exists(GetGamePath() + L"mods/multiplayer")) {
|
if (!fs::exists(GetGamePath() + beammp_wide("mods/multiplayer"))) {
|
||||||
fs::create_directories(GetGamePath() + L"mods/multiplayer");
|
fs::create_directories(GetGamePath() + beammp_wide("mods/multiplayer"));
|
||||||
}
|
}
|
||||||
EnableMP();
|
EnableMP();
|
||||||
} catch (std::exception& e) {
|
} catch (std::exception& e) {
|
||||||
@ -327,7 +323,7 @@ void PreGame(const std::wstring& GamePath) {
|
|||||||
std::wstring ZipPath(GetGamePath() + LR"(mods\multiplayer\BeamMP.zip)");
|
std::wstring ZipPath(GetGamePath() + LR"(mods\multiplayer\BeamMP.zip)");
|
||||||
#elif defined(__linux__)
|
#elif defined(__linux__)
|
||||||
// Linux version of the game cant handle mods with uppercase names
|
// Linux version of the game cant handle mods with uppercase names
|
||||||
std::wstring ZipPath(GetGamePath() + LR"(mods/multiplayer/beammp.zip)");
|
std::string ZipPath(GetGamePath() + R"(mods/multiplayer/beammp.zip)");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::string FileHash = Utils::GetSha256HashReallyFast(ZipPath);
|
std::string FileHash = Utils::GetSha256HashReallyFast(ZipPath);
|
||||||
@ -340,7 +336,7 @@ void PreGame(const std::wstring& GamePath) {
|
|||||||
ZipPath);
|
ZipPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::wstring Target(GetGamePath() + L"mods/unpacked/beammp");
|
beammp_fs_string Target(GetGamePath() + beammp_wide("mods/unpacked/beammp"));
|
||||||
|
|
||||||
if (fs::is_directory(Target) && !fs::is_directory(Target + "/.git")) {
|
if (fs::is_directory(Target) && !fs::is_directory(Target + "/.git")) {
|
||||||
fs::remove_all(Target);
|
fs::remove_all(Target);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user