ES-DE/src/FolderData.cpp
Aloshi 80e33849b5 Fixed a few crashes, better support for higan
Fixed AudioManager/InputManager unsigned vs signed comparison warnings.
Fixed a FolderData sorting crash (I can't believe nobody's reported
this).
Fixed a GuiTheme crash for empty paths.
Added the %ROM_RAW% tag, for the unescaped ROM name - useful for higan
on windows.
SystemData will now add folders that end in EXTENSION as GameDatas, and
not recurse through them.  Also useful for higan.
2013-05-27 12:13:38 -05:00

72 lines
1.5 KiB
C++

#include "FolderData.h"
#include "SystemData.h"
#include <algorithm>
#include <iostream>
bool FolderData::isFolder() { return true; }
std::string FolderData::getName() { return mName; }
std::string FolderData::getPath() { return mPath; }
unsigned int FolderData::getFileCount() { return mFileVector.size(); }
FileData* FolderData::getFile(unsigned int i) { return mFileVector.at(i); }
FolderData::FolderData(SystemData* system, std::string path, std::string name)
{
mSystem = system;
mPath = path;
mName = name;
}
FolderData::~FolderData()
{
for(unsigned int i = 0; i < mFileVector.size(); i++)
{
delete mFileVector.at(i);
}
mFileVector.clear();
}
void FolderData::pushFileData(FileData* file)
{
mFileVector.push_back(file);
}
//returns if file1 should come before file2
bool filesort(FileData* file1, FileData* file2)
{
std::string name1 = file1->getName();
std::string name2 = file2->getName();
//min of name1/name2 .length()s
unsigned int count = name1.length() > name2.length() ? name2.length() : name1.length();
for(unsigned int i = 0; i < count; i++)
{
if(toupper(name1[i]) != toupper(name2[i]))
{
if(toupper(name1[i]) < toupper(name2[i]))
{
return true;
}else{
return false;
}
}
}
if(name1.length() < name2.length())
return true;
else
return false;
}
//sort this folder and any subfolders
void FolderData::sort()
{
std::sort(mFileVector.begin(), mFileVector.end(), filesort);
for(unsigned int i = 0; i < mFileVector.size(); i++)
{
if(mFileVector.at(i)->isFolder())
((FolderData*)mFileVector.at(i))->sort();
}
}