diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index 88304fe..62489f7 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -17,8 +17,11 @@ #include "Item.h" #include "../Database/Configuration.h" #include "../Utility/Utils.h" +#include "../Utility/Log.h" #include +#include #include +#include CollectionInfo::CollectionInfo(std::string name, std::string listPath, @@ -27,6 +30,7 @@ CollectionInfo::CollectionInfo(std::string name, std::string metadataPath) : name(name) , listpath(listPath) + , saveRequest(false) , metadataType(metadataType) , menusort(true) , metadataPath_(metadataPath) @@ -38,8 +42,31 @@ CollectionInfo::~CollectionInfo() { // remove items from the subcollections so their destructors do not // delete the items since the parent collection will delete them. + if(saveRequest) + { + std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "favorites.txt"); + Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file); + + std::ofstream filestream; + try + { + filestream.open(file.c_str()); + std::vector *saveitems = playlists["favorites"]; + for(std::vector::iterator it = saveitems->begin(); it != saveitems->end(); it++) + { + filestream << (*it)->name << std::endl; + } + + filestream.close(); + } + catch(std::exception &) + { + Logger::write(Logger::ZONE_ERROR, "Collection", "Save failed: " + file); + } + } + std::vector::iterator subit; - for (subit != subcollections_.begin(); subit != subcollections_.end(); subit++) + for (subit = subcollections_.begin(); subit != subcollections_.end(); subit++) { CollectionInfo *info = *subit; info->items.clear(); diff --git a/RetroFE/Source/Collection/CollectionInfo.h b/RetroFE/Source/Collection/CollectionInfo.h index b017fcf..c520f4f 100644 --- a/RetroFE/Source/Collection/CollectionInfo.h +++ b/RetroFE/Source/Collection/CollectionInfo.h @@ -33,6 +33,7 @@ public: void extensionList(std::vector &extensions); std::string name; std::string listpath; + bool saveRequest; std::string metadataType; std::string launcher; std::vector items; diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 8d1e07e..1b24174 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -505,18 +505,20 @@ bool Page::popCollection() if(collections_.size() <= 1) return false; // queue the collection for deletion - MenuInfo_S &info = collections_.back(); - info.queueDelete = true; + MenuInfo_S *info = &collections_.back(); + info->queueDelete = true; + deleteCollections_.push_back(*info); // get the next collection off of the stack collections_.pop_back(); - info = collections_.back(); - playlist_ = info.playlist; + info = &collections_.back(); + playlist_ = info->playlist; playlistChanged_ = true; if(activeMenu_) { activeMenu_->triggerMenuExitEvent(); + } menuDepth_--; @@ -532,7 +534,7 @@ bool Page::popCollection() { for(std::vector::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it) { - (*it)->collectionName = info.collection->name; + (*it)->collectionName = info->collection->name; if(menuEnterIndex >= 0) { @@ -607,9 +609,9 @@ void Page::update(float dt) // many nodes still have handles on the collection info. We need to delete // them once everything is done using them - std::list::iterator del = collections_.begin(); + std::list::iterator del = deleteCollections_.begin(); - while(del != collections_.end()) + while(del != deleteCollections_.end()) { MenuInfo_S &info = *del; if(info.queueDelete && info.menu && info.menu->isIdle()) @@ -618,7 +620,8 @@ void Page::update(float dt) ++next; if(info.collection) delete info.collection; - collections_.erase(del); + deleteCollections_.erase(del); + del = next; } else { @@ -658,6 +661,7 @@ void Page::removePlaylist() if(it != items->end()) { items->erase(it); + collection->saveRequest = true; if(activeMenu_) { @@ -678,6 +682,7 @@ void Page::addPlaylist() if(playlist_->first != "favorites" && std::find(items->begin(), items->end(), selectedItem_) == items->end()) { items->push_back(selectedItem_); + collection->saveRequest = true; if(activeMenu_) { activeMenu_->deallocateSpritePoints(); diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 1d634c0..6ac2a8b 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -104,6 +104,7 @@ private: unsigned int menuDepth_; MenuVector_T menus_; CollectionVector_T collections_; + CollectionVector_T deleteCollections_; static const unsigned int NUM_LAYERS = 8; std::vector LayerComponents[NUM_LAYERS];