diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index 59f8f0c..725c767 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -23,6 +23,13 @@ #include #include +#ifdef __linux +#include +#include +#include +#include +#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 *saveitems = playlists["favorites"]; for(std::vector::iterator it = saveitems->begin(); it != saveitems->end(); it++) diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index a6ab599..6dd8eb5 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -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; diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 8594aee..77c2082 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -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); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 5b0e35e..ca26ed6 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -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; }