Corrected switching to favorites list by adding a separate function for that purpose.

Restricted playlist add/remove to games for now.
Fixed not writing playlist if the playlists directory does not exist; directory is now created.
This commit is contained in:
Pieter Hulshoff 2016-05-11 09:00:55 +02:00
parent 84d301dd5a
commit 9c47adc9cc
4 changed files with 65 additions and 1 deletions

View File

@ -23,6 +23,13 @@
#include <algorithm>
#include <exception>
#ifdef __linux
#include <sys/stat.h>
#include <sys/types.h>
#include <errno.h>
#include <cstring>
#endif
CollectionInfo::CollectionInfo(std::string name,
std::string listPath,
std::string extensions,
@ -76,12 +83,38 @@ bool CollectionInfo::Save()
bool retval = true;
if(saveRequest)
{
std::string dir = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists");
std::string file = Utils::combinePath(Configuration::absolutePath, "collections", name, "playlists/favorites.txt");
Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file);
std::ofstream filestream;
try
{
// Create playlists directory if it does not exist yet.
struct stat info;
if ( stat( dir.c_str(), &info ) != 0 && (info.st_mode & S_IFDIR) )
{
#if defined(_WIN32) && !defined(__GNUC__)
if(!CreateDirectory(dir, NULL))
{
if(ERROR_ALREADY_EXISTS != GetLastError())
{
std::cout << "Could not create folder \"" << *it << "\"" << std::endl;
return false;
}
}
#else
#if defined(__MINGW32__)
if(mkdir(dir.c_str()) == -1)
#else
if(mkdir(dir.c_str(), 0755) == -1)
#endif
{
std::cout << "Could not create folder \"" << dir << "\":" << errno << std::endl;
}
#endif
}
filestream.open(file.c_str());
std::vector<Item *> *saveitems = playlists["favorites"];
for(std::vector<Item *>::iterator it = saveitems->begin(); it != saveitems->end(); it++)

View File

@ -606,6 +606,34 @@ void Page::nextPlaylist()
playlistChanged_ = true;
}
void Page::favPlaylist()
{
MenuInfo_S &info = collections_.back();
info.collection->Save();
unsigned int numlists = info.collection->playlists.size();
// Store current playlist
CollectionInfo::Playlists_T::iterator playlist_store = playlist_;
for(unsigned int i = 0; i <= numlists; ++i)
{
playlist_++;
// wrap
if(playlist_ == info.collection->playlists.end()) playlist_ = info.collection->playlists.begin();
// find the first playlist
if(playlist_->second->size() != 0 && playlist_->first == "favorites") break;
}
// Do not change playlist if favorites does not exist
if ( playlist_->first != "favorites" )
playlist_ = playlist_store;
activeMenu_->setItems(playlist_->second);
activeMenu_->triggerMenuEnterEvent();
playlistChanged_ = true;
}
void Page::update(float dt)
{
for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++)
@ -690,6 +718,7 @@ void Page::draw()
void Page::removePlaylist()
{
if(!selectedItem_) return;
if(!selectedItem_->leaf) return;
MenuInfo_S &info = collections_.back();
CollectionInfo *collection = info.collection;
@ -713,6 +742,7 @@ void Page::removePlaylist()
void Page::addPlaylist()
{
if(!selectedItem_) return;
if(!selectedItem_->leaf) return;
MenuInfo_S &info = collections_.back();
CollectionInfo *collection = info.collection;

View File

@ -48,6 +48,7 @@ public:
bool pushCollection(CollectionInfo *collection);
bool popCollection();
void nextPlaylist();
void favPlaylist();
void pushMenu(ScrollingList *s);
bool isMenusFull();
void setLoadSound(Sound *chunk);

View File

@ -533,7 +533,7 @@ RetroFE::RETROFE_STATE RetroFE::processUserInput(Page *page)
config_.getProperty("autoFavorites", autoFavorites);
if (autoFavorites)
page->nextPlaylist(); // Switch to favorites if it exists
page->favPlaylist(); // Switch to favorites if it exists
state = RETROFE_NEXT_PAGE_REQUEST;
}