From d50e7817811e4fada0eca587e72a5a38c7d5a16b Mon Sep 17 00:00:00 2001 From: CompSciOrBust <54033033+CompSciOrBust@users.noreply.github.com> Date: Mon, 25 Nov 2019 00:49:46 +0000 Subject: [PATCH] Added experimental support for categories --- include/AmiigoUI.h | 1 + include/Utils.h | 6 +++++ source/AmiigoUI.cpp | 55 ++++++++++++++++++++++++++++++--------------- source/Utils.cpp | 26 +++++++++++++++++++++ 4 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 include/Utils.h create mode 100644 source/Utils.cpp diff --git a/include/AmiigoUI.h b/include/AmiigoUI.h index 961e2d3..7d72fc7 100644 --- a/include/AmiigoUI.h +++ b/include/AmiigoUI.h @@ -36,4 +36,5 @@ class AmiigoUI int *IsDone; ScrollList *MenuList; int AmiiboListWidth; + string ListDir = "sdmc:/emuiibo/amiibo/"; }; \ No newline at end of file diff --git a/include/Utils.h b/include/Utils.h new file mode 100644 index 0000000..a6b3b0c --- /dev/null +++ b/include/Utils.h @@ -0,0 +1,6 @@ +#include +#include +using namespace std; + +bool CheckFileExists(string); +string GoUpDir(string); \ No newline at end of file diff --git a/source/AmiigoUI.cpp b/source/AmiigoUI.cpp index 20aa251..b9db0b7 100644 --- a/source/AmiigoUI.cpp +++ b/source/AmiigoUI.cpp @@ -5,6 +5,7 @@ #include #include #include +#include using namespace std; class AmiigoUI @@ -37,6 +38,7 @@ class AmiigoUI int *IsDone; ScrollList *MenuList; int AmiiboListWidth; + string ListDir = "sdmc:/emuiibo/amiibo/"; }; AmiigoUI::AmiigoUI() @@ -168,11 +170,18 @@ void AmiigoUI::GetInput() *WindowState = MenuList->SelectedIndex; } } + //B pressed + else if(Event->jbutton.button == 1) + { + ListDir = GoUpDir(ListDir); + ScanForAmiibos(); + } //Left stick pressed else if(Event->jbutton.button == 4) { //Delete Amiibo. This is temporary until I have time to implement a proper menu for deleting and renaming - char PathToAmiibo[FS_MAX_PATH] = "sdmc:/emuiibo/amiibo/"; + char PathToAmiibo[FS_MAX_PATH] = ""; //Without assigning we get a random char. Why? + strcat(PathToAmiibo, ListDir.c_str()); strcat(PathToAmiibo, Files.at(AmiiboList->SelectedIndex).d_name); fsdevDeleteDirectoryRecursively(PathToAmiibo); ScanForAmiibos(); @@ -181,6 +190,20 @@ void AmiigoUI::GetInput() break; } } + + //Check if list item selected via touch screen + if(AmiiboList->ItemSelected) + { + SetAmiibo(AmiiboList->SelectedIndex); + MenuList->IsActive = false; + AmiiboList->IsActive = true; + } + else if(MenuList->ItemSelected) + { + *WindowState = MenuList->SelectedIndex; + MenuList->IsActive = true; + AmiiboList->IsActive = false; + } } void AmiigoUI::DrawUI() @@ -196,20 +219,6 @@ void AmiigoUI::DrawUI() AmiiboList->DrawList(); MenuList->DrawList(); DrawButtonBorders(renderer, AmiiboList, MenuList, HeaderHeight, FooterHeight, *Width, *Height, false); - //DrawButtonBorders(); - //Check if list item selected via touch screen - if(AmiiboList->ItemSelected) - { - SetAmiibo(AmiiboList->SelectedIndex); - MenuList->IsActive = false; - AmiiboList->IsActive = true; - } - else if(MenuList->ItemSelected) - { - *WindowState = MenuList->SelectedIndex; - MenuList->IsActive = true; - AmiiboList->IsActive = false; - } //Reset touch coords TouchX = -1; @@ -310,7 +319,7 @@ void AmiigoUI::ScanForAmiibos() //Do the actual scanning DIR* dir; struct dirent* ent; - dir = opendir("sdmc:/emuiibo/amiibo/"); + dir = opendir(ListDir.c_str()); while ((ent = readdir(dir))) { Files.push_back(*ent); @@ -342,9 +351,19 @@ void AmiigoUI::PleaseWait() void AmiigoUI::SetAmiibo(int Index) { - char PathToAmiibo[FS_MAX_PATH] = "sdmc:/emuiibo/amiibo/"; + char PathToAmiibo[FS_MAX_PATH] = ""; + strcat(PathToAmiibo, ListDir.c_str()); strcat(PathToAmiibo, Files.at(Index).d_name); - nfpemuSetCustomAmiibo(PathToAmiibo); + //Check if Amiibo or empty folder + string TagPath = PathToAmiibo; + TagPath += "/tag.json"; + if(CheckFileExists(TagPath)) + { + ListDir = PathToAmiibo; + ListDir += "/"; + ScanForAmiibos(); + } + else nfpemuSetCustomAmiibo(PathToAmiibo); } void AmiigoUI::InitList() diff --git a/source/Utils.cpp b/source/Utils.cpp new file mode 100644 index 0000000..08f907f --- /dev/null +++ b/source/Utils.cpp @@ -0,0 +1,26 @@ +#include +#include +#include +#include +using namespace std; + +bool CheckFileExists(string Path) +{ + struct stat Buffer; + return !(stat (Path.c_str(), &Buffer) == 0); +} + +string GoUpDir(string Path) +{ + char CurrentPath[Path.length()] = ""; + strcat(CurrentPath, Path.c_str()); + CurrentPath[Path.length()-1] = 0x00; + Path = CurrentPath; + int LastSlash = Path.find_last_of('/'); + CurrentPath[LastSlash] = 0x00; + if(strlen(CurrentPath) < 21) + { + return "sdmc:/emuiibo/amiibo/"; + } + return CurrentPath; +} \ No newline at end of file