mirror of
https://github.com/DarkStore-3DS/DarkStore.git
synced 2026-07-06 00:38:59 +00:00
Next work.
This commit is contained in:
Binary file not shown.
+3
-3
@@ -1,6 +1,6 @@
|
|||||||
BasicInfo:
|
BasicInfo:
|
||||||
Title : "LeafEdit"
|
Title : "UNIV-UPDATER"
|
||||||
ProductCode : "CTR-H-LEDT"
|
ProductCode : "CTR-H-UVUP"
|
||||||
Logo : Homebrew # Nintendo / Licensed / Distributed / iQue / iQueForSystem
|
Logo : Homebrew # Nintendo / Licensed / Distributed / iQue / iQueForSystem
|
||||||
|
|
||||||
RomFs:
|
RomFs:
|
||||||
@@ -8,7 +8,7 @@ RomFs:
|
|||||||
|
|
||||||
TitleInfo:
|
TitleInfo:
|
||||||
Category : Application
|
Category : Application
|
||||||
UniqueId : 0x43921
|
UniqueId : 0x43917
|
||||||
|
|
||||||
Option:
|
Option:
|
||||||
UseOnSD : true # true if App is to be installed to SD
|
UseOnSD : true # true if App is to be installed to SD
|
||||||
|
|||||||
Binary file not shown.
Binary file not shown.
|
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 3.5 KiB |
+3
-3
@@ -38,9 +38,9 @@
|
|||||||
#include <unordered_map>
|
#include <unordered_map>
|
||||||
#include <wchar.h>
|
#include <wchar.h>
|
||||||
|
|
||||||
#define BarColor C2D_Color32(0, 102, 204, 255)
|
#define BarColor C2D_Color32(57, 84, 114, 255)
|
||||||
#define TopBGColor C2D_Color32(51, 153, 255, 255)
|
#define TopBGColor C2D_Color32(96, 168, 192, 255)
|
||||||
#define BottomBGColor C2D_Color32(0, 64, 128, 255)
|
#define BottomBGColor C2D_Color32(38, 44, 77, 255)
|
||||||
#define BLACK C2D_Color32(0, 0, 0, 255)
|
#define BLACK C2D_Color32(0, 0, 0, 255)
|
||||||
#define WHITE C2D_Color32(255, 255, 255, 255)
|
#define WHITE C2D_Color32(255, 255, 255, 255)
|
||||||
#define TextColor C2D_Color32(102, 179, 255, 255)
|
#define TextColor C2D_Color32(102, 179, 255, 255)
|
||||||
|
|||||||
@@ -28,13 +28,19 @@
|
|||||||
|
|
||||||
#include "screens/screen.hpp"
|
#include "screens/screen.hpp"
|
||||||
|
|
||||||
|
#include "utils/structs.hpp"
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
class MainMenu : public Screen
|
class MainMenu : public Screen
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
void Draw(void) const override;
|
void Draw(void) const override;
|
||||||
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
|
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
std::vector<Structs::ButtonPos> mainButtons = {
|
||||||
|
{90, 40, 140, 35, -1}, // ScriptList.
|
||||||
|
{90, 160, 140, 35, -1}, // Settings?
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -29,6 +29,8 @@
|
|||||||
|
|
||||||
#include "gui.hpp"
|
#include "gui.hpp"
|
||||||
|
|
||||||
|
#include "lang/lang.hpp"
|
||||||
|
|
||||||
extern C3D_RenderTarget* top;
|
extern C3D_RenderTarget* top;
|
||||||
extern C3D_RenderTarget* bottom;
|
extern C3D_RenderTarget* bottom;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Universal-Updater
|
||||||
|
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
#ifndef SCRIPTLIST_HPP
|
||||||
|
#define SCRIPTLIST_HPP
|
||||||
|
|
||||||
|
#include "screens/screen.hpp"
|
||||||
|
#include "screens/screenCommon.hpp"
|
||||||
|
|
||||||
|
#include "utils/fileBrowse.h"
|
||||||
|
|
||||||
|
class ScriptList : public Screen
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void Draw(void) const override;
|
||||||
|
void Logic(u32 hDown, u32 hHeld, touchPosition touch) override;
|
||||||
|
ScriptList();
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<DirEntry> dirContents;
|
||||||
|
uint selectedFile = 0;
|
||||||
|
int keyRepeatDelay = 0;
|
||||||
|
int fastMode = false;
|
||||||
|
bool dirChanged = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -58,4 +58,5 @@ using json = nlohmann::json;
|
|||||||
|
|
||||||
extern char * arg0;
|
extern char * arg0;
|
||||||
|
|
||||||
#define WORKING_DIR "/3ds/"
|
#define WORKING_DIR "/3ds/"
|
||||||
|
#define SCRIPTS_PATH "/3ds/Universal-Updater/scripts/" // The Scripts will be here.
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
#ifndef PARSE_HPP
|
||||||
|
#define PARSE_HPP
|
||||||
|
|
||||||
|
void parse(std::string fileName);
|
||||||
|
std::string get(nlohmann::json json, const std::string &key, const std::string &key2);
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Universal-Updater
|
||||||
|
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef STRUCTS_HPP
|
||||||
|
#define STRUCTS_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
class Structs
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
struct ButtonPos {
|
||||||
|
int x;
|
||||||
|
int y;
|
||||||
|
int w;
|
||||||
|
int h;
|
||||||
|
int link;
|
||||||
|
};
|
||||||
|
private:
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -12,5 +12,8 @@
|
|||||||
"DOWNLOAD_NDSBOOTSTRAP_NIGHTLY": "Downloading nds-bootstrap...\n(Nightly)",
|
"DOWNLOAD_NDSBOOTSTRAP_NIGHTLY": "Downloading nds-bootstrap...\n(Nightly)",
|
||||||
"EXTRACT_NDSBOOTSTRAP_NIGHTLY": "Extracting nds-bootstrap...\n(Nightly)",
|
"EXTRACT_NDSBOOTSTRAP_NIGHTLY": "Extracting nds-bootstrap...\n(Nightly)",
|
||||||
"DOWNLOAD_NDSBOOTSTRAP_RELEASE": "Downloading nds-bootstrap...\n(Release)",
|
"DOWNLOAD_NDSBOOTSTRAP_RELEASE": "Downloading nds-bootstrap...\n(Release)",
|
||||||
"EXTRACT_NDSBOOTSTRAP_RELEASE": "Extracting nds-bootstrap...\n(Release)"
|
"EXTRACT_NDSBOOTSTRAP_RELEASE": "Extracting nds-bootstrap...\n(Release)",
|
||||||
|
|
||||||
|
"SCRIPTLIST": "Scriptlist",
|
||||||
|
"SETTINGS": "Settings"
|
||||||
}
|
}
|
||||||
|
|||||||
+15
-1
@@ -31,13 +31,23 @@
|
|||||||
#include "screens/mainMenu.hpp"
|
#include "screens/mainMenu.hpp"
|
||||||
#include "screens/screenCommon.hpp"
|
#include "screens/screenCommon.hpp"
|
||||||
|
|
||||||
|
#include "utils/structs.hpp"
|
||||||
|
|
||||||
#include <3ds.h>
|
#include <3ds.h>
|
||||||
#include <unistd.h>
|
#include <dirent.h>
|
||||||
|
|
||||||
bool exiting = false;
|
bool exiting = false;
|
||||||
|
|
||||||
touchPosition touch;
|
touchPosition touch;
|
||||||
|
|
||||||
|
// If button Position pressed -> Do something.
|
||||||
|
bool touching(touchPosition touch, Structs::ButtonPos button) {
|
||||||
|
if (touch.px >= button.x && touch.px <= (button.x + button.w) && touch.py >= button.y && touch.py <= (button.y + button.h))
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
gfxInitDefault();
|
gfxInitDefault();
|
||||||
@@ -46,6 +56,10 @@ int main()
|
|||||||
sdmcInit();
|
sdmcInit();
|
||||||
cfguInit();
|
cfguInit();
|
||||||
Lang::load(1);
|
Lang::load(1);
|
||||||
|
// Create Folder if missing.
|
||||||
|
mkdir("sdmc:/3ds", 0777);
|
||||||
|
mkdir("sdmc:/3ds/Universal-Updater", 0777);
|
||||||
|
mkdir("sdmc:/3ds/Universal-Updater/scripts", 0777);
|
||||||
|
|
||||||
Gui::setScreen(std::make_unique<MainMenu>());
|
Gui::setScreen(std::make_unique<MainMenu>());
|
||||||
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
|
osSetSpeedupEnable(true); // Enable speed-up for New 3DS users
|
||||||
|
|||||||
@@ -24,17 +24,23 @@
|
|||||||
* reasonable ways as different from the original version.
|
* reasonable ways as different from the original version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "download.hpp"
|
|
||||||
#include "screens/mainMenu.hpp"
|
#include "screens/mainMenu.hpp"
|
||||||
#include "screens/screenCommon.hpp"
|
#include "screens/scriptlist.hpp"
|
||||||
|
|
||||||
extern bool exiting;
|
extern bool exiting;
|
||||||
|
extern bool touching(touchPosition touch, Structs::ButtonPos button);
|
||||||
|
|
||||||
void MainMenu::Draw(void) const {
|
void MainMenu::Draw(void) const {
|
||||||
Gui::DrawTop();
|
Gui::DrawTop();
|
||||||
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
|
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
|
||||||
Gui::DrawString(395-Gui::GetStringWidth(0.72f, VERSION_STRING), 218, 0.72f, WHITE, VERSION_STRING);
|
Gui::DrawString(395-Gui::GetStringWidth(0.72f, VERSION_STRING), 218, 0.72f, WHITE, VERSION_STRING);
|
||||||
Gui::DrawBottom();
|
Gui::DrawBottom();
|
||||||
|
|
||||||
|
// Draw 2 'Buttons'.
|
||||||
|
Gui::Draw_Rect(mainButtons[0].x, mainButtons[0].y, mainButtons[0].w, mainButtons[0].h, TopBGColor);
|
||||||
|
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SCRIPTLIST")))/2, mainButtons[0].y+10, 0.6f, WHITE, Lang::get("SCRIPTLIST"), 140);
|
||||||
|
Gui::Draw_Rect(mainButtons[1].x, mainButtons[1].y, mainButtons[1].w, mainButtons[1].h, TopBGColor);
|
||||||
|
Gui::DrawString((320-Gui::GetStringWidth(0.6f, Lang::get("SETTINGS")))/2, mainButtons[1].y+10, 0.6f, WHITE, Lang::get("SETTINGS"), 140);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
@@ -42,7 +48,9 @@ void MainMenu::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
|||||||
exiting = true;
|
exiting = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hDown & KEY_X) {
|
if (hDown & KEY_TOUCH) {
|
||||||
updateBootstrap(true);
|
if (touching(touch, mainButtons[0])) {
|
||||||
|
Gui::setScreen(std::make_unique<ScriptList>());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,89 @@
|
|||||||
|
/*
|
||||||
|
* This file is part of Universal-Updater
|
||||||
|
* Copyright (C) 2019 VoltZ, Epicpkmn11, Flame, RocketRobz, TotallyNotGuy
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* Additional Terms 7.b and 7.c of GPLv3 apply to this file:
|
||||||
|
* * Requiring preservation of specified reasonable legal notices or
|
||||||
|
* author attributions in that material or in the Appropriate Legal
|
||||||
|
* Notices displayed by works containing it.
|
||||||
|
* * Prohibiting misrepresentation of the origin of that material,
|
||||||
|
* or requiring that modified versions of such material be marked in
|
||||||
|
* reasonable ways as different from the original version.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "download/download.hpp"
|
||||||
|
|
||||||
|
#include "screens/mainMenu.hpp"
|
||||||
|
#include "screens/scriptlist.hpp"
|
||||||
|
|
||||||
|
#include "utils/parse.hpp"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <fstream>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#define ENTRIES_PER_SCREEN 3
|
||||||
|
|
||||||
|
struct Info {
|
||||||
|
std::string title;
|
||||||
|
std::string description;
|
||||||
|
};
|
||||||
|
|
||||||
|
Info parseInfo(std::string fileName) {
|
||||||
|
FILE* file = fopen(fileName.c_str(), "rt");
|
||||||
|
if(!file) {
|
||||||
|
printf("File not found\n");
|
||||||
|
fclose(file);
|
||||||
|
return {"", ""};
|
||||||
|
}
|
||||||
|
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
Info info;
|
||||||
|
info.title = get(json, "info", "title");
|
||||||
|
info.description = get(json, "info", "description");
|
||||||
|
return info;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Info> fileInfo;
|
||||||
|
|
||||||
|
ScriptList::ScriptList() {
|
||||||
|
dirContents.clear();
|
||||||
|
chdir(SCRIPTS_PATH);
|
||||||
|
getDirectoryContents(dirContents);
|
||||||
|
for(uint i=0;i<dirContents.size();i++) {
|
||||||
|
fileInfo.push_back(parseInfo(dirContents[i].name));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptList::Draw(void) const {
|
||||||
|
std::string titleinfo;
|
||||||
|
Gui::DrawTop();
|
||||||
|
Gui::DrawStringCentered(0, 2, 0.7f, TextColor, "Universal-Updater", 400);
|
||||||
|
Gui::DrawBottom();
|
||||||
|
for(int i=0;i<ENTRIES_PER_SCREEN && i<(int)fileInfo.size();i++) {
|
||||||
|
titleinfo = fileInfo[i].title + '\n' + fileInfo[i].description;
|
||||||
|
Gui::Draw_Rect(0, 40+(i*57), 320, 45, TopBGColor);
|
||||||
|
Gui::DrawString(0, 40+(i*57), 0.7f, WHITE, titleinfo, 320);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScriptList::Logic(u32 hDown, u32 hHeld, touchPosition touch) {
|
||||||
|
if (hDown & KEY_B) {
|
||||||
|
Gui::screenBack();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,162 @@
|
|||||||
|
#include "utils/fileBrowse.h"
|
||||||
|
|
||||||
|
#include "gui.hpp"
|
||||||
|
#include <3ds.h>
|
||||||
|
#include <cstring>
|
||||||
|
#include <dirent.h>
|
||||||
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <functional>
|
||||||
|
#include <array>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
int file_count = 0;
|
||||||
|
|
||||||
|
extern bool continueNdsScan;
|
||||||
|
extern uint selectedFile;
|
||||||
|
extern int keyRepeatDelay;
|
||||||
|
extern bool dirChanged;
|
||||||
|
extern std::vector<DirEntry> dirContents;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the title ID.
|
||||||
|
* @param ndsFile DS ROM image.
|
||||||
|
* @param buf Output buffer for title ID. (Must be at least 4 characters.)
|
||||||
|
* @return 0 on success; non-zero on error.
|
||||||
|
*/
|
||||||
|
int grabTID(FILE *ndsFile, char *buf) {
|
||||||
|
fseek(ndsFile, offsetof(sNDSHeadertitlecodeonly, gameCode), SEEK_SET);
|
||||||
|
size_t read = fread(buf, 1, 4, ndsFile);
|
||||||
|
return !(read == 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
void findNdsFiles(vector<DirEntry>& dirContents) {
|
||||||
|
struct stat st;
|
||||||
|
DIR *pdir = opendir(".");
|
||||||
|
|
||||||
|
if (pdir == NULL) {
|
||||||
|
DisplayMsg("Unable to open the directory.");
|
||||||
|
for(int i=0;i<120;i++)
|
||||||
|
gspWaitForVBlank();
|
||||||
|
} else {
|
||||||
|
while (continueNdsScan)
|
||||||
|
{
|
||||||
|
DirEntry dirEntry;
|
||||||
|
|
||||||
|
struct dirent* pent = readdir(pdir);
|
||||||
|
if (pent == NULL) break;
|
||||||
|
|
||||||
|
stat(pent->d_name, &st);
|
||||||
|
dirEntry.name = pent->d_name;
|
||||||
|
char scanningMessage[512];
|
||||||
|
snprintf(scanningMessage, sizeof(scanningMessage), "Scanning SD card for DS roms...\n\n(Press B to cancel)\n\n\n\n\n\n\n\n\n%s", dirEntry.name.c_str());
|
||||||
|
DisplayMsg(scanningMessage);
|
||||||
|
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
|
||||||
|
if(!(dirEntry.isDirectory) && dirEntry.name.length() >= 3) {
|
||||||
|
if (strcasecmp(dirEntry.name.substr(dirEntry.name.length()-3, 3).c_str(), "nds") == 0) {
|
||||||
|
// Get game's TID
|
||||||
|
FILE *f_nds_file = fopen(dirEntry.name.c_str(), "rb");
|
||||||
|
// char game_TID[5];
|
||||||
|
grabTID(f_nds_file, dirEntry.tid);
|
||||||
|
dirEntry.tid[4] = 0;
|
||||||
|
fclose(f_nds_file);
|
||||||
|
|
||||||
|
// dirEntry.tid = game_TID;
|
||||||
|
|
||||||
|
dirContents.push_back(dirEntry);
|
||||||
|
file_count++;
|
||||||
|
}
|
||||||
|
} else if (dirEntry.isDirectory
|
||||||
|
&& dirEntry.name.compare(".") != 0
|
||||||
|
&& dirEntry.name.compare("_nds") != 0
|
||||||
|
&& dirEntry.name.compare("3ds") != 0
|
||||||
|
&& dirEntry.name.compare("DCIM") != 0
|
||||||
|
&& dirEntry.name.compare("gm9") != 0
|
||||||
|
&& dirEntry.name.compare("luma") != 0
|
||||||
|
&& dirEntry.name.compare("Nintendo 3DS") != 0
|
||||||
|
&& dirEntry.name.compare("private") != 0
|
||||||
|
&& dirEntry.name.compare("retroarch") != 0) {
|
||||||
|
chdir(dirEntry.name.c_str());
|
||||||
|
findNdsFiles(dirContents);
|
||||||
|
chdir("..");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(pdir);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
off_t getFileSize(const char *fileName)
|
||||||
|
{
|
||||||
|
FILE* fp = fopen(fileName, "rb");
|
||||||
|
off_t fsize = 0;
|
||||||
|
if (fp) {
|
||||||
|
fseek(fp, 0, SEEK_END);
|
||||||
|
fsize = ftell(fp); // Get source file's size
|
||||||
|
fseek(fp, 0, SEEK_SET);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
|
||||||
|
return fsize;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool nameEndsWith(const std::string& name, const std::vector<std::string> extensionList) {
|
||||||
|
if(name.substr(0, 2) == "._") return false;
|
||||||
|
|
||||||
|
if(name.size() == 0) return false;
|
||||||
|
|
||||||
|
if(extensionList.size() == 0) return true;
|
||||||
|
|
||||||
|
for(int i = 0; i <(int)extensionList.size(); i++) {
|
||||||
|
const std::string ext = extensionList.at(i);
|
||||||
|
if(strcasecmp(name.c_str() + name.size() - ext.size(), ext.c_str()) == 0) return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool dirEntryPredicate(const DirEntry& lhs, const DirEntry& rhs) {
|
||||||
|
if(!lhs.isDirectory && rhs.isDirectory) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if(lhs.isDirectory && !rhs.isDirectory) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return strcasecmp(lhs.name.c_str(), rhs.name.c_str()) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDirectoryContents(std::vector<DirEntry>& dirContents, const std::vector<std::string> extensionList) {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
dirContents.clear();
|
||||||
|
|
||||||
|
DIR *pdir = opendir(".");
|
||||||
|
|
||||||
|
if(pdir == NULL) {
|
||||||
|
DisplayMsg("Unable to open the directory.");
|
||||||
|
for(int i=0;i<120;i++) gspWaitForVBlank();
|
||||||
|
} else {
|
||||||
|
while(true) {
|
||||||
|
DirEntry dirEntry;
|
||||||
|
|
||||||
|
struct dirent* pent = readdir(pdir);
|
||||||
|
if(pent == NULL) break;
|
||||||
|
|
||||||
|
stat(pent->d_name, &st);
|
||||||
|
dirEntry.name = pent->d_name;
|
||||||
|
dirEntry.isDirectory = (st.st_mode & S_IFDIR) ? true : false;
|
||||||
|
|
||||||
|
if(dirEntry.name.compare(".") != 0 && (dirEntry.isDirectory || nameEndsWith(dirEntry.name, extensionList))) {
|
||||||
|
dirContents.push_back(dirEntry);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
closedir(pdir);
|
||||||
|
}
|
||||||
|
sort(dirContents.begin(), dirContents.end(), dirEntryPredicate);
|
||||||
|
}
|
||||||
|
|
||||||
|
void getDirectoryContents(std::vector<DirEntry>& dirContents) {
|
||||||
|
getDirectoryContents(dirContents, {});
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
#include <string>
|
||||||
|
#include "json.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
std::string get(nlohmann::json json, const std::string &key, const std::string &key2) {
|
||||||
|
if(!json.contains(key)) return "MISSING: " + key;
|
||||||
|
if(!json.at(key).is_object()) return "NOT OBJECT: " + key;
|
||||||
|
|
||||||
|
if(!json.at(key).contains(key2)) return "MISSING: " + key + "." + key2;
|
||||||
|
if(!json.at(key).at(key2).is_string()) return "NOT STRING: " + key + "." + key2;
|
||||||
|
|
||||||
|
return json.at(key).at(key2).get_ref<const std::string&>();
|
||||||
|
}
|
||||||
|
|
||||||
|
void parse(std::string fileName) {
|
||||||
|
FILE* file = fopen(fileName.c_str(), "rt");
|
||||||
|
if(!file) {
|
||||||
|
printf("File not found\n");
|
||||||
|
fclose(file);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
nlohmann::json json = nlohmann::json::parse(file, nullptr, false);
|
||||||
|
fclose(file);
|
||||||
|
|
||||||
|
std::string title = get(json, "info", "title");
|
||||||
|
std::string description = get(json, "info", "description");
|
||||||
|
|
||||||
|
printf("%s\n", title.c_str());
|
||||||
|
printf("%s\n", description.c_str());
|
||||||
|
printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
printf("Options:\n");
|
||||||
|
for(auto it = json.begin();it != json.end(); it++) {
|
||||||
|
if(it.key() != "info") {
|
||||||
|
printf("> %s\n", it.key().c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
|
||||||
|
char choise[16];
|
||||||
|
while(!json.contains(choise)) {
|
||||||
|
printf("Choose an option: ");
|
||||||
|
scanf("%s", choise);
|
||||||
|
}
|
||||||
|
|
||||||
|
printf("Parsing %s...\n", choise);
|
||||||
|
for(int i=0;i<json.at(choise).size();i++) {
|
||||||
|
std::string type = json.at(choise).at(i).at("type");
|
||||||
|
printf("------------------------------------------------------------------------------------------\n");
|
||||||
|
printf("Running: %s\n", type.c_str());
|
||||||
|
|
||||||
|
|
||||||
|
if(type == "downloadFile") {
|
||||||
|
std::string file = json.at(choise).at(i).at("file");
|
||||||
|
std::string output = json.at(choise).at(i).at("output");
|
||||||
|
printf("Downloading %s to %s\n", file.c_str(), output.c_str());
|
||||||
|
} else if(type == "downloadRelease") {
|
||||||
|
std::string file = json.at(choise).at(i).at("file");
|
||||||
|
std::string repo = json.at(choise).at(i).at("repo");
|
||||||
|
std::string output = json.at(choise).at(i).at("output");
|
||||||
|
printf("Downloading %s from %s to %s\n", file.c_str(), repo.c_str(), output.c_str());
|
||||||
|
} else if(type == "installCia") {
|
||||||
|
std::string file = json.at(choise).at(i).at("file");
|
||||||
|
printf("Installing %s\n", file.c_str());
|
||||||
|
} else if(type == "deleteFile") {
|
||||||
|
std::string file = json.at(choise).at(i).at("file");
|
||||||
|
printf("Deleting %s\n", file.c_str());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user