diff --git a/source/fs/fsdrive.c b/source/fs/fsdrive.c index decaa59..8393759 100644 --- a/source/fs/fsdrive.c +++ b/source/fs/fsdrive.c @@ -1,4 +1,5 @@ #include "fsdrive.h" +#include "fsgame.h" #include "fsinit.h" #include "virtual.h" #include "sddata.h" @@ -6,9 +7,10 @@ #include "ui.h" #include "ff.h" -// last search pattern & path +// last search pattern, path & mode static char search_pattern[256] = { 0 }; static char search_path[256] = { 0 }; +static bool search_title_mode = false; int DriveType(const char* path) { int type = DRV_UNKNOWN; @@ -59,10 +61,11 @@ int DriveType(const char* path) { return type; } -void SetFSSearch(const char* pattern, const char* path) { +void SetFSSearch(const char* pattern, const char* path, bool mode) { if (pattern && path) { strncpy(search_pattern, pattern, 256); strncpy(search_path, path, 256); + search_title_mode = mode; } else *search_pattern = *search_path = '\0'; } @@ -171,16 +174,17 @@ void SearchDirContents(DirStruct* contents, const char* path, const char* patter if (!GetDirContentsWorker(contents, fpath, 256, pattern, recursive)) contents->n_entries = 0; } - SortDirStruct(contents); } } void GetDirContents(DirStruct* contents, const char* path) { - if (DriveType(path) & DRV_SEARCH) { + if (*search_path && DriveType(path) & DRV_SEARCH) { ShowString("Searching, please wait..."); SearchDirContents(contents, search_path, search_pattern, true); + if (search_title_mode) SetDirGoodNames(contents); ClearScreenF(true, false, COLOR_STD_BG); } else SearchDirContents(contents, path, NULL, false); + if (*path) SortDirStruct(contents); } uint64_t GetFreeSpace(const char* path) diff --git a/source/fs/fsdrive.h b/source/fs/fsdrive.h index ea1fedc..d0652d3 100644 --- a/source/fs/fsdrive.h +++ b/source/fs/fsdrive.h @@ -45,8 +45,8 @@ /** Function to identify the type of a drive **/ int DriveType(const char* path); -/** Set search pattern / path for special Z: drive **/ -void SetFSSearch(const char* pattern, const char* path); +/** Set search pattern / path / mode for special Z: drive **/ +void SetFSSearch(const char* pattern, const char* path, bool mode); /** Get directory content under a given path **/ void GetDirContents(DirStruct* contents, const char* path); diff --git a/source/fs/fsgame.c b/source/fs/fsgame.c new file mode 100644 index 0000000..3cd35ca --- /dev/null +++ b/source/fs/fsgame.c @@ -0,0 +1,15 @@ +#include "fsgame.h" +#include "gameutil.h" + +void SetDirGoodNames(DirStruct* contents) { + char goodname[256]; + for (u32 s = 0; s < contents->n_entries; s++) { + DirEntry* entry = &(contents->entry[s]); + u32 plen = strnlen(entry->path, 256); + if ((GetGoodName(goodname, entry->path, false) != 0) || + (plen + 1 + strnlen(goodname, 256) + 1 > 256)) + continue; + strncpy(entry->path + plen + 1, goodname, 256 - 1 - plen - 1); + entry->name = entry->path + plen + 1; + } +} diff --git a/source/fs/fsgame.h b/source/fs/fsgame.h new file mode 100644 index 0000000..d6fc59b --- /dev/null +++ b/source/fs/fsgame.h @@ -0,0 +1,6 @@ +#pragma once + +#include "common.h" +#include "fsdir.h" + +void SetDirGoodNames(DirStruct* contents); diff --git a/source/godmode.c b/source/godmode.c index a1bfcda..5e8c921 100644 --- a/source/godmode.c +++ b/source/godmode.c @@ -1394,24 +1394,32 @@ u32 GodMode() { // basic navigation commands if ((pad_state & BUTTON_A) && (curr_entry->type != T_FILE) && (curr_entry->type != T_DOTDOT)) { // for dirs if (switched && !(DriveType(curr_entry->path) & DRV_SEARCH)) { // search directory - const char* optionstr[3] = { "Search for files...", "Directory info", "Copy to " OUTPUT_PATH }; - u32 n_opt = (*current_path && (strncmp(current_path, OUTPUT_PATH, 256) != 0)) ? 3 : 2; + const char* optionstr[4] = { NULL }; + int n_opt = 0; + int srch_t = (strncmp(curr_entry->path + 1, ":/title", 7) == 0) ? ++n_opt : -1; + int srch_f = ++n_opt; + int dirnfo = ++n_opt; + int stdcpy = (strncmp(current_path, OUTPUT_PATH, 256) != 0) ? ++n_opt : -1; + if (srch_t > 0) optionstr[srch_t-1] = "Search for titles"; + if (srch_f > 0) optionstr[srch_f-1] = "Search for files..."; + if (dirnfo > 0) optionstr[dirnfo-1] = "Directory info"; + if (stdcpy > 0) optionstr[stdcpy-1] = "Copy to " OUTPUT_PATH; char namestr[32+1]; TruncateString(namestr, (*current_path) ? curr_entry->path : curr_entry->name, 32, 8); - u32 user_select = ShowSelectPrompt(n_opt, optionstr, "%s", namestr); - if (user_select == 1) { + int user_select = ShowSelectPrompt(n_opt, optionstr, "%s", namestr); + if ((user_select == srch_f) || (user_select == srch_t)) { char searchstr[256]; - snprintf(searchstr, 256, "*"); + snprintf(searchstr, 256, (user_select == srch_t) ? "*.tmd" : "*"); TruncateString(namestr, curr_entry->name, 20, 8); - if (ShowStringPrompt(searchstr, 256, "Search %s?\nEnter search below.", namestr)) { - SetFSSearch(searchstr, curr_entry->path); + if ((user_select == srch_t) || ShowStringPrompt(searchstr, 256, "Search %s?\nEnter search below.", namestr)) { + SetFSSearch(searchstr, curr_entry->path, (user_select == srch_t)); snprintf(current_path, 256, "Z:"); GetDirContents(current_dir, current_path); if (current_dir->n_entries) ShowPrompt(false, "Found %lu results.", current_dir->n_entries - 1); cursor = 1; scroll = 0; } - } else if (user_select == 2) { + } else if (user_select == dirnfo) { u64 tsize = 0; u32 tdirs = 0; u32 tfiles = 0; @@ -1420,7 +1428,7 @@ u32 GodMode() { FormatBytes(bytestr, tsize); ShowPrompt(false, "%s\n%lu files & %lu subdirs\n%s total", namestr, tfiles, tdirs, bytestr); } else ShowPrompt(false, "Analyze dir: failed!"); - } else if (user_select == 3) { + } else if (user_select == stdcpy) { StandardCopy(&cursor, current_dir); } } else { // one level up