Profile(Manager): add basic 0.8 profile support.

This commit is contained in:
Guillaume Jacquemin 2022-03-06 14:42:24 +01:00
parent 89bba618fb
commit db6836ec33
3 changed files with 17 additions and 7 deletions

View file

@ -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<StringProperty>("Account");
auto account_prop = _profile.at<StringProperty>("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 {

View file

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

View file

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