diff --git a/RetroFE/Source/CMakeLists.txt b/RetroFE/Source/CMakeLists.txt
index c1b5f1e..f0899fe 100644
--- a/RetroFE/Source/CMakeLists.txt
+++ b/RetroFE/Source/CMakeLists.txt
@@ -79,9 +79,9 @@ set(RETROFE_HEADERS
"${RETROFE_DIR}/Source/Collection/Item.h"
"${RETROFE_DIR}/Source/Collection/MenuParser.h"
"${RETROFE_DIR}/Source/Control/UserInput.h"
- "${RETROFE_DIR}/Source/Database/CollectionDatabase.h"
"${RETROFE_DIR}/Source/Database/Configuration.h"
"${RETROFE_DIR}/Source/Database/DB.h"
+ "${RETROFE_DIR}/Source/Database/MetadataDatabase.h"
"${RETROFE_DIR}/Source/Database/MamelistMetadata.h"
"${RETROFE_DIR}/Source/Execute/AttractMode.h"
"${RETROFE_DIR}/Source/Execute/Launcher.h"
@@ -122,9 +122,9 @@ set(RETROFE_SOURCES
"${RETROFE_DIR}/Source/Collection/Item.cpp"
"${RETROFE_DIR}/Source/Collection/MenuParser.cpp"
"${RETROFE_DIR}/Source/Control/UserInput.cpp"
- "${RETROFE_DIR}/Source/Database/CollectionDatabase.cpp"
"${RETROFE_DIR}/Source/Database/Configuration.cpp"
"${RETROFE_DIR}/Source/Database/DB.cpp"
+ "${RETROFE_DIR}/Source/Database/MetadataDatabase.cpp"
"${RETROFE_DIR}/Source/Database/MamelistMetadata.cpp"
"${RETROFE_DIR}/Source/Execute/AttractMode.cpp"
"${RETROFE_DIR}/Source/Execute/Launcher.cpp"
diff --git a/RetroFE/Source/Collection/CollectionInfo.cpp b/RetroFE/Source/Collection/CollectionInfo.cpp
index b4fee86..61b5308 100644
--- a/RetroFE/Source/Collection/CollectionInfo.cpp
+++ b/RetroFE/Source/Collection/CollectionInfo.cpp
@@ -14,6 +14,7 @@
* along with RetroFE. If not, see .
*/
#include "CollectionInfo.h"
+#include "Item.h"
#include "../Database/Configuration.h"
#include
@@ -32,6 +33,14 @@ CollectionInfo::CollectionInfo(std::string name,
CollectionInfo::~CollectionInfo()
{
+ std::vector- ::iterator it = Items.begin();
+
+ while(it != Items.end())
+ {
+ delete *it;
+ Items.erase(it);
+ it = Items.begin();
+ }
}
std::string CollectionInfo::GetName() const
@@ -74,6 +83,10 @@ void CollectionInfo::GetExtensions(std::vector &extensions)
extensions.push_back(token);
}
}
+std::vector
- *CollectionInfo::GetItems()
+{
+ return &Items;
+}
diff --git a/RetroFE/Source/Collection/CollectionInfo.h b/RetroFE/Source/Collection/CollectionInfo.h
index 9f5750e..c3d2d4b 100644
--- a/RetroFE/Source/Collection/CollectionInfo.h
+++ b/RetroFE/Source/Collection/CollectionInfo.h
@@ -6,6 +6,8 @@
#include
#include
+class Item;
+
class CollectionInfo
{
public:
@@ -17,6 +19,7 @@ public:
std::string GetMetadataType() const;
std::string GetMetadataPath() const;
std::string GetExtensions() const;
+ std::vector
- *GetItems();
void GetExtensions(std::vector &extensions);
private:
@@ -25,4 +28,5 @@ private:
std::string Extensions;
std::string MetadataType;
std::string MetadataPath;
+ std::vector
- Items;
};
diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp
index 41138be..fb68d51 100644
--- a/RetroFE/Source/Collection/CollectionInfoBuilder.cpp
+++ b/RetroFE/Source/Collection/CollectionInfoBuilder.cpp
@@ -15,86 +15,28 @@
*/
#include "CollectionInfoBuilder.h"
#include "CollectionInfo.h"
+#include "Item.h"
#include "../Database/Configuration.h"
+#include "../Database/MetadataDatabase.h"
+#include "../Database/DB.h"
#include "../Utility/Log.h"
+#include "../Utility/Utils.h"
+#include
#include
#include
-CollectionInfoBuilder::CollectionInfoBuilder(Configuration &c)
+CollectionInfoBuilder::CollectionInfoBuilder(Configuration &c, DB &db)
: Conf(c)
+ , MetaDB(db, c)
{
}
CollectionInfoBuilder::~CollectionInfoBuilder()
{
- std::map::iterator it = InfoMap.begin();
-
- for(it == InfoMap.begin(); it != InfoMap.end(); ++it)
- {
- delete it->second;
- }
-
- InfoMap.clear();
}
-bool CollectionInfoBuilder::LoadAllCollections()
+CollectionInfo *CollectionInfoBuilder::BuildCollection(std::string name)
{
- std::vector collections;
-
- Conf.GetChildKeyCrumbs("collections", collections);
-
- if(collections.size() == 0)
- {
- Logger::Write(Logger::ZONE_ERROR, "Collections", "No collections were found. Please configure Settings.conf");
- return false;
- }
-
- bool retVal = true;
- std::vector::iterator it;
-
- for(it = collections.begin(); it != collections.end(); ++it)
- {
- // todo: There is nothing that should really stop us from creating a collection
- // in the main folder. I just need to find some time to look at the impacts if
- // I remove this conditional check.
- if(*it != "Main")
- {
- std::string oldCollection = Conf.GetCurrentCollection();
- Conf.SetCurrentCollection(*it);
- if(ImportCollection(*it))
- {
- Logger::Write(Logger::ZONE_INFO, "Collections", "Adding collection " + *it);
- }
- else
- {
- // Continue processing the rest of the collections if an error occurs during import.
- // ImportCollection() will print out an error to the log file.
- retVal = false;
- }
- Conf.SetCurrentCollection(oldCollection);
- }
- }
-
- return retVal;
-}
-
-void CollectionInfoBuilder::GetCollections(std::vector &collections)
-{
- std::map::iterator InfoMapIt;
-
- for(InfoMapIt = InfoMap.begin(); InfoMapIt != InfoMap.end(); ++InfoMapIt)
- {
- collections.push_back(InfoMapIt->second);
- }
-}
-
-bool CollectionInfoBuilder::ImportCollection(std::string name)
-{
- // create a new instance if one does not exist
- if(InfoMap.find(name) != InfoMap.end())
- {
- return true;
- }
std::string listItemsPathKey = "collections." + name + ".list.path";
std::string listFilterKey = "collections." + name + ".list.filter";
std::string extensionsKey = "collections." + name + ".list.extensions";
@@ -128,7 +70,87 @@ bool CollectionInfoBuilder::ImportCollection(std::string name)
Logger::Write(Logger::ZONE_WARNING, "Collections", ss.str());
}
- InfoMap[name] = new CollectionInfo(name, listItemsPath, extensions, metadataType, metadataPath);
+ CollectionInfo *collection = new CollectionInfo(name, listItemsPath, extensions, metadataType, metadataPath);
+ std::vector
- *list = collection->GetItems();
- return (InfoMap[name] != NULL);
+ ImportDirectory(collection);
+
+ return collection;
}
+
+bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
+{
+ DIR *dp;
+ struct dirent *dirp;
+ std::string path = info->GetListPath();
+ std::map includeFilter;
+ std::map excludeFilter;
+ bool retVal = true;
+ std::string includeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.txt";
+ std::string excludeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Exclude.txt";
+ std::string launcher;
+
+ (void)Conf.GetProperty("collections." + info->GetName() + ".launcher", launcher);
+
+ dp = opendir(path.c_str());
+ std::vector extensions;
+ info->GetExtensions(extensions);
+ std::vector::iterator extensionsIt;
+
+ if(dp == NULL)
+ {
+ Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + path + "\"");
+ //todo: store into a database
+ }
+ else
+ {
+ while((dirp = readdir(dp)) != NULL)
+ {
+ std::string file = dirp->d_name;
+
+ Utils::NormalizeBackSlashes(file);
+ size_t position = file.find_last_of(".");
+ std::string basename = (std::string::npos == position)? file : file.substr(0, position);
+
+ if((includeFilter.size() == 0 || includeFilter.find(basename) != includeFilter.end()) &&
+ (excludeFilter.size() == 0 || excludeFilter.find(basename) == excludeFilter.end()))
+ {
+ for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt)
+ {
+ std::string comparator = "." + *extensionsIt;
+ int start = file.length() - comparator.length() + 1;
+
+ if(start >= 0)
+ {
+ if(file.compare(start, comparator.length(), *extensionsIt) == 0)
+ {
+ Item *i = new Item();
+ i->SetName(basename);
+ i->SetFullTitle(basename);
+ i->SetTitle(basename);
+ i->SetLauncher(launcher);
+ info->GetItems()->push_back(i);
+ }
+ }
+ }
+ }
+ }
+ }
+
+ MetaDB.UpdateMetadata(info);
+
+ while(includeFilter.size() > 0)
+ {
+ std::map::iterator it = includeFilter.begin();
+ delete it->second;
+ includeFilter.erase(it);
+ }
+ while(excludeFilter.size() > 0)
+ {
+ std::map::iterator it = excludeFilter.begin();
+ delete it->second;
+ excludeFilter.erase(it);
+ }
+
+ return true;
+}
\ No newline at end of file
diff --git a/RetroFE/Source/Collection/CollectionInfoBuilder.h b/RetroFE/Source/Collection/CollectionInfoBuilder.h
index f512bcf..b07f444 100644
--- a/RetroFE/Source/Collection/CollectionInfoBuilder.h
+++ b/RetroFE/Source/Collection/CollectionInfoBuilder.h
@@ -3,6 +3,8 @@
*/
#pragma once
+#include "../Database/DB.h"
+#include "../Database/MetadataDatabase.h"
#include
#include