add CachingDirectory config setting to cache mods elsewhere

also moved cls/clear to the beginning, idk wtf it was doing in there.
This commit is contained in:
Lion Kortlepel 2024-09-23 22:31:58 +02:00
parent 4bedfc8e96
commit 1362471657
No known key found for this signature in database
GPG Key ID: 4322FF2B4C71259B
5 changed files with 22 additions and 16 deletions

View File

@ -30,6 +30,7 @@ extern int DEFAULT_PORT;
extern uint64_t UDPSock; extern uint64_t UDPSock;
extern uint64_t TCPSock; extern uint64_t TCPSock;
extern std::string Branch; extern std::string Branch;
extern std::string CachingDirectory;
extern bool TCPTerminate; extern bool TCPTerminate;
extern std::string LastIP; extern std::string LastIP;
extern std::string MStatus; extern std::string MStatus;

View File

@ -11,6 +11,8 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
std::string Branch; std::string Branch;
std::string CachingDirectory = "./Resources";
void ParseConfig(const nlohmann::json& d) { void ParseConfig(const nlohmann::json& d) {
if (d["Port"].is_number()) { if (d["Port"].is_number()) {
DEFAULT_PORT = d["Port"].get<int>(); DEFAULT_PORT = d["Port"].get<int>();
@ -20,12 +22,15 @@ void ParseConfig(const nlohmann::json& d) {
// EA 2 // EA 2
// Dev 3 // Dev 3
// Custom 3 // Custom 3
if (d["Build"].is_string()) { if (d["Build"].is_string()) {
Branch = d["Build"].get<std::string>(); Branch = d["Build"].get<std::string>();
for (char& c : Branch) for (char& c : Branch)
c = char(tolower(c)); c = char(tolower(c));
} }
if (d.contains("CachingDirectory") && d["CachingDirectory"].is_string()) {
CachingDirectory = d["CachingDirectory"].get<std::string>();
info("Mod caching directory: " + CachingDirectory);
}
} }
void ConfigInit() { void ConfigInit() {
@ -49,7 +54,8 @@ void ConfigInit() {
cfg << cfg <<
R"({ R"({
"Port": 4444, "Port": 4444,
"Build": "Default" "Build": "Default",
"CachingDirectory": "./Resources",
})"; })";
cfg.close(); cfg.close();
} else { } else {

View File

@ -36,13 +36,8 @@
namespace fs = std::filesystem; namespace fs = std::filesystem;
void CheckForDir() { void CheckForDir() {
if (!fs::exists("Resources")) { if (!fs::exists(CachingDirectory)) {
// Could we just use fs::create_directory instead? fs::create_directory(CachingDirectory);
#if defined(_WIN32)
_wmkdir(L"Resources");
#elif defined(__linux__)
fs::create_directory(L"Resources");
#endif
} }
} }
void WaitForConfirm() { void WaitForConfirm() {
@ -297,7 +292,7 @@ void SyncResources(SOCKET Sock) {
for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) { for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) {
auto pos = FN->find_last_of('/'); auto pos = FN->find_last_of('/');
if (pos != std::string::npos) { if (pos != std::string::npos) {
PathToSaveTo = "Resources" + FN->substr(pos); PathToSaveTo = CachingDirectory + FN->substr(pos);
} else { } else {
continue; continue;
} }

View File

@ -101,6 +101,7 @@ void ReLaunch(int argc, char* args[]) {
Arg += " "; Arg += " ";
Arg += args[c - 1]; Arg += args[c - 1];
} }
info("Relaunch!");
system("cls"); system("cls");
ShellExecute(nullptr, "runas", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL); ShellExecute(nullptr, "runas", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL);
ShowWindow(GetConsoleWindow(), 0); ShowWindow(GetConsoleWindow(), 0);
@ -125,6 +126,7 @@ void ReLaunch(int argc, char* args[]) {
Arg += " "; Arg += " ";
Arg += args[c - 1]; Arg += args[c - 1];
} }
info("Relaunch!");
system("clear"); system("clear");
execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL); execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL);
std::this_thread::sleep_for(std::chrono::seconds(1)); std::this_thread::sleep_for(std::chrono::seconds(1));
@ -167,10 +169,6 @@ void CheckForUpdates(int argc, char* args[], const std::string& CV) {
std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back"); std::string EP(GetEP() + GetEN()), Back(GetEP() + "BeamMP-Launcher.back");
std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP); std::string FileHash = hashpp::get::getFileHash(hashpp::ALGORITHMS::SHA2_256, EP);
#if defined(_WIN32)
#elif defined(__linux__)
system("clear");
#endif
if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion))) && !Dev) { if (FileHash != LatestHash && IsOutdated(Version(VersionStrToInts(GetVer() + GetPatch())), Version(VersionStrToInts(LatestVersion))) && !Dev) {
info("Launcher update found!"); info("Launcher update found!");
@ -237,7 +235,6 @@ void LinuxPatch() {
#if defined(_WIN32) #if defined(_WIN32)
void InitLauncher(int argc, char* argv[]) { void InitLauncher(int argc, char* argv[]) {
system("cls");
SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str()); SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str());
InitLog(); InitLog();
CheckName(argc, argv); CheckName(argc, argv);
@ -249,7 +246,6 @@ void InitLauncher(int argc, char* argv[]) {
} }
#elif defined(__linux__) #elif defined(__linux__)
void InitLauncher(int argc, char* argv[]) { void InitLauncher(int argc, char* argv[]) {
system("clear");
InitLog(); InitLog();
CheckName(argc, argv); CheckName(argc, argv);
CheckLocalKey(); CheckLocalKey();

View File

@ -26,6 +26,14 @@ int main(int argc, char* argv[]) {
th.detach(); th.detach();
#endif #endif
#if defined(_WIN32)
system("cls");
#elif defined(__linux__)
system("clear");
#endif
GetEP(argv[0]); GetEP(argv[0]);
for (int i = 0; i < argc; ++i) { for (int i = 0; i < argc; ++i) {