mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 17:58:53 +01:00
Save support for favorites.txt. Misc bug fixes. Not fully tested.
This commit is contained in:
parent
b940534e48
commit
248f1993a0
@ -17,8 +17,11 @@
|
||||
#include "Item.h"
|
||||
#include "../Database/Configuration.h"
|
||||
#include "../Utility/Utils.h"
|
||||
#include "../Utility/Log.h"
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <exception>
|
||||
|
||||
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<Item *> *saveitems = playlists["favorites"];
|
||||
for(std::vector<Item *>::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<CollectionInfo *>::iterator subit;
|
||||
for (subit != subcollections_.begin(); subit != subcollections_.end(); subit++)
|
||||
for (subit = subcollections_.begin(); subit != subcollections_.end(); subit++)
|
||||
{
|
||||
CollectionInfo *info = *subit;
|
||||
info->items.clear();
|
||||
|
||||
@ -33,6 +33,7 @@ public:
|
||||
void extensionList(std::vector<std::string> &extensions);
|
||||
std::string name;
|
||||
std::string listpath;
|
||||
bool saveRequest;
|
||||
std::string metadataType;
|
||||
std::string launcher;
|
||||
std::vector<Item *> items;
|
||||
|
||||
@ -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<Component *>::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<MenuInfo_S>::iterator del = collections_.begin();
|
||||
std::list<MenuInfo_S>::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();
|
||||
|
||||
@ -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<Component *> LayerComponents[NUM_LAYERS];
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user