From a9dbc4e004496407274cb031ca19c72b308df4ce Mon Sep 17 00:00:00 2001 From: emb <> Date: Fri, 27 Feb 2015 23:16:47 -0600 Subject: [PATCH] Added genre type. Fixed invalid error where folders starting with _ were treated as actual collections. --- RetroFE/Source/Collection/Item.cpp | 10 ++++++ RetroFE/Source/Collection/Item.h | 3 ++ RetroFE/Source/Database/MetadataDatabase.cpp | 33 +++++++++++-------- .../Graphics/Component/ReloadableMedia.cpp | 6 ++++ .../Graphics/Component/ReloadableText.cpp | 7 ++++ .../Graphics/Component/ReloadableText.h | 1 + RetroFE/Source/Main.cpp | 28 ++++++++-------- RetroFE/Source/Utility/Utils.cpp | 7 ++++ RetroFE/Source/Utility/Utils.h | 1 + 9 files changed, 68 insertions(+), 28 deletions(-) diff --git a/RetroFE/Source/Collection/Item.cpp b/RetroFE/Source/Collection/Item.cpp index 40247df..0c46ad8 100644 --- a/RetroFE/Source/Collection/Item.cpp +++ b/RetroFE/Source/Collection/Item.cpp @@ -63,6 +63,16 @@ void Item::SetManufacturer(const std::string& manufacturer) Manufacturer = manufacturer; } +const std::string& Item::GetGenre() const +{ + return Genre; +} + +void Item::SetGenre(const std::string& genre) +{ + Genre = genre; +} + const std::string& Item::GetName() const { return Name; diff --git a/RetroFE/Source/Collection/Item.h b/RetroFE/Source/Collection/Item.h index 80da0cf..f08cecc 100644 --- a/RetroFE/Source/Collection/Item.h +++ b/RetroFE/Source/Collection/Item.h @@ -29,6 +29,8 @@ public: void SetLauncher(const std::string& launcher); const std::string& GetManufacturer() const; void SetManufacturer(const std::string& manufacturer); + const std::string& GetGenre() const; + void SetGenre(const std::string& genre); const std::string& GetName() const; void SetName(const std::string& name); void SetNumberButtons(std::string numberbuttons); @@ -56,6 +58,7 @@ private: std::string FullTitle; std::string Year; std::string Manufacturer; + std::string Genre; std::string CloneOf; std::string NumberPlayers; std::string NumberButtons; diff --git a/RetroFE/Source/Database/MetadataDatabase.cpp b/RetroFE/Source/Database/MetadataDatabase.cpp index 7828a5b..0aa4d49 100644 --- a/RetroFE/Source/Database/MetadataDatabase.cpp +++ b/RetroFE/Source/Database/MetadataDatabase.cpp @@ -81,6 +81,7 @@ bool MetadataDatabase::Initialize() sql.append("title TEXT NOT NULL DEFAULT '',"); sql.append("year TEXT NOT NULL DEFAULT '',"); sql.append("manufacturer TEXT NOT NULL DEFAULT '',"); + sql.append("genre TEXT NOT NULL DEFAULT '',"); sql.append("cloneOf TEXT NOT NULL DEFAULT '',"); sql.append("players TEXT NOT NULL DEFAULT '',"); sql.append("buttons TEXT NOT NULL DEFAULT '');"); @@ -110,7 +111,7 @@ bool MetadataDatabase::ImportDirectory() DIR *dp; struct dirent *dirp; std::string hyperListPath = Configuration::GetAbsolutePath() + "/meta/hyperlist"; - std::string mameListPath = Configuration::GetAbsolutePath() + "/meta/Mamelist"; + std::string mameListPath = Configuration::GetAbsolutePath() + "/meta/mamelist"; dp = opendir(hyperListPath.c_str()); @@ -204,7 +205,7 @@ void MetadataDatabase::InjectMetadata(CollectionInfo *collection) //todo: program crashes if this query fails sqlite3_prepare_v2(handle, - "SELECT DISTINCT Meta.name, Meta.title, Meta.year, Meta.manufacturer, Meta.players, Meta.buttons, Meta.cloneOf " + "SELECT DISTINCT Meta.name, Meta.title, Meta.year, Meta.manufacturer, Meta.genre, Meta.players, Meta.buttons, Meta.cloneOf " "FROM Meta WHERE collectionName=? ORDER BY title ASC;", -1, &stmt, 0); @@ -218,9 +219,10 @@ void MetadataDatabase::InjectMetadata(CollectionInfo *collection) std::string fullTitle = (char *)sqlite3_column_text(stmt, 1); std::string year = (char *)sqlite3_column_text(stmt, 2); std::string manufacturer = (char *)sqlite3_column_text(stmt, 3); - std::string numberPlayers = (char *)sqlite3_column_text(stmt, 4); - std::string numberButtons = (char *)sqlite3_column_text(stmt, 5); - std::string cloneOf = (char *)sqlite3_column_text(stmt, 6); + std::string genre = (char *)sqlite3_column_text(stmt, 4); + std::string numberPlayers = (char *)sqlite3_column_text(stmt, 5); + std::string numberButtons = (char *)sqlite3_column_text(stmt, 6); + std::string cloneOf = (char *)sqlite3_column_text(stmt, 7); std::string launcher; std::string title = fullTitle; @@ -267,6 +269,7 @@ void MetadataDatabase::InjectMetadata(CollectionInfo *collection) item->SetFullTitle(fullTitle); item->SetYear(year); item->SetManufacturer(manufacturer); + item->SetGenre(genre); item->SetNumberPlayers(numberPlayers); item->SetNumberButtons(numberButtons); item->SetCloneOf(cloneOf); @@ -348,15 +351,16 @@ bool MetadataDatabase::ImportHyperList(std::string hyperlistFile, std::string co sqlite3_stmt *stmt; sqlite3_prepare_v2(handle, - "INSERT OR REPLACE INTO Meta (name, title, year, manufacturer, cloneOf, collectionName) VALUES (?,?,?,?,?,?)", + "INSERT OR REPLACE INTO Meta (name, title, year, manufacturer, genre, cloneOf, collectionName) VALUES (?,?,?,?,?,?,?)", -1, &stmt, 0); sqlite3_bind_text(stmt, 1, name.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 2, description.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, year.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 4, manufacturer.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, cloneOf.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 6, collectionName.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, genre.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 6, cloneOf.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 7, collectionName.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); sqlite3_finalize(stmt); @@ -424,11 +428,13 @@ bool MetadataDatabase::ImportMameList(std::string filename, std::string collecti rapidxml::xml_node<> *descriptionNode = game->first_node("description"); rapidxml::xml_node<> *yearNode = game->first_node("year"); rapidxml::xml_node<> *manufacturerNode = game->first_node("manufacturer"); + rapidxml::xml_node<> *genreNode = game->first_node("genre"); rapidxml::xml_node<> *inputNode = game->first_node("input"); std::string description = (descriptionNode == NULL) ? nameNode->value() : descriptionNode->value(); std::string year = (yearNode == NULL) ? "" : yearNode->value(); std::string manufacturer = (manufacturerNode == NULL) ? "" : manufacturerNode->value(); + std::string genre = (genreNode == NULL) ? "" : genreNode->value(); std::string cloneOf = (cloneOfXml == NULL) ? "" : cloneOfXml->value(); std::string players; std::string buttons; @@ -453,7 +459,7 @@ bool MetadataDatabase::ImportMameList(std::string filename, std::string collecti sqlite3_stmt *stmt; sqlite3_prepare_v2(handle, - "INSERT OR REPLACE INTO Meta (name, title, year, manufacturer, players, buttons, cloneOf, collectionName) VALUES (?,?,?,?,?,?,?,?)", + "INSERT OR REPLACE INTO Meta (name, title, year, manufacturer, genre, players, buttons, cloneOf, collectionName) VALUES (?,?,?,?,?,?,?,?,?)", -1, &stmt, 0); @@ -461,10 +467,11 @@ bool MetadataDatabase::ImportMameList(std::string filename, std::string collecti sqlite3_bind_text(stmt, 2, description.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 3, year.c_str(), -1, SQLITE_TRANSIENT); sqlite3_bind_text(stmt, 4, manufacturer.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 5, players.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 6, buttons.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 7, cloneOf.c_str(), -1, SQLITE_TRANSIENT); - sqlite3_bind_text(stmt, 8, collectionName.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 5, genre.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 6, players.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 7, buttons.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 8, cloneOf.c_str(), -1, SQLITE_TRANSIENT); + sqlite3_bind_text(stmt, 9, collectionName.c_str(), -1, SQLITE_TRANSIENT); sqlite3_step(stmt); sqlite3_finalize(stmt); diff --git a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp index f075784..ca4db75 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableMedia.cpp @@ -215,6 +215,12 @@ void ReloadableMedia::ReloadTexture() { imageBasename = selectedItem->GetManufacturer(); } + else if(typeLC == "genre") + { + imageBasename = selectedItem->GetGenre(); + } + + Utils::ReplaceSlashesWithUnderscores(imageBasename); if(!LoadedComponent) { diff --git a/RetroFE/Source/Graphics/Component/ReloadableText.cpp b/RetroFE/Source/Graphics/Component/ReloadableText.cpp index 2fdce16..5ba4d99 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableText.cpp +++ b/RetroFE/Source/Graphics/Component/ReloadableText.cpp @@ -55,6 +55,10 @@ ReloadableText::ReloadableText(std::string type, Font *font, std::string layoutK { Type = TextTypeManufacturer; } + else if(type == "genre") + { + Type = TextTypeGenre; + } AllocateGraphicsMemory(); } @@ -147,6 +151,9 @@ void ReloadableText::ReloadTexture() case TextTypeManufacturer: ss << selectedItem->GetManufacturer(); break; + case TextTypeGenre: + ss << selectedItem->GetGenre(); + break; default: break; } diff --git a/RetroFE/Source/Graphics/Component/ReloadableText.h b/RetroFE/Source/Graphics/Component/ReloadableText.h index 7972784..da45618 100644 --- a/RetroFE/Source/Graphics/Component/ReloadableText.h +++ b/RetroFE/Source/Graphics/Component/ReloadableText.h @@ -42,6 +42,7 @@ private: TextTypeYear, TextTypeTitle, TextTypeManufacturer, + TextTypeGenre, }; void ReloadTexture(); diff --git a/RetroFE/Source/Main.cpp b/RetroFE/Source/Main.cpp index 6a0fc62..b0a6937 100644 --- a/RetroFE/Source/Main.cpp +++ b/RetroFE/Source/Main.cpp @@ -89,23 +89,20 @@ bool ImportConfiguration(Configuration *c) { std::string basename = dirp->d_name; - // if(basename.length() > 0) + std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1); + basename = basename.substr(0, basename.find_last_of(".")); + + if(extension == ".conf") { - std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1); - basename = basename.substr(0, basename.find_last_of(".")); + std::string prefix = "launchers." + basename; - if(extension == ".conf") + std::string importFile = launchersPath + "/" + std::string(dirp->d_name); + + if(!c->Import(prefix, importFile)) { - std::string prefix = "launchers." + basename; - - std::string importFile = launchersPath + "/" + std::string(dirp->d_name); - - if(!c->Import(prefix, importFile)) - { - Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\""); - closedir(dp); - return false; - } + Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\""); + closedir(dp); + return false; } } } @@ -123,7 +120,8 @@ bool ImportConfiguration(Configuration *c) while((dirp = readdir(dp)) != NULL) { - if (dirp->d_type == DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..") + std::string dirName = (dirp->d_name); + if (dirp->d_type == DT_DIR && dirName != "." && dirName != ".." && dirName.length() > 0 && dirName[0] != '_') { std::string prefix = "collections." + std::string(dirp->d_name); diff --git a/RetroFE/Source/Utility/Utils.cpp b/RetroFE/Source/Utility/Utils.cpp index 55f349f..244123f 100644 --- a/RetroFE/Source/Utility/Utils.cpp +++ b/RetroFE/Source/Utility/Utils.cpp @@ -114,6 +114,13 @@ void Utils::NormalizeBackSlashes(std::string& content) std::replace(content.begin(), content.end(), '\\', '/'); } +void Utils::ReplaceSlashesWithUnderscores(std::string &content) +{ + std::replace(content.begin(), content.end(), '\\', '_'); + std::replace(content.begin(), content.end(), '/', '_'); +} + + std::string Utils::GetDirectory(std::string filePath) { diff --git a/RetroFE/Source/Utility/Utils.h b/RetroFE/Source/Utility/Utils.h index 1760772..babe76f 100644 --- a/RetroFE/Source/Utility/Utils.h +++ b/RetroFE/Source/Utility/Utils.h @@ -27,6 +27,7 @@ public: static float ConvertFloat(std::string content); static int ConvertInt(std::string content); static void NormalizeBackSlashes(std::string &content); + static void ReplaceSlashesWithUnderscores(std::string &content); static std::string GetDirectory(std::string filePath); static std::string GetParentDirectory(std::string filePath); static std::string GetFileName(std::string filePath);