Skip to content

Commit

Permalink
Added experimental support for categories
Browse files Browse the repository at this point in the history
  • Loading branch information
CompSciOrBust committed Nov 25, 2019
1 parent 5fa1f9b commit d50e781
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 18 deletions.
1 change: 1 addition & 0 deletions include/AmiigoUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ class AmiigoUI
int *IsDone;
ScrollList *MenuList;
int AmiiboListWidth;
string ListDir = "sdmc:/emuiibo/amiibo/";
};
6 changes: 6 additions & 0 deletions include/Utils.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <string>
#include <sys/stat.h>
using namespace std;

bool CheckFileExists(string);
string GoUpDir(string);
55 changes: 37 additions & 18 deletions source/AmiigoUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <vector>
#include <dirent.h>
#include <UI.h>
#include <Utils.h>
using namespace std;

class AmiigoUI
Expand Down Expand Up @@ -37,6 +38,7 @@ class AmiigoUI
int *IsDone;
ScrollList *MenuList;
int AmiiboListWidth;
string ListDir = "sdmc:/emuiibo/amiibo/";
};

AmiigoUI::AmiigoUI()
Expand Down Expand Up @@ -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();
Expand All @@ -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()
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down
26 changes: 26 additions & 0 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#include <iostream>
#include <string>
#include <sys/stat.h>
#include <cstring>
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;
}

0 comments on commit d50e781

Please sign in to comment.