1
0
mirror of git://projects.qi-hardware.com/gmenu2x.git synced 2024-07-04 22:24:32 +03:00

Split huge function readPackages into two functions

This commit is contained in:
Paul Cercueil 2013-07-10 18:57:56 -04:00
parent 1337eb5ed8
commit 78ad051756
2 changed files with 59 additions and 57 deletions

View File

@ -214,7 +214,7 @@ bool Menu::addLink(string path, string file, string section) {
string::size_type pos = title.rfind(".");
if (pos!=string::npos && pos>0) {
string ext = title.substr(pos, title.length());
transform(ext.begin(), ext.end(), ext.begin(), (int(*)(int)) tolower);
transform(ext.begin(), ext.end(), ext.begin(), ::tolower);
title = title.substr(0, pos);
}
@ -438,47 +438,16 @@ void Menu::setLinkIndex(int i) {
}
#ifdef HAVE_LIBOPK
void Menu::readPackages(std::string parentDir)
void Menu::openPackage(std::string path)
{
DIR *dirp;
struct dirent *dptr;
vector<string> linkfiles;
dirp = opendir(parentDir.c_str());
if (!dirp)
return;
while ((dptr = readdir(dirp))) {
char *c;
std::string path;
unsigned int i;
struct OPK *opk;
if (dptr->d_type != DT_REG)
continue;
c = strrchr(dptr->d_name, '.');
if (!c) /* File without extension */
continue;
if (strcasecmp(c + 1, "opk"))
continue;
if (dptr->d_name[0] == '.') {
// Ignore hidden files.
// Mac OS X places these on SD cards, probably to store metadata.
continue;
}
path = parentDir + '/' + dptr->d_name;
opk = opk_open(path.c_str());
struct OPK *opk = opk_open(path.c_str());
if (!opk) {
ERROR("Unable to open OPK %s\n", path.c_str());
continue;
return;
}
for (;;) {
unsigned int i;
bool has_metadata = false;
LinkApp *link;
@ -523,6 +492,38 @@ void Menu::readPackages(std::string parentDir)
}
opk_close(opk);
}
void Menu::readPackages(std::string parentDir)
{
DIR *dirp;
struct dirent *dptr;
vector<string> linkfiles;
dirp = opendir(parentDir.c_str());
if (!dirp)
return;
while ((dptr = readdir(dirp))) {
char *c;
if (dptr->d_type != DT_REG)
continue;
c = strrchr(dptr->d_name, '.');
if (!c) /* File without extension */
continue;
if (strcasecmp(c + 1, "opk"))
continue;
if (dptr->d_name[0] == '.') {
// Ignore hidden files.
// Mac OS X places these on SD cards, probably to store metadata.
continue;
}
openPackage(parentDir + '/' + dptr->d_name);
}
closedir(dirp);

View File

@ -52,6 +52,7 @@ private:
#ifdef HAVE_LIBOPK
// Load all the .opk packages of the given directory
void readPackages(std::string parentDir);
void openPackage(std::string path);
#endif
// Load all the links on the given section directory.