usbloadergx/source/listfiles.c
giantpune a02013f03f put in a possible "fix" for the disappearing cursors that some people are getting. when menu_disclist is called the cursors are deleted and recreated. so at least if they do go away, this may make them come back.
make the homebrew menu read the XML data from meta.xml file.  put this data on the homebrew buttons and prompt.  there is 4 structs created globally that hold the XML daa.  i tried to make them pointers but i got errors so i'll leave it like this and let dimok fix it :P
2009-07-20 14:20:27 +00:00

112 lines
2.0 KiB
C

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <gccore.h>
#include <fat.h>
#include <sys/dir.h>
#include <dirent.h>
#include <unistd.h>
#include "listfiles.h"
static char alldirfiles[300][70];
char filenames[80];
bool findfile(const char * filename, const char * path)
{
DIR *dir;
struct dirent *file;
dir = opendir(path);
char temp[11];
while ((file = readdir(dir)))
{
snprintf(temp,sizeof(temp),"%s",file->d_name);
if (!strncmpi(temp,filename,11))
{
closedir(dir);
return true;
}
}
closedir(dir);
return false;
}
bool subfoldercreate(char * fullpath) {
//check forsubfolders
char dircheck[300];
char dirnoslash[300];
char * pch = NULL;
u32 cnt = 0;
struct stat st;
snprintf(dirnoslash, strlen(fullpath), "%s", fullpath);
if(stat(fullpath, &st) != 0) {
pch = strrchr(dirnoslash, '/');
cnt = pch-dirnoslash;
snprintf(dircheck, cnt+2, "%s", dirnoslash);
subfoldercreate(dircheck);
};
if (mkdir(dirnoslash, 0777) == -1) {
return false;
}
return true;
}
char * GetFileName(int i)
{
return alldirfiles[i];
}
s32 filenamescmp(const void *a, const void *b)
{
/* Compare strings */
return stricmp((char *)a, (char *)b);
}
int GetAllDirFiles(char * filespath)
{
int countfiles = 0;
struct stat st;
DIR_ITER* dir;
dir = diropen (filespath);
if (dir == NULL) //If empty
return 0;
while (dirnext(dir,filenames,&st) == 0)
{
if ((st.st_mode & S_IFDIR) == 0)
{
// st.st_mode & S_IFDIR indicates a directory
snprintf(alldirfiles[countfiles], 70, "%s", filenames);
countfiles++;
}
}
dirclose(dir);
qsort(alldirfiles, countfiles, sizeof(char[70]), filenamescmp);
return countfiles;
}
bool checkfile(char * path)
{
FILE * f;
f = fopen(path,"r");
if(f) {
fclose(f);
return true;
}
return false;
}