mirror of
https://github.com/FunKey-Project/RetroFE.git
synced 2025-12-12 09:48:51 +01:00
Added the ability to add additional information via the
collections/<collection name>/info/<item name>.conf files. This files work like all configuration files. The global configuration overwriteXML can be used to give the values in this file preference over those in the meta XML. This can also be used for ReloadableMedia as well as ReloadableText items.
This commit is contained in:
parent
7294dc9ee9
commit
6f41300b56
@ -15,7 +15,9 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "Item.h"
|
#include "Item.h"
|
||||||
|
#include "../Utility/Log.h"
|
||||||
#include "../Utility/Utils.h"
|
#include "../Utility/Utils.h"
|
||||||
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -50,3 +52,63 @@ std::string Item::lowercaseFullTitle()
|
|||||||
return lcstr;
|
return lcstr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Item::setInfo( std::string key, std::string value )
|
||||||
|
{
|
||||||
|
info_.insert( InfoPair( key, value ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool Item::getInfo( std::string key, std::string & value )
|
||||||
|
{
|
||||||
|
|
||||||
|
bool retVal = false;
|
||||||
|
|
||||||
|
if ( info_.find( key ) != info_.end( ) )
|
||||||
|
{
|
||||||
|
value = info_[key];
|
||||||
|
retVal = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return retVal;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void Item::loadInfo( std::string path )
|
||||||
|
{
|
||||||
|
|
||||||
|
int lineCount = 0;
|
||||||
|
std::string line;
|
||||||
|
std::ifstream ifs( path.c_str( ) );
|
||||||
|
size_t position;
|
||||||
|
std::string key;
|
||||||
|
std::string value;
|
||||||
|
|
||||||
|
if ( !ifs.is_open( ) )
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
while ( std::getline( ifs, line ) )
|
||||||
|
{
|
||||||
|
lineCount++;
|
||||||
|
line = Utils::filterComments( line );
|
||||||
|
// Check if the line has an assigment operator
|
||||||
|
if ( (position = line.find( "=" )) != std::string::npos )
|
||||||
|
{
|
||||||
|
key = line.substr( 0, position );
|
||||||
|
key = Utils::trimEnds( key );
|
||||||
|
value = line.substr( position + 1, line.size( )-1 );
|
||||||
|
value = Utils::trimEnds( value );
|
||||||
|
setInfo( key, value );
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
std::stringstream ss;
|
||||||
|
ss << "Missing an assignment operator (=) on line " << lineCount;
|
||||||
|
Logger::write(Logger::ZONE_ERROR, "Item", ss.str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|||||||
@ -16,6 +16,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
#include "CollectionInfo.h"
|
#include "CollectionInfo.h"
|
||||||
|
|
||||||
class Item
|
class Item
|
||||||
@ -43,4 +44,11 @@ public:
|
|||||||
std::string score;
|
std::string score;
|
||||||
CollectionInfo *collectionInfo;
|
CollectionInfo *collectionInfo;
|
||||||
bool leaf;
|
bool leaf;
|
||||||
|
|
||||||
|
typedef std::map<std::string, std::string> InfoType;
|
||||||
|
typedef std::pair<std::string, std::string> InfoPair;
|
||||||
|
InfoType info_;
|
||||||
|
void setInfo( std::string key, std::string value );
|
||||||
|
bool getInfo( std::string key, std::string &value );
|
||||||
|
void loadInfo( std::string path );
|
||||||
};
|
};
|
||||||
|
|||||||
@ -236,10 +236,7 @@ void ReloadableMedia::reloadTexture()
|
|||||||
}
|
}
|
||||||
else if(typeLC == "manufacturer")
|
else if(typeLC == "manufacturer")
|
||||||
{
|
{
|
||||||
if ( selectedItem->leaf ) // item is a leaf
|
|
||||||
basename = selectedItem->manufacturer;
|
basename = selectedItem->manufacturer;
|
||||||
else // item is a collection
|
|
||||||
(void)config_.getProperty("collections." + selectedItem->name + ".manufacturer", basename );
|
|
||||||
}
|
}
|
||||||
else if(typeLC == "genre")
|
else if(typeLC == "genre")
|
||||||
{
|
{
|
||||||
@ -270,6 +267,23 @@ void ReloadableMedia::reloadTexture()
|
|||||||
basename = selectedItem->fullTitle.at(0);
|
basename = selectedItem->fullTitle.at(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!selectedItem->leaf) // item is not a leaf
|
||||||
|
{
|
||||||
|
(void)config_.getProperty("collections." + selectedItem->name + "." + type_, basename );
|
||||||
|
}
|
||||||
|
|
||||||
|
bool overwriteXML = false;
|
||||||
|
config_.getProperty( "overwriteXML", overwriteXML );
|
||||||
|
if ( basename == "" || overwriteXML ) // No basename was found yet; check the info in stead
|
||||||
|
{
|
||||||
|
std::string basename_tmp;
|
||||||
|
selectedItem->getInfo( type_, basename_tmp );
|
||||||
|
if ( basename_tmp != "" )
|
||||||
|
{
|
||||||
|
basename = basename_tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Utils::replaceSlashesWithUnderscores(basename);
|
Utils::replaceSlashesWithUnderscores(basename);
|
||||||
|
|
||||||
if(systemMode_)
|
if(systemMode_)
|
||||||
|
|||||||
@ -149,10 +149,7 @@ void ReloadableText::ReloadTexture()
|
|||||||
}
|
}
|
||||||
else if (type_ == "year")
|
else if (type_ == "year")
|
||||||
{
|
{
|
||||||
if (selectedItem->leaf) // item is a leaf
|
|
||||||
text = selectedItem->year;
|
text = selectedItem->year;
|
||||||
else // item is a collection
|
|
||||||
(void)config_.getProperty("collections." + selectedItem->name + ".year", text );
|
|
||||||
}
|
}
|
||||||
else if (type_ == "title")
|
else if (type_ == "title")
|
||||||
{
|
{
|
||||||
@ -169,17 +166,11 @@ void ReloadableText::ReloadTexture()
|
|||||||
}
|
}
|
||||||
else if (type_ == "manufacturer")
|
else if (type_ == "manufacturer")
|
||||||
{
|
{
|
||||||
if (selectedItem->leaf) // item is a leaf
|
|
||||||
text = selectedItem->manufacturer;
|
text = selectedItem->manufacturer;
|
||||||
else // item is a collection
|
|
||||||
(void)config_.getProperty("collections." + selectedItem->name + ".manufacturer", text );
|
|
||||||
}
|
}
|
||||||
else if (type_ == "genre")
|
else if (type_ == "genre")
|
||||||
{
|
{
|
||||||
if (selectedItem->leaf) // item is a leaf
|
|
||||||
text = selectedItem->genre;
|
text = selectedItem->genre;
|
||||||
else // item is a collection
|
|
||||||
(void)config_.getProperty("collections." + selectedItem->name + ".genre", text );
|
|
||||||
}
|
}
|
||||||
else if (type_ == "playlist")
|
else if (type_ == "playlist")
|
||||||
{
|
{
|
||||||
@ -238,11 +229,24 @@ void ReloadableText::ReloadTexture()
|
|||||||
ss << pluralPrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << pluralPostfix_;
|
ss << pluralPrefix_ << (page.getSelectedIndex()+1) << "/" << page.getCollectionSize() << pluralPostfix_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!selectedItem->leaf) // item is not a leaf
|
|
||||||
|
if (!selectedItem->leaf) // item is not a leaf
|
||||||
{
|
{
|
||||||
(void)config_.getProperty("collections." + selectedItem->name + "." + type_, text );
|
(void)config_.getProperty("collections." + selectedItem->name + "." + type_, text );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool overwriteXML = false;
|
||||||
|
config_.getProperty( "overwriteXML", overwriteXML );
|
||||||
|
if ( text == "" || overwriteXML ) // No text was found yet; check the info in stead
|
||||||
|
{
|
||||||
|
std::string text_tmp;
|
||||||
|
selectedItem->getInfo( type_, text_tmp );
|
||||||
|
if ( text_tmp != "" )
|
||||||
|
{
|
||||||
|
text = text_tmp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (text == "0")
|
if (text == "0")
|
||||||
{
|
{
|
||||||
text = singlePrefix_ + text + pluralPostfix_;
|
text = singlePrefix_ + text + pluralPostfix_;
|
||||||
|
|||||||
@ -168,7 +168,7 @@ void ScrollingList::allocateSpritePoints( )
|
|||||||
|
|
||||||
resetTweens( c, tweenPoints_->at( i ), view, view, 0 );
|
resetTweens( c, tweenPoints_->at( i ), view, view, 0 );
|
||||||
|
|
||||||
if ( old )
|
if ( old && !newItemSelected )
|
||||||
{
|
{
|
||||||
c->baseViewInfo = old->baseViewInfo;
|
c->baseViewInfo = old->baseViewInfo;
|
||||||
delete old;
|
delete old;
|
||||||
|
|||||||
@ -1090,6 +1090,13 @@ CollectionInfo *RetroFE::getCollection(std::string collectionName)
|
|||||||
cib.addPlaylists( collection );
|
cib.addPlaylists( collection );
|
||||||
collection->sortFavoriteItems( );
|
collection->sortFavoriteItems( );
|
||||||
|
|
||||||
|
// Add extra info, if available
|
||||||
|
for ( std::vector<Item *>::iterator it = collection->items.begin( ); it != collection->items.end( ); it++ )
|
||||||
|
{
|
||||||
|
std::string path = Utils::combinePath( Configuration::absolutePath, "collections", collectionName, "info", (*it)->name + ".conf" );
|
||||||
|
(*it)->loadInfo( path );
|
||||||
|
}
|
||||||
|
|
||||||
// Remove parenthesis and brackets, if so configured
|
// Remove parenthesis and brackets, if so configured
|
||||||
bool showParenthesis = true;
|
bool showParenthesis = true;
|
||||||
bool showSquareBrackets = true;
|
bool showSquareBrackets = true;
|
||||||
|
|||||||
@ -237,3 +237,19 @@ std::string Utils::getFileName(std::string filePath)
|
|||||||
return filename;
|
return filename;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
std::string Utils::trimEnds(std::string str)
|
||||||
|
{
|
||||||
|
// strip off any initial tabs or spaces
|
||||||
|
size_t trimStart = str.find_first_not_of(" \t");
|
||||||
|
|
||||||
|
if(trimStart != std::string::npos)
|
||||||
|
{
|
||||||
|
size_t trimEnd = str.find_last_not_of(" \t");
|
||||||
|
|
||||||
|
str = str.substr(trimStart, trimEnd - trimStart + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@ -34,6 +34,7 @@ public:
|
|||||||
static std::string toLower(std::string str);
|
static std::string toLower(std::string str);
|
||||||
static std::string uppercaseFirst(std::string str);
|
static std::string uppercaseFirst(std::string str);
|
||||||
static std::string filterComments(std::string line);
|
static std::string filterComments(std::string line);
|
||||||
|
static std::string trimEnds(std::string str);
|
||||||
|
|
||||||
//todo: there has to be a better way to do this
|
//todo: there has to be a better way to do this
|
||||||
static std::string combinePath(std::list<std::string> &paths);
|
static std::string combinePath(std::list<std::string> &paths);
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
|
|
||||||
std::string retrofe_version_major = "0";
|
std::string retrofe_version_major = "0";
|
||||||
std::string retrofe_version_minor = "8";
|
std::string retrofe_version_minor = "8";
|
||||||
std::string retrofe_version_build = "10";
|
std::string retrofe_version_build = "11";
|
||||||
|
|
||||||
|
|
||||||
std::string Version::getString( )
|
std::string Version::getString( )
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user