add cases for empty paths

edit path usages to use filesystem
This commit is contained in:
Anonymous275 2022-08-20 19:51:00 +03:00
parent 4b09048d10
commit 000af36510
6 changed files with 36 additions and 26 deletions

View File

@ -43,8 +43,8 @@ class Launcher {
void setDiscordMessage(const std::string& message);
static void setExit(bool exit) noexcept;
const std::string& getFullVersion();
const std::string& getMPUserPath();
const std::string& getCachePath();
const fs::path& getMPUserPath();
const fs::path& getCachePath();
static bool Terminated() noexcept;
const std::string& getPublicKey();
const std::string& getUserRole();
@ -70,6 +70,9 @@ class Launcher {
private: // variables
uint32_t GamePID{0};
bool EnableUI = true;
fs::path MPUserPath{};
fs::path BeamUserPath{};
fs::path LauncherCache{};
int64_t DiscordTime{};
bool LoginAuth = false;
fs::path CurrentPath{};
@ -78,13 +81,11 @@ class Launcher {
std::string PublicKey{};
std::thread IPCSystem{};
std::thread DiscordRPC{};
std::string MPUserPath{};
std::string BeamVersion{};
std::string BeamUserPath{};
std::string DiscordMessage{};
Server ServerHandler{this};
std::string TargetBuild{"default"};
std::string LauncherCache{};
static inline std::atomic<bool> Shutdown{false}, Exit{false};
std::unique_ptr<IPC> IPCToGame{};
std::unique_ptr<IPC> IPCFromGame{};

View File

@ -25,19 +25,28 @@ void Launcher::LoadConfig() {
for (char& c : TargetBuild) c = char(tolower(c));
} else LOG(ERROR) << "Failed to get 'Build' string from config";
if (GamePath.is_string()) BeamRoot = GamePath.as_string()->get();
if (GamePath.is_string()) {
if(!GamePath.as_string()->get().empty()) {
BeamRoot = GamePath.as_string()->get();
} else throw ShutdownException("GamePath cannot be empty");
}
else LOG(ERROR) << "Failed to get 'GamePath' string from config";
if (ProfilePath.is_string()) {
BeamUserPath = ProfilePath.as_string()->get();
if (!BeamUserPath.empty()) {
MPUserPath = BeamUserPath + "\\mods\\multiplayer";
}
auto GameVer = VersionParser(UIData::GameVer).split;
if (!ProfilePath.as_string()->get().empty()) {
BeamUserPath = fs::path(ProfilePath.as_string()->get())/(GameVer[0] + '.' + GameVer[1]);
MPUserPath = BeamUserPath/"mods"/"multiplayer";
} else throw ShutdownException("ProfilePath cannot be empty");
}
else LOG(ERROR) << "Failed to get 'ProfilePath' string from config";
if (CachePath.is_string()) LauncherCache = CachePath.as_string()->get();
else LOG(ERROR) << "Failed to get 'CachePath' string from config";
if (CachePath.is_string()) {
if(!CachePath.as_string()->get().empty()) {
LauncherCache = CachePath.as_string()->get();
} else throw ShutdownException("CachePath cannot be empty");
} else LOG(ERROR) << "Failed to get 'CachePath' string from config";
BeamVersion = UIData::GameVer;
} else {

View File

@ -208,7 +208,7 @@ void Launcher::setExit(bool exit) noexcept {
Exit.store(exit);
}
const std::string& Launcher::getMPUserPath() {
const fs::path& Launcher::getMPUserPath() {
return MPUserPath;
}
@ -216,6 +216,6 @@ const std::string& Launcher::getPublicKey() {
return PublicKey;
}
const std::string& Launcher::getCachePath() {
const fs::path& Launcher::getCachePath() {
return LauncherCache;
}

View File

@ -255,7 +255,7 @@ void Server::SyncResources() {
FN != FNames.end() && !Terminate; ++FN, ++FS) {
auto pos = FN->find_last_of('/');
if (pos != std::string::npos) {
a = LauncherInstance->getCachePath() + FN->substr(pos);
a = (LauncherInstance->getCachePath()/FN->substr(pos+1)).string();
} else continue;
Pos++;
if (fs::exists(a)) {
@ -269,8 +269,8 @@ void Server::SyncResources() {
fs::create_directories(LauncherInstance->getMPUserPath());
}
fs::copy_file(a,
LauncherInstance->getMPUserPath() +
a.substr(a.find_last_of('/')),
LauncherInstance->getMPUserPath() /
a.substr(a.find_last_of('/')+1),
fs::copy_options::overwrite_existing);
} catch (std::exception& e) {
LOG(ERROR) << "Failed copy to the mods folder! " << e.what();
@ -282,7 +282,7 @@ void Server::SyncResources() {
} else remove(a.c_str());
}
CheckForDir();
std::string FName = a.substr(a.find_last_of('/'));
std::string FName = a.substr(a.find_last_of('/')+1);
do {
TCPSend("f" + *FN);
@ -313,7 +313,7 @@ void Server::SyncResources() {
if (!fs::exists(LauncherInstance->getMPUserPath())) {
fs::create_directories(LauncherInstance->getMPUserPath());
}
fs::copy_file(a, LauncherInstance->getMPUserPath() + FName,
fs::copy_file(a, LauncherInstance->getMPUserPath()/FName,
fs::copy_options::overwrite_existing);
}
WaitForConfirm();

View File

@ -44,7 +44,7 @@ void Launcher::ResetMods() {
fs::create_directories(MPUserPath);
return;
}
if (DirCount(fs::path(MPUserPath)) > 3) {
if (DirCount(MPUserPath) > 3) {
LOG(WARNING)
<< "mods/multiplayer will be cleared in 15 seconds, close to abort";
std::this_thread::sleep_for(std::chrono::seconds(15));
@ -54,7 +54,7 @@ void Launcher::ResetMods() {
}
void Launcher::EnableMP() {
std::string File(BeamUserPath + "mods\\db.json");
fs::path File(BeamUserPath/"mods"/"db.json");
if (!fs::exists(File)) return;
auto Size = fs::file_size(File);
if (Size < 2) return;
@ -86,5 +86,5 @@ void Launcher::SetupMOD() {
"https://backend.beammp.com/builds/client?download=true"
"&pk=" +
PublicKey + "&branch=" + TargetBuild,
MPUserPath + "\\BeamMP.zip");
(MPUserPath/"BeamMP.zip").string());
}

View File

@ -758,8 +758,8 @@ MySettingsFrame::MySettingsFrame() :
ctrlProfileDirectory->SetLabel("ProfilePath");
auto btnDetectProfileDirectory = new wxButton(panel, 204, wxT("Detect"), wxPoint(185, 240), wxSize(90, 25));
auto* txtCacheDirectory = new wxStaticText(panel, wxID_ANY, wxT("Cache Directory: "), wxPoint(30, 300));
ctrlCacheDirectory = new wxDirPickerCtrl(panel, 202, wxEmptyString, wxT("Cache Directory"), wxPoint(130, 300), wxSize(300, -1));
auto* txtCacheDirectory = new wxStaticText(panel, wxID_ANY, wxT("Download Cache: "), wxPoint(30, 300));
ctrlCacheDirectory = new wxDirPickerCtrl(panel, 202, wxEmptyString, wxT("Download Cache"), wxPoint(130, 300), wxSize(300, -1));
ctrlCacheDirectory->SetLabel("CachePath");
auto btnCacheDirectory = new wxButton(panel, 205, wxT("Reset"), wxPoint(185, 340), wxSize(90, 25));