2012-07-27 16:58:27 +00:00
|
|
|
#include "FolderData.h"
|
|
|
|
#include "SystemData.h"
|
2012-08-02 04:03:15 +00:00
|
|
|
#include <algorithm>
|
2012-08-08 00:50:45 +00:00
|
|
|
#include <iostream>
|
2012-07-27 16:58:27 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2012-08-02 04:03:15 +00:00
|
|
|
//returns if file1 should come before file2
|
|
|
|
bool filesort(FileData* file1, FileData* file2)
|
|
|
|
{
|
|
|
|
std::string name1 = file1->getName();
|
|
|
|
std::string name2 = file2->getName();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < name1.length(); i++)
|
|
|
|
{
|
2012-08-08 00:50:45 +00:00
|
|
|
if(toupper(name1[i]) != toupper(name2[i]))
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
2012-08-08 00:50:45 +00:00
|
|
|
if(toupper(name1[i]) < toupper(name2[i]))
|
2012-08-02 04:03:15 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}else{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if(name1.length() < name2.length())
|
|
|
|
return true;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-08-08 00:50:45 +00:00
|
|
|
//sort this folder and any subfolders
|
2012-08-02 04:03:15 +00:00
|
|
|
void FolderData::sort()
|
|
|
|
{
|
|
|
|
std::sort(mFileVector.begin(), mFileVector.end(), filesort);
|
2012-08-08 00:50:45 +00:00
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mFileVector.size(); i++)
|
|
|
|
{
|
|
|
|
if(mFileVector.at(i)->isFolder())
|
|
|
|
((FolderData*)mFileVector.at(i))->sort();
|
|
|
|
}
|
2012-08-02 04:03:15 +00:00
|
|
|
}
|