mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-13 02:08:52 +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 "Item.h"
|
||||||
#include "../Database/Configuration.h"
|
#include "../Database/Configuration.h"
|
||||||
#include "../Utility/Utils.h"
|
#include "../Utility/Utils.h"
|
||||||
|
#include "../Utility/Log.h"
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
#include <fstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <exception>
|
||||||
|
|
||||||
CollectionInfo::CollectionInfo(std::string name,
|
CollectionInfo::CollectionInfo(std::string name,
|
||||||
std::string listPath,
|
std::string listPath,
|
||||||
@ -27,6 +30,7 @@ CollectionInfo::CollectionInfo(std::string name,
|
|||||||
std::string metadataPath)
|
std::string metadataPath)
|
||||||
: name(name)
|
: name(name)
|
||||||
, listpath(listPath)
|
, listpath(listPath)
|
||||||
|
, saveRequest(false)
|
||||||
, metadataType(metadataType)
|
, metadataType(metadataType)
|
||||||
, menusort(true)
|
, menusort(true)
|
||||||
, metadataPath_(metadataPath)
|
, metadataPath_(metadataPath)
|
||||||
@ -38,8 +42,31 @@ CollectionInfo::~CollectionInfo()
|
|||||||
{
|
{
|
||||||
// remove items from the subcollections so their destructors do not
|
// remove items from the subcollections so their destructors do not
|
||||||
// delete the items since the parent collection will delete them.
|
// 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;
|
std::vector<CollectionInfo *>::iterator subit;
|
||||||
for (subit != subcollections_.begin(); subit != subcollections_.end(); subit++)
|
for (subit = subcollections_.begin(); subit != subcollections_.end(); subit++)
|
||||||
{
|
{
|
||||||
CollectionInfo *info = *subit;
|
CollectionInfo *info = *subit;
|
||||||
info->items.clear();
|
info->items.clear();
|
||||||
|
|||||||
@ -33,6 +33,7 @@ public:
|
|||||||
void extensionList(std::vector<std::string> &extensions);
|
void extensionList(std::vector<std::string> &extensions);
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string listpath;
|
std::string listpath;
|
||||||
|
bool saveRequest;
|
||||||
std::string metadataType;
|
std::string metadataType;
|
||||||
std::string launcher;
|
std::string launcher;
|
||||||
std::vector<Item *> items;
|
std::vector<Item *> items;
|
||||||
|
|||||||
@ -505,18 +505,20 @@ bool Page::popCollection()
|
|||||||
if(collections_.size() <= 1) return false;
|
if(collections_.size() <= 1) return false;
|
||||||
|
|
||||||
// queue the collection for deletion
|
// queue the collection for deletion
|
||||||
MenuInfo_S &info = collections_.back();
|
MenuInfo_S *info = &collections_.back();
|
||||||
info.queueDelete = true;
|
info->queueDelete = true;
|
||||||
|
deleteCollections_.push_back(*info);
|
||||||
|
|
||||||
// get the next collection off of the stack
|
// get the next collection off of the stack
|
||||||
collections_.pop_back();
|
collections_.pop_back();
|
||||||
info = collections_.back();
|
info = &collections_.back();
|
||||||
playlist_ = info.playlist;
|
playlist_ = info->playlist;
|
||||||
playlistChanged_ = true;
|
playlistChanged_ = true;
|
||||||
|
|
||||||
if(activeMenu_)
|
if(activeMenu_)
|
||||||
{
|
{
|
||||||
activeMenu_->triggerMenuExitEvent();
|
activeMenu_->triggerMenuExitEvent();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
menuDepth_--;
|
menuDepth_--;
|
||||||
@ -532,7 +534,7 @@ bool Page::popCollection()
|
|||||||
{
|
{
|
||||||
for(std::vector<Component *>::iterator it = LayerComponents[i].begin(); it != LayerComponents[i].end(); ++it)
|
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)
|
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
|
// many nodes still have handles on the collection info. We need to delete
|
||||||
// them once everything is done using them
|
// 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;
|
MenuInfo_S &info = *del;
|
||||||
if(info.queueDelete && info.menu && info.menu->isIdle())
|
if(info.queueDelete && info.menu && info.menu->isIdle())
|
||||||
@ -618,7 +620,8 @@ void Page::update(float dt)
|
|||||||
++next;
|
++next;
|
||||||
|
|
||||||
if(info.collection) delete info.collection;
|
if(info.collection) delete info.collection;
|
||||||
collections_.erase(del);
|
deleteCollections_.erase(del);
|
||||||
|
del = next;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -658,6 +661,7 @@ void Page::removePlaylist()
|
|||||||
if(it != items->end())
|
if(it != items->end())
|
||||||
{
|
{
|
||||||
items->erase(it);
|
items->erase(it);
|
||||||
|
collection->saveRequest = true;
|
||||||
|
|
||||||
if(activeMenu_)
|
if(activeMenu_)
|
||||||
{
|
{
|
||||||
@ -678,6 +682,7 @@ void Page::addPlaylist()
|
|||||||
if(playlist_->first != "favorites" && std::find(items->begin(), items->end(), selectedItem_) == items->end())
|
if(playlist_->first != "favorites" && std::find(items->begin(), items->end(), selectedItem_) == items->end())
|
||||||
{
|
{
|
||||||
items->push_back(selectedItem_);
|
items->push_back(selectedItem_);
|
||||||
|
collection->saveRequest = true;
|
||||||
if(activeMenu_)
|
if(activeMenu_)
|
||||||
{
|
{
|
||||||
activeMenu_->deallocateSpritePoints();
|
activeMenu_->deallocateSpritePoints();
|
||||||
|
|||||||
@ -104,6 +104,7 @@ private:
|
|||||||
unsigned int menuDepth_;
|
unsigned int menuDepth_;
|
||||||
MenuVector_T menus_;
|
MenuVector_T menus_;
|
||||||
CollectionVector_T collections_;
|
CollectionVector_T collections_;
|
||||||
|
CollectionVector_T deleteCollections_;
|
||||||
|
|
||||||
static const unsigned int NUM_LAYERS = 8;
|
static const unsigned int NUM_LAYERS = 8;
|
||||||
std::vector<Component *> LayerComponents[NUM_LAYERS];
|
std::vector<Component *> LayerComponents[NUM_LAYERS];
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user