From db6836ec33c077229a8db6338cdb17e7ec6f86fe Mon Sep 17 00:00:00 2001 From: William JCM Date: Sun, 6 Mar 2022 14:42:24 +0100 Subject: [PATCH] Profile(Manager): add basic 0.8 profile support. --- src/Profile/Profile.cpp | 11 ++++++++--- src/ProfileManager/ProfileManager.cpp | 5 +++-- src/SaveTool/SaveTool_ProfileManager.cpp | 8 ++++++-- 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/Profile/Profile.cpp b/src/Profile/Profile.cpp index d956d98..6931dcc 100644 --- a/src/Profile/Profile.cpp +++ b/src/Profile/Profile.cpp @@ -36,16 +36,21 @@ using namespace Containers::Literals; Profile::Profile(Containers::StringView path): _profile(path) { + if(!_profile.valid()) { + _lastError = _profile.lastError(); + return; + } + _filename = Utility::Directory::filename(path); - if(Utility::String::beginsWith(_filename, "Demo"_s)) { + if(_filename.hasPrefix("Demo"_s)) { _type = ProfileType::Demo; } else { _type = ProfileType::FullGame; } - auto account_prop = _profile.at("Account"); + auto account_prop = _profile.at("Account"_s); if(!account_prop) { _lastError = "Couldn't find an account ID in "_s + _filename; _valid = false; @@ -53,7 +58,7 @@ Profile::Profile(Containers::StringView path): } _account = account_prop->value; - if(Utility::String::beginsWith(_account, "PMCSlot"_s)) { + if(_account.hasPrefix("PMCSlot"_s)) { _version = ProfileVersion::Normal; } else { diff --git a/src/ProfileManager/ProfileManager.cpp b/src/ProfileManager/ProfileManager.cpp index a97cc22..cc995ed 100644 --- a/src/ProfileManager/ProfileManager.cpp +++ b/src/ProfileManager/ProfileManager.cpp @@ -60,9 +60,10 @@ auto ProfileManager::refreshProfiles() -> bool { auto files = Utility::Directory::list(_saveDirectory, Flag::SkipSpecial|Flag::SkipDirectories|Flag::SkipDotAndDotDot); auto predicate = [](Containers::StringView file)->bool{ - std::regex regex("(Demo)?Profile[0-9]{17}\\.sav", std::regex::nosubs); + std::regex legacy_regex("(Demo)?Profile[0-9]{17}\\.sav", std::regex::nosubs); + std::regex new_regex("(Demo)?ProfilePMCSlot[0-9]{3}\\.sav", std::regex::nosubs); std::cmatch m; - return !std::regex_match(file.data(), m, regex); + return !std::regex_match(file.data(), m, legacy_regex) && !std::regex_match(file.data(), m, new_regex); }; files.erase(std::remove_if(files.begin(), files.end(), predicate), files.end()); diff --git a/src/SaveTool/SaveTool_ProfileManager.cpp b/src/SaveTool/SaveTool_ProfileManager.cpp index 4752bf1..5840a06 100644 --- a/src/SaveTool/SaveTool_ProfileManager.cpp +++ b/src/SaveTool/SaveTool_ProfileManager.cpp @@ -77,11 +77,13 @@ void SaveTool::drawProfileManager() { ImGui::TextUnformatted("Actions"); for(std::size_t i = 0; i < _profileManager->profiles().size(); ++i) { + Profile& profile = _profileManager->profiles()[i]; + ImGui::TableNextRow(); ImGui::TableSetColumnIndex(0); ImGui::PushID(i); - if(ImGui::Selectable(_profileManager->profiles()[i].companyName().data(), false, + if(ImGui::Selectable(profile.companyName().data(), false, ImGuiSelectableFlags_SpanAllColumns|ImGuiSelectableFlags_AllowItemOverlap)) { _currentProfile = _profileManager->getProfile(i); @@ -90,7 +92,9 @@ void SaveTool::drawProfileManager() { } ImGui::TableSetColumnIndex(1); - ImGui::TextUnformatted(_profileManager->profiles()[i].type() == ProfileType::Demo ? "Demo (legacy)" : "Full (legacy)"); + ImGui::Text("%s%s", + profile.type() == ProfileType::Demo ? "Demo" : "Full", + profile.version() == ProfileVersion::Legacy ? " (legacy)" : ""); ImGui::TableSetColumnIndex(2); if(ImGui::SmallButton(ICON_FA_FILE_ARCHIVE)) {