Skip to content

Commit

Permalink
- Tidy file management code, now available only via Z trigger
Browse files Browse the repository at this point in the history
- Add option to show hidden files #547
- Add file/dir rename support #491 #514
- Add delete dir support #514
- Add delete prompt
- Fix DrawGetTextEntry memory leak
- Fix focus issue when cancelling from Recent list
- Remove .gci from known file types list since it has no handler
  • Loading branch information
emukidid committed Jul 26, 2021
1 parent 699593b commit bd05320
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 332 deletions.
4 changes: 3 additions & 1 deletion cube/swiss/include/swiss.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ typedef struct {
u8 configDeviceId; // see deviceHandler.h
int fileBrowserType;
int bs2Boot;
int showHiddenFiles;
char autoload[PATHNAME_MAX];
char recent[RECENT_MAX][PATHNAME_MAX];
} SwissSettings;
Expand All @@ -133,7 +134,8 @@ enum fileOptions
{
COPY_OPTION=0,
MOVE_OPTION,
DELETE_OPTION
DELETE_OPTION,
RENAME_OPTION
};

enum fileBrowserTypes
Expand Down
2 changes: 2 additions & 0 deletions cube/swiss/include/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@ int endsWith(char *str, char *end);
bool canLoadFileType(char *filename);
bool checkExtension(char *filename);
char *getRelativeName(char *str);
void getParentPath(char *src, char *dst);
char *stripInvalidChars(char *str);
void load_auto_dol();
void print_gecko(const char* fmt, ...);
extern void __libogc_exit(int status);
bool update_recent();
int load_existing_entry(char *entry);
bool deleteFileOrDir(file_handle* entry);

#endif
5 changes: 5 additions & 0 deletions cube/swiss/source/config/config.c
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,8 @@ int config_update_file() {
string_append(configString, txtbuffer);
sprintf(txtbuffer, "FSPPassword=%s\r\n",swissSettings.fspPassword);
string_append(configString, txtbuffer);
sprintf(txtbuffer, "ShowHiddenFiles=%s\r\n", (swissSettings.showHiddenFiles ? "Yes":"No"));
string_append(configString, txtbuffer);
sprintf(txtbuffer, "Autoload=%s\r\n",swissSettings.autoload);
string_append(configString, txtbuffer);
int i;
Expand Down Expand Up @@ -565,6 +567,9 @@ void config_parse(char *configData) {
else if(!strcmp("FSPPassword", name)) {
strlcpy(&swissSettings.fspPassword[0], value, sizeof(swissSettings.fspPassword));
}
else if(!strcmp("ShowHiddenFiles", name)) {
swissSettings.showHiddenFiles = !strcmp("Yes", value) ? 1:0;
}
else if(!strcmp("Autoload", name)) {
strlcpy(&swissSettings.autoload[0], value, sizeof(swissSettings.autoload));
}
Expand Down
2 changes: 1 addition & 1 deletion cube/swiss/source/devices/fat/deviceHandler-FAT.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ s32 deviceHandler_FAT_readDir(file_handle* ffile, file_handle** dir, u32 type) {
}
memset(&file_name[0],0,PATHNAME_MAX);
snprintf(&file_name[0], PATHNAME_MAX, "%s/%s", ffile->name, entry.fname);
if(f_stat(file_name, &fno) != FR_OK || (fno.fattrib & AM_HID) || entry.fname[0] == '.') {
if(f_stat(file_name, &fno) != FR_OK || (!swissSettings.showHiddenFiles && fno.fattrib & AM_HID) || entry.fname[0] == '.') {
continue;
}
// Do we want this one?
Expand Down
49 changes: 44 additions & 5 deletions cube/swiss/source/gui/FrameBufferMagic.c
Original file line number Diff line number Diff line change
Expand Up @@ -1622,8 +1622,8 @@ void DrawCheatsSelector(const char *fileName) {

void DrawGetTextEntry(int mode, const char *label, void *src, int size) {

print_gecko("DrawGetTextEntry Modes: Alpha [%s] Numeric [%s] IP [%s] Masked [%s]\r\n", mode & ENTRYMODE_ALPHA ? "Y":"N", mode & ENTRYMODE_NUMERIC ? "Y":"N",
mode & ENTRYMODE_IP ? "Y":"N", mode & ENTRYMODE_MASKED ? "Y":"N");
print_gecko("DrawGetTextEntry Modes: Alpha [%s] Numeric [%s] IP [%s] Masked [%s] File [%s]\r\n", mode & ENTRYMODE_ALPHA ? "Y":"N", mode & ENTRYMODE_NUMERIC ? "Y":"N",
mode & ENTRYMODE_IP ? "Y":"N", mode & ENTRYMODE_MASKED ? "Y":"N", mode & ENTRYMODE_FILE ? "Y":"N");
char *text = calloc(1, size);
if(mode & (ENTRYMODE_ALPHA|ENTRYMODE_IP)) {
strncpy(text, src, size);
Expand All @@ -1648,6 +1648,9 @@ void DrawGetTextEntry(int mode, const char *label, void *src, int size) {
char *num_mode_chars = "1234567890\b";
char *txt_mode_chars_lower = "1234567890-=\bqwertyuiop[]\\asdfghjkl;'zxcvbnm,./`!@\a#$%";
char *txt_mode_chars_upper = "1234567890_+\bQWERTYUIOP{}|ASDFGHJKL:\"ZXCVBNM<>?^&*\a()~";
char *txt_mode_file_chars_lower = "1234567890-=\bqwertyuiop[]asdfghjkl;'zxcvbnm.`!\a#$%";
char *txt_mode_file_chars_upper = "1234567890_+\bQWERTYUIOP{}ASDFGHJKL^&ZXCVBNM,@~\a()%";

int cur_txt_mode = 0;
char *gridText = NULL;

Expand Down Expand Up @@ -1694,8 +1697,8 @@ void DrawGetTextEntry(int mode, const char *label, void *src, int size) {
// TODO if we ever have to.
}

// Alphanumeric
else if((mode & (ENTRYMODE_NUMERIC | ENTRYMODE_ALPHA)) && !(mode & ENTRYMODE_IP)) {
// Alphanumeric (not file)
else if((mode & (ENTRYMODE_NUMERIC | ENTRYMODE_ALPHA)) && !(mode & ENTRYMODE_IP) && !(mode & ENTRYMODE_FILE)) {
/* Mode 0:
1234567890-=<\b aka backspace>
qwertyuiop[]\
Expand Down Expand Up @@ -1726,6 +1729,38 @@ void DrawGetTextEntry(int mode, const char *label, void *src, int size) {
pos_for_row[4] = 160;
}

// Alphanumeric (file)
else if(mode & ENTRYMODE_FILE) {
/* Mode 0:
1234567890-=<\b aka backspace>
qwertyuiop[]\
asdfghjkl;'
zxcvbnm
.`!<\a aka space>#$%
Mode 1:
1234567890_+<\b aka backspace>
QWERTYUIOP{}
ASDFGHJKL^&
ZXCVBNM
,@~<\a aka space>()%
*/

num_txt_modes = 2;
num_rows = 5;
grid_gap = 10;
num_per_row[0] = 13;
pos_for_row[0] = 40;
num_per_row[1] = 12;
pos_for_row[1] = 60;
num_per_row[2] = 11;
pos_for_row[2] = 100;
num_per_row[3] = 7;
pos_for_row[3] = 120;
num_per_row[4] = 7;
pos_for_row[4] = 160;
}

// Wait for any A or Left/Right presses to finish
while ((PAD_ButtonsHeld(0) & (PAD_BUTTON_A|PAD_BUTTON_LEFT|PAD_BUTTON_RIGHT))){ VIDEO_WaitVSync (); }
uiDrawObj_t *container = NULL;
Expand All @@ -1743,7 +1778,10 @@ void DrawGetTextEntry(int mode, const char *label, void *src, int size) {

// Alphanumeric has a little "mode" hint at the bottom (upper/lower case set switching)
if(mode & ENTRYMODE_ALPHA) {
gridText = cur_txt_mode == 0 ? txt_mode_chars_lower : txt_mode_chars_upper;
gridText = cur_txt_mode == 0 ?
(mode & ENTRYMODE_FILE ? txt_mode_file_chars_lower : txt_mode_chars_lower)
:
(mode & ENTRYMODE_FILE ? txt_mode_file_chars_upper : txt_mode_chars_upper);
sprintf(txtbuffer, "Press X to change to [%s], current mode is [%s]",
txt_modes_str[(cur_txt_mode + 1 >= num_txt_modes ? 0 : cur_txt_mode + 1)], txt_modes_str[cur_txt_mode]);
DrawAddChild(newPanel, DrawStyledLabel(25, 420, txtbuffer, 0.65f, false, defaultColor));
Expand Down Expand Up @@ -1858,6 +1896,7 @@ void DrawGetTextEntry(int mode, const char *label, void *src, int size) {
while (PAD_ButtonsHeld(0) & (PAD_TRIGGER_L|PAD_TRIGGER_R|PAD_BUTTON_UP|PAD_BUTTON_DOWN|PAD_BUTTON_LEFT | PAD_BUTTON_RIGHT|PAD_BUTTON_B|PAD_BUTTON_A|PAD_BUTTON_X|PAD_BUTTON_Y|PAD_BUTTON_START))
{ VIDEO_WaitVSync (); }
}
if(text) free(text);
DrawDispose(container);
}

Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/gui/FrameBufferMagic.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ typedef struct kbBtn_ {
#define ENTRYMODE_NUMERIC (1<<1)
#define ENTRYMODE_IP (1<<2)
#define ENTRYMODE_MASKED (1<<3)
#define ENTRYMODE_FILE (1<<4)

uiDrawObj_t* DrawImage(int textureId, int x, int y, int width, int height, int depth, float s1, float s2, float t1, float t2, int centered);
uiDrawObj_t* DrawTexObj(GXTexObj *texObj, int x, int y, int width, int height, int depth, float s1, float s2, float t1, float t2, int centered);
Expand Down
6 changes: 5 additions & 1 deletion cube/swiss/source/gui/settings.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static char *tooltips_advanced[PAGE_ADVANCED_MAX+1] = {
"Hide Unknown file types:\n\nDisabled - Show all files (default)\nEnabled - Swiss will hide unknown file types from being displayed\n\nKnown file types are:\n GameCube Executables (.dol)\n Disc backups (.iso/.gcm/.tgc)\n MP3 Music (.mp3)\n WASP/WKF Flash files (.fzn)\n GameCube Memory Card Files (.gci)\n GameCube Executables with parameters appended (.dol+cli)\n GameCube ELF files (.elf)",
"Stop DVD Motor on startup\n\nDisabled - Leave it as-is (default)\nEnabled - Stop the DVD drive from spinning when Swiss starts\n\nThis option is mostly for users booting from game\nexploits where the disc will already be spinning.",
"WiiRD debugging:\n\nDisabled - Boot as normal (default)\nEnabled - This will start a game with the WiiRD debugger enabled & paused\n\nThe WiiRD debugger takes up more memory and can cause issues.",
"File Management:\n\nDisabled - Known files will load immediately instead (default)\nEnabled - A file management prompt will be displayed for all files",
"File Management:\n\nWhen enabled, pressing Z on an entry in the file browser will allow it to be managed.",
"Auto-load all cheats:\n\nIf enabled, and a cheats file for a particular game is found\ne.g. sd:/cheats/GPOP8D.txt (on a compatible device)\nthen all cheats in the file will be enabled",
NULL,
NULL,
Expand Down Expand Up @@ -219,6 +219,7 @@ uiDrawObj_t* settings_draw_page(int page_num, int option, file_handle *file, Con
drawSettingEntryString(page, &page_y_ofs, "Configuration Device:", getConfigDeviceName(&swissSettings), option == SET_CONFIG_DEV, true);
drawSettingEntryString(page, &page_y_ofs, "AVE Compatibility:", aveCompatStr[swissSettings.aveCompat], option == SET_AVE_COMPAT, true);
drawSettingEntryString(page, &page_y_ofs, "File Browser Type:", fileBrowserStr[swissSettings.fileBrowserType], option == SET_FILEBROWSER_TYPE, true);
drawSettingEntryBoolean(page, &page_y_ofs, "Show hidden files:", swissSettings.showHiddenFiles, option == SET_SHOW_HIDDEN, true);
}
else if(page_num == PAGE_NETWORK) {
bool netEnable = exi_bba_exists();
Expand Down Expand Up @@ -395,6 +396,9 @@ void settings_toggle(int page, int option, int direction, file_handle *file, Con
case SET_FILEBROWSER_TYPE:
swissSettings.fileBrowserType ^= 1;
break;
case SET_SHOW_HIDDEN:
swissSettings.showHiddenFiles ^= 1;
break;
}
}
else if(page == PAGE_NETWORK) {
Expand Down
1 change: 1 addition & 0 deletions cube/swiss/source/gui/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ enum SETTINGS_GLOBAL {
SET_CONFIG_DEV,
SET_AVE_COMPAT,
SET_FILEBROWSER_TYPE,
SET_SHOW_HIDDEN,
SET_PAGE_1_NEXT,
SET_PAGE_1_SAVE,
SET_PAGE_1_CANCEL
Expand Down
Loading

0 comments on commit bd05320

Please sign in to comment.