diff --git a/Makefile b/Makefile index 582b9f3..ed74736 100644 --- a/Makefile +++ b/Makefile @@ -38,7 +38,7 @@ INCLUDES := include EXEFS_SRC := exefs_src APP_TITLE := Haku33 APP_AUTHOR := Kronos2308 -APP_VERSION := 2.6 +APP_VERSION := 2.7 ROMFS := romfs #--------------------------------------------------------------------------------- diff --git a/romfs/Haku33_payload.bin b/romfs/Haku33_payload.bin index 13962e0..324093e 100644 Binary files a/romfs/Haku33_payload.bin and b/romfs/Haku33_payload.bin differ diff --git a/source/FileSystem.cpp b/source/FileSystem.cpp new file mode 100644 index 0000000..55afb01 --- /dev/null +++ b/source/FileSystem.cpp @@ -0,0 +1,269 @@ +#include "FileSystem.hpp" +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include + +#include + + +namespace fs +{ + + bool IsExist(std::string Path) + { + std::ifstream ifs(Path); + bool ex = ifs.good(); + ifs.close(); + return ex; + } + + bool DirExists(const char* const path) + { + struct stat info; + + int statRC = stat(path, &info); + if (statRC != 0) + { + if (errno == ENOENT) { return 0; } // something along the path does not exist + if (errno == ENOTDIR) { return 0; } // something in path prefix is not a dir + return false; + } + + return (info.st_mode & S_IFDIR) ? true : false; + } + + bool IsFile(std::string Path) + { + bool is = false; + struct stat st; + if (stat(Path.c_str(), &st) == 0) if (st.st_mode & S_IFREG) is = true; + return is; + } + void CreateFile(std::string Path) + { + std::ofstream ofs(Path); + ofs.close(); + } + void CreateDir(std::string Path) + { + mkdir(Path.c_str(), 777); + } + void DeleteFile(std::string Path) + { + if(IsExist(Path)) + remove(Path.c_str()); + } + + void DeleteDir(std::string Path) + { + DIR *d = opendir(Path.c_str()); + if (d) + { + struct dirent *dent; + while (true) + { + dent = readdir(d); + if (dent == NULL) break; + std::string nd = dent->d_name; + std::string pd = Path + "/" + nd; + if (fs::IsFile(pd)) DeleteFile(pd); + else DeleteDir(pd); + } + } + closedir(d); + } + + void WriteFile(std::string Path, std::string Content) + { + DeleteFile(Path); + std::ofstream file(Path); + if (file.is_open()) + { + file << Content; + file.close(); + } + } +/* + bool Unzip(std::string Path) + { + //DeleteDir("sdmc://Update/tmp"); + //CreateDir("sdmc://Update/tmp"); + //Zipper zipper(NULL); + zipper::Unzipper unzipper(Path);// = new Unzipper(true); + bool res = unzipper.extract("sdmc://"); + unzipper.close(); + + if (res) + DeleteFile(Path); + + return res; + } + + bool UnzipTo(std::string Path, std::string unzipTo) + { + //DeleteDir("sdmc://Update/tmp"); + //CreateDir("sdmc://Update/tmp"); + //Zipper zipper(NULL); + zipper::Unzipper unzipper(Path);// = new Unzipper(true); + bool res = unzipper.extract(unzipTo); + unzipper.close(); + + if (res) + DeleteFile(Path); + + return res; + } +*/ + std::string ReadFile(std::string Path) + { + std::ifstream file(Path); + if (file.is_open()) + { + std::string res((std::istreambuf_iterator(file)), + std::istreambuf_iterator()); + + return res; + } + else + return ""; + } + + void copyDirToDir(const std::string& from, const std::string& to) + { + dirList list; + list.assign(from); + + for (unsigned i = 0; i < list.getCount(); i++) + { + if (list.isDir(i)) + { + std::string newFrom = from + list.getItem(i) + "/"; + std::string newTo = to + list.getItem(i); + if(!fs::DirExists(newTo.c_str())) + mkdir(newTo.c_str(), 0777); + newTo += "/"; + + copyDirToDir(newFrom, newTo); + } + else + { + std::string fullFrom = from + list.getItem(i); + std::string fullTo = to + list.getItem(i); + + copyFile(fullFrom, fullTo); + } + } + } + + void copyFile(const std::string& from, const std::string& to) + { + std::fstream f(from, std::ios::in | std::ios::binary); + std::fstream t(to, std::ios::out | std::ios::binary); + + f.seekg(0, f.end); + size_t fileSize = f.tellg(); + f.seekg(0, f.beg); + + uint8_t* buff = new uint8_t[0x80000]; + for (unsigned i = 0; i < fileSize; ) + { + f.read((char*)buff, 0x80000); + t.write((char*)buff, f.gcount()); + + i += f.gcount(); + } + + delete[] buff; + + f.close(); + t.close(); + } + +/* char* FS_GetFilePermission(const char* filename) + { + static char perms[11]; + struct stat attr; + + if (!R_SUCCEEDED(stat(filename, &attr))) + return "f"; + + snprintf(perms, 11, "%s%s%s%s%s%s%s%s%s%s", (S_ISDIR(attr.st_mode)) ? "d" : "-", (attr.st_mode & S_IRUSR) ? "r" : "-", + (attr.st_mode & S_IWUSR) ? "w" : "-", (attr.st_mode & S_IXUSR) ? "x" : "-", (attr.st_mode & S_IRGRP) ? "r" : "-", + (attr.st_mode & S_IWGRP) ? "w" : "-", (attr.st_mode & S_IXGRP) ? "x" : "-", (attr.st_mode & S_IROTH) ? "r" : "-", + (attr.st_mode & S_IWOTH) ? "w" : "-", (attr.st_mode & S_IXOTH) ? "x" : "-"); + + return perms; + }*/ + void dirList::assign(const std::string& _path) + { + path = _path; + + d = opendir(path.c_str()); + + item.clear(); + + while ((ent = readdir(d))) + { + char ext[5]; + memset(ext, 0, 5); + memcpy(ext, &ent->d_name[strlen(ent->d_name) - 4], 4); + item.push_back(ent->d_name); + } + + closedir(d); + } + void dirList::rescan() + { + item.clear(); + d = opendir(path.c_str()); + + while ((ent = readdir(d))) + item.push_back(ent->d_name); + + closedir(d); + } + std::string dirList::getItem(int index) + { + return item[index]; + } + bool dirList::isDir(int index) + { + std::string fullPath = path + item[index]; + struct stat s; + return stat(fullPath.c_str(), &s) == 0 && S_ISDIR(s.st_mode); + } + unsigned dirList::getCount() + { + return item.size(); + } +} \ No newline at end of file diff --git a/source/FileSystem.hpp b/source/FileSystem.hpp new file mode 100644 index 0000000..ad474b9 --- /dev/null +++ b/source/FileSystem.hpp @@ -0,0 +1,41 @@ +#pragma once +#include +#include +#include +#include +#include + +namespace fs +{ + bool IsExist(std::string Path); + bool IsFile(std::string Path); + bool DirExists(const char* const path); + void CreateFile(std::string Path); + void CreateDir(std::string Path); + void DeleteFile(std::string Path); + void DeleteDir(std::string Path); + void WriteFile(std::string Path, std::string Content); +// bool Unzip(std::string Path); +// bool UnzipTo(std::string Path, std::string unzipTo); + std::string ReadFile(std::string Path); + void copyDirToDir(const std::string& from, const std::string& to); + void copyFile(const std::string& from, const std::string& to); + char *FS_GetFilePermission(const char* filename); + + class dirList + { + public: + void assign(const std::string& _path); + void rescan(); + + std::string getItem(int index); + bool isDir(int index); + unsigned getCount(); + + private: + DIR* d; + struct dirent* ent; + std::string path; + std::vector item; + }; +} \ No newline at end of file diff --git a/source/main.cpp b/source/main.cpp index 565b463..0d270b9 100644 --- a/source/main.cpp +++ b/source/main.cpp @@ -21,6 +21,7 @@ #include #include #include +#include "FileSystem.hpp" extern "C" { #include "reboot.h" @@ -29,153 +30,84 @@ extern "C" { using namespace std; -//traduction -bool isSpanish = false; -void set_LANG() -{ - setInitialize(); - u64 lcode = 0; - SetLanguage lang; - setGetSystemLanguage(&lcode); - setMakeLanguage(lcode, &lang); - switch(lang) - { - case 5: - case 14: - isSpanish = true; - break; - default: - isSpanish = false; - break; - } - setsysExit(); -} - -//ask to the switch for the serial detect incognito -char *incognito(void) { - setInitialize(); - setsysInitialize(); - Result ret = 0; - static char serial[0x19]; - if (R_FAILED(ret = setsysGetSerialNumber(serial))) - printf("setsysGetSerialNumber() failed: 0x%x.\n\n", ret); - setsysExit(); - return serial; -} - - - bool fileExists(const char* path) - { - FILE* f = fopen(path, "rb"); - if (f) - { - fclose(f); - return true; - } - return false; - } - - bool IsExist(std::string Path) + void espera(u32 timeS) { - std::ifstream ifs(Path); - bool ex = ifs.good(); - ifs.close(); - return ex; + u32 cout = 0; + while (appletMainLoop()){cout++; if(cout >= timeS*1000000) break;}//1000000 } - bool DirExists(const char* const path) - { - struct stat info; - - int statRC = stat(path, &info); - if (statRC != 0) - { - if (errno == ENOENT) { return 0; } // something along the path does not exist - if (errno == ENOTDIR) { return 0; } // something in path prefix is not a dir - return false; - } - - return (info.st_mode & S_IFDIR) ? true : false; - } - - bool IsFile(std::string Path) - { - bool is = false; - struct stat st; - if (stat(Path.c_str(), &st) == 0) if (st.st_mode & S_IFREG) is = true; - return is; - } - void CreateFile(std::string Path) - { - std::ofstream ofs(Path); - ofs.close(); - } - void CreateDir(std::string Path) - { - mkdir(Path.c_str(), 777); - } - void DeleteFile(std::string Path) + //traduction + bool isSpanish = false; + void set_LANG() { - if(IsExist(Path)) - remove(Path.c_str()); + setInitialize(); + u64 lcode = 0; + SetLanguage lang; + setGetSystemLanguage(&lcode); + setMakeLanguage(lcode, &lang); + switch(lang) + { + case 5: + case 14: + isSpanish = true; + break; + default: + isSpanish = false; + break; + } + setsysExit(); } - void DeleteDir(std::string Path) + //ask to the switch for the serial detect incognito + char *incognito(void) { - DIR *d = opendir(Path.c_str()); - if (d) - { - struct dirent *dent; - while (true) - { - dent = readdir(d); - if (dent == NULL) break; - std::string nd = dent->d_name; - std::string pd = Path + "/" + nd; - if (IsFile(pd)) DeleteFile(pd); - else DeleteDir(pd); - } - } - closedir(d); + setInitialize(); + setsysInitialize(); + Result ret = 0; + static char serial[0x19]; + if (R_FAILED(ret = setsysGetSerialNumber(serial))) + printf("setsysGetSerialNumber() failed: 0x%x.\n\n", ret); + setsysExit(); + return serial; } //Power on led bool led_on(void) { - Result rc=0; - s32 i; - s32 total_entries; - u64 UniquePadIds[2]; - HidsysNotificationLedPattern pattern; - hidsysExit(); - rc = hidsysInitialize(); - if (R_FAILED(rc)) { - printf("hidsysInitialize(): 0x%x\n", rc); - } - - - memset(&pattern, 0, sizeof(pattern)); - // Setup Breathing effect pattern data. - pattern.baseMiniCycleDuration = 0x8; // 100ms. - pattern.totalMiniCycles = 0x2; // 3 mini cycles. Last one 12.5ms. - pattern.totalFullCycles = 0x0; // Repeat forever. - pattern.startIntensity = 0x2; // 13%. + Result rc=0; + s32 i; + s32 total_entries; + u64 UniquePadIds[2]; + HidsysNotificationLedPattern pattern; + hidsysExit(); + rc = hidsysInitialize(); + if (R_FAILED(rc)) { + printf("hidsysInitialize(): 0x%x\n", rc); + } - pattern.miniCycles[0].ledIntensity = 0xF; // 100%. - pattern.miniCycles[0].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. - pattern.miniCycles[0].finalStepDuration = 0x0; // Forced 12.5ms. - pattern.miniCycles[1].ledIntensity = 0x2; // 13%. - pattern.miniCycles[1].transitionSteps = 0xF; // 15 steps. Transition time 1.5s. - pattern.miniCycles[1].finalStepDuration = 0x0; // Forced 12.5ms. - - rc = hidsysGetUniquePadsFromNpad(hidGetHandheldMode() ? CONTROLLER_HANDHELD : CONTROLLER_PLAYER_1, UniquePadIds, 2, &total_entries); - if (R_SUCCEEDED(rc)) { - for(i=0; i