mirror of
https://github.com/wiidev/usbloadergx.git
synced 2024-11-18 17:29:17 +01:00
71adda33e0
*Added HomebrewFiles Class NOTE 1: In settings/custompaths you can change the HomebrewPath and the standard is SD:/apps/. Our browser searches for EVERY .dol and .elf file in the directory even if its not called boot.dol. NOTE 2: Giantpune and me tested the homebrewbooting and it worked for every homebrew we tested except our own application. (a bit ironic) NOTE 3: Right now the information on the Buttons is the path to the Homebrew. This and the BootPrompt will be replaced with the XML information inside the path of the homebrew later but for now i am taking a break NOTE 4: Right now the button to the HomebrewMenu is next to WiiMenuButton and has the same image as the listgamebrowser. I didnt have any images so i took what i had and cyrex will change the images when he is back. Also there will be a no icon image added later.
103 lines
2.5 KiB
C++
103 lines
2.5 KiB
C++
/****************************************************************************
|
|
* HomebrewFiles Class
|
|
* for USB Loader GX
|
|
***************************************************************************/
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/dir.h>
|
|
|
|
#include "HomebrewFiles.h"
|
|
|
|
HomebrewFiles::HomebrewFiles(const char * path)
|
|
{
|
|
filecount = 0;
|
|
this->LoadPath(path);
|
|
this->SortList();
|
|
}
|
|
|
|
HomebrewFiles::~HomebrewFiles()
|
|
{
|
|
}
|
|
|
|
bool HomebrewFiles::LoadPath(const char * folderpath)
|
|
{
|
|
struct stat st;
|
|
DIR_ITER *dir = NULL;
|
|
char filename[1024];
|
|
|
|
dir = diropen(folderpath);
|
|
if(dir == NULL) {
|
|
return false;
|
|
}
|
|
|
|
while (dirnext(dir,filename,&st) == 0)
|
|
{
|
|
if((st.st_mode & S_IFDIR) != 0) {
|
|
if(strcmp(filename,".") != 0 && strcmp(filename,"..") != 0) {
|
|
char currentname[200];
|
|
snprintf(currentname, sizeof(currentname), "%s%s/", folderpath, filename);
|
|
this->LoadPath(currentname);
|
|
}
|
|
} else {
|
|
char temp[5];
|
|
for(int i = 0; i < 5; i++) {
|
|
temp[i] = filename[strlen(filename)-4+i];
|
|
}
|
|
|
|
if(strncasecmp(temp, ".dol", 4) == 0 || strncasecmp(temp, ".elf", 4) == 0
|
|
&& filecount < MAXHOMEBREWS) {
|
|
|
|
strncpy(FileInfo[filecount].FilePath, folderpath, sizeof(FileInfo[filecount].FilePath));
|
|
strncpy(FileInfo[filecount].FileName, filename, sizeof(FileInfo[filecount].FileName));
|
|
FileInfo[filecount].FileSize = st.st_size;
|
|
filecount++;
|
|
}
|
|
}
|
|
}
|
|
dirclose(dir);
|
|
|
|
return true;
|
|
}
|
|
|
|
char * HomebrewFiles::GetFilename(int ind)
|
|
{
|
|
if(ind > filecount)
|
|
return NULL;
|
|
else
|
|
return FileInfo[ind].FileName;
|
|
}
|
|
|
|
char * HomebrewFiles::GetFilepath(int ind)
|
|
{
|
|
if(ind > filecount)
|
|
return NULL;
|
|
else
|
|
return FileInfo[ind].FilePath;
|
|
}
|
|
|
|
unsigned int HomebrewFiles::GetFilesize(int ind)
|
|
{
|
|
if(ind > filecount)
|
|
return NULL;
|
|
else
|
|
return FileInfo[ind].FileSize;
|
|
}
|
|
|
|
int HomebrewFiles::GetFilecount()
|
|
{
|
|
return filecount;
|
|
}
|
|
|
|
int ListCompare(const void *a, const void *b)
|
|
{
|
|
FileInfos *ab = (FileInfos*) a;
|
|
FileInfos *bb = (FileInfos*) b;
|
|
|
|
return stricmp((char *) ab->FilePath, (char *) bb->FilePath);
|
|
}
|
|
void HomebrewFiles::SortList()
|
|
{
|
|
qsort(FileInfo, filecount, sizeof(FileInfos), ListCompare);
|
|
}
|