diff --git a/include/Network/network.hpp b/include/Network/network.hpp index 9d59e74..406f914 100644 --- a/include/Network/network.hpp +++ b/include/Network/network.hpp @@ -30,6 +30,7 @@ extern int DEFAULT_PORT; extern uint64_t UDPSock; extern uint64_t TCPSock; extern std::string Branch; +extern std::string CachingDirectory; extern bool TCPTerminate; extern std::string LastIP; extern std::string MStatus; diff --git a/src/Config.cpp b/src/Config.cpp index 9c6affc..f8cb242 100644 --- a/src/Config.cpp +++ b/src/Config.cpp @@ -11,6 +11,8 @@ namespace fs = std::filesystem; std::string Branch; +std::string CachingDirectory = "./Resources"; + void ParseConfig(const nlohmann::json& d) { if (d["Port"].is_number()) { DEFAULT_PORT = d["Port"].get(); @@ -20,12 +22,15 @@ void ParseConfig(const nlohmann::json& d) { // EA 2 // Dev 3 // Custom 3 - if (d["Build"].is_string()) { Branch = d["Build"].get(); for (char& c : Branch) c = char(tolower(c)); } + if (d.contains("CachingDirectory") && d["CachingDirectory"].is_string()) { + CachingDirectory = d["CachingDirectory"].get(); + info("Mod caching directory: " + CachingDirectory); + } } void ConfigInit() { @@ -49,7 +54,8 @@ void ConfigInit() { cfg << R"({ "Port": 4444, - "Build": "Default" + "Build": "Default", + "CachingDirectory": "./Resources", })"; cfg.close(); } else { diff --git a/src/Network/Resources.cpp b/src/Network/Resources.cpp index 8b491c3..d1849a8 100644 --- a/src/Network/Resources.cpp +++ b/src/Network/Resources.cpp @@ -36,13 +36,8 @@ namespace fs = std::filesystem; void CheckForDir() { - if (!fs::exists("Resources")) { -// Could we just use fs::create_directory instead? -#if defined(_WIN32) - _wmkdir(L"Resources"); -#elif defined(__linux__) - fs::create_directory(L"Resources"); -#endif + if (!fs::exists(CachingDirectory)) { + fs::create_directory(CachingDirectory); } } void WaitForConfirm() { @@ -297,7 +292,7 @@ void SyncResources(SOCKET Sock) { for (auto FN = FNames.begin(), FS = FSizes.begin(); FN != FNames.end() && !Terminate; ++FN, ++FS) { auto pos = FN->find_last_of('/'); if (pos != std::string::npos) { - PathToSaveTo = "Resources" + FN->substr(pos); + PathToSaveTo = CachingDirectory + FN->substr(pos); } else { continue; } diff --git a/src/Startup.cpp b/src/Startup.cpp index bfe9ccf..c7442e7 100644 --- a/src/Startup.cpp +++ b/src/Startup.cpp @@ -101,6 +101,7 @@ void ReLaunch(int argc, char* args[]) { Arg += " "; Arg += args[c - 1]; } + info("Relaunch!"); system("cls"); ShellExecute(nullptr, "runas", (GetEP() + GetEN()).c_str(), Arg.c_str(), nullptr, SW_SHOWNORMAL); ShowWindow(GetConsoleWindow(), 0); @@ -125,6 +126,7 @@ void ReLaunch(int argc, char* args[]) { Arg += " "; Arg += args[c - 1]; } + info("Relaunch!"); system("clear"); execl((GetEP() + GetEN()).c_str(), Arg.c_str(), NULL); 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 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) { info("Launcher update found!"); @@ -237,7 +235,6 @@ void LinuxPatch() { #if defined(_WIN32) void InitLauncher(int argc, char* argv[]) { - system("cls"); SetConsoleTitleA(("BeamMP Launcher v" + std::string(GetVer()) + GetPatch()).c_str()); InitLog(); CheckName(argc, argv); @@ -249,7 +246,6 @@ void InitLauncher(int argc, char* argv[]) { } #elif defined(__linux__) void InitLauncher(int argc, char* argv[]) { - system("clear"); InitLog(); CheckName(argc, argv); CheckLocalKey(); diff --git a/src/main.cpp b/src/main.cpp index 8c0dfe9..1fc13f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,14 @@ int main(int argc, char* argv[]) { th.detach(); #endif + +#if defined(_WIN32) + system("cls"); +#elif defined(__linux__) + system("clear"); +#endif + + GetEP(argv[0]); for (int i = 0; i < argc; ++i) {