Skip to content

Commit

Permalink
Added zip support
Browse files Browse the repository at this point in the history
  • Loading branch information
CompSciOrBust committed Feb 9, 2020
1 parent e8ff65d commit 641bd7e
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[submodule "SimpleIniParser"]
path = SimpleIniParser
url = https://github.com/AtlasNX/SimpleIniParser
url = https://github.com/AtlasNX/SimpleIniParser
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ ASFLAGS := -g $(ARCH)
LDFLAGS = -specs=$(DEVKITPRO)/libnx/switch.specs -g $(ARCH) -Wl,-Map,$(notdir $*.map)

#Stolen from https://github.com/devolution2409/NX-input-recorder/blob/master/Makefile#L63 because SDL_Mixer is hard
LIBS := -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx -lSimpleIniParser
LIBS := -lfreetype -lSDL2_mixer -lopusfile -lopus -lmodplug -lmpg123 -lvorbisidec -logg -lSDL2_ttf -lSDL2_gfx -lSDL2_image -lSDL2 -lEGL -lGLESv2 -lglapi -ldrm_nouveau -lwebp -lpng -ljpeg `sdl2-config --libs` `freetype-config --libs` -lnx -lSimpleIniParser -lminizip -lz

#---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing
Expand Down
4 changes: 3 additions & 1 deletion include/ExplorerUI.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <thread>
#include <mutex>
#include <unordered_map>

class ExplorerUI : public UIWindow
{
private:
Expand All @@ -28,6 +29,7 @@ class ExplorerUI : public UIWindow
std::string DirPath = "mount:/";
std::string CurrentMount;
std::string ClipBoardMount;
std::string *LongOpMessagePtr;
int FileSortMode = 0;
int HeaderColour_R = 94;
int HeaderColour_G = 94;
Expand Down Expand Up @@ -62,7 +64,6 @@ class MenuUI : public UIWindow
//vars
std::string ClipboardPath = "";
std::string ClipboardFileName = "";
std::string LongOpMessage = "";
//functions
void RecFileCopy();
public:
Expand All @@ -78,6 +79,7 @@ class MenuUI : public UIWindow
int LongOpMessageTextColour_R = 255;
int LongOpMessageTextColour_G = 255;
int LongOpMessageTextColour_B = 255;
std::string LongOpMessage = "Unset";
//Functions
MenuUI();
void GetInput();
Expand Down
3 changes: 2 additions & 1 deletion include/Utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ std::string GetKeyboardInput(std::string, std::string, std::string);
std::string GetFileSize(std::string);
void RecursiveFileCopy(std::string, std::string, std::string);
std::string GetFileExtension(std::string);
bool GetParentalControl(void);
bool GetParentalControl(void);
void UnzipFile(std::string, std::string);
11 changes: 10 additions & 1 deletion source/ExplorerUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ExplorerUI : public UIWindow
std::string DirPath = "mount:/";
std::string CurrentMount;
std::string ClipBoardMount;
std::string *LongOpMessagePtr;
int FileSortMode = 0;
int HeaderColour_R = 94;
int HeaderColour_G = 94;
Expand Down Expand Up @@ -366,6 +367,14 @@ void ExplorerUI::OpenFile(string Path)
//*WindowState = 4;
*ChosenFile = Path;
}
else if(FileSuffix == "zip")
{
*WindowState = 4;
*LongOpMessagePtr = "Unzipping " + FileNameList->ListingTextVec.at(FileNameList->SelectedIndex) + ". please wait!";
UnzipFile(Path, DirPath);
*WindowState = 0;
LoadListDirs(DirPath);
}
}

std::vector <std::string> ExplorerUI::GetSaveDataMounts()
Expand Down Expand Up @@ -437,7 +446,6 @@ class MenuUI : public UIWindow
//vars
std::string ClipboardPath = "";
std::string ClipboardFileName = "";
std::string LongOpMessage = "";
//functions
void RecFileCopy();
public:
Expand All @@ -453,6 +461,7 @@ class MenuUI : public UIWindow
int LongOpMessageTextColour_R = 255;
int LongOpMessageTextColour_G = 255;
int LongOpMessageTextColour_B = 255;
std::string LongOpMessage = "Unset";
//Functions
MenuUI();
void GetInput();
Expand Down
43 changes: 43 additions & 0 deletions source/Utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <switch.h>
#include <fstream>
#include <algorithm>
#include <minizip/unzip.h>

std::vector <dirent> SortFiles(std::string Path, std::vector <dirent> FilesVec, int SortMode)
{
Expand Down Expand Up @@ -234,4 +235,46 @@ bool GetParentalControl()
{
return true;
}
}

//Based on https://github.com/ITotalJustice/atmosphere-updater/blob/master/source/unzip.c
void UnzipFile(std::string FileLocation, std::string LocationToUnzipTo)
{
unzFile ZipFile = unzOpen(FileLocation.c_str());
//Get info about the zip
unz_global_info ZipInfo;
unzGetGlobalInfo(ZipFile, &ZipInfo);
//Loop through every file
for(int i = 0; i < ZipInfo.number_entry; i++)
{
char FileNameInZip[256];
unz_file_info FileInfo;
unzOpenCurrentFile(ZipFile);
unzGetCurrentFileInfo(ZipFile, &FileInfo, FileNameInZip, sizeof(FileNameInZip), NULL, 0, NULL, 0);
//Check if a dir
if ((FileNameInZip[strlen(FileNameInZip) - 1]) == '/')
{
std::string DirPa = LocationToUnzipTo.c_str();
DirPa += FileNameInZip;
mkdir(DirPa.c_str(), 0);
}
else
{
const char *write_filename = FileNameInZip;
void *buf = malloc(500000);
FILE *outfile;
std::string FilePathOfFile = LocationToUnzipTo.c_str();
FilePathOfFile += write_filename;
outfile = fopen(FilePathOfFile.c_str(), "wb");
for (int j = unzReadCurrentFile(ZipFile, buf, 500000); j > 0; j = unzReadCurrentFile(ZipFile, buf, 500000))
{
fwrite(buf, 1, j, outfile);
}
fclose(outfile);
free(buf);
}
unzCloseCurrentFile(ZipFile);
unzGoToNextFile(ZipFile);
}
unzClose(ZipFile);
}
1 change: 1 addition & 0 deletions source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ int main(int argc, char* argv[])
Menu->WindowState = WindowStatePtr;
Menu->MenuList->Renderer = Renderer;
Menu->Explorer = Explorer;
Explorer->LongOpMessagePtr = &Menu->LongOpMessage;

//Init text editor
TextUI *TextEditor = new TextUI();
Expand Down

0 comments on commit 641bd7e

Please sign in to comment.