mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-25 23:55:38 +00:00
save also metadata that have default values. they might not had default values on start so they have to be saved
This commit is contained in:
parent
723b17ae4c
commit
a136179fc9
|
@ -448,6 +448,8 @@ void CollectionSystemManager::exitEditMode()
|
|||
mWindow->setInfoPopup(s);
|
||||
mIsEditingCustom = false;
|
||||
mEditingCollection = "Favorites";
|
||||
|
||||
mEditingCollectionSystemData->system->onMetaDataSavePoint();
|
||||
}
|
||||
|
||||
// adds or removes a game from a specific collection
|
||||
|
@ -521,6 +523,9 @@ bool CollectionSystemManager::toggleGameInCollection(FileData* file)
|
|||
md->set("favorite", "false");
|
||||
}
|
||||
file->getSourceFileData()->getSystem()->getIndex()->addToIndex(file);
|
||||
|
||||
file->getSourceFileData()->getSystem()->onMetaDataSavePoint();
|
||||
|
||||
refreshCollectionSystems(file->getSourceFileData());
|
||||
}
|
||||
if (adding)
|
||||
|
|
|
@ -309,6 +309,8 @@ void FileData::launchGame(Window* window)
|
|||
//update last played time
|
||||
gameToUpdate->metadata.set("lastplayed", Utils::Time::DateTime(Utils::Time::now()));
|
||||
CollectionSystemManager::get()->refreshCollectionSystems(gameToUpdate);
|
||||
|
||||
gameToUpdate->mSystem->onMetaDataSavePoint();
|
||||
}
|
||||
|
||||
CollectionFileData::CollectionFileData(FileData* file, SystemData* system)
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
#include "Gamelist.h"
|
||||
|
||||
#include <chrono>
|
||||
|
||||
#include "utils/FileSystemUtil.h"
|
||||
#include "FileData.h"
|
||||
#include "FileFilterIndex.h"
|
||||
|
@ -217,11 +219,6 @@ void updateGamelist(SystemData* system)
|
|||
{
|
||||
const char* tag = ((*fit)->getType() == GAME) ? "game" : "folder";
|
||||
|
||||
// check if current file has metadata, if no, skip it as it wont be in the gamelist anyway.
|
||||
if ((*fit)->metadata.isDefault()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// do not touch if it wasn't changed anyway
|
||||
if (!(*fit)->metadata.wasChanged())
|
||||
continue;
|
||||
|
@ -255,6 +252,8 @@ void updateGamelist(SystemData* system)
|
|||
//now write the file
|
||||
|
||||
if (numUpdated > 0) {
|
||||
const auto startTs = std::chrono::system_clock::now();
|
||||
|
||||
//make sure the folders leading up to this path exist (or the write will fail)
|
||||
std::string xmlWritePath(system->getGamelistPath(true));
|
||||
Utils::FileSystem::createDirectory(Utils::FileSystem::getParent(xmlWritePath));
|
||||
|
@ -264,6 +263,9 @@ void updateGamelist(SystemData* system)
|
|||
if (!doc.save_file(xmlWritePath.c_str())) {
|
||||
LOG(LogError) << "Error saving gamelist.xml to \"" << xmlWritePath << "\" (for system " << system->getName() << ")!";
|
||||
}
|
||||
|
||||
const auto endTs = std::chrono::system_clock::now();
|
||||
LOG(LogInfo) << "Saved gamelist.xml for system \"" << system->getName() << "\" in " << std::chrono::duration_cast<std::chrono::milliseconds>(endTs - startTs).count() << " ms";
|
||||
}
|
||||
}else{
|
||||
LOG(LogError) << "Found no root folder for system \"" << system->getName() << "\"!";
|
||||
|
|
|
@ -140,17 +140,6 @@ float MetaDataList::getFloat(const std::string& key) const
|
|||
return (float)atof(get(key).c_str());
|
||||
}
|
||||
|
||||
bool MetaDataList::isDefault()
|
||||
{
|
||||
const std::vector<MetaDataDecl>& mdd = getMDD();
|
||||
|
||||
for (unsigned int i = 1; i < mMap.size(); i++) {
|
||||
if (mMap.at(mdd[i].key) != mdd[i].defaultValue) return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MetaDataList::wasChanged() const
|
||||
{
|
||||
return mWasChanged;
|
||||
|
|
|
@ -55,8 +55,6 @@ public:
|
|||
int getInt(const std::string& key) const;
|
||||
float getFloat(const std::string& key) const;
|
||||
|
||||
bool isDefault();
|
||||
|
||||
bool wasChanged() const;
|
||||
void resetChangedFlag();
|
||||
|
||||
|
|
|
@ -50,11 +50,8 @@ SystemData::SystemData(const std::string& name, const std::string& fullName, Sys
|
|||
|
||||
SystemData::~SystemData()
|
||||
{
|
||||
//save changed game data back to xml
|
||||
if(!Settings::getInstance()->getBool("IgnoreGamelist") && Settings::getInstance()->getBool("SaveGamelistsOnExit") && !mIsCollectionSystem)
|
||||
{
|
||||
updateGamelist(this);
|
||||
}
|
||||
if(Settings::getInstance()->getString("SaveGamelistsMode") == "on exit")
|
||||
writeMetaData();
|
||||
|
||||
delete mRootFolder;
|
||||
delete mFilterIndex;
|
||||
|
@ -502,3 +499,18 @@ void SystemData::loadTheme()
|
|||
mTheme = std::make_shared<ThemeData>(); // reset to empty
|
||||
}
|
||||
}
|
||||
|
||||
void SystemData::writeMetaData() {
|
||||
if(Settings::getInstance()->getBool("IgnoreGamelist") || mIsCollectionSystem)
|
||||
return;
|
||||
|
||||
//save changed game data back to xml
|
||||
updateGamelist(this);
|
||||
}
|
||||
|
||||
void SystemData::onMetaDataSavePoint() {
|
||||
if(Settings::getInstance()->getString("SaveGamelistsMode") != "always")
|
||||
return;
|
||||
|
||||
writeMetaData();
|
||||
}
|
||||
|
|
|
@ -68,6 +68,7 @@ public:
|
|||
void loadTheme();
|
||||
|
||||
FileFilterIndex* getIndex() { return mFilterIndex; };
|
||||
void onMetaDataSavePoint();
|
||||
|
||||
private:
|
||||
bool mIsCollectionSystem;
|
||||
|
@ -81,6 +82,7 @@ private:
|
|||
void populateFolder(FileData* folder);
|
||||
void indexAllGameFilters(const FileData* folder);
|
||||
void setIsGameSystemStatus();
|
||||
void writeMetaData();
|
||||
|
||||
FileFilterIndex* mFilterIndex;
|
||||
|
||||
|
|
|
@ -400,10 +400,18 @@ void GuiMenu::openOtherSettings()
|
|||
});
|
||||
|
||||
// gamelists
|
||||
auto save_gamelists = std::make_shared<SwitchComponent>(mWindow);
|
||||
save_gamelists->setState(Settings::getInstance()->getBool("SaveGamelistsOnExit"));
|
||||
s->addWithLabel("SAVE METADATA ON EXIT", save_gamelists);
|
||||
s->addSaveFunc([save_gamelists] { Settings::getInstance()->setBool("SaveGamelistsOnExit", save_gamelists->getState()); });
|
||||
auto gamelistsSaveMode = std::make_shared< OptionListComponent<std::string> >(mWindow, "SAVE METADATA", false);
|
||||
std::vector<std::string> saveModes;
|
||||
saveModes.push_back("on exit");
|
||||
saveModes.push_back("always");
|
||||
saveModes.push_back("never");
|
||||
|
||||
for(auto it = saveModes.cbegin(); it != saveModes.cend(); it++)
|
||||
gamelistsSaveMode->add(*it, *it, Settings::getInstance()->getString("SaveGamelistsMode") == *it);
|
||||
s->addWithLabel("SAVE METADATA", gamelistsSaveMode);
|
||||
s->addSaveFunc([gamelistsSaveMode] {
|
||||
Settings::getInstance()->setString("SaveGamelistsMode", gamelistsSaveMode->getSelected());
|
||||
});
|
||||
|
||||
auto parse_gamelists = std::make_shared<SwitchComponent>(mWindow);
|
||||
parse_gamelists->setState(Settings::getInstance()->getBool("ParseGamelistOnly"));
|
||||
|
|
|
@ -199,6 +199,8 @@ void GuiMetaDataEd::save()
|
|||
|
||||
// update respective Collection Entries
|
||||
CollectionSystemManager::get()->refreshCollectionSystems(mScraperParams.game);
|
||||
|
||||
mScraperParams.system->onMetaDataSavePoint();
|
||||
}
|
||||
|
||||
void GuiMetaDataEd::fetch()
|
||||
|
|
|
@ -76,7 +76,6 @@ void Settings::setDefaults()
|
|||
mBoolMap["HideConsole"] = true;
|
||||
mBoolMap["QuickSystemSelect"] = true;
|
||||
mBoolMap["MoveCarousel"] = true;
|
||||
mBoolMap["SaveGamelistsOnExit"] = true;
|
||||
|
||||
mBoolMap["Debug"] = false;
|
||||
mBoolMap["DebugGrid"] = false;
|
||||
|
@ -97,6 +96,7 @@ void Settings::setDefaults()
|
|||
mStringMap["ScreenSaverBehavior"] = "dim";
|
||||
mStringMap["Scraper"] = "TheGamesDB";
|
||||
mStringMap["GamelistViewStyle"] = "automatic";
|
||||
mStringMap["SaveGamelistsMode"] = "on exit";
|
||||
|
||||
mBoolMap["ScreenSaverControls"] = true;
|
||||
mStringMap["ScreenSaverGameInfo"] = "never";
|
||||
|
@ -228,6 +228,19 @@ void Settings::loadFile()
|
|||
setFloat(node.attribute("name").as_string(), node.attribute("value").as_float());
|
||||
for(pugi::xml_node node = doc.child("string"); node; node = node.next_sibling("string"))
|
||||
setString(node.attribute("name").as_string(), node.attribute("value").as_string());
|
||||
|
||||
processBackwardCompatibility();
|
||||
}
|
||||
|
||||
void Settings::processBackwardCompatibility()
|
||||
{
|
||||
{ // SaveGamelistsOnExit -> SaveGamelistsMode
|
||||
std::map<std::string, bool>::const_iterator it = mBoolMap.find("SaveGamelistsOnExit");
|
||||
if (it != mBoolMap.end()) {
|
||||
mStringMap["SaveGamelistsMode"] = it->second ? "on exit" : "never";
|
||||
mBoolMap.erase(it);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//Print a warning message if the setting we're trying to get doesn't already exist in the map, then return the value in the map.
|
||||
|
|
|
@ -31,6 +31,7 @@ private:
|
|||
|
||||
//Clear everything and load default values.
|
||||
void setDefaults();
|
||||
void processBackwardCompatibility();
|
||||
|
||||
std::map<std::string, bool> mBoolMap;
|
||||
std::map<std::string, int> mIntMap;
|
||||
|
|
Loading…
Reference in a new issue