mirror of
https://github.com/rvtr/GodMode9i.git
synced 2025-11-02 00:11:07 -04:00
Add drive menu, and show all file extentions
This commit is contained in:
parent
9f99b62c16
commit
85d5f07685
86
arm9/source/driveMenu.cpp
Normal file
86
arm9/source/driveMenu.cpp
Normal file
@ -0,0 +1,86 @@
|
||||
/*-----------------------------------------------------------------
|
||||
Copyright (C) 2005 - 2013
|
||||
Michael "Chishm" Chisholm
|
||||
Dave "WinterMute" Murphy
|
||||
Claudio "sverx"
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
------------------------------------------------------------------*/
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "date.h"
|
||||
|
||||
#define SCREEN_COLS 32
|
||||
#define ENTRIES_PER_SCREEN 22
|
||||
#define ENTRIES_START_ROW 2
|
||||
#define ENTRY_PAGE_LENGTH 10
|
||||
|
||||
using namespace std;
|
||||
|
||||
void driveMenu (void) {
|
||||
int pressed = 0;
|
||||
int dmCursorPosition = 0;
|
||||
|
||||
while (true) {
|
||||
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
|
||||
iprintf ("\x1b[23;0H");
|
||||
printf (titleName);
|
||||
|
||||
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true);
|
||||
|
||||
iprintf ("[root]");
|
||||
|
||||
// Move to 2nd row
|
||||
iprintf ("\x1b[1;0H");
|
||||
// Print line of dashes
|
||||
iprintf ("--------------------------------");
|
||||
|
||||
// Show cursor
|
||||
iprintf ("\x1b[%d;0H*", dmCursorPosition + ENTRIES_START_ROW);
|
||||
|
||||
iprintf ("\x1b[2;1H");
|
||||
if (isDSiMode()){
|
||||
iprintf ("[sd:] SDCARD");
|
||||
iprintf ("\x1b[3;1H");
|
||||
}
|
||||
iprintf ("[fat:] GAMECART");
|
||||
|
||||
// Power saving loop. Only poll the keys once per frame and sleep the CPU if there is nothing else to do
|
||||
do {
|
||||
// Move to right side of screen
|
||||
iprintf ("\x1b[0;27H");
|
||||
// Print time
|
||||
printf (RetTime().c_str());
|
||||
|
||||
scanKeys();
|
||||
pressed = keysDownRepeat();
|
||||
swiWaitForVBlank();
|
||||
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_A));
|
||||
|
||||
if (pressed & KEY_UP) dmCursorPosition -= 1;
|
||||
if (pressed & KEY_DOWN) dmCursorPosition += 1;
|
||||
|
||||
if (dmCursorPosition < 0) dmCursorPosition = 1; // Wrap around to bottom of list
|
||||
if (dmCursorPosition > 1) dmCursorPosition = 0; // Wrap around to top of list
|
||||
|
||||
if (pressed & KEY_A) {
|
||||
screenMode = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
11
arm9/source/driveMenu.h
Normal file
11
arm9/source/driveMenu.h
Normal file
@ -0,0 +1,11 @@
|
||||
#ifndef DRIVE_MENU_H
|
||||
#define DRIVE_MENU_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
extern void driveMenu (void);
|
||||
|
||||
|
||||
|
||||
#endif //DRIVE_MENU_H
|
||||
@ -30,6 +30,7 @@
|
||||
|
||||
#include <nds.h>
|
||||
|
||||
#include "main.h"
|
||||
#include "date.h"
|
||||
#include "fileOperations.h"
|
||||
|
||||
@ -45,17 +46,11 @@ struct DirEntry {
|
||||
bool isDirectory;
|
||||
} ;
|
||||
|
||||
bool nameEndsWith (const string& name, const vector<string> extensionList) {
|
||||
bool nameEndsWith (const string& name) {
|
||||
|
||||
if (name.size() == 0) return false;
|
||||
|
||||
if (extensionList.size() == 0) return true;
|
||||
|
||||
for (int i = 0; i < (int)extensionList.size(); i++) {
|
||||
const string ext = extensionList.at(i);
|
||||
if ( strcasecmp (name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
|
||||
}
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) {
|
||||
@ -69,7 +64,7 @@ bool dirEntryPredicate (const DirEntry& lhs, const DirEntry& rhs) {
|
||||
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
|
||||
}
|
||||
|
||||
void getDirectoryContents (vector<DirEntry>& dirContents, const vector<string> extensionList) {
|
||||
void getDirectoryContents (vector<DirEntry>& dirContents) {
|
||||
struct stat st;
|
||||
|
||||
dirContents.clear();
|
||||
@ -90,7 +85,7 @@ void getDirectoryContents (vector<DirEntry>& dirContents, const vector<string> e
|
||||
dirEntry.name = pent->d_name;
|
||||
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
|
||||
|
||||
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
|
||||
if (dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name))) {
|
||||
dirContents.push_back (dirEntry);
|
||||
}
|
||||
|
||||
@ -102,11 +97,6 @@ void getDirectoryContents (vector<DirEntry>& dirContents, const vector<string> e
|
||||
sort(dirContents.begin(), dirContents.end(), dirEntryPredicate);
|
||||
}
|
||||
|
||||
void getDirectoryContents (vector<DirEntry>& dirContents) {
|
||||
vector<string> extensionList;
|
||||
getDirectoryContents (dirContents, extensionList);
|
||||
}
|
||||
|
||||
void showDirectoryContents (const vector<DirEntry>& dirContents, int startRow) {
|
||||
char path[PATH_MAX];
|
||||
|
||||
@ -148,14 +138,14 @@ void showDirectoryContents (const vector<DirEntry>& dirContents, int startRow) {
|
||||
}
|
||||
}
|
||||
|
||||
string browseForFile (const vector<string> extensionList) {
|
||||
string browseForFile (void) {
|
||||
int pressed = 0;
|
||||
int screenOffset = 0;
|
||||
int fileOffset = 0;
|
||||
off_t fileSize = 0;
|
||||
vector<DirEntry> dirContents;
|
||||
|
||||
getDirectoryContents (dirContents, extensionList);
|
||||
getDirectoryContents (dirContents);
|
||||
|
||||
while (true) {
|
||||
consoleInit(NULL, 1, BgType_Text4bpp, BgSize_T_256x256, 15, 0, false, true);
|
||||
@ -170,7 +160,7 @@ string browseForFile (const vector<string> extensionList) {
|
||||
iprintf ("%i Bytes", (int)fileSize);
|
||||
}
|
||||
iprintf ("\x1b[23;0H");
|
||||
printf ("GodMode9i v0.1.0");
|
||||
printf (titleName);
|
||||
|
||||
consoleInit(NULL, 0, BgType_Text4bpp, BgSize_T_256x256, 15, 0, true, true);
|
||||
//consoleClear();
|
||||
@ -195,7 +185,8 @@ string browseForFile (const vector<string> extensionList) {
|
||||
scanKeys();
|
||||
pressed = keysDownRepeat();
|
||||
swiWaitForVBlank();
|
||||
} while (!pressed);
|
||||
} while (!(pressed & KEY_UP) && !(pressed & KEY_DOWN) && !(pressed & KEY_LEFT) && !(pressed & KEY_RIGHT)
|
||||
&& !(pressed & KEY_A) && !(pressed & KEY_B));
|
||||
|
||||
if (pressed & KEY_UP) fileOffset -= 1;
|
||||
if (pressed & KEY_DOWN) fileOffset += 1;
|
||||
@ -221,11 +212,12 @@ string browseForFile (const vector<string> extensionList) {
|
||||
iprintf("Entering directory\n");
|
||||
// Enter selected directory
|
||||
chdir (entry->name.c_str());
|
||||
getDirectoryContents (dirContents, extensionList);
|
||||
getDirectoryContents (dirContents);
|
||||
screenOffset = 0;
|
||||
fileOffset = 0;
|
||||
showDirectoryContents (dirContents, screenOffset);
|
||||
} else {
|
||||
applaunch = true;
|
||||
// Clear the screen
|
||||
iprintf ("\x1b[2J");
|
||||
// Return the chosen file
|
||||
@ -234,9 +226,15 @@ string browseForFile (const vector<string> extensionList) {
|
||||
}
|
||||
|
||||
if (pressed & KEY_B) {
|
||||
char path[PATH_MAX];
|
||||
getcwd(path, PATH_MAX);
|
||||
if ((strcmp (path, "sd:/") == 0) || (strcmp (path, "fat:/") == 0)) {
|
||||
screenMode = 0;
|
||||
return "null";
|
||||
}
|
||||
// Go up a directory
|
||||
chdir ("..");
|
||||
getDirectoryContents (dirContents, extensionList);
|
||||
getDirectoryContents (dirContents);
|
||||
screenOffset = 0;
|
||||
fileOffset = 0;
|
||||
showDirectoryContents (dirContents, screenOffset);
|
||||
|
||||
@ -25,7 +25,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
std::string browseForFile (const std::vector<std::string> extensionList);
|
||||
std::string browseForFile (void);
|
||||
|
||||
|
||||
|
||||
|
||||
@ -29,10 +29,17 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "nds_loader_arm9.h"
|
||||
#include "driveMenu.h"
|
||||
#include "file_browse.h"
|
||||
|
||||
//#include "iconTitle.h"
|
||||
|
||||
char titleName[32];
|
||||
|
||||
int screenMode = 0;
|
||||
|
||||
bool applaunch = false;
|
||||
|
||||
using namespace std;
|
||||
|
||||
//---------------------------------------------------------------------------------
|
||||
@ -59,6 +66,8 @@ int main(int argc, char **argv) {
|
||||
std::string filename;
|
||||
|
||||
//iconTitleInit();
|
||||
|
||||
snprintf(titleName, sizeof(titleName), "GodMode9i v%i.%i.%i", 0, 1, 0);
|
||||
|
||||
// Subscreen as a console
|
||||
videoSetMode(MODE_0_2D);
|
||||
@ -74,69 +83,68 @@ int main(int argc, char **argv) {
|
||||
|
||||
keysSetRepeat(25,5);
|
||||
|
||||
vector<string> extensionList;
|
||||
extensionList.push_back(".nds");
|
||||
extensionList.push_back(".firm");
|
||||
//extensionList.push_back(".argv");
|
||||
|
||||
chdir("/nds");
|
||||
|
||||
while(1) {
|
||||
|
||||
filename = browseForFile(extensionList);
|
||||
if (screenMode == 0) {
|
||||
driveMenu();
|
||||
} else {
|
||||
filename = browseForFile();
|
||||
}
|
||||
|
||||
// Construct a command line
|
||||
getcwd (filePath, PATH_MAX);
|
||||
pathLen = strlen (filePath);
|
||||
vector<char*> argarray;
|
||||
if (applaunch) {
|
||||
// Construct a command line
|
||||
getcwd (filePath, PATH_MAX);
|
||||
pathLen = strlen (filePath);
|
||||
vector<char*> argarray;
|
||||
|
||||
if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) {
|
||||
if ( strcasecmp (filename.c_str() + filename.size() - 5, ".argv") == 0) {
|
||||
|
||||
FILE *argfile = fopen(filename.c_str(),"rb");
|
||||
char str[PATH_MAX], *pstr;
|
||||
const char seps[]= "\n\r\t ";
|
||||
FILE *argfile = fopen(filename.c_str(),"rb");
|
||||
char str[PATH_MAX], *pstr;
|
||||
const char seps[]= "\n\r\t ";
|
||||
|
||||
while( fgets(str, PATH_MAX, argfile) ) {
|
||||
// Find comment and end string there
|
||||
if( (pstr = strchr(str, '#')) )
|
||||
*pstr= '\0';
|
||||
while( fgets(str, PATH_MAX, argfile) ) {
|
||||
// Find comment and end string there
|
||||
if( (pstr = strchr(str, '#')) )
|
||||
*pstr= '\0';
|
||||
|
||||
// Tokenize arguments
|
||||
pstr= strtok(str, seps);
|
||||
// Tokenize arguments
|
||||
pstr= strtok(str, seps);
|
||||
|
||||
while( pstr != NULL ) {
|
||||
argarray.push_back(strdup(pstr));
|
||||
pstr= strtok(NULL, seps);
|
||||
while( pstr != NULL ) {
|
||||
argarray.push_back(strdup(pstr));
|
||||
pstr= strtok(NULL, seps);
|
||||
}
|
||||
}
|
||||
fclose(argfile);
|
||||
filename = argarray.at(0);
|
||||
} else {
|
||||
argarray.push_back(strdup(filename.c_str()));
|
||||
}
|
||||
fclose(argfile);
|
||||
filename = argarray.at(0);
|
||||
} else {
|
||||
argarray.push_back(strdup(filename.c_str()));
|
||||
}
|
||||
|
||||
if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) {
|
||||
iprintf("no nds file specified\n");
|
||||
} else {
|
||||
char *name = argarray.at(0);
|
||||
strcpy (filePath + pathLen, name);
|
||||
free(argarray.at(0));
|
||||
argarray.at(0) = filePath;
|
||||
iprintf ("Running %s with %d parameters\n", argarray[0], argarray.size());
|
||||
int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]);
|
||||
iprintf ("Start failed. Error %i\n", err);
|
||||
if ( strcasecmp (filename.c_str() + filename.size() - 4, ".nds") != 0 || argarray.size() == 0 ) {
|
||||
iprintf("no nds file specified\n");
|
||||
} else {
|
||||
char *name = argarray.at(0);
|
||||
strcpy (filePath + pathLen, name);
|
||||
free(argarray.at(0));
|
||||
argarray.at(0) = filePath;
|
||||
iprintf ("Running %s with %d parameters\n", argarray[0], argarray.size());
|
||||
int err = runNdsFile (argarray[0], argarray.size(), (const char **)&argarray[0]);
|
||||
iprintf ("Start failed. Error %i\n", err);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
while(argarray.size() !=0 ) {
|
||||
free(argarray.at(0));
|
||||
argarray.erase(argarray.begin());
|
||||
}
|
||||
while(argarray.size() !=0 ) {
|
||||
free(argarray.at(0));
|
||||
argarray.erase(argarray.begin());
|
||||
}
|
||||
|
||||
while (1) {
|
||||
swiWaitForVBlank();
|
||||
scanKeys();
|
||||
if (!(keysHeld() & KEY_A)) break;
|
||||
while (1) {
|
||||
swiWaitForVBlank();
|
||||
scanKeys();
|
||||
if (!(keysHeld() & KEY_A)) break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
12
arm9/source/main.h
Normal file
12
arm9/source/main.h
Normal file
@ -0,0 +1,12 @@
|
||||
#ifndef MAIN_H
|
||||
#define MAIN_H
|
||||
|
||||
extern char titleName[32];
|
||||
|
||||
extern int screenMode;
|
||||
|
||||
extern bool applaunch;
|
||||
|
||||
|
||||
|
||||
#endif //MAIN_H
|
||||
Loading…
Reference in New Issue
Block a user