Cleaning up cppcheck issues.

This commit is contained in:
Don Honerbrink
2015-01-30 17:11:37 -06:00
parent 16b3a7e7d9
commit eb671042c9
7 changed files with 206 additions and 170 deletions

View File

@@ -21,7 +21,7 @@
#include "../Database/DB.h" #include "../Database/DB.h"
#include "../Utility/Log.h" #include "../Utility/Log.h"
#include "../Utility/Utils.h" #include "../Utility/Utils.h"
#include <dirent.h> #include <dirent.h>
#include <sstream> #include <sstream>
#include <vector> #include <vector>
@@ -78,79 +78,81 @@ CollectionInfo *CollectionInfoBuilder::BuildCollection(std::string name)
return collection; return collection;
} }
bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info) bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
{ {
DIR *dp; DIR *dp;
struct dirent *dirp; struct dirent *dirp;
std::string path = info->GetListPath(); std::string path = info->GetListPath();
std::map<std::string, Item *> includeFilter; std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> excludeFilter; std::map<std::string, Item *> excludeFilter;
bool retVal = true; bool retVal = true;
std::string includeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.txt"; std::string includeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Include.txt";
std::string excludeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Exclude.txt"; std::string excludeFile = Configuration::GetAbsolutePath() + "/Collections/" + info->GetName() + "/Exclude.txt";
std::string launcher; std::string launcher;
(void)Conf.GetProperty("collections." + info->GetName() + ".launcher", launcher); std::vector<std::string> extensions;
std::vector<std::string>::iterator extensionsIt;
dp = opendir(path.c_str());
std::vector<std::string> extensions; info->GetExtensions(extensions);
info->GetExtensions(extensions);
std::vector<std::string>::iterator extensionsIt; (void)Conf.GetProperty("collections." + info->GetName() + ".launcher", launcher);
if(dp == NULL) dp = opendir(path.c_str());
{
Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + path + "\""); if(dp == NULL)
//todo: store into a database {
} Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + path + "\"");
else return false;
{ }
while((dirp = readdir(dp)) != NULL)
{ while((dirp = readdir(dp)) != NULL)
std::string file = dirp->d_name; {
std::string file = dirp->d_name;
Utils::NormalizeBackSlashes(file);
size_t position = file.find_last_of("."); Utils::NormalizeBackSlashes(file);
std::string basename = (std::string::npos == position)? file : file.substr(0, position); 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())) 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) {
{ for(extensionsIt = extensions.begin(); extensionsIt != extensions.end(); ++extensionsIt)
std::string comparator = "." + *extensionsIt; {
int start = file.length() - comparator.length() + 1; std::string comparator = "." + *extensionsIt;
int start = file.length() - comparator.length() + 1;
if(start >= 0)
{ if(start >= 0)
if(file.compare(start, comparator.length(), *extensionsIt) == 0) {
{ if(file.compare(start, comparator.length(), *extensionsIt) == 0)
Item *i = new Item(); {
i->SetName(basename); Item *i = new Item();
i->SetFullTitle(basename); i->SetName(basename);
i->SetTitle(basename); i->SetFullTitle(basename);
i->SetLauncher(launcher); i->SetTitle(basename);
info->GetItems()->push_back(i); i->SetLauncher(launcher);
} info->GetItems()->push_back(i);
} }
} }
} }
} }
} }
MetaDB.InjectMetadata(info); closedir(dp);
while(includeFilter.size() > 0) MetaDB.InjectMetadata(info);
{
std::map<std::string, Item *>::iterator it = includeFilter.begin(); while(includeFilter.size() > 0)
delete it->second; {
includeFilter.erase(it); std::map<std::string, Item *>::iterator it = includeFilter.begin();
} delete it->second;
while(excludeFilter.size() > 0) includeFilter.erase(it);
{ }
std::map<std::string, Item *>::iterator it = excludeFilter.begin(); while(excludeFilter.size() > 0)
delete it->second; {
excludeFilter.erase(it); std::map<std::string, Item *>::iterator it = excludeFilter.begin();
} delete it->second;
excludeFilter.erase(it);
return true; }
}
return true;
}

View File

@@ -75,34 +75,32 @@ bool MenuParser::GetMenuItems(CollectionInfo *collection)
Logger::Write(Logger::ZONE_ERROR, "Menu", "Menu item tag is missing collection attribute"); Logger::Write(Logger::ZONE_ERROR, "Menu", "Menu item tag is missing collection attribute");
break; break;
} }
//todo: too much nesting! Ack!
std::string import;
if(importAttribute)
{
import = importAttribute->value();
}
if(import != "true")
{
//todo, check for empty string
std::string title = collectionAttribute->value();
Item *item = new Item();
item->SetTitle(title);
item->SetFullTitle(title);
item->SetName(collectionAttribute->value());
item->SetIsLeaf(false);
collection->GetItems()->push_back(item);
}
else else
{ {
//todo: too much nesting! Ack! std::string collectionName = collectionAttribute->value();
std::string import; Logger::Write(Logger::ZONE_INFO, "Menu", "Loading collection into menu: " + collectionName);
if(importAttribute)
{
import = importAttribute->value();
}
if(import != "true")
{
//todo, check for empty string
std::string title = collectionAttribute->value();
Item *item = new Item();
item->SetTitle(title);
item->SetFullTitle(title);
item->SetName(collectionAttribute->value());
item->SetIsLeaf(false);
collection->GetItems()->push_back(item);
} //todo: unsupported option with this refactor
else // need to append the collection
{
std::string collectionName = collectionAttribute->value();
Logger::Write(Logger::ZONE_INFO, "Menu", "Loading collection into menu: " + collectionName);
//todo: unsupported option with this refactor
// need to append the collection
}
} }
} }

View File

@@ -114,51 +114,68 @@ bool MetadataDatabase::ImportDirectory()
dp = opendir(hyperListPath.c_str()); dp = opendir(hyperListPath.c_str());
while((dirp = readdir(dp)) != NULL) if(dp == NULL)
{ {
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..") Logger::Write(Logger::ZONE_INFO, "MetadataDatabase", "Could not read directory \"" + hyperListPath + "\"");
}
else
{
while((dirp = readdir(dp)) != NULL)
{ {
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
std::string basename = dirp->d_name;
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
basename = basename.substr(0, basename.find_last_of("."));
std::string collectionName = basename.substr(0, basename.find_first_of("."));
if(extension == ".xml")
{ {
std::string importFile = Configuration::GetAbsolutePath() + "/" + hyperListPath + "/" + dirp->d_name;
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing hyperlist: " + importFile); std::string basename = dirp->d_name;
ImportHyperList(importFile, collectionName);
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
basename = basename.substr(0, basename.find_last_of("."));
std::string collectionName = basename.substr(0, basename.find_first_of("."));
if(extension == ".xml")
{
std::string importFile = Configuration::GetAbsolutePath() + "/" + hyperListPath + "/" + dirp->d_name;
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing hyperlist: " + importFile);
ImportHyperList(importFile, collectionName);
}
} }
} }
closedir(dp);
} }
dp = opendir(mameListPath.c_str()); dp = opendir(mameListPath.c_str());
while((dirp = readdir(dp)) != NULL) if(dp == NULL)
{ {
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..") Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + mameListPath + "\"");
{
std::string basename = dirp->d_name;
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
basename = basename.substr(0, basename.find_last_of("."));
std::string collectionName = basename.substr(0, basename.find_first_of("."));
if(extension == ".xml")
{
std::string importFile = Configuration::GetAbsolutePath() + "/" + mameListPath + "/" + dirp->d_name;
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing mamelist: " + importFile);
Config.SetStatus("Scraping data from " + importFile);
ImportMameList(importFile, collectionName);
}
}
} }
else
{
while((dirp = readdir(dp)) != NULL)
{
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
{
std::string basename = dirp->d_name;
std::string extension = basename.substr(basename.find_last_of("."), basename.size()-1);
basename = basename.substr(0, basename.find_last_of("."));
std::string collectionName = basename.substr(0, basename.find_first_of("."));
if(extension == ".xml")
{
std::string importFile = Configuration::GetAbsolutePath() + "/" + mameListPath + "/" + dirp->d_name;
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing mamelist: " + importFile);
Config.SetStatus("Scraping data from " + importFile);
ImportMameList(importFile, collectionName);
}
}
}
closedir(dp);
}
return true; return true;
} }

View File

@@ -13,3 +13,40 @@
* You should have received a copy of the GNU General Public License * You should have received a copy of the GNU General Public License
* along with RetroFE. If not, see <http://www.gnu.org/licenses/>. * along with RetroFE. If not, see <http://www.gnu.org/licenses/>.
*/ */
#include "TweenSet.h"
TweenSets *TweenSet::GetOnEnterTweens()
{
return &OnEnterTweens;
}
TweenSets *TweenSet::GetOnExitTweens()
{
return &OnExitTweens;
}
TweenSets *TweenSet::GetOnIdleTweens()
{
return &OnIdleTweens;
}
TweenSets *TweenSet::GetOnHighlightEnterTweens()
{
return &OnHighlightEnterTweens;
}
TweenSets *TweenSet::GetOnHighlightExitTweens()
{
return &OnHighlightExitTweens;
}
TweenSets *TweenSet::GetOnMenuEnterTweens()
{
return &OnMenuEnterTweens;
}
TweenSets *TweenSet::GetOnMenuScrollTweens()
{
return &OnMenuScrollTweens;
}
TweenSets *TweenSet::GetOnMenuExitTweens()
{
return &OnMenuExitTweens;
}

View File

@@ -28,38 +28,14 @@ public:
//todo: delete the tweens in a destructor //todo: delete the tweens in a destructor
TweenSets *GetOnEnterTweens() TweenSets *GetOnEnterTweens();
{ TweenSets *GetOnExitTweens();
return &OnEnterTweens; TweenSets *GetOnIdleTweens();
} TweenSets *GetOnHighlightEnterTweens();
TweenSets *GetOnExitTweens() TweenSets *GetOnHighlightExitTweens();
{ TweenSets *GetOnMenuEnterTweens();
return &OnExitTweens; TweenSets *GetOnMenuScrollTweens();
} TweenSets *GetOnMenuExitTweens();
TweenSets *GetOnIdleTweens()
{
return &OnIdleTweens;
}
TweenSets *GetOnHighlightEnterTweens()
{
return &OnHighlightEnterTweens;
}
TweenSets *GetOnHighlightExitTweens()
{
return &OnHighlightExitTweens;
}
TweenSets *GetOnMenuEnterTweens()
{
return &OnMenuEnterTweens;
}
TweenSets *GetOnMenuScrollTweens()
{
return &OnMenuScrollTweens;
}
TweenSets *GetOnMenuExitTweens()
{
return &OnMenuExitTweens;
}
private: private:
TweenSets OnEnterTweens; TweenSets OnEnterTweens;
@@ -71,4 +47,4 @@ private:
TweenSets OnMenuScrollTweens; TweenSets OnMenuScrollTweens;
TweenSets OnMenuExitTweens; TweenSets OnMenuExitTweens;
}; };

View File

@@ -70,7 +70,7 @@ bool Font::Initialize(std::string fontPath, int fontSize, SDL_Color color)
for(unsigned short int i = 32; i < 128; ++i) for(unsigned short int i = 32; i < 128; ++i)
{ {
GlyphInfoBuild *info = new GlyphInfoBuild; GlyphInfoBuild *info = new GlyphInfoBuild;
memset(info, sizeof(GlyphInfoBuild), 0); memset(info, 0, sizeof(GlyphInfoBuild));
color.a = 255; color.a = 255;
info->Surface = TTF_RenderGlyph_Blended(font, i, color); info->Surface = TTF_RenderGlyph_Blended(font, i, color);

View File

@@ -103,6 +103,7 @@ bool ImportConfiguration(Configuration *c)
if(!c->Import(prefix, importFile)) if(!c->Import(prefix, importFile))
{ {
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\""); Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + importFile + "\"");
closedir(dp);
return false; return false;
} }
} }
@@ -110,6 +111,8 @@ bool ImportConfiguration(Configuration *c)
} }
} }
closedir(dp);
dp = opendir(collectionsPath.c_str()); dp = opendir(collectionsPath.c_str());
if(dp == NULL) if(dp == NULL)
@@ -129,10 +132,13 @@ bool ImportConfiguration(Configuration *c)
if(!c->Import(prefix, settingsFile)) if(!c->Import(prefix, settingsFile))
{ {
Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsFile + "\""); Logger::Write(Logger::ZONE_ERROR, "RetroFE", "Could not import \"" + settingsFile + "\"");
closedir(dp);
return false; return false;
} }
} }
} }
closedir(dp);
Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration"); Logger::Write(Logger::ZONE_INFO, "RetroFE", "Imported configuration");