diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp index 4d4d7ce..51de9be 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include CollectionInfoBuilder::CollectionInfoBuilder(Configuration &c, MetadataDatabase &mdb) @@ -36,6 +37,100 @@ CollectionInfoBuilder::~CollectionInfoBuilder() { } +bool CollectionInfoBuilder::CreateCollectionDirectory(std::string name) +{ + std::string collectionPath = Configuration::GetAbsolutePath() + "/collections/" + name; + + std::vector paths; + paths.push_back(collectionPath); + paths.push_back(collectionPath + "/medium_artwork"); + paths.push_back(collectionPath + "/medium_artwork/artwork_back"); + paths.push_back(collectionPath + "/medium_artwork/artwork_front"); + paths.push_back(collectionPath + "/medium_artwork/bezel"); + paths.push_back(collectionPath + "/medium_artwork/logo"); + paths.push_back(collectionPath + "/medium_artwork/medium_back"); + paths.push_back(collectionPath + "/medium_artwork/medium_front"); + paths.push_back(collectionPath + "/medium_artwork/screenshot"); + paths.push_back(collectionPath + "/medium_artwork/screentitle"); + paths.push_back(collectionPath + "/medium_artwork/video"); + paths.push_back(collectionPath + "/roms"); + paths.push_back(collectionPath + "/system_artwork"); + + for(std::vector::iterator it = paths.begin(); it != paths.end(); it++) + { + std::cout << "Creating folder \"" << *it << "\"" << std::endl; + +#if defined(_WIN32) + if(!CreateDirectory(it->c_str(), NULL)) + { + if(ERROR_ALREADY_EXISTS != GetLastError()) + { + std::cout << "Could not create folder \"" << *it << "\"" << std::endl; + return false; + } + } +#else + if(mkdir(it->c_str(), 0644) == -1) + { + std::cout << "Could not create folder \"" << *it << "\" error: " << errno << std::endl; + } + #endif + } + + std::ofstream includeFile; + std::cout << "Creating file \"" << collectionPath + "/include.txt" << "\"" << std::endl; + includeFile.open(collectionPath + "/include.txt"); + includeFile << "# Add a list of files to show on the menu (one filename per line, without the extension)." << std::endl; + includeFile << "# If no items are in this list then all files in the folder specified" << std::endl; + includeFile << "# by settings.conf will be used" << std::endl; + includeFile.close(); + + std::ofstream excludeFile; + std::cout << "Creating file \"" << collectionPath + "/exclude.txt" << "\"" << std::endl; + excludeFile.open(collectionPath + "/exclude.txt"); + includeFile << "# Add a list of files to hide on the menu (one filename per line, without the extension)." << std::endl; + excludeFile.close(); + + std::ofstream settingsFile; + std::cout << "Creating file \"" << collectionPath + "/settings.conf" << "\"" << std::endl; + settingsFile.open(collectionPath + "/settings.conf"); + settingsFile << "# Uncomment and edit the following line to use a different ROM path." << std::endl; + settingsFile << "#list.path = %BASE_ITEM_PATH%/%ITEM_COLLECTION_NAME%/roms" << std::endl; + settingsFile << "list.extensions = zip" << std::endl; + settingsFile << "launcher = mame" << std::endl; + settingsFile << "metadata.type = MAME" << std::endl; + settingsFile << std::endl; + settingsFile << "#media.screenshot = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/screenshot" << std::endl; + settingsFile << "#media.screentitle = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/screentitle" << std::endl; + settingsFile << "#media.artwork_back = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/artwork_back" << std::endl; + settingsFile << "#media.artwork_front = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/artwork_front" << std::endl; + settingsFile << "#media.logo = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/logo" << std::endl; + settingsFile << "#media.medium_back = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/medium_back" << std::endl; + settingsFile << "#media.medium_front = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/medium_front" << std::endl; + settingsFile << "#media.screenshot = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/screenshot" << std::endl; + settingsFile << "#media.screentitle = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/screentitle" << std::endl; + settingsFile << "#media.video = %BASE_MEDIA_PATH%/%ITEM_COLLECTION_NAME%/medium_artwork/video" << std::endl; + settingsFile.close(); + + std::ofstream menuFile; + std::cout << "Creating file \"" << collectionPath + "/menu.xml" << "\"" << std::endl; + menuFile.open(collectionPath + "/menu.xml"); + + menuFile << "" << std::endl; + menuFile << std::endl; + menuFile << "" << std::endl; + menuFile << std::endl; + menuFile << "" << std::endl; + menuFile.close(); + + return true; +} + CollectionInfo *CollectionInfoBuilder::BuildCollection(std::string name) { std::string listItemsPathKey = "collections." + name + ".list.path"; diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h index cff4809..d87eaf9 100644 --- a/RetroFE/Source/Collection/CollectionInfoBuilder.h +++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h @@ -30,6 +30,7 @@ public: CollectionInfoBuilder(Configuration &c, MetadataDatabase &mdb); virtual ~CollectionInfoBuilder(); CollectionInfo *BuildCollection(std::string collectionName); + static bool CreateCollectionDirectory(std::string collectionName); private: Configuration &Conf; diff --git a/RetroFE/Source/Main.cpp b/RetroFE/Source/Main.cpp index c2af6e4..47dbb2e 100644 --- a/RetroFE/Source/Main.cpp +++ b/RetroFE/Source/Main.cpp @@ -15,6 +15,7 @@ */ #include "Database/Configuration.h" +#include "Collection/CollectionInfoBuilder.h" #include "Execute/Launcher.h" #include "Utility/Log.h" #include "Utility/Utils.h" @@ -27,9 +28,8 @@ static bool ImportConfiguration(Configuration *c); static bool StartLogging(); -int main(int /* argc */, char ** /* argv */) +int main(int argc, char **argv) { - Configuration::Initialize(); Configuration config; @@ -39,6 +39,21 @@ int main(int /* argc */, char ** /* argv */) return -1; } + // check to see if createcollection was requested + if(argc == 3) + { + std::string param = argv[1]; + std::string value = argv[2]; + + if(param == "-createcollection") + { + CollectionInfoBuilder::CreateCollectionDirectory(value); + } + + return 0; + } + + if(!ImportConfiguration(&config)) { return -1;