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 "../Utility/Log.h"
#include "../Utility/Utils.h"
#include <dirent.h>
#include <dirent.h>
#include <sstream>
#include <vector>
@ -78,79 +78,81 @@ CollectionInfo *CollectionInfoBuilder::BuildCollection(std::string name)
return collection;
}
bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
{
DIR *dp;
struct dirent *dirp;
std::string path = info->GetListPath();
std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> 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<std::string> extensions;
info->GetExtensions(extensions);
std::vector<std::string>::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.InjectMetadata(info);
while(includeFilter.size() > 0)
{
std::map<std::string, Item *>::iterator it = includeFilter.begin();
delete it->second;
includeFilter.erase(it);
}
while(excludeFilter.size() > 0)
{
std::map<std::string, Item *>::iterator it = excludeFilter.begin();
delete it->second;
excludeFilter.erase(it);
}
return true;
}
bool CollectionInfoBuilder::ImportDirectory(CollectionInfo *info)
{
DIR *dp;
struct dirent *dirp;
std::string path = info->GetListPath();
std::map<std::string, Item *> includeFilter;
std::map<std::string, Item *> 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;
std::vector<std::string> extensions;
std::vector<std::string>::iterator extensionsIt;
info->GetExtensions(extensions);
(void)Conf.GetProperty("collections." + info->GetName() + ".launcher", launcher);
dp = opendir(path.c_str());
if(dp == NULL)
{
Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + path + "\"");
return false;
}
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);
}
}
}
}
}
closedir(dp);
MetaDB.InjectMetadata(info);
while(includeFilter.size() > 0)
{
std::map<std::string, Item *>::iterator it = includeFilter.begin();
delete it->second;
includeFilter.erase(it);
}
while(excludeFilter.size() > 0)
{
std::map<std::string, Item *>::iterator it = excludeFilter.begin();
delete it->second;
excludeFilter.erase(it);
}
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");
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
{
//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);
std::string collectionName = collectionAttribute->value();
Logger::Write(Logger::ZONE_INFO, "Menu", "Loading collection into menu: " + collectionName);
}
else
{
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
}
//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());
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)
{
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")
if (dirp->d_type != DT_DIR && std::string(dirp->d_name) != "." && std::string(dirp->d_name) != "..")
{
std::string importFile = Configuration::GetAbsolutePath() + "/" + hyperListPath + "/" + dirp->d_name;
Logger::Write(Logger::ZONE_INFO, "Metadata", "Importing hyperlist: " + importFile);
ImportHyperList(importFile, collectionName);
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);
ImportHyperList(importFile, collectionName);
}
}
}
closedir(dp);
}
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) != "..")
{
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);
}
}
Logger::Write(Logger::ZONE_ERROR, "CollectionInfoBuilder", "Could not read directory \"" + mameListPath + "\"");
}
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;
}

View File

@ -13,3 +13,40 @@
* You should have received a copy of the GNU General Public License
* 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
TweenSets *GetOnEnterTweens()
{
return &OnEnterTweens;
}
TweenSets *GetOnExitTweens()
{
return &OnExitTweens;
}
TweenSets *GetOnIdleTweens()
{
return &OnIdleTweens;
}
TweenSets *GetOnHighlightEnterTweens()
{
return &OnHighlightEnterTweens;
}
TweenSets *GetOnHighlightExitTweens()
{
return &OnHighlightExitTweens;
}
TweenSets *GetOnMenuEnterTweens()
{
return &OnMenuEnterTweens;
}
TweenSets *GetOnMenuScrollTweens()
{
return &OnMenuScrollTweens;
}
TweenSets *GetOnMenuExitTweens()
{
return &OnMenuExitTweens;
}
TweenSets *GetOnEnterTweens();
TweenSets *GetOnExitTweens();
TweenSets *GetOnIdleTweens();
TweenSets *GetOnHighlightEnterTweens();
TweenSets *GetOnHighlightExitTweens();
TweenSets *GetOnMenuEnterTweens();
TweenSets *GetOnMenuScrollTweens();
TweenSets *GetOnMenuExitTweens();
private:
TweenSets OnEnterTweens;
@ -71,4 +47,4 @@ private:
TweenSets OnMenuScrollTweens;
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)
{
GlyphInfoBuild *info = new GlyphInfoBuild;
memset(info, sizeof(GlyphInfoBuild), 0);
memset(info, 0, sizeof(GlyphInfoBuild));
color.a = 255;
info->Surface = TTF_RenderGlyph_Blended(font, i, color);

View File

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