Compare commits

..

1 commit

Author SHA1 Message Date
PhilaPhan80
3cd6d4bba5
Merge feab8293e5 into 4a064a2130 2024-04-27 16:02:51 +02:00
4 changed files with 86 additions and 131 deletions

View file

@ -15,7 +15,6 @@
#include "ThemeData.h"
#include <pugixml.hpp>
#include <fstream>
#include <cstring>
/* Handling the getting, initialization, deinitialization, saving and deletion of
* a CollectionSystemManager Instance */
@ -100,29 +99,17 @@ void CollectionSystemManager::deinit()
}
}
bool CollectionSystemManager::saveCustomCollection(SystemData* sys)
void CollectionSystemManager::saveCustomCollection(SystemData* sys)
{
std::string name = sys->getName();
std::unordered_map<std::string, FileData*> games = sys->getRootFolder()->getChildrenByFilename();
bool found = mCustomCollectionSystemsData.find(name) != mCustomCollectionSystemsData.cend();
if (!found)
{
LOG(LogError) << "Couldn't find collection to save! " << name;
return false;
}
if (found) {
CollectionSystemData sysData = mCustomCollectionSystemsData.at(name);
if (sysData.needsSave)
{
std::string absCollectionFn = getCustomCollectionConfigPath(name);
std::ofstream configFile;
configFile.open(absCollectionFn);
if (!configFile.good())
{
auto const errNo = errno;
LOG(LogError) << "Failed to create file, collection not created: " << absCollectionFn << ": " << std::strerror(errNo) << " (" << errNo << ")";
return false;
}
configFile.open(getCustomCollectionConfigPath(name));
for(std::unordered_map<std::string, FileData*>::const_iterator iter = games.cbegin(); iter != games.cend(); ++iter)
{
std::string path = iter->first;
@ -130,7 +117,11 @@ bool CollectionSystemManager::saveCustomCollection(SystemData* sys)
}
configFile.close();
}
return true;
}
else
{
LOG(LogError) << "Couldn't find collection to save! " << name;
}
}
/* Methods to load all Collections into memory, and handle enabling the active ones */
@ -139,7 +130,7 @@ void CollectionSystemManager::loadCollectionSystems(bool async)
{
initAutoCollectionSystems();
CollectionSystemDecl decl = mCollectionSystemDeclsIndex[CUSTOM_COLL_ID];
mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, CollectionFlags::NONE);
mCustomCollectionsBundle = createNewCollectionEntry(decl.name, decl, false);
// we will also load custom systems here
initCustomCollectionSystems();
if(Settings::getInstance()->getString("CollectionSystemsAuto") != "" || Settings::getInstance()->getString("CollectionSystemsCustom") != "")
@ -386,7 +377,6 @@ bool CollectionSystemManager::isThemeCustomCollectionCompatible(std::vector<std:
std::string CollectionSystemManager::getValidNewCollectionName(std::string inName, int index)
{
std::string name = inName;
const std::string infix = " (" + std::to_string(index) + ")";
if(index == 0)
{
@ -400,7 +390,7 @@ std::string CollectionSystemManager::getValidNewCollectionName(std::string inNam
}
else
{
name += infix;
name += " (" + std::to_string(index) + ")";
}
if(name == "")
@ -410,7 +400,7 @@ std::string CollectionSystemManager::getValidNewCollectionName(std::string inNam
if(name != inName)
{
LOG(LogInfo) << "Name collision, had to change name from: " << inName << " to: " << name;
LOG(LogInfo) << "Had to change name, from: " << inName << " to: " << name;
}
// get used systems in es_systems.cfg
@ -430,7 +420,7 @@ std::string CollectionSystemManager::getValidNewCollectionName(std::string inNam
if (*sysIt == name)
{
if(index > 0) {
name = name.substr(0, name.size() - infix.size());
name = name.substr(0, name.size()-4);
}
return getValidNewCollectionName(name, index+1);
}
@ -460,7 +450,7 @@ void CollectionSystemManager::setEditMode(std::string collectionName, bool quiet
mEditingCollectionSystemData = sysData;
if (!quiet) {
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Editing the '" + Utils::String::toUpper(collectionName) + "' Collection. Add/remove games with Y.", 8000);
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Editing the '" + Utils::String::toUpper(collectionName) + "' Collection. Add/remove games with Y.", 10000);
mWindow->setInfoPopup(s);
}
}
@ -468,14 +458,14 @@ void CollectionSystemManager::setEditMode(std::string collectionName, bool quiet
void CollectionSystemManager::exitEditMode(bool quiet)
{
if (!quiet) {
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Finished editing the '" + Utils::String::toUpper(mEditingCollection) + "' Collection.", 4000);
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Finished editing the '" + mEditingCollection + "' Collection.", 4000);
mWindow->setInfoPopup(s);
}
if (mIsEditingCustom) {
mIsEditingCustom = false;
mEditingCollection = "Favorites";
mEditingCollectionSystemData->system->onMetaDataSavePoint();
saveCustomCollection(mEditingCollectionSystemData->system);
}
}
@ -668,7 +658,7 @@ void CollectionSystemManager::initAutoCollectionSystems()
CollectionSystemDecl sysDecl = it->second;
if (!sysDecl.isCustom)
{
SystemData* newCol = createNewCollectionEntry(sysDecl.name, sysDecl, CollectionFlags::HOLD_IN_MAP);
SystemData* newCol = createNewCollectionEntry(sysDecl.name, sysDecl);
if (sysDecl.type == AUTO_RANDOM)
mRandomCollection = newCol;
}
@ -768,20 +758,17 @@ SystemData* CollectionSystemManager::getAllGamesCollection()
return allSysData->system;
}
SystemData* CollectionSystemManager::addNewCustomCollection(std::string name, bool needsSave)
SystemData* CollectionSystemManager::addNewCustomCollection(std::string name)
{
CollectionSystemDecl decl = mCollectionSystemDeclsIndex[CUSTOM_COLL_ID];
decl.themeFolder = name;
decl.name = name;
decl.longName = name;
CollectionFlags flags = CollectionFlags::HOLD_IN_MAP;
if (needsSave)
flags = flags | CollectionFlags::NEEDS_SAVE;
return createNewCollectionEntry(name, decl, flags);
return createNewCollectionEntry(name, decl);
}
// creates a new, empty Collection system, based on the name and declaration
SystemData* CollectionSystemManager::createNewCollectionEntry(std::string name, CollectionSystemDecl sysDecl, const CollectionFlags flags)
SystemData* CollectionSystemManager::createNewCollectionEntry(std::string name, CollectionSystemDecl sysDecl, bool index)
{
SystemData* newSys = new SystemData(name, sysDecl.longName, mCollectionEnvData, sysDecl.themeFolder, true);
@ -790,9 +777,9 @@ SystemData* CollectionSystemManager::createNewCollectionEntry(std::string name,
newCollectionData.decl = sysDecl;
newCollectionData.isEnabled = false;
newCollectionData.isPopulated = false;
newCollectionData.needsSave = (flags & CollectionFlags::NEEDS_SAVE) == CollectionFlags::NEEDS_SAVE ? true : false;
newCollectionData.needsSave = false;
if ((flags & CollectionFlags::HOLD_IN_MAP) == CollectionFlags::HOLD_IN_MAP)
if (index)
{
if (!sysDecl.isCustom)
{

View file

@ -30,24 +30,6 @@ enum CollectionSystemType
CUSTOM_COLLECTION
};
// Flags when loading or creating a collection
enum class CollectionFlags : uint8_t
{
NONE, // create only
HOLD_IN_MAP, // create and keep in mAutoCollectionSystemsData or mCustomCollectionSystemsData
NEEDS_SAVE // force save of newly added collection
};
constexpr CollectionFlags operator|(CollectionFlags a,CollectionFlags b)
{
return static_cast<CollectionFlags>(static_cast<uint8_t>(a) | static_cast<uint8_t>(b));
}
constexpr CollectionFlags operator&(CollectionFlags a, CollectionFlags b)
{
return static_cast<CollectionFlags>(static_cast<uint8_t>(a) & static_cast<uint8_t>(b));
}
struct CollectionSystemDecl
{
CollectionSystemType type; // type of system
@ -76,7 +58,7 @@ public:
static CollectionSystemManager* get();
static void init(Window* window);
static void deinit();
bool saveCustomCollection(SystemData* sys);
void saveCustomCollection(SystemData* sys);
void loadCollectionSystems(bool async=false);
void loadEnabledListFromSettings();
@ -92,7 +74,7 @@ public:
inline SystemData* getCustomCollectionsBundle() { return mCustomCollectionsBundle; };
inline SystemData* getRandomCollection() { return mRandomCollection; };
std::vector<std::string> getUnusedSystemsFromTheme();
SystemData* addNewCustomCollection(std::string name, bool needsSave = false);
SystemData* addNewCustomCollection(std::string name);
bool isThemeGenericCollectionCompatible(bool genericCustomCollections);
bool isThemeCustomCollectionCompatible(std::vector<std::string> stringVector);
@ -125,7 +107,7 @@ private:
void initAutoCollectionSystems();
void initCustomCollectionSystems();
SystemData* createNewCollectionEntry(std::string name, CollectionSystemDecl sysDecl, const CollectionFlags flags);
SystemData* createNewCollectionEntry(std::string name, CollectionSystemDecl sysDecl, bool index = true);
void populateAutoCollection(CollectionSystemData* sysData);
void populateCustomCollection(CollectionSystemData* sysData);
void addRandomGames(SystemData* newSys, SystemData* sourceSystem, FileData* rootFolder, FileFilterIndex* index,

View file

@ -1,10 +1,7 @@
#include <fstream>
#include "guis/GuiCollectionSystemsOptions.h"
#include "components/OptionListComponent.h"
#include "components/SwitchComponent.h"
#include "guis/GuiInfoPopup.h"
#include "guis/GuiRandomCollectionOptions.h"
#include "guis/GuiSettings.h"
#include "guis/GuiTextEditPopup.h"
@ -28,16 +25,6 @@ void GuiCollectionSystemsOptions::initializeMenu()
// manage random collection
addEntry("RANDOM GAME COLLECTION SETTINGS", 0x777777FF, true, [this] { openRandomCollectionSettings(); });
ComponentListRow row;
if(CollectionSystemManager::get()->isEditing())
{
row.addElement(std::make_shared<TextComponent>(mWindow, "FINISH EDITING '" + Utils::String::toUpper(CollectionSystemManager::get()->getEditingCollection()) + "' COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.makeAcceptInputHandler(std::bind(&GuiCollectionSystemsOptions::exitEditMode, this));
mMenu.addRow(row);
}
else
{
// add "Create New Custom Collection from Theme"
std::vector<std::string> unusedFolders = CollectionSystemManager::get()->getUnusedSystemsFromTheme();
if (unusedFolders.size() > 0)
@ -66,6 +53,7 @@ void GuiCollectionSystemsOptions::initializeMenu()
});
}
ComponentListRow row;
row.addElement(std::make_shared<TextComponent>(mWindow, "CREATE NEW CUSTOM COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
auto createCustomCollection = [this](const std::string& newVal) {
std::string name = newVal;
@ -78,8 +66,8 @@ void GuiCollectionSystemsOptions::initializeMenu()
row.makeAcceptInputHandler([this, createCustomCollection] {
mWindow->pushGui(new GuiTextEditPopup(mWindow, "New Collection Name", "", createCustomCollection, false));
});
mMenu.addRow(row);
}
bundleCustomCollections = std::make_shared<SwitchComponent>(mWindow);
bundleCustomCollections->setState(Settings::getInstance()->getBool("UseCustomCollectionsSystem"));
@ -115,6 +103,14 @@ void GuiCollectionSystemsOptions::initializeMenu()
mMenu.addWithLabel("ADD/REMOVE GAMES WHILE SCREENSAVER TO", defaultScreenSaverCollection);
if(CollectionSystemManager::get()->isEditing())
{
row.elements.clear();
row.addElement(std::make_shared<TextComponent>(mWindow, "FINISH EDITING '" + Utils::String::toUpper(CollectionSystemManager::get()->getEditingCollection()) + "' COLLECTION", Font::get(FONT_SIZE_MEDIUM), 0x777777FF), true);
row.makeAcceptInputHandler(std::bind(&GuiCollectionSystemsOptions::exitEditMode, this));
mMenu.addRow(row);
}
mMenu.addButton("BACK", "back", std::bind(&GuiCollectionSystemsOptions::applySettings, this));
mMenu.setPosition((Renderer::getScreenWidth() - mMenu.getSize().x()) / 2, Renderer::getScreenHeight() * 0.15f);
@ -141,15 +137,8 @@ void GuiCollectionSystemsOptions::addEntry(const char* name, unsigned int color,
void GuiCollectionSystemsOptions::createCollection(std::string inName)
{
CollectionSystemManager* collSysMgr = CollectionSystemManager::get();
std::string name = collSysMgr->getValidNewCollectionName(inName);
SystemData* newSys = collSysMgr->addNewCustomCollection(name, true);
if (!collSysMgr->saveCustomCollection(newSys)) {
GuiInfoPopup* s = new GuiInfoPopup(mWindow, "Failed creating '" + Utils::String::toUpper(name) + "' Collection. See log for details.", 8000);
mWindow->setInfoPopup(s);
return;
}
std::string name = CollectionSystemManager::get()->getValidNewCollectionName(inName);
SystemData* newSys = CollectionSystemManager::get()->addNewCustomCollection(name);
customOptionList->add(name, name, true);
std::string outAuto = Utils::String::vectorToDelimitedString(autoOptionList->getSelectedObjects(), ",");
std::string outCustom = Utils::String::vectorToDelimitedString(customOptionList->getSelectedObjects(), ",");
@ -157,9 +146,10 @@ void GuiCollectionSystemsOptions::createCollection(std::string inName)
ViewController::get()->goToSystemView(newSys);
Window* window = mWindow;
collSysMgr->setEditMode(name);
CollectionSystemManager::get()->setEditMode(name);
while(window->peekGui() && window->peekGui() != ViewController::get())
delete window->peekGui();
return;
}
void GuiCollectionSystemsOptions::openRandomCollectionSettings()

View file

@ -66,13 +66,9 @@ void BasicGameListView::setCursor(FileData* cursor, bool refreshListCursorPos)
if (refreshListCursorPos)
setViewportTop(mList.REFRESH_LIST_CURSOR_POS);
bool notInList = !mList.setCursor(cursor);
if(!refreshListCursorPos && notInList && !cursor->isPlaceHolder())
if(!mList.setCursor(cursor) && (!cursor->isPlaceHolder()))
{
populateList(cursor->getParent()->getChildrenListToDisplay());
// this extra call is needed iff a system has games organized in folders
// and the cursor is focusing a game in a folder
if (cursor->getParent()->getType() == FOLDER)
mList.setCursor(cursor);
// update our cursor stack in case our cursor just got set to some folder we weren't in before