mirror of
git://projects.qi-hardware.com/gmenu2x.git
synced 2024-11-29 18:21:54 +02:00
Split huge function readPackages into two functions
This commit is contained in:
parent
1337eb5ed8
commit
78ad051756
73
src/menu.cpp
73
src/menu.cpp
@ -214,7 +214,7 @@ bool Menu::addLink(string path, string file, string section) {
|
|||||||
string::size_type pos = title.rfind(".");
|
string::size_type pos = title.rfind(".");
|
||||||
if (pos!=string::npos && pos>0) {
|
if (pos!=string::npos && pos>0) {
|
||||||
string ext = title.substr(pos, title.length());
|
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);
|
title = title.substr(0, pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -438,47 +438,16 @@ void Menu::setLinkIndex(int i) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
void Menu::readPackages(std::string parentDir)
|
void Menu::openPackage(std::string path)
|
||||||
{
|
{
|
||||||
DIR *dirp;
|
struct OPK *opk = opk_open(path.c_str());
|
||||||
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());
|
|
||||||
if (!opk) {
|
if (!opk) {
|
||||||
ERROR("Unable to open OPK %s\n", path.c_str());
|
ERROR("Unable to open OPK %s\n", path.c_str());
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
|
unsigned int i;
|
||||||
bool has_metadata = false;
|
bool has_metadata = false;
|
||||||
LinkApp *link;
|
LinkApp *link;
|
||||||
|
|
||||||
@ -525,6 +494,38 @@ void Menu::readPackages(std::string parentDir)
|
|||||||
opk_close(opk);
|
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);
|
closedir(dirp);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -52,6 +52,7 @@ private:
|
|||||||
#ifdef HAVE_LIBOPK
|
#ifdef HAVE_LIBOPK
|
||||||
// Load all the .opk packages of the given directory
|
// Load all the .opk packages of the given directory
|
||||||
void readPackages(std::string parentDir);
|
void readPackages(std::string parentDir);
|
||||||
|
void openPackage(std::string path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Load all the links on the given section directory.
|
// Load all the links on the given section directory.
|
||||||
|
Loading…
Reference in New Issue
Block a user