2018-05-09 09:25:01 +00:00
|
|
|
/*
|
|
|
|
* This file is part of Checkpoint
|
2019-03-07 20:15:24 +00:00
|
|
|
* Copyright (C) 2017-2019 Bernardo Giordano, FlagBrew
|
2018-05-09 09:25:01 +00:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2018-06-10 20:24:37 +00:00
|
|
|
#include "main.hpp"
|
|
|
|
|
|
|
|
u128 g_currentUId = 0;
|
2019-04-12 21:39:55 +00:00
|
|
|
bool g_backupScrollEnabled = 0;
|
2018-05-09 09:25:01 +00:00
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
|
|
|
Result res = servicesInit();
|
|
|
|
if (R_FAILED(res))
|
|
|
|
{
|
|
|
|
servicesExit();
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
2018-09-03 19:35:35 +00:00
|
|
|
loadTitles();
|
2019-04-12 21:39:55 +00:00
|
|
|
// get the user IDs
|
|
|
|
std::vector<u128> userIds = Account::ids();
|
|
|
|
// set g_currentUId to a default user in case we loaded at least one user
|
|
|
|
if (g_currentUId == 0) g_currentUId = userIds.at(0);
|
2018-05-09 09:25:01 +00:00
|
|
|
|
|
|
|
int selectionTimer = 0;
|
|
|
|
while(appletMainLoop() && !(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_PLUS))
|
|
|
|
{
|
|
|
|
hidScanInput();
|
|
|
|
u32 kdown = hidKeysDown(CONTROLLER_P1_AUTO);
|
2018-12-16 14:27:48 +00:00
|
|
|
u32 kheld = hidKeysHeld(CONTROLLER_P1_AUTO);
|
2019-04-12 21:39:55 +00:00
|
|
|
if (kdown & KEY_ZL || kdown & KEY_ZR)
|
2018-06-11 20:41:37 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
while((g_currentUId = Account::selectAccount()) == 0);
|
2018-06-15 14:13:15 +00:00
|
|
|
Gui::index(TITLES, 0);
|
2018-10-17 19:44:14 +00:00
|
|
|
Gui::index(CELLS, 0);
|
2018-12-16 14:27:48 +00:00
|
|
|
Gui::setPKSMBridgeFlag(false);
|
|
|
|
}
|
|
|
|
// handle PKSM bridge
|
|
|
|
if (Configuration::getInstance().isPKSMBridgeEnabled())
|
|
|
|
{
|
|
|
|
Title title;
|
|
|
|
getTitle(title, g_currentUId, Gui::index(TITLES));
|
|
|
|
if (!Gui::getPKSMBridgeFlag())
|
|
|
|
{
|
|
|
|
if ((kheld & KEY_L) && (kheld & KEY_R) && isPKSMBridgeTitle(title.id()))
|
|
|
|
{
|
|
|
|
Gui::setPKSMBridgeFlag(true);
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons();
|
2018-12-16 14:27:48 +00:00
|
|
|
}
|
|
|
|
}
|
2018-06-11 20:41:37 +00:00
|
|
|
}
|
|
|
|
|
2018-06-12 14:01:38 +00:00
|
|
|
// handle touchscreen
|
|
|
|
touchPosition touch;
|
|
|
|
hidTouchRead(&touch, 0);
|
2019-04-12 21:39:55 +00:00
|
|
|
if (!g_backupScrollEnabled &&
|
|
|
|
hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
|
|
|
|
touch.px >= 1200 && touch.px <= 1200 + USER_ICON_SIZE &&
|
|
|
|
touch.py >= 626 && touch.py <= 626 + USER_ICON_SIZE)
|
2018-06-12 14:01:38 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
while ((g_currentUId = Account::selectAccount()) == 0);
|
|
|
|
Gui::index(TITLES, 0);
|
|
|
|
Gui::index(CELLS, 0);
|
|
|
|
Gui::setPKSMBridgeFlag(false);
|
2018-06-12 14:01:38 +00:00
|
|
|
}
|
|
|
|
|
2018-09-09 19:10:25 +00:00
|
|
|
// Handle touching the backup list
|
|
|
|
if ((hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
|
2019-04-12 21:39:55 +00:00
|
|
|
(int)touch.px > 538 &&
|
|
|
|
(int)touch.px < 952 &&
|
|
|
|
(int)touch.py > 276 &&
|
|
|
|
(int)touch.py < 656))
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2018-09-09 19:10:25 +00:00
|
|
|
// Activate backup list only if multiple selections are enabled
|
2019-04-21 09:41:51 +00:00
|
|
|
if (!MS::multipleSelectionEnabled())
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
g_backupScrollEnabled = true;
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons();
|
2018-09-09 19:10:25 +00:00
|
|
|
Gui::entryType(CELLS);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Handle pressing A
|
|
|
|
// Backup list active: Backup/Restore
|
|
|
|
// Backup list inactive: Activate backup list only if multiple
|
2019-04-12 21:39:55 +00:00
|
|
|
// selections are enabled
|
2018-09-09 19:10:25 +00:00
|
|
|
if (kdown & KEY_A)
|
|
|
|
{
|
|
|
|
// If backup list is active...
|
2019-04-12 21:39:55 +00:00
|
|
|
if (g_backupScrollEnabled)
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
|
|
|
// If the "New..." entry is selected...
|
|
|
|
if (0 == Gui::index(CELLS))
|
|
|
|
{
|
2018-12-16 22:29:26 +00:00
|
|
|
if (!Gui::getPKSMBridgeFlag())
|
|
|
|
{
|
|
|
|
io::backup(Gui::index(TITLES), g_currentUId);
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2018-12-16 22:29:26 +00:00
|
|
|
if (Gui::getPKSMBridgeFlag())
|
|
|
|
{
|
|
|
|
recvFromPKSMBridge(Gui::index(TITLES), g_currentUId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
io::restore(Gui::index(TITLES), g_currentUId);
|
2018-12-16 22:29:26 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Activate backup list only if multiple selections are not enabled
|
2019-04-21 09:41:51 +00:00
|
|
|
if (!MS::multipleSelectionEnabled())
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
g_backupScrollEnabled = true;
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons();
|
2018-09-09 19:10:25 +00:00
|
|
|
Gui::entryType(CELLS);
|
|
|
|
}
|
|
|
|
}
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
|
|
|
// Handle pressing B
|
2018-07-17 19:42:49 +00:00
|
|
|
if (kdown & KEY_B ||
|
|
|
|
(hidKeysDown(CONTROLLER_P1_AUTO) & KEY_TOUCH &&
|
2019-04-12 21:39:55 +00:00
|
|
|
(int)touch.px >= 0 &&
|
|
|
|
(int)touch.px <= 532 &&
|
|
|
|
(int)touch.py >= 0 &&
|
|
|
|
(int)touch.py <= 664))
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2018-07-17 16:25:07 +00:00
|
|
|
Gui::index(CELLS, 0);
|
2019-04-12 21:39:55 +00:00
|
|
|
g_backupScrollEnabled = false;
|
2018-05-30 20:56:19 +00:00
|
|
|
Gui::entryType(TITLES);
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-12-16 14:27:48 +00:00
|
|
|
Gui::setPKSMBridgeFlag(false);
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons(); // Do this last
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
|
2019-04-12 21:39:55 +00:00
|
|
|
// Handle pressing X
|
2018-05-09 09:25:01 +00:00
|
|
|
if (kdown & KEY_X)
|
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
if (g_backupScrollEnabled)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
|
|
|
size_t index = Gui::index(CELLS);
|
|
|
|
if (index > 0 && Gui::askForConfirmation("Delete selected backup?"))
|
|
|
|
{
|
|
|
|
Title title;
|
2018-06-10 20:24:37 +00:00
|
|
|
getTitle(title, g_currentUId, Gui::index(TITLES));
|
2018-07-17 16:25:07 +00:00
|
|
|
std::string path = title.fullPath(index);
|
2018-09-03 19:35:35 +00:00
|
|
|
io::deleteFolderRecursively((path + "/").c_str());
|
2018-05-09 09:25:01 +00:00
|
|
|
refreshDirectories(title.id());
|
2018-09-09 19:10:25 +00:00
|
|
|
Gui::index(CELLS, index - 1);
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-09 19:10:25 +00:00
|
|
|
// Handle pressing Y
|
|
|
|
// Backup list active: Deactivate backup list, select title, and
|
2019-04-12 21:39:55 +00:00
|
|
|
// enable backup button
|
2018-09-09 19:10:25 +00:00
|
|
|
// Backup list inactive: Select title and enable backup button
|
|
|
|
if (kdown & KEY_Y)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
if (g_backupScrollEnabled)
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
|
|
|
Gui::index(CELLS, 0);
|
2019-04-12 21:39:55 +00:00
|
|
|
g_backupScrollEnabled = false;
|
2018-09-09 19:10:25 +00:00
|
|
|
}
|
|
|
|
Gui::entryType(TITLES);
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::addSelectedEntry(Gui::index(TITLES));
|
2018-12-16 14:27:48 +00:00
|
|
|
Gui::setPKSMBridgeFlag(false);
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons(); // Do this last
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
|
|
|
// Handle holding Y
|
2019-04-12 21:39:55 +00:00
|
|
|
if (hidKeysHeld(CONTROLLER_P1_AUTO) & KEY_Y && !(g_backupScrollEnabled))
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
|
|
|
selectionTimer++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectionTimer = 0;
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-07-16 14:00:34 +00:00
|
|
|
if (selectionTimer > 45)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-06-10 20:24:37 +00:00
|
|
|
for (size_t i = 0, sz = getTitleCount(g_currentUId); i < sz; i++)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::addSelectedEntry(i);
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
selectionTimer = 0;
|
|
|
|
}
|
|
|
|
|
2018-09-09 19:10:25 +00:00
|
|
|
// Handle pressing/touching L
|
|
|
|
if (Gui::isBackupReleased() || (kdown & KEY_L))
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
if (MS::multipleSelectionEnabled())
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
|
|
|
Gui::resetIndex(CELLS);
|
2019-04-21 09:41:51 +00:00
|
|
|
std::vector<size_t> list = MS::selectedEntries();
|
2018-05-09 09:25:01 +00:00
|
|
|
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
|
|
|
{
|
2018-06-10 20:24:37 +00:00
|
|
|
io::backup(list.at(i), g_currentUId);
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-12-17 19:18:43 +00:00
|
|
|
Gui::updateButtons();
|
2019-05-06 18:55:04 +00:00
|
|
|
blinkLed(4);
|
2019-04-12 21:39:55 +00:00
|
|
|
Gui::showInfo("Progress correctly saved to disk.");
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
2019-04-12 21:39:55 +00:00
|
|
|
else if (g_backupScrollEnabled)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2018-12-16 14:27:48 +00:00
|
|
|
if (Gui::getPKSMBridgeFlag())
|
|
|
|
{
|
|
|
|
sendToPKSMBrigde(Gui::index(TITLES), g_currentUId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io::backup(Gui::index(TITLES), g_currentUId);
|
|
|
|
}
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
|
|
|
// Handle pressing/touching R
|
|
|
|
if (Gui::isRestoreReleased() || (kdown & KEY_R))
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
if (g_backupScrollEnabled)
|
2018-05-09 09:25:01 +00:00
|
|
|
{
|
2018-12-16 22:29:26 +00:00
|
|
|
if (Gui::getPKSMBridgeFlag())
|
|
|
|
{
|
|
|
|
recvFromPKSMBridge(Gui::index(TITLES), g_currentUId);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-04-12 21:39:55 +00:00
|
|
|
io::restore(Gui::index(TITLES), g_currentUId);
|
2018-12-16 22:29:26 +00:00
|
|
|
}
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-05-04 10:54:56 +00:00
|
|
|
if ((Gui::isCheatReleased() || (hidKeysDown(CONTROLLER_P1_AUTO) & KEY_RSTICK)) && CheatManager::loaded())
|
2019-04-12 21:39:55 +00:00
|
|
|
{
|
2019-05-01 10:23:03 +00:00
|
|
|
if (MS::multipleSelectionEnabled())
|
|
|
|
{
|
|
|
|
MS::clearSelectedEntries();
|
|
|
|
Gui::updateButtons();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Title title;
|
|
|
|
getTitle(title, g_currentUId, Gui::index(TITLES));
|
|
|
|
std::string key = StringUtils::format("%016llX", title.id());
|
|
|
|
if (CheatManager::availableCodes(key))
|
|
|
|
{
|
|
|
|
CheatManager::manageCheats(key);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gui::showInfo("No available cheat codes for this title.");
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 21:39:55 +00:00
|
|
|
}
|
|
|
|
|
2018-05-09 09:25:01 +00:00
|
|
|
Gui::updateSelector();
|
2019-04-30 19:24:44 +00:00
|
|
|
Gui::draw();
|
2019-04-12 21:39:55 +00:00
|
|
|
|
|
|
|
// poll server
|
|
|
|
Configuration::getInstance().pollServer();
|
2018-05-09 09:25:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
servicesExit();
|
|
|
|
return 0;
|
|
|
|
}
|