WIP: Argument | Shortcut support.

This commit is contained in:
StackZ
2020-11-16 13:28:45 +01:00
parent 24a7b90dea
commit f08bed5813
15 changed files with 294 additions and 20 deletions
+54 -5
View File
@@ -24,11 +24,15 @@
* reasonable ways as different from the original version.
*/
#include "keyboard.hpp"
#include "scriptUtils.hpp"
#include "storeUtils.hpp"
#include "structs.hpp"
#include <fstream>
#define DOWNLOAD_ENTRIES 7
extern std::string _3dsxPath;
extern bool is3DSX;
extern bool touching(touchPosition touch, Structs::ButtonPos button);
static const std::vector<Structs::ButtonPos> downloadBoxes = {
{ 54, 32, 262, 22 },
@@ -40,6 +44,45 @@ static const std::vector<Structs::ButtonPos> downloadBoxes = {
{ 54, 212, 262, 22 }
};
/*
With this, we can create a shortcut. ;P
const std::string &entryName: The name of the Entry. AKA: The Title Name.
int index: The Download index.
const std::string &unistoreName: The name of the UniStore filename.
const std::string &author: The author of the app.
*/
static void CreateShortcut(const std::string &entryName, int index, const std::string &unistoreName, const std::string &author) {
std::string sName = Input::setkbdString(30, Lang::get("ENTER_SHORTCUT_FILENAME"), {});
if (sName == "") sName = "tmp";
std::ofstream out(config->shortcut() + "/" + sName + ".xml", std::ios::binary);
out << "<shortcut>" << std::endl;
/* Executable. */
const std::string executable = _3dsxPath.substr(5, _3dsxPath.size()); // It must be '/3ds/...'.
out << " <executable>" << executable << "</executable>" << std::endl;
/* Arguments. */
out << " <arg>\"" << unistoreName << "\" \"" << entryName << "\" \"" << std::to_string(index) << "\"" << "</arg>" << std::endl;
/* Title. */
const std::string title = Input::setkbdString(30, Lang::get("ENTER_TITLE_SHORTCUT"), {});
if (title != "") out << " <name>" << title << "</name>" << std::endl;
else out << " <name>" << entryName << "</name>" << std::endl;
/* Description. */
const std::string desc = Input::setkbdString(50, Lang::get("ENTER_DESC_SHORTCUT"), {});
if (desc != "") out << " <description>" << desc << "</description>" << std::endl;
else out << " <description>" << entryName << "</description>" << std::endl;
/* Author and end. */
out << " <author>" << author << "</author>" << std::endl;
out << "</shortcut>" << std::endl;
out.close();
}
/*
Draw the Download Entries part.
@@ -87,6 +130,15 @@ void StoreUtils::DownloadHandle(const std::unique_ptr<Store> &store, const std::
smallDelay--;
}
if ((hDown & KEY_Y) || (hDown & KEY_START)) {
if (is3DSX) { // Only allow if 3DSX.
if (Msg::promptMsg(Lang::get("CREATE_SHORTCUT"))) {
CreateShortcut(entry->GetTitle(), store->GetDownloadIndex(), store->GetFileName(), entry->GetAuthor());
Msg::waitMsg(Lang::get("SHORTCUT_CREATED"));
}
}
}
if (hRepeat & KEY_DOWN) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
@@ -122,9 +174,7 @@ void StoreUtils::DownloadHandle(const std::unique_ptr<Store> &store, const std::
for (int i = 0; i < DOWNLOAD_ENTRIES; i++) {
if (touching(touch, downloadBoxes[i])) {
if (i + store->GetDownloadSIndex() < (int)entries.size()) {
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[i + store->GetDownloadSIndex()];
if (Msg::promptMsg(tmp)) {
if (Msg::promptMsg(Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[i + store->GetDownloadSIndex()])) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[i + store->GetDownloadSIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
@@ -137,8 +187,7 @@ void StoreUtils::DownloadHandle(const std::unique_ptr<Store> &store, const std::
if (smallDelay == 0 && hDown & KEY_A) {
if (entries.size() <= 0) return; // Smaller *than* 0 -> Invalid.
const std::string tmp = Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[store->GetDownloadIndex()];
if (Msg::promptMsg(tmp)) {
if (Msg::promptMsg(Lang::get("EXECUTE_ENTRY") + "\n\n" + entries[store->GetDownloadIndex()])) {
ScriptUtils::runFunctions(store->GetJson(), entry->GetEntryIndex(), entries[store->GetDownloadIndex()]);
if (meta) meta->SetUpdated(store->GetUniStoreTitle(), entry->GetTitle(), entry->GetLastUpdated());
entry->SetUpdateAvl(false);
+15 -6
View File
@@ -63,7 +63,7 @@ static const Structs::ButtonPos back = { 52, 0, 24, 24 }; // Back arrow for dire
static const std::vector<std::string> mainStrings = { "LANGUAGE", "SELECT_UNISTORE", "AUTO_UPDATE_SETTINGS_BTN", "GUI_SETTINGS_BTN", "DIRECTORY_SETTINGS_BTN", "CREDITS", "EXIT_APP" };
static const std::vector<std::string> dirStrings = { "CHANGE_3DSX_PATH", "CHANGE_NDS_PATH", "CHANGE_ARCHIVE_PATH" };
static const std::vector<std::string> dirStrings = { "CHANGE_3DSX_PATH", "CHANGE_NDS_PATH", "CHANGE_ARCHIVE_PATH", "CHANGE_SHORTCUT_PATH" };
/* Note: Украïнська is spelled using a latin i with dieresis to work in the system font */
static const std::vector<std::string> languages = { "Bruh", "Dansk", "Deutsch", "English", "Español", "Français", "Italiano", "Lietuvių", "Magyar", "Polski", "Português", "Português (Brasil)", "Русский", "Украïнська", "日本語" };
@@ -115,7 +115,7 @@ static void DrawSettingsDir(int selection) {
GFX::DrawSprite(sprites_arrow_idx, back.x, back.y);
Gui::DrawStringCentered(32, 2, 0.6, TEXT_COLOR, Lang::get("DIRECTORY_SETTINGS"), 240, 0, font);
for (int i = 0; i < 3; i++) {
for (int i = 0; i < 4; i++) {
if (i == selection) GFX::DrawBox(mainButtons[i].x, mainButtons[i].y, mainButtons[i].w, mainButtons[i].h, false);
Gui::DrawStringCentered(30, mainButtons[i].y + 4, 0.45f, TEXT_COLOR, Lang::get(dirStrings[i]), 255, 0, font);
}
@@ -293,18 +293,18 @@ static void SettingsHandleDir(int &page, int &selection, const std::unique_ptr<S
}
if (hRepeat & KEY_DOWN) {
if (selection < 2) selection++;
if (selection < 3) selection++;
else selection = 0;
}
if (hRepeat & KEY_UP) {
if (selection > 0) selection--;
else selection = dirStrings.size()-1;
else selection = dirStrings.size() - 1;
}
if (hRepeat & KEY_RIGHT) {
if (selection + 8 < (int)dirStrings.size()-1) selection += 8;
else selection = dirStrings.size()-1;
if (selection + 8 < (int)dirStrings.size() - 1) selection += 8;
else selection = dirStrings.size() - 1;
}
if (hRepeat & KEY_LEFT) {
@@ -328,6 +328,10 @@ static void SettingsHandleDir(int &page, int &selection, const std::unique_ptr<S
} else if (touching(touch, mainButtons[2])) {
const std::string path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"), store);
if (path != "") config->archPath(path);
} else if (touching(touch, mainButtons[3])) {
const std::string path = Overlays::SelectDir(config->shortcut(), Lang::get("SELECT_DIR"), store);
if (path != "") config->shortcut(path);
}
}
@@ -349,6 +353,11 @@ static void SettingsHandleDir(int &page, int &selection, const std::unique_ptr<S
path = Overlays::SelectDir(config->archPath(), Lang::get("SELECT_DIR"), store);
if (path != "") config->archPath(path);
break;
case 3:
path = Overlays::SelectDir(config->shortcut(), Lang::get("SELECT_DIR"), store);
if (path != "") config->shortcut(path);
break;
}
}
}
+12 -3
View File
@@ -39,10 +39,19 @@ static bool firstStart = true;
Initialize a store.
const std::string &file: The UniStore file.
const std::string &file2: The UniStore file.. without full path.
bool ARGMode: If Argument mode.
*/
Store::Store(const std::string &file) {
this->update(file);
this->SetC2DBGImage();
Store::Store(const std::string &file, const std::string &file2, bool ARGMode) {
this->fileName = file2;
if (!ARGMode) {
this->update(file);
this->SetC2DBGImage();
} else {
this->LoadFromFile(file);
}
};
/*