mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-05 02:55:07 +01:00
30535c6f5d
formatted the code to make it easier to read. no functional changes at all. i didn't put anything from the libwiigui folder or banner folder in the beautifier. my automated .bat seems to have done a good job. the only places i see it fucked up was on (GXColor){blablabla}. it treated the brackets in the color like all the other brackets and put the color on a new line and indented it. i think i fixed most of them. not sure if it messed up anywhere else. also not sure about how it handled different linebreaks. it looks fine on windows. if it looks messed up on linux, it can be reverted. the code still compiles and runs fine.
103 lines
2.1 KiB
C
103 lines
2.1 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;
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|