2009-05-30 18:58:34 +02:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <gccore.h>
|
|
|
|
#include <fat.h>
|
|
|
|
#include <sys/dir.h>
|
2009-06-05 00:13:39 +02:00
|
|
|
#include <dirent.h>
|
2009-05-30 18:58:34 +02:00
|
|
|
#include <unistd.h>
|
|
|
|
|
|
|
|
#include "listfiles.h"
|
|
|
|
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
static char alldirfiles[300][70];
|
|
|
|
char filenames[80];
|
2009-05-30 18:58:34 +02:00
|
|
|
|
2009-06-05 00:13:39 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-16 10:28:50 +02:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
char * GetFileName(int i)
|
|
|
|
{
|
|
|
|
return alldirfiles[i];
|
|
|
|
}
|
2009-05-30 18:58:34 +02:00
|
|
|
|
|
|
|
s32 filenamescmp(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
/* Compare strings */
|
|
|
|
return stricmp((char *)a, (char *)b);
|
|
|
|
}
|
|
|
|
|
2009-06-06 19:26:52 +02:00
|
|
|
int GetAllDirFiles(char * filespath)
|
2009-05-30 18:58:34 +02:00
|
|
|
{
|
2009-06-10 01:26:03 +02:00
|
|
|
int countfiles = 0;
|
2009-06-16 10:28:50 +02:00
|
|
|
|
2009-06-10 01:26:03 +02:00
|
|
|
struct stat st;
|
|
|
|
DIR_ITER* dir;
|
|
|
|
dir = diropen (filespath);
|
2009-06-16 10:28:50 +02:00
|
|
|
|
2009-06-10 01:26:03 +02:00
|
|
|
if (dir == NULL) //If empty
|
2009-05-30 18:58:34 +02:00
|
|
|
return 0;
|
2009-06-06 19:26:52 +02:00
|
|
|
while (dirnext(dir,filenames,&st) == 0)
|
2009-06-10 01:26:03 +02:00
|
|
|
{
|
2009-05-30 18:58:34 +02:00
|
|
|
if ((st.st_mode & S_IFDIR) == 0)
|
2009-06-10 01:26:03 +02:00
|
|
|
{
|
2009-05-30 18:58:34 +02:00
|
|
|
// st.st_mode & S_IFDIR indicates a directory
|
2009-06-06 19:26:52 +02:00
|
|
|
snprintf(alldirfiles[countfiles], 70, "%s", filenames);
|
2009-05-30 18:58:34 +02:00
|
|
|
countfiles++;
|
|
|
|
}
|
|
|
|
}
|
2009-06-10 01:26:03 +02:00
|
|
|
dirclose(dir);
|
2009-05-30 18:58:34 +02:00
|
|
|
qsort(alldirfiles, countfiles, sizeof(char[70]), filenamescmp);
|
2009-06-10 01:26:03 +02:00
|
|
|
return countfiles;
|
2009-05-30 18:58:34 +02:00
|
|
|
}
|
2009-06-23 20:59:28 +02:00
|
|
|
|
|
|
|
bool checkfile(char * path)
|
|
|
|
{
|
|
|
|
FILE * f;
|
|
|
|
f = fopen(path,"r");
|
|
|
|
if(f) {
|
|
|
|
fclose(f);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2009-07-20 09:23:30 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|