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 TCPSock;
extern std::string Branch;
extern std::string CachingDirectory;
extern bool TCPTerminate;
extern std::string LastIP;
extern std::string MStatus;

View File

@ -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<int>();
@ -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<std::string>();
for (char& c : Branch)
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() {
@ -49,7 +54,8 @@ void ConfigInit() {
cfg <<
R"({
"Port": 4444,
"Build": "Default"
"Build": "Default",
"CachingDirectory": "./Resources",
})";
cfg.close();
} else {

View File

@ -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;
}

View File

@ -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();

View File

@ -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) {