- fix tooltips in GameCarousel

- change gui_keyboard stuff
- change filebrowser stuff
This commit is contained in:
ardi@ist-einmalig.de 2009-10-05 10:53:19 +00:00
parent 608dd91a21
commit 505e4cd09c
8 changed files with 622 additions and 503 deletions

View File

@ -193,6 +193,7 @@ GuiFileBrowser::~GuiFileBrowser()
void GuiFileBrowser::SetFocus(int f) void GuiFileBrowser::SetFocus(int f)
{ {
LOCK(this);
focus = f; focus = f;
for(int i=0; i<FILEBROWSERSIZE; i++) for(int i=0; i<FILEBROWSERSIZE; i++)
@ -204,11 +205,13 @@ void GuiFileBrowser::SetFocus(int f)
void GuiFileBrowser::DisableTriggerUpdate(bool set) void GuiFileBrowser::DisableTriggerUpdate(bool set)
{ {
LOCK(this);
triggerdisabled = set; triggerdisabled = set;
} }
void GuiFileBrowser::ResetState() void GuiFileBrowser::ResetState()
{ {
LOCK(this);
state = STATE_DEFAULT; state = STATE_DEFAULT;
stateChan = -1; stateChan = -1;
selectedItem = 0; selectedItem = 0;
@ -221,6 +224,7 @@ void GuiFileBrowser::ResetState()
void GuiFileBrowser::TriggerUpdate() void GuiFileBrowser::TriggerUpdate()
{ {
LOCK(this);
listChanged = true; listChanged = true;
} }
@ -229,6 +233,7 @@ void GuiFileBrowser::TriggerUpdate()
*/ */
void GuiFileBrowser::Draw() void GuiFileBrowser::Draw()
{ {
LOCK(this);
if(!this->IsVisible()) if(!this->IsVisible())
return; return;
@ -249,6 +254,7 @@ void GuiFileBrowser::Draw()
void GuiFileBrowser::Update(GuiTrigger * t) void GuiFileBrowser::Update(GuiTrigger * t)
{ {
LOCK(this);
if(state == STATE_DISABLED || !t || triggerdisabled) if(state == STATE_DISABLED || !t || triggerdisabled)
return; return;
@ -263,7 +269,7 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(scrollbarBoxBtn->GetState() == STATE_HELD && if(scrollbarBoxBtn->GetState() == STATE_HELD &&
scrollbarBoxBtn->GetStateChan() == t->chan && scrollbarBoxBtn->GetStateChan() == t->chan &&
t->wpad.ir.valid && t->wpad.ir.valid &&
browser.numEntries > FILEBROWSERSIZE browser->browserList.size() > FILEBROWSERSIZE
) )
{ {
scrollbarBoxBtn->SetPosition(20,-10); scrollbarBoxBtn->SetPosition(20,-10);
@ -274,15 +280,15 @@ void GuiFileBrowser::Update(GuiTrigger * t)
else if(positionWiimote > scrollbarBoxBtn->GetMaxY()) else if(positionWiimote > scrollbarBoxBtn->GetMaxY())
positionWiimote = scrollbarBoxBtn->GetMaxY(); positionWiimote = scrollbarBoxBtn->GetMaxY();
browser.pageIndex = (positionWiimote * browser.numEntries)/136.0 - selectedItem; browser->pageIndex = (positionWiimote * browser->browserList.size())/136.0 - selectedItem;
if(browser.pageIndex <= 0) if(browser->pageIndex <= 0)
{ {
browser.pageIndex = 0; browser->pageIndex = 0;
} }
else if(browser.pageIndex+FILEBROWSERSIZE >= browser.numEntries) else if(browser->pageIndex+FILEBROWSERSIZE >= (int)browser->browserList.size())
{ {
browser.pageIndex = browser.numEntries-FILEBROWSERSIZE; browser->pageIndex = browser->browserList.size()-FILEBROWSERSIZE;
} }
listChanged = true; listChanged = true;
focus = false; focus = false;
@ -314,32 +320,32 @@ void GuiFileBrowser::Update(GuiTrigger * t)
*/ */
if(t->Right()) if(t->Right())
{ {
if(browser.pageIndex < browser.numEntries && browser.numEntries > FILEBROWSERSIZE) if(browser->pageIndex < (int)browser->browserList.size() && browser->browserList.size() > FILEBROWSERSIZE)
{ {
browser.pageIndex += FILEBROWSERSIZE; browser->pageIndex += FILEBROWSERSIZE;
if(browser.pageIndex+FILEBROWSERSIZE >= browser.numEntries) if(browser->pageIndex+FILEBROWSERSIZE >= (int)browser->browserList.size())
browser.pageIndex = browser.numEntries-FILEBROWSERSIZE; browser->pageIndex = browser->browserList.size()-FILEBROWSERSIZE;
listChanged = true; listChanged = true;
} }
} }
else if(t->Left()) else if(t->Left())
{ {
if(browser.pageIndex > 0) if(browser->pageIndex > 0)
{ {
browser.pageIndex -= FILEBROWSERSIZE; browser->pageIndex -= FILEBROWSERSIZE;
if(browser.pageIndex < 0) if(browser->pageIndex < 0)
browser.pageIndex = 0; browser->pageIndex = 0;
listChanged = true; listChanged = true;
} }
} }
else if(t->Down()) else if(t->Down())
{ {
if(browser.pageIndex + selectedItem + 1 < browser.numEntries) if(browser->pageIndex + selectedItem + 1 < (int)browser->browserList.size())
{ {
if(selectedItem == FILEBROWSERSIZE-1) if(selectedItem == FILEBROWSERSIZE-1)
{ {
// move list down by 1 // move list down by 1
browser.pageIndex++; browser->pageIndex++;
listChanged = true; listChanged = true;
} }
else if(fileList[selectedItem+1]->IsVisible()) else if(fileList[selectedItem+1]->IsVisible())
@ -351,10 +357,10 @@ void GuiFileBrowser::Update(GuiTrigger * t)
} }
else if(t->Up()) else if(t->Up())
{ {
if(selectedItem == 0 && browser.pageIndex + selectedItem > 0) if(selectedItem == 0 && browser->pageIndex + selectedItem > 0)
{ {
// move list up by 1 // move list up by 1
browser.pageIndex--; browser->pageIndex--;
listChanged = true; listChanged = true;
} }
else if(selectedItem > 0) else if(selectedItem > 0)
@ -370,17 +376,21 @@ void GuiFileBrowser::Update(GuiTrigger * t)
{ {
if(listChanged) if(listChanged)
{ {
if(browser.pageIndex+i < browser.numEntries) bool haveselected = false;
if(browser->pageIndex+i < (int)browser->browserList.size())
{ {
if(fileList[i]->GetState() == STATE_DISABLED) if(fileList[i]->GetState() == STATE_DISABLED)
fileList[i]->SetState(STATE_DEFAULT); fileList[i]->SetState(STATE_DEFAULT);
if(fileList[i]->GetState() == STATE_SELECTED)
haveselected = true;
fileList[i]->SetVisible(true); fileList[i]->SetVisible(true);
fileListText[i]->SetText(browserList[browser.pageIndex+i].displayname); fileListText[i]->SetText(browser->browserList[browser->pageIndex+i].displayname);
fileListTextOver[i]->SetText(browserList[browser.pageIndex+i].displayname); fileListTextOver[i]->SetText(browser->browserList[browser->pageIndex+i].displayname);
if(browserList[browser.pageIndex+i].isdir) // directory if(browser->browserList[browser->pageIndex+i].isdir) // directory
{ {
fileList[i]->SetIcon(fileListFolder[i]); fileList[i]->SetIcon(fileListFolder[i]);
fileListText[i]->SetPosition(30,0); fileListText[i]->SetPosition(30,0);
@ -427,6 +437,9 @@ void GuiFileBrowser::Update(GuiTrigger * t)
fileList[i]->SetVisible(false); fileList[i]->SetVisible(false);
fileList[i]->SetState(STATE_DISABLED); fileList[i]->SetState(STATE_DISABLED);
} }
if(!haveselected && browser->pageIndex < (int)browser->browserList.size())
fileList[i]->SetState(STATE_SELECTED, t->chan);
} }
if(i != selectedItem && fileList[i]->GetState() == STATE_SELECTED) if(i != selectedItem && fileList[i]->GetState() == STATE_SELECTED)
@ -445,7 +458,6 @@ void GuiFileBrowser::Update(GuiTrigger * t)
if(fileList[i]->GetState() == STATE_SELECTED) if(fileList[i]->GetState() == STATE_SELECTED)
{ {
selectedItem = i; selectedItem = i;
browser.selIndex = browser.pageIndex + i;
} }
} }
@ -456,11 +468,11 @@ void GuiFileBrowser::Update(GuiTrigger * t)
} }
else else
{ {
position = 136*(browser.pageIndex + FILEBROWSERSIZE/2.0) / (browser.numEntries*1.0); position = 136*(browser->pageIndex + FILEBROWSERSIZE/2.0) / (browser->browserList.size()*1.0);
if(browser.pageIndex/(FILEBROWSERSIZE/2.0) < 1) if(browser->pageIndex/(FILEBROWSERSIZE/2.0) < 1)
position = -10; position = -10;
else if((browser.pageIndex+FILEBROWSERSIZE)/(FILEBROWSERSIZE*1.0) >= (browser.numEntries)/(FILEBROWSERSIZE*1.0)) else if((browser->pageIndex+FILEBROWSERSIZE)/(FILEBROWSERSIZE*1.0) >= (browser->browserList.size())/(FILEBROWSERSIZE*1.0))
position = 156; position = 156;
} }

View File

@ -344,10 +344,7 @@ void GuiGameCarousel::Update(GuiTrigger * t)
else else
gamename->SetText((char*)NULL); gamename->SetText((char*)NULL);
if(selectedItem_old>=0) if(selectedItem_old>=0)
{
game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100); game[selectedItem_old]->SetEffect(EFFECT_SCALE, -1, 100);
game[selectedItem_old]->RemoveToolTip();
}
} }
// navigation // navigation
if(focus && gameCnt>6) if(focus && gameCnt>6)

View File

@ -32,10 +32,10 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
focus = 0; // allow focus focus = 0; // allow focus
alignmentHor = ALIGN_CENTRE; alignmentHor = ALIGN_CENTRE;
alignmentVert = ALIGN_MIDDLE; alignmentVert = ALIGN_MIDDLE;
strncpy(kbtextstr, t, max); // do not change from strncpy to strlcpy, it needs to be padded with 0 kbtextmaxlen = max>sizeof(kbtextstr) ? sizeof(kbtextstr) : max; // limit max up to sizeof(kbtextstr)
kbtextstr[max] = 0; // strlcpy(kbtextstr, t, kbtextmaxlen);
kbtextmaxlen = max; strncpy(kbtextstr, t, kbtextmaxlen); // strncpy is needed to fill the rest with \0
kbtextstr[sizeof(kbtextstr)-1] = 0; // terminate with \0
//QWERTY// //QWERTY//
if (mode == 0){ if (mode == 0){
Key thekeys[4][11] = { Key thekeys[4][11] = {
@ -471,6 +471,7 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
//keySpace->SetEffectGrow(); //keySpace->SetEffectGrow();
this->Append(keySpace); this->Append(keySpace);
char txt[2] = { 0, 0 };
for(int i=0; i<4; i++) for(int i=0; i<4; i++)
{ {
for(int j=0; j<11; j++) for(int j=0; j<11; j++)
@ -479,7 +480,8 @@ GuiKeyboard::GuiKeyboard(char * t, u32 max, int min, int lang)
{ {
keyImg[i][j] = new GuiImage(key); keyImg[i][j] = new GuiImage(key);
keyImgOver[i][j] = new GuiImage(keyOver); keyImgOver[i][j] = new GuiImage(keyOver);
keyTxt[i][j] = new GuiText(NULL, 20, (GXColor){0, 0, 0, 0xff}); txt[0] = keys[i][j].ch;
keyTxt[i][j] = new GuiText(txt, 20, (GXColor){0, 0, 0, 0xff});
keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); keyTxt[i][j]->SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
keyTxt[i][j]->SetPosition(0, -10); keyTxt[i][j]->SetPosition(0, -10);
keyBtn[i][j] = new GuiButton(keyImg[i][j], keyImgOver[i][j], 0, 3, (j*42+21*i+40)+eurocheck, i*42+120, trigA, keySoundOver, keySoundClick,1); keyBtn[i][j] = new GuiButton(keyImg[i][j], keyImgOver[i][j], 0, 3, (j*42+21*i+40)+eurocheck, i*42+120, trigA, keySoundOver, keySoundClick,1);
@ -563,11 +565,11 @@ void GuiKeyboard::Update(GuiTrigger * t)
catch (const std::exception& e) { } catch (const std::exception& e) { }
} }
bool update = false; bool changedShiftKey = false;
if(keySpace->GetState() == STATE_CLICKED) if(keySpace->GetState() == STATE_CLICKED)
{ {
if(strlen(kbtextstr) < kbtextmaxlen) if(strlen(kbtextstr) < kbtextmaxlen-1) // -1 --> kbtextmaxlen means with terminating '\0'
{ {
kbtextstr[strlen(kbtextstr)] = ' '; kbtextstr[strlen(kbtextstr)] = ' ';
kbText->SetText(kbtextstr); kbText->SetText(kbtextstr);
@ -577,20 +579,22 @@ void GuiKeyboard::Update(GuiTrigger * t)
else if(keyBack->GetState() == STATE_CLICKED) else if(keyBack->GetState() == STATE_CLICKED)
{ {
if (strlen(kbtextstr) >(m)){ if (strlen(kbtextstr) >(m)){
kbtextstr[strlen(kbtextstr)-1] = 0; kbtextstr[strlen(kbtextstr)-1] = 0;
kbText->SetText(kbtextstr);} kbText->SetText(kbtextstr);
}
keyBack->SetState(STATE_SELECTED, t->chan); keyBack->SetState(STATE_SELECTED, t->chan);
} }
else if(keyClear->GetState() == STATE_CLICKED) else if(keyClear->GetState() == STATE_CLICKED)
{ clearMore: {
if (strlen(kbtextstr) >(m)){ while (strlen(kbtextstr) >(m)){
kbtextstr[strlen(kbtextstr)-1] = 0; kbtextstr[strlen(kbtextstr)-1] = 0;
kbText->SetText(kbtextstr); kbText->SetText(kbtextstr);
goto clearMore;} }
keyClear->SetState(STATE_SELECTED, t->chan); keyClear->SetState(STATE_SELECTED, t->chan);
} }
else if(keyShift->GetState() == STATE_CLICKED) else if(keyShift->GetState() == STATE_CLICKED)
{ {
changedShiftKey =true;
shift ^= 1; shift ^= 1;
if(alt) alt ^= 1; if(alt) alt ^= 1;
if(alt2) alt2 ^= 1; if(alt2) alt2 ^= 1;
@ -598,6 +602,7 @@ void GuiKeyboard::Update(GuiTrigger * t)
} }
else if(keyAlt->GetState() == STATE_CLICKED) else if(keyAlt->GetState() == STATE_CLICKED)
{ {
changedShiftKey =true;
alt ^= 1; alt ^= 1;
if(shift) shift ^= 1; if(shift) shift ^= 1;
if(alt2) alt2 ^= 1; if(alt2) alt2 ^= 1;
@ -605,6 +610,7 @@ void GuiKeyboard::Update(GuiTrigger * t)
} }
else if(keyAlt2->GetState() == STATE_CLICKED) else if(keyAlt2->GetState() == STATE_CLICKED)
{ {
changedShiftKey =true;
alt2 ^= 1; alt2 ^= 1;
if(shift) shift ^= 1; if(shift) shift ^= 1;
if(alt) alt ^= 1; if(alt) alt ^= 1;
@ -612,68 +618,59 @@ void GuiKeyboard::Update(GuiTrigger * t)
} }
else if(keyCaps->GetState() == STATE_CLICKED) else if(keyCaps->GetState() == STATE_CLICKED)
{ {
changedShiftKey =true;
caps ^= 1; caps ^= 1;
keyCaps->SetState(STATE_SELECTED, t->chan); keyCaps->SetState(STATE_SELECTED, t->chan);
} }
bool update = false;
char txt[2] = { 0, 0 }; char txt[2] = { 0, 0 };
startloop: do
for(int i=0; i<4; i++)
{ {
for(int j=0; j<11; j++) update = false;
for(int i=0; i<4; i++)
{ {
if(keys[i][j].ch != '\0') for(int j=0; j<11; j++)
{ {
if(shift || caps) if(keys[i][j].ch != '\0')
txt[0] = keys[i][j].chShift;
else if(alt)
txt[0] = keys[i][j].chalt;
else if(alt2)
txt[0] = keys[i][j].chalt2;
else
txt[0] = keys[i][j].ch;
keyTxt[i][j]->SetText(txt);
if(keyBtn[i][j]->GetState() == STATE_CLICKED)
{ {
if(strlen(kbtextstr) < kbtextmaxlen) if(shift || caps)
txt[0] = keys[i][j].chShift;
else if(alt)
txt[0] = keys[i][j].chalt;
else if(alt2)
txt[0] = keys[i][j].chalt2;
else
txt[0] = keys[i][j].ch;
if(changedShiftKey) // change text only if needed
keyTxt[i][j]->SetText(txt);
if(keyBtn[i][j]->GetState() == STATE_CLICKED)
{ {
if(shift || caps) if(strlen(kbtextstr) < kbtextmaxlen-1) // -1 --> kbtextmaxlen means with term. '\0'
{ {
kbtextstr[strlen(kbtextstr)] = keys[i][j].chShift; kbtextstr[strlen(kbtextstr)] = txt[0];
kbText->SetText(kbtextstr);
} }
else if(alt) keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
{
kbtextstr[strlen(kbtextstr)] = keys[i][j].chalt;
}
else if(alt2)
{
kbtextstr[strlen(kbtextstr)] = keys[i][j].chalt2;
}
else
{
kbtextstr[strlen(kbtextstr)] = keys[i][j].ch;
}
}
kbText->SetText(kbtextstr);
keyBtn[i][j]->SetState(STATE_SELECTED, t->chan);
if(shift || alt || alt2)
if(shift || alt || alt2) {
{ if(shift) shift ^= 1;
if(shift) shift ^= 1; if(alt) alt ^= 1;
if(alt) alt ^= 1; if(alt2) alt2 ^= 1;
if(alt2) alt2 ^= 1; update = true;
update = true; changedShiftKey = true;
goto startloop; }
} }
} }
} }
} }
} } while(update);
kbText->SetPosition(0, 53); kbText->SetPosition(0, 53);

View File

@ -31,28 +31,37 @@ bool findfile(const char * filename, const char * path) {
return false; return false;
} }
bool subfoldercreate(char * fullpath) { bool subfoldercreate(const char * fullpath) {
//check forsubfolders //check forsubfolders
char dircheck[300]; char dir[300];
char dirnoslash[300]; char * pch = NULL;
char * pch = NULL; u32 len;
u32 cnt = 0; struct stat st;
struct stat st;
snprintf(dirnoslash, strlen(fullpath), "%s", fullpath); strlcpy(dir, fullpath, sizeof(dir));
len = strlen(dir);
if (stat(fullpath, &st) != 0) { if(len && len< sizeof(dir)-2 && dir[len-1] != '/');
pch = strrchr(dirnoslash, '/'); {
cnt = pch-dirnoslash; dir[len++] = '/';
snprintf(dircheck, cnt+2, "%s", dirnoslash); dir[len] = '\0';
subfoldercreate(dircheck); }
}; if (stat(dir, &st) != 0) // fullpath not exist?
{
if (mkdir(dirnoslash, 0777) == -1) { while(len && dir[len-1] == '/')
return false; dir[--len] = '\0'; // remove all trailing /
} pch = strrchr(dir, '/');
if(pch == NULL) return false;
return true; *pch = '\0';
if(subfoldercreate(dir))
{
*pch = '/';
if (mkdir(dir, 0777) == -1)
return false;
}
else
return false;
}
return true;
} }
char * GetFileName(int i) { char * GetFileName(int i) {

View File

@ -8,7 +8,7 @@ extern "C" {
bool findfile(const char * filename, const char * path); bool findfile(const char * filename, const char * path);
char * GetFileName(int i); char * GetFileName(int i);
int GetAllDirFiles(char * filespath); int GetAllDirFiles(char * filespath);
bool subfoldercreate(char * fullpath); bool subfoldercreate(const char * fullpath);
bool checkfile(char * path); bool checkfile(char * path);
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -15,9 +15,10 @@
#include <string.h> #include <string.h>
#include <wiiuse/wpad.h> #include <wiiuse/wpad.h>
#include <sys/dir.h> #include <sys/dir.h>
#include <sys/iosupport.h>
#include <malloc.h> #include <malloc.h>
#include <algorithm>
#include "filebrowser.h"
#include "menu.h" #include "menu.h"
#include "listfiles.h" #include "listfiles.h"
@ -25,6 +26,7 @@
#include "PromptWindows.h" #include "PromptWindows.h"
#include "libwiigui/gui.h" #include "libwiigui/gui.h"
#include "sys.h" #include "sys.h"
#include "filebrowser.h"
/*** Extern variables ***/ /*** Extern variables ***/
extern GuiWindow * mainWindow; extern GuiWindow * mainWindow;
@ -35,421 +37,498 @@ extern u8 reset;
extern void ResumeGui(); extern void ResumeGui();
extern void HaltGui(); extern void HaltGui();
BROWSERINFO browser; static int curDevice = -1;
BROWSERENTRY * browserList = NULL; // list of files/folders in browser static std::vector<BROWSERINFO> browsers;
BROWSERINFO *browser = NULL;
/****************************************************************************
* FileFilterCallbacks
* return: 1-visible 0-hidden
***************************************************************************/
int noDIRS(BROWSERENTRY *Entry, void* Args)
{
return !Entry->isdir;
}
int noFILES(BROWSERENTRY *Entry, void* Args)
{
return Entry->isdir;
}
int noEXT(BROWSERENTRY *Entry, void* Args)
{
if(!Entry->isdir)
{
char *cptr = strrchr(Entry->displayname, '.');
if(cptr && cptr!= Entry->displayname) *cptr = 0;
}
return 1;
}
void ResetBrowser(BROWSERINFO *browser);
/****************************************************************************
* InitBrowsers()
* Clears the file browser memory, and allocates one initial entry
***************************************************************************/
int InitBrowsers() {
curDevice = -1;
browsers.clear();
browser = NULL;
char rootdir[ROOTDIRLEN];
for(int i=3; i<STD_MAX; i++)
{
if(strcmp(devoptab_list[i]->name, "stdnull"))
{
snprintf(rootdir, sizeof(rootdir) , "%s:/", devoptab_list[i]->name);
if(DIR_ITER *dir = diropen(rootdir))
{
dirclose(dir);
BROWSERINFO browser;
browser.dir[0] = '\0';
strcpy(browser.rootdir, rootdir);
ResetBrowser(&browser);
browsers.push_back(browser);
}
}
}
if(!browsers.size()) return -1;
curDevice = 0;
browser = &browsers[curDevice];
return 0;
}
/**************************************************************************** /****************************************************************************
* ResetBrowser() * ResetBrowser()
* Clears the file browser memory, and allocates one initial entry * Clears the file browser memory, and allocates one initial entry
***************************************************************************/ ***************************************************************************/
void ResetBrowser() { void ResetBrowser(BROWSERINFO *browser) {
browser.numEntries = 0; browser->pageIndex = 0;
browser.selIndex = 0; browser->browserList.clear();
browser.pageIndex = 0; /*
// Clear any existing values
// Clear any existing values if (browser->browserList != NULL) {
if (browserList != NULL) { free(browser->browserList);
free(browserList); browser->browserList = NULL;
browserList = NULL; }
} // set aside space for 1 entry
// set aside space for 1 entry browser->browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY));
browserList = (BROWSERENTRY *)malloc(sizeof(BROWSERENTRY)); if(browser->browserList)
memset(browserList, 0, sizeof(BROWSERENTRY)); memset(browser->browserList, 0, sizeof(BROWSERENTRY));
} */
/****************************************************************************
* UpdateDirName()
* Update curent directory name for file browser
***************************************************************************/
int UpdateDirName() {
int size=0;
char * test;
char temp[1024];
/* current directory doesn't change */
if (strcmp(browserList[browser.selIndex].filename,".") == 0) {
return 0;
}
/* go up to parent directory */
else if (strcmp(browserList[browser.selIndex].filename,"..") == 0) {
/* determine last subdirectory namelength */
sprintf(temp,"%s",browser.dir);
test = strtok(temp,"/");
while (test != NULL) {
size = strlen(test);
test = strtok(NULL,"/");
}
/* remove last subdirectory name */
size = strlen(browser.dir) - size - 1;
browser.dir[size] = 0;
return 1;
}
/* Open a directory */
else {
/* test new directory namelength */
if ((strlen(browser.dir)+1+strlen(browserList[browser.selIndex].filename)) < MAXPATHLEN) {
/* update current directory name */
sprintf(browser.dir, "%s/%s",browser.dir, browserList[browser.selIndex].filename);
return 1;
} else {
return -1;
}
}
} }
/**************************************************************************** /****************************************************************************
* FileSortCallback * FileSortCallback
* *
* Quick sort callback to sort file entries with the following order: * sort callback to sort file entries with the following order:
* . * .
* .. * ..
* <dirs> * <dirs>
* <files> * <files>
***************************************************************************/ ***************************************************************************/
int FileSortCallback(const void *f1, const void *f2) { //int FileSortCallback(const void *f1, const void *f2) {
/* Special case for implicit directories */ bool operator< (const BROWSERENTRY &f1, const BROWSERENTRY &f2) {
if (((BROWSERENTRY *)f1)->filename[0] == '.' || ((BROWSERENTRY *)f2)->filename[0] == '.') { /* Special case for implicit directories */
if (strcmp(((BROWSERENTRY *)f1)->filename, ".") == 0) { if (f1.filename[0] == '.' || f2.filename[0] == '.') {
return -1; if (strcmp(f1.filename, ".") == 0) {
} return true;
if (strcmp(((BROWSERENTRY *)f2)->filename, ".") == 0) { }
return 1; if (strcmp(f2.filename, ".") == 0) {
} return false;
if (strcmp(((BROWSERENTRY *)f1)->filename, "..") == 0) { }
return -1; if (strcmp(f1.filename, "..") == 0) {
} return true;
if (strcmp(((BROWSERENTRY *)f2)->filename, "..") == 0) { }
return 1; if (strcmp(f2.filename, "..") == 0) {
} return false;
} }
}
/* If one is a file and one is a directory the directory is first. */ /* If one is a file and one is a directory the directory is first. */
if (((BROWSERENTRY *)f1)->isdir && !(((BROWSERENTRY *)f2)->isdir)) return -1; if (f1.isdir && !(f2.isdir)) return true;
if (!(((BROWSERENTRY *)f1)->isdir) && ((BROWSERENTRY *)f2)->isdir) return 1; if (!(f1.isdir) && f2.isdir) return false;
return stricmp(((BROWSERENTRY *)f1)->filename, ((BROWSERENTRY *)f2)->filename); return stricmp(f1.filename, f2.filename)<0;
} }
int ParseFilter(FILTERCASCADE *Filter, BROWSERENTRY* Entry)
{
while(Filter)
{
if(Filter->filter && Filter->filter(Entry, Filter->filter_args) == 0)
return 0;
Filter = Filter->next;
}
return 1;
}
/*************************************************************************** /***************************************************************************
* Browse subdirectories * Browse subdirectories
**************************************************************************/ **************************************************************************/
int int ParseDirectory(const char* Path, int Flags, FILTERCASCADE *Filter) {
ParseDirectory() { DIR_ITER *dir = NULL;
DIR_ITER *dir = NULL; char fulldir[MAXPATHLEN];
char fulldir[MAXPATHLEN]; char filename[MAXPATHLEN];
char filename[MAXPATHLEN]; struct stat filestat;
struct stat filestat; unsigned int i;
// reset browser if(curDevice == -1)
ResetBrowser(); if(InitBrowsers()) return -1; // InitBrowser fails
// open the directory if(Path) // note in this codeblock use filename temporary
sprintf(fulldir, "%s%s", browser.rootdir, browser.dir); // add currentDevice to path {
dir = diropen(fulldir); strlcpy(fulldir, Path, sizeof(fulldir));
if(*fulldir && fulldir[strlen(fulldir)-1] != '/') // a file
{
char * chrp = strrchr(fulldir, '/');
if(chrp) chrp[1] = 0;
}
if(strchr(fulldir, ':') == NULL) // Path has no device device
{
getcwd(filename, sizeof(filename)); // save the current working dir
if(*fulldir==0) // if path is empty
strlcpy(fulldir, filename, sizeof(fulldir)); // we use the current working dir
else
{ // path is not empty
if(chdir(fulldir)); // sets the path to concatenate and validate
{
if(Flags & (FB_TRYROOTDIR | FB_TRYSTDDEV))
if(chdir("/") && !(Flags & FB_TRYSTDDEV))// try to set root if is needed
return -1;
}
if(getcwd(fulldir, sizeof(fulldir))) return -1; // gets the concatenated current working dir
chdir(filename); // restore the saved cwd
}
}
for(i=0; i<browsers.size(); i++) // searchs the browser who match the path
{
if(strnicmp(fulldir, browsers[i].rootdir, strlen(browsers[i].rootdir)-1 /*means without trailing '/'*/) == 0)
{
browser = &browsers[curDevice];
break;
}
}
if(i != browsers.size()) // found browser
{
curDevice = i;
browser = &browsers[curDevice];
strcpy(browser->dir, &fulldir[strlen(browser->rootdir)]);
}
else if(Flags & FB_TRYSTDDEV)
{
curDevice = 0;
browser = &browsers[curDevice]; // when no browser was found and
browser->dir[0] = 0; // we alowed try StdDevice and try RootDir
strlcpy(fulldir, browser->rootdir, sizeof(fulldir)); // set the first browser with root-dir
}
else
return -1;
}
else
snprintf(fulldir, sizeof(fulldir), "%s%s", browser->rootdir, browser->dir);
// if we can't open the dir, try opening the root dir // reset browser
if (dir == NULL) { ResetBrowser(browser);
sprintf(browser.dir,"/");
dir = diropen(browser.rootdir);
if (dir == NULL) {
return -1;
}
}
// index files/folders // open the directory
int entryNum = 0; if((dir = diropen(fulldir)) == NULL)
{
if(Flags & FB_TRYROOTDIR)
{
browser->dir[0] = 0;
if((dir = diropen(browser->rootdir)) == NULL)
return -1;
}
else
return -1;
}
while (dirnext(dir,filename,&filestat) == 0) { while (dirnext(dir,filename,&filestat) == 0)
if (strcmp(filename,".") != 0) { {
BROWSERENTRY * newBrowserList = (BROWSERENTRY *)realloc(browserList, (entryNum+1) * sizeof(BROWSERENTRY)); if (strcmp(filename,".") != 0)
{
BROWSERENTRY newEntry;
memset(&newEntry, 0, sizeof(BROWSERENTRY)); // clear the new entry
strlcpy(newEntry.filename, filename, sizeof(newEntry.filename));
strlcpy(newEntry.displayname, filename, sizeof(newEntry.displayname));
newEntry.length = filestat.st_size;
newEntry.isdir = (filestat.st_mode & S_IFDIR) == 0 ? 0 : 1; // flag this as a dir
if(ParseFilter(Filter, &newEntry))
browser->browserList.push_back(newEntry);
}
}
if (!newBrowserList) { // failed to allocate required memory // close directory
ResetBrowser(); dirclose(dir);
entryNum = -1;
break;
} else {
browserList = newBrowserList;
}
memset(&(browserList[entryNum]), 0, sizeof(BROWSERENTRY)); // clear the new entry
strncpy(browserList[entryNum].filename, filename, MAXJOLIET); // Sort the file list
std::sort(browser->browserList.begin(), browser->browserList.end());
if (strcmp(filename,"..") == 0) { return 0;
sprintf(browserList[entryNum].displayname, "..");
} else {
strcpy(browserList[entryNum].displayname, filename); // crop name for display
}
browserList[entryNum].length = filestat.st_size;
browserList[entryNum].isdir = (filestat.st_mode & _IFDIR) == 0 ? 0 : 1; // flag this as a dir
entryNum++;
}
}
// close directory
dirclose(dir);
// Sort the file list
qsort(browserList, entryNum, sizeof(BROWSERENTRY), FileSortCallback);
browser.numEntries = entryNum;
return entryNum;
} }
int ParseDirectory(int Device, int Flags, FILTERCASCADE *Filter)
/**************************************************************************** {
* BrowserChangeFolder if(Device >=0 && Device < (int)browsers.size())
* {
* Update current directory and set new entry list if directory has changed int old_curDevice = curDevice;
***************************************************************************/ curDevice = Device;
int BrowserChangeFolder() { browser = &browsers[curDevice];
if (!UpdateDirName()) if(ParseDirectory((char*)NULL, Flags, Filter) == 0) return 0;
return -1; curDevice = old_curDevice;
browser = &browsers[old_curDevice];
ParseDirectory(); }
return -1;
return browser.numEntries;
} }
/**************************************************************************** /****************************************************************************
* BrowseDevice * BrowseDevice
* Displays a list of files on the selected device * Displays a list of files on the selected path
***************************************************************************/
int BrowseDevice(int device) {
sprintf(browser.dir, "/");
switch (device) {
case SD:
sprintf(browser.rootdir, "SD:");
break;
case USB:
sprintf(browser.rootdir, "USB:");
break;
}
ParseDirectory(); // Parse root directory
return browser.numEntries;
}
/****************************************************************************
* MenuBrowseDevice
***************************************************************************/ ***************************************************************************/
int BrowseDevice(char * var, int force) { int BrowseDevice(char * Path, int Path_size, int Flags, FILTERCASCADE *Filter/*=NULL*/)
{
int result=-1;
int i;
int result=-1; if(InitBrowsers() || ParseDirectory(Path, Flags, Filter))
int i; {
char currentdir[90]; WindowPrompt(tr("Error"),0,tr("Ok"));
int curDivice = -1; return -1;
int forced =force; }
int menu = MENU_NONE;
if (forced>-1) { /*
if (BrowseDevice(forced) > 0) { GuiText titleTxt("Browse Files", 28, (GXColor){0, 0, 0, 230});
curDivice = forced; titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP);
goto main; titleTxt.SetPosition(70,20);
} */
} GuiTrigger trigA;
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiTrigger trigB;
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
else if ((!strcasecmp(bootDevice, "USB:"))&&(BrowseDevice(USB) > 0)) { GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
curDivice = USB; GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
goto main;
} else if ((!strcasecmp(bootDevice, "SD:"))&&(BrowseDevice(SD) > 0)) {
curDivice = SD;
goto main;
} else {
WindowPrompt(tr("Error"),0,tr("OK"));
return -1;
}
main: GuiImageData folderImgData(icon_folder_png);
int menu = MENU_NONE; GuiImage folderImg(&folderImgData);
GuiButton folderBtn(folderImg.GetWidth(), folderImg.GetHeight());
/* folderBtn.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
GuiText titleTxt("Browse Files", 28, (GXColor){0, 0, 0, 230}); folderBtn.SetPosition(-210, -145);
titleTxt.SetAlignment(ALIGN_LEFT, ALIGN_TOP); folderBtn.SetImage(&folderImg);
titleTxt.SetPosition(70,20); folderBtn.SetTrigger(&trigA);
*/ folderBtn.SetEffectGrow();
GuiTrigger trigA;
trigA.SetSimpleTrigger(-1, WPAD_BUTTON_A | WPAD_CLASSIC_BUTTON_A, PAD_BUTTON_A);
GuiTrigger trigB;
trigB.SetButtonOnlyTrigger(-1, WPAD_BUTTON_B | WPAD_CLASSIC_BUTTON_B, PAD_BUTTON_B);
GuiSound btnSoundOver(button_over_pcm, button_over_pcm_size, SOUND_PCM, Settings.sfxvolume);
GuiSound btnClick(button_click2_pcm, button_click2_pcm_size, SOUND_PCM, Settings.sfxvolume);
GuiImageData folderImgData(icon_folder_png);
GuiImage folderImg(&folderImgData);
GuiButton folderBtn(folderImg.GetWidth(), folderImg.GetHeight());
folderBtn.SetAlignment(ALIGN_CENTRE, ALIGN_MIDDLE);
folderBtn.SetPosition(-210, -145);
folderBtn.SetImage(&folderImg);
folderBtn.SetTrigger(&trigA);
folderBtn.SetEffectGrow();
char imgPath[100]; char imgPath[100];
snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path); snprintf(imgPath, sizeof(imgPath), "%sbutton_dialogue_box.png", CFG.theme_path);
GuiImageData btnOutline(imgPath, button_dialogue_box_png); GuiImageData btnOutline(imgPath, button_dialogue_box_png);
GuiText ExitBtnTxt(tr("Cancel"), 24, (GXColor) {0, 0, 0, 255}); GuiText ExitBtnTxt(tr("Cancel"), 24, (GXColor) {0, 0, 0, 255});
GuiImage ExitBtnImg(&btnOutline); GuiImage ExitBtnImg(&btnOutline);
if (Settings.wsprompt == yes) { if (Settings.wsprompt == yes) {
ExitBtnTxt.SetWidescreen(CFG.widescreen); ExitBtnTxt.SetWidescreen(CFG.widescreen);
ExitBtnImg.SetWidescreen(CFG.widescreen); ExitBtnImg.SetWidescreen(CFG.widescreen);
} }
GuiButton ExitBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); GuiButton ExitBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
ExitBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM); ExitBtn.SetAlignment(ALIGN_RIGHT, ALIGN_BOTTOM);
ExitBtn.SetPosition(-40, -35); ExitBtn.SetPosition(-40, -35);
ExitBtn.SetLabel(&ExitBtnTxt); ExitBtn.SetLabel(&ExitBtnTxt);
ExitBtn.SetImage(&ExitBtnImg); ExitBtn.SetImage(&ExitBtnImg);
ExitBtn.SetTrigger(&trigA); ExitBtn.SetTrigger(&trigA);
ExitBtn.SetTrigger(&trigB); ExitBtn.SetTrigger(&trigB);
ExitBtn.SetEffectGrow(); ExitBtn.SetEffectGrow();
GuiText usbBtnTxt((curDivice==SD?"USB":"SD"), 24, (GXColor) {0, 0, 0, 255}); GuiText usbBtnTxt(browsers[(curDevice+1)%browsers.size()].rootdir, 24, (GXColor) {0, 0, 0, 255});
GuiImage usbBtnImg(&btnOutline); GuiImage usbBtnImg(&btnOutline);
if (Settings.wsprompt == yes) { if (Settings.wsprompt == yes) {
usbBtnTxt.SetWidescreen(CFG.widescreen); usbBtnTxt.SetWidescreen(CFG.widescreen);
usbBtnImg.SetWidescreen(CFG.widescreen); usbBtnImg.SetWidescreen(CFG.widescreen);
} }
GuiButton usbBtn(btnOutline.GetWidth(), btnOutline.GetHeight()); GuiButton usbBtn(btnOutline.GetWidth(), btnOutline.GetHeight());
usbBtn.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM); usbBtn.SetAlignment(ALIGN_CENTRE, ALIGN_BOTTOM);
usbBtn.SetPosition(0, -35); usbBtn.SetPosition(0, -35);
usbBtn.SetLabel(&usbBtnTxt); usbBtn.SetLabel(&usbBtnTxt);
usbBtn.SetImage(&usbBtnImg); usbBtn.SetImage(&usbBtnImg);
usbBtn.SetTrigger(&trigA); usbBtn.SetTrigger(&trigA);
usbBtn.SetEffectGrow(); usbBtn.SetEffectGrow();
GuiText okBtnTxt(tr("OK"), 22, THEME.prompttext); GuiText okBtnTxt(tr("Ok"), 22, THEME.prompttext);
GuiImage okBtnImg(&btnOutline); GuiImage okBtnImg(&btnOutline);
if (Settings.wsprompt == yes) { if (Settings.wsprompt == yes) {
okBtnTxt.SetWidescreen(CFG.widescreen); okBtnTxt.SetWidescreen(CFG.widescreen);
okBtnImg.SetWidescreen(CFG.widescreen); okBtnImg.SetWidescreen(CFG.widescreen);
} }
GuiButton okBtn(&okBtnImg,&okBtnImg, 0, 4, 40, -35, &trigA, &btnSoundOver, &btnClick,1); GuiButton okBtn(&okBtnImg,&okBtnImg, 0, 4, 40, -35, &trigA, &btnSoundOver, &btnClick,1);
okBtn.SetLabel(&okBtnTxt); okBtn.SetLabel(&okBtnTxt);
GuiFileBrowser fileBrowser(396, 248); GuiFileBrowser fileBrowser(396, 248);
fileBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); fileBrowser.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
fileBrowser.SetPosition(0, 120); fileBrowser.SetPosition(0, 120);
GuiImageData Address(addressbar_textbox_png); GuiImageData Address(addressbar_textbox_png);
snprintf(currentdir, sizeof(currentdir), "%s%s", browser.rootdir, browser.dir); GuiText AdressText(NULL, 20, (GXColor) { 0, 0, 0, 255});
GuiText AdressText(currentdir, 20, (GXColor) { 0, 0, 0, 255}); AdressText.SetTextf("%s%s", browser->rootdir, browser->dir);
AdressText.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE); AdressText.SetAlignment(ALIGN_LEFT, ALIGN_MIDDLE);
AdressText.SetPosition(20, 0); AdressText.SetPosition(20, 0);
AdressText.SetMaxWidth(Address.GetWidth()-40, GuiText::SCROLL); AdressText.SetMaxWidth(Address.GetWidth()-40, GuiText::SCROLL);
GuiImage AdressbarImg(&Address); GuiImage AdressbarImg(&Address);
GuiButton Adressbar(Address.GetWidth(), Address.GetHeight()); GuiButton Adressbar(Address.GetWidth(), Address.GetHeight());
Adressbar.SetAlignment(ALIGN_CENTRE, ALIGN_TOP); Adressbar.SetAlignment(ALIGN_CENTRE, ALIGN_TOP);
Adressbar.SetPosition(0, fileBrowser.GetTop()-45); Adressbar.SetPosition(0, fileBrowser.GetTop()-45);
Adressbar.SetImage(&AdressbarImg); Adressbar.SetImage(&AdressbarImg);
Adressbar.SetLabel(&AdressText); Adressbar.SetLabel(&AdressText);
//save var in case they cancel and return it to them HaltGui();
snprintf(currentdir, sizeof(currentdir), "%s", var); GuiWindow w(screenwidth, screenheight);
sprintf(var,"%s", browser.rootdir); w.Append(&ExitBtn);
HaltGui();
GuiWindow w(screenwidth, screenheight);
w.Append(&ExitBtn);
// w.Append(&titleTxt); // w.Append(&titleTxt);
w.Append(&fileBrowser); w.Append(&fileBrowser);
w.Append(&Adressbar); w.Append(&Adressbar);
w.Append(&okBtn); w.Append(&okBtn);
w.Append(&folderBtn); if(!(Flags & FB_NOFOLDER_BTN))
w.Append(&usbBtn); w.Append(&folderBtn);
mainWindow->Append(&w); if(browsers.size()>1 && !(Flags & FB_NODEVICE_BTN))
ResumeGui(); w.Append(&usbBtn);
mainWindow->Append(&w);
ResumeGui();
int clickedIndex = -1;
while (menu == MENU_NONE) {
VIDEO_WaitVSync();
while (menu == MENU_NONE) { if (shutdown == 1)
VIDEO_WaitVSync(); Sys_Shutdown();
if (shutdown == 1) if (reset == 1)
Sys_Shutdown(); Sys_Reboot();
if (reset == 1) for (i=0; i<FILEBROWSERSIZE; i++) {
Sys_Reboot(); if (fileBrowser.fileList[i]->GetState() == STATE_CLICKED) {
fileBrowser.fileList[i]->ResetState();
for (i=0; i<PAGESIZE; i++) { clickedIndex = browser->pageIndex + i;
if (fileBrowser.fileList[i]->GetState() == STATE_CLICKED) { bool pathCanged = false;
fileBrowser.fileList[i]->ResetState(); // check corresponding browser entry
// check corresponding browser entry if (browser->browserList[clickedIndex].isdir)
if (browserList[browser.selIndex].isdir) { {
if (BrowserChangeFolder()) { /* go up to parent directory */
fileBrowser.ResetState(); if (strcmp(browser->browserList[clickedIndex].filename,"..") == 0)
fileBrowser.fileList[0]->SetState(STATE_SELECTED); {
fileBrowser.TriggerUpdate(); /* remove last subdirectory name */
sprintf(var,"%s", browser.rootdir); int len = strlen(browser->dir);
int len=strlen(browser.rootdir); while(browser->dir[0] && browser->dir[len-1] == '/')
for (unsigned int i=len;i<strlen(browser.rootdir)+strlen(browser.dir);i++) { browser->dir[--len] = '\0'; // remove all trailing '/'
var[i]=browser.dir[i-(len-1)]; char *cptr = strrchr(browser->dir, '/');
} if(cptr) *++cptr = 0; else browser->dir[0] = '\0'; // remove trailing dir
AdressText.SetTextf("%s", var); pathCanged = true;
} else {
menu = MENU_DISCLIST;
break;
}
} else {
mainWindow->SetState(STATE_DISABLED);
mainWindow->SetState(STATE_DEFAULT);
}
}
}
if (ExitBtn.GetState() == STATE_CLICKED) {
snprintf(var,sizeof(currentdir),"%s", currentdir);
break;
}
if (okBtn.GetState() == STATE_CLICKED) {
result = 1;
break;
} else if (usbBtn.GetState() == STATE_CLICKED) {
HaltGui();
mainWindow->Remove(&w);
ResumeGui();
result = BrowseDevice(var, (curDivice==SD?USB:SD));
break;
} else if (folderBtn.GetState() == STATE_CLICKED) {
HaltGui();
mainWindow->Remove(&w);
ResumeGui();
char newfolder[100];
char oldfolder[100];
sprintf(newfolder,"%s/",var);
strcpy(oldfolder,newfolder);
int result = OnScreenKeyboard(newfolder,100,0);
if ( result == 1 ) {
int len = (strlen(newfolder)-1);
if (newfolder[len] !='/')
strncat (newfolder, "/", 1);
char* pos = newfolder;
char root[6];
sprintf(root,"%s/",browser.rootdir);
if (len > 0 && strcmp(oldfolder,newfolder)!=0 && strstr(newfolder,root) == pos && strstr(newfolder,"//") == NULL) {
struct stat st;
if (stat(newfolder, &st) != 0) {
if (subfoldercreate(newfolder) != 1) {
WindowPrompt(tr("Error !"),tr("Can't create directory"),tr("OK"));
break;
}
} else {
break;
} }
/* Open a directory */
/* current directory doesn't change */
else if (strcmp(browser->browserList[clickedIndex].filename,"."))
{
/* test new directory namelength */
if ((strlen(browser->dir) + strlen(browser->browserList[clickedIndex].filename)
+ 1/*'/'*/) < MAXPATHLEN)
{
/* update current directory name */
sprintf(browser->dir, "%s%s/",browser->dir,
browser->browserList[clickedIndex].filename);
pathCanged = true;
}
}
if (pathCanged)
{
LOCK(&fileBrowser);
ParseDirectory((char*)NULL, Flags, Filter);
fileBrowser.ResetState();
fileBrowser.TriggerUpdate();
AdressText.SetTextf("%s%s", browser->rootdir, browser->dir);
}
clickedIndex = -1;
} }
} else /* isFile */
result = BrowseDevice(var, (curDivice==SD?SD:USB)); {
break; AdressText.SetTextf("%s%s%s", browser->rootdir, browser->dir, browser->browserList[clickedIndex].filename);
} }
}
}
} if (ExitBtn.GetState() == STATE_CLICKED) {
HaltGui(); break;
mainWindow->Remove(&w); }
ResumeGui(); else if (okBtn.GetState() == STATE_CLICKED) {
if(clickedIndex>=0)
snprintf(Path, Path_size, "%s%s%s", browser->rootdir, browser->dir,browser->browserList[clickedIndex].filename);
else
snprintf(Path, Path_size, "%s%s", browser->rootdir, browser->dir);
result = 1;
break;
}
else if (usbBtn.GetState() == STATE_CLICKED) {
usbBtn.ResetState();
for(u32 i=1; i<browsers.size(); i++)
{
LOCK(&fileBrowser);
if(ParseDirectory((curDevice+i) % browsers.size(), Flags, Filter)==0)
{
fileBrowser.ResetState();
fileBrowser.TriggerUpdate();
AdressText.SetTextf("%s%s", browser->rootdir, browser->dir);
usbBtnTxt.SetText(browsers[(curDevice+1)%browsers.size()].rootdir);
break;
}
}
}
else if (folderBtn.GetState() == STATE_CLICKED) {
folderBtn.ResetState();
//} HaltGui();
mainWindow->Remove(&w);
ResumeGui();
char newfolder[100];
char oldfolder[100];
snprintf(newfolder, sizeof(newfolder), "%s%s", browser->rootdir, browser->dir);
strcpy(oldfolder,newfolder);
int result = OnScreenKeyboard(newfolder, sizeof(newfolder), strlen(browser->rootdir));
if ( result == 1 ) {
unsigned int len = strlen(newfolder);
if (len>0 && len+1 < sizeof(newfolder) && newfolder[len-1] !='/')
{
newfolder[len] = '/';
newfolder[len+1] = '\0';
}
return result; struct stat st;
if (stat(newfolder, &st) != 0) {
if(WindowPrompt(tr("Directory does not exist!"),tr("The entered directory does not exist. Would you like to create it?") ,tr("OK"), tr("Cancel")) == 1)
if (subfoldercreate(newfolder) == false)
WindowPrompt(tr("Error !"),tr("Can't create directory"),tr("OK"));
}
if(ParseDirectory(newfolder, Flags, Filter)==0)
{
fileBrowser.ResetState();
fileBrowser.TriggerUpdate();
AdressText.SetTextf("%s%s", browser->rootdir, browser->dir);
usbBtnTxt.SetText(browsers[(curDevice+1)%browsers.size()].rootdir);
}
}
HaltGui();
mainWindow->Append(&w);
ResumeGui();
}
}
HaltGui();
mainWindow->Remove(&w);
ResumeGui();
//}
return result;
} }
int BrowseDevice(char * Path, int Path_size, int Flags, FILEFILTERCALLBACK Filter, void *FilterArgs)
{
if(Filter)
{
FILTERCASCADE filter = {Filter, FilterArgs, NULL};
return BrowseDevice(Path, Path_size, Flags, &filter);
}
return BrowseDevice(Path, Path_size, Flags);
}

View File

@ -1,8 +1,8 @@
/**************************************************************************** /****************************************************************************
* libwiigui Template * libwiigui Template
* Tantric 2009 * Tantric 2009
* *
* modified by dimok * modified by dimok and ardi
* *
* filebrowser.h * filebrowser.h
* *
@ -17,21 +17,9 @@
#define MAXJOLIET 255 #define MAXJOLIET 255
#define MAXDISPLAY MAXPATHLEN #define MAXDISPLAY MAXPATHLEN
#define ROOTDIRLEN 10
enum {
SD,
USB
};
typedef struct {
char dir[MAXPATHLEN]; // directory path of browserList
char rootdir[10]; // directory path of browserList
int numEntries; // # of entries in browserList
int selIndex; // currently selected index of browserList
int pageIndex; // starting index of browserList page display
} BROWSERINFO;
typedef struct { typedef struct {
u64 offset; // DVD offset u64 offset; // DVD offset
u64 length; // file length in 64 bytes for sizes higher than 4GB u64 length; // file length in 64 bytes for sizes higher than 4GB
@ -40,15 +28,52 @@ typedef struct {
char displayname[MAXDISPLAY + 1]; // name for browser display char displayname[MAXDISPLAY + 1]; // name for browser display
} BROWSERENTRY; } BROWSERENTRY;
extern BROWSERINFO browser; typedef struct {
extern BROWSERENTRY * browserList; char dir[MAXPATHLEN]; // directory path of browserList
char rootdir[ROOTDIRLEN];// directory path of browserList
int pageIndex; // starting index of browserList page display
std::vector<BROWSERENTRY> browserList;
} BROWSERINFO;
extern BROWSERINFO *browser;
int UpdateDirName();
int FileSortCallback(const void *f1, const void *f2); #define FB_NOFOLDER_BTN 0x0001
void ResetBrowser(); #define FB_NODEVICE_BTN 0x0002
int ParseDirectory(); #define FB_TRYROOTDIR 0x0004
int BrowserChangeFolder(); #define FB_TRYSTDDEV 0x0008
int BrowseDevice(int device); #define FB_DEFAULT (FB_TRYROOTDIR | FB_TRYSTDDEV)
int BrowseDevice(char * var, int force =-1);
typedef int (*FILEFILTERCALLBACK)(BROWSERENTRY *Entry, void* Args);
int noDIRS(BROWSERENTRY *Entry, void* Args);
int noFILES(BROWSERENTRY *Entry, void* Args);
int noEXT(BROWSERENTRY *Entry, void* Args);
typedef struct _FILTERCASCADE{
FILEFILTERCALLBACK filter;
void *filter_args;
_FILTERCASCADE *next;
} FILTERCASCADE;
/****************************************************************************
* BrowseDevice
* Displays a list of files on the selected path
* Path returns the selectet Path/File
* Path_size is the space of the Path-array
* Ret: 0 ok / -1 Error
***************************************************************************/
/***************************************************************************
* Example:
* FILTERKASKADE filter2 = {noEXT, NULL, NULL};
* FILTERKASKADE filter1 = {noDirs, NULL, &filter2};
* char Path[MAXPATHLEN] = "SD:/";
* BrowseDevice(Path, MAXPATHLEN, FB_DEFAULT, &filter1);
*
*
***************************************************************************/
int BrowseDevice(char * Path, int Path_size, int Flags/*=FB_DEFAULT*/, FILTERCASCADE *Filter=NULL) ;
int BrowseDevice(char * Path, int Path_size, int Flags, FILEFILTERCALLBACK Filter, void *FilterArgs=NULL);
#endif #endif

View File

@ -1259,7 +1259,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.covers_path, sizeof(entered)); strlcpy(entered, Settings.covers_path, sizeof(entered));
titleTxt.SetText(tr("3D Cover Path")); titleTxt.SetText(tr("3D Cover Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1285,7 +1285,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.covers2d_path, sizeof(entered)); strlcpy(entered, Settings.covers2d_path, sizeof(entered));
titleTxt.SetText(tr("2D Cover Path")); titleTxt.SetText(tr("2D Cover Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1311,7 +1311,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.disc_path, sizeof(entered)); strlcpy(entered, Settings.disc_path, sizeof(entered));
titleTxt.SetText(tr("Disc Artwork Path")); titleTxt.SetText(tr("Disc Artwork Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1337,7 +1337,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
titleTxt.SetText(tr("Theme Path")); titleTxt.SetText(tr("Theme Path"));
strlcpy(entered, CFG.theme_path, sizeof(entered)); strlcpy(entered, CFG.theme_path, sizeof(entered));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
HaltGui(); HaltGui();
w.RemoveAll(); w.RemoveAll();
if ( result == 1 ) { if ( result == 1 ) {
@ -1394,7 +1394,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
titleTxt.SetText(tr("WiiTDB Path")); titleTxt.SetText(tr("WiiTDB Path"));
strlcpy(entered, Settings.titlestxt_path, sizeof(entered)); strlcpy(entered, Settings.titlestxt_path, sizeof(entered));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&backBtn); w.Append(&backBtn);
@ -1425,7 +1425,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.update_path, sizeof(entered)); strlcpy(entered, Settings.update_path, sizeof(entered));
titleTxt.SetText(tr("Update Path")); titleTxt.SetText(tr("Update Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1446,7 +1446,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.Cheatcodespath, sizeof(entered)); strlcpy(entered, Settings.Cheatcodespath, sizeof(entered));
titleTxt.SetText(tr("GCT Cheatcodes Path")); titleTxt.SetText(tr("GCT Cheatcodes Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1467,7 +1467,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.TxtCheatcodespath, sizeof(entered)); strlcpy(entered, Settings.TxtCheatcodespath, sizeof(entered));
titleTxt.SetText(tr("TXT Cheatcodes Path")); titleTxt.SetText(tr("TXT Cheatcodes Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1488,7 +1488,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.dolpath, sizeof(entered)); strlcpy(entered, Settings.dolpath, sizeof(entered));
titleTxt.SetText(tr("DOL Path")); titleTxt.SetText(tr("DOL Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);
@ -1514,7 +1514,7 @@ int MenuSettings() {
char entered[43] = ""; char entered[43] = "";
strlcpy(entered, Settings.homebrewapps_path, sizeof(entered)); strlcpy(entered, Settings.homebrewapps_path, sizeof(entered));
titleTxt.SetText(tr("Homebrew Apps Path")); titleTxt.SetText(tr("Homebrew Apps Path"));
int result = BrowseDevice(entered); int result = BrowseDevice(entered, sizeof(entered), FB_DEFAULT, noFILES);
titleTxt.SetText(tr("Custom Paths")); titleTxt.SetText(tr("Custom Paths"));
w.Append(&optionBrowser2); w.Append(&optionBrowser2);
w.Append(&backBtn); w.Append(&backBtn);