diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp index d40cae0..cd8915c 100644 --- a/RetroFE/Source/Collection/CollectionInfo.cpp +++ b/RetroFE/Source/Collection/CollectionInfo.cpp @@ -143,6 +143,7 @@ bool CollectionInfo::Save() return retval; } + std::string CollectionInfo::settingsPath() const { return Utils::combinePath(Configuration::absolutePath, "collections", name); diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 57cfed8..f9dc409 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -484,10 +484,134 @@ void CollectionInfoBuilder::addPlaylists(CollectionInfo *info) info->playlists["favorites"] = new std::vector(); } + if(info->playlists["lastplayed"] == NULL) + { + info->playlists["lastplayed"] = new std::vector(); + } + return; } +void CollectionInfoBuilder::updateLastPlayedPlaylist(CollectionInfo *info, Item *item) +{ + std::string path = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "playlists"); + Logger::write(Logger::ZONE_INFO, "RetroFE", "Updating lastplayed playlist"); + + std::vector lastplayedList; + std::string playlistFile = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "playlists", "lastplayed.txt"); + ImportBasicList(info, playlistFile, lastplayedList); + + if (info->playlists["lastplayed"] == NULL) + info->playlists["lastplayed"] = new std::vector(); + else + info->playlists["lastplayed"]->clear(); + + int lastplayedSize = 0; + (void)conf_.getProperty("lastplayedSize", lastplayedSize); + + if (lastplayedSize == 0) + return; + + // Put the new item at the front of the list. + info->playlists["lastplayed"]->push_back(item); + + // Add the items already in the playlist up to the lastplayedSize. + for(std::vector::iterator it = lastplayedList.begin(); it != lastplayedList.end(); it++) + { + if (info->playlists["lastplayed"]->size() >= static_cast( lastplayedSize )) + break; + + std::string collectionName = info->name; + std::string itemName = (*it)->name; + if (itemName.at(0) == '_') // name consists of _: + { + itemName.erase(0, 1); // Remove _ + size_t position = itemName.find(":"); + if (position != std::string::npos ) + { + collectionName = itemName.substr(0, position); + itemName = itemName.erase(0, position+1); + } + } + + for(std::vector::iterator it = info->items.begin(); it != info->items.end(); it++) + { + if ( (*it)->name == itemName && (*it)->collectionInfo->name == collectionName && (*it) != item) + { + info->playlists["lastplayed"]->push_back((*it)); + } + } + } + + // Write new lastplayed playlist + std::string dir = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "playlists"); + std::string file = Utils::combinePath(Configuration::absolutePath, "collections", info->name, "playlists/lastplayed.txt"); + Logger::write(Logger::ZONE_INFO, "Collection", "Saving " + file); + + std::ofstream filestream; + try + { + // Create playlists directory if it does not exist yet. + struct stat infostat; + if ( stat( dir.c_str(), &infostat ) != 0 ) + { +#if defined(_WIN32) && !defined(__GNUC__) + if(!CreateDirectory(dir.c_str(), NULL)) + { + if(ERROR_ALREADY_EXISTS != GetLastError()) + { + Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir); + return false; + } + } +#else +#if defined(__MINGW32__) + if(mkdir(dir.c_str()) == -1) +#else + if(mkdir(dir.c_str(), 0755) == -1) +#endif + { + Logger::write(Logger::ZONE_WARNING, "Collection", "Could not create directory " + dir); + return; + } +#endif + } + else if ( !(infostat.st_mode & S_IFDIR) ) + { + Logger::write(Logger::ZONE_WARNING, "Collection", dir + " exists, but is not a directory."); + return; + } + + filestream.open(file.c_str()); + std::vector *saveitems = info->playlists["lastplayed"]; + for(std::vector::iterator it = saveitems->begin(); it != saveitems->end(); it++) + { + if ((*it)->collectionInfo->name == info->name) + { + filestream << (*it)->name << std::endl; + } + else + { + filestream << "_" << (*it)->collectionInfo->name << ":" << (*it)->name << std::endl; + } + } + + filestream.close(); + } + catch(std::exception &) + { + Logger::write(Logger::ZONE_ERROR, "Collection", "Save failed: " + file); + } + + // Sort the playlist(s) + info->sortPlaylists( ); + + return; + +} + + void CollectionInfoBuilder::ImportRomDirectory(std::string path, CollectionInfo *info, std::map includeFilter, std::map excludeFilter, bool romHierarchy, bool emuarc) { diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index b3c8255..dfd53e1 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -32,6 +32,7 @@ public: CollectionInfo *buildCollection(std::string collectionName); CollectionInfo *buildCollection(std::string collectionName, std::string mergedCollectionName); void addPlaylists(CollectionInfo *info); + void updateLastPlayedPlaylist(CollectionInfo *info, Item *item); void injectMetadata(CollectionInfo *info); static bool createCollectionDirectory(std::string collectionName); bool ImportBasicList(CollectionInfo *info, std::string file, std::vector &list); diff --git a/RetroFE/Source/Graphics/Page.cpp b/RetroFE/Source/Graphics/Page.cpp index 2691597..f9cf29f 100644 --- a/RetroFE/Source/Graphics/Page.cpp +++ b/RetroFE/Source/Graphics/Page.cpp @@ -1195,6 +1195,12 @@ std::string Page::getCollectionName() } +CollectionInfo *Page::getCollection() +{ + return collections_.back().collection; +} + + void Page::freeGraphicsMemory() { for(MenuVector_T::iterator it = menus_.begin(); it != menus_.end(); it++) diff --git a/RetroFE/Source/Graphics/Page.h b/RetroFE/Source/Graphics/Page.h index 5310167..2f99e6d 100644 --- a/RetroFE/Source/Graphics/Page.h +++ b/RetroFE/Source/Graphics/Page.h @@ -95,6 +95,7 @@ public: void playSelect(); bool isSelectPlaying(); std::string getCollectionName(); + CollectionInfo *getCollection(); void setMinShowTime(float value); float getMinShowTime(); void menuScroll(); @@ -108,6 +109,7 @@ public: void setText( std::string text, int id ); void addPlaylist(); void removePlaylist(); + void updateLastPlayedPlaylist( Item *item ); void reallocateMenuSpritePoints(); bool isMenuScrolling(); bool isPlaying(); diff --git a/RetroFE/Source/RetroFE.cpp b/RetroFE/Source/RetroFE.cpp index 5f29d93..3a243d3 100644 --- a/RetroFE/Source/RetroFE.cpp +++ b/RetroFE/Source/RetroFE.cpp @@ -701,6 +701,8 @@ void RetroFE::run( ) { nextPageItem_ = currentPage_->getSelectedItem( ); launchEnter( ); + CollectionInfoBuilder cib(config_, *metadb_); + cib.updateLastPlayedPlaylist( currentPage_->getCollection(), nextPageItem_ ); l.run(nextPageItem_->collectionInfo->name, nextPageItem_); launchExit( ); currentPage_->exitGame( ); diff --git a/RetroFE/Source/Version.cpp b/RetroFE/Source/Version.cpp index 4f01f09..d3e612e 100644 --- a/RetroFE/Source/Version.cpp +++ b/RetroFE/Source/Version.cpp @@ -21,7 +21,7 @@ std::string retrofe_version_major = "0"; std::string retrofe_version_minor = "8"; -std::string retrofe_version_build = "31"; +std::string retrofe_version_build = "32"; std::string Version::getString( )