2018-05-14 06:52:41 +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-14 06:52:41 +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.
|
2017-09-29 07:45:56 +00:00
|
|
|
*/
|
|
|
|
|
2019-04-21 16:05:26 +00:00
|
|
|
#include "main.hpp"
|
2017-09-29 07:45:56 +00:00
|
|
|
|
|
|
|
int main() {
|
2018-12-14 21:14:05 +00:00
|
|
|
if (R_FAILED(servicesInit())) {
|
|
|
|
servicesExit();
|
|
|
|
return -1;
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
int selectionTimer = 0;
|
|
|
|
int refreshTimer = 0;
|
|
|
|
Threads::create((ThreadFunc)Threads::titles);
|
2017-09-29 07:45:56 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
u32 kHeld, kDown = hidKeysDown();
|
|
|
|
while (aptMainLoop() && !(kDown & KEY_START)) {
|
2018-05-14 06:52:41 +00:00
|
|
|
hidScanInput();
|
2018-05-25 17:52:44 +00:00
|
|
|
kDown = hidKeysDown();
|
|
|
|
kHeld = hidKeysHeld();
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2019-03-07 20:13:15 +00:00
|
|
|
updateCard();
|
|
|
|
|
2018-09-09 19:10:25 +00:00
|
|
|
// Handle pressing A
|
|
|
|
// Backup list active: Backup/Restore
|
|
|
|
// Backup list inactive: Activate backup list only if multiple
|
|
|
|
// selections are enabled
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kDown & KEY_A)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2018-09-09 19:10:25 +00:00
|
|
|
// If backup list is active...
|
2019-04-21 16:05:26 +00:00
|
|
|
if (g_bottomScrollEnabled)
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
|
|
|
// If the "New..." entry is selected...
|
|
|
|
if (0 == Gui::scrollableIndex())
|
|
|
|
{
|
|
|
|
io::backup(Gui::index());
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
io::restore(Gui::index());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
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-21 16:05:26 +00:00
|
|
|
g_bottomScrollEnabled = true;
|
2019-04-22 10:40:06 +00:00
|
|
|
Gui::updateButtons();
|
2018-09-09 19:10:25 +00:00
|
|
|
}
|
|
|
|
}
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kDown & KEY_B)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2019-04-21 16:05:26 +00:00
|
|
|
g_bottomScrollEnabled = false;
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-05-28 20:05:13 +00:00
|
|
|
Gui::resetScrollableIndex();
|
2019-04-22 10:40:06 +00:00
|
|
|
Gui::updateButtons();
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kDown & KEY_X)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2019-04-21 16:05:26 +00:00
|
|
|
if (g_bottomScrollEnabled)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
|
|
|
bool isSaveMode = Archive::mode() == MODE_SAVE;
|
|
|
|
size_t index = Gui::scrollableIndex();
|
|
|
|
// avoid actions if X is pressed on "New..."
|
|
|
|
if (index > 0 && Gui::askForConfirmation("Delete selected backup?"))
|
|
|
|
{
|
|
|
|
Title title;
|
|
|
|
getTitle(title, Gui::index());
|
2018-06-01 15:57:35 +00:00
|
|
|
std::u16string path = isSaveMode ? title.fullSavePath(index) : title.fullExtdataPath(index);
|
|
|
|
io::deleteBackupFolder(path);
|
2018-05-14 06:52:41 +00:00
|
|
|
refreshDirectories(title.id());
|
|
|
|
Gui::scrollableIndex(index - 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Gui::resetIndex();
|
|
|
|
Archive::mode(Archive::mode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-06-01 14:58:42 +00:00
|
|
|
Gui::resetScrollableIndex();
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kDown & KEY_Y)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2019-04-21 16:05:26 +00:00
|
|
|
if (g_bottomScrollEnabled)
|
2018-09-09 19:10:25 +00:00
|
|
|
{
|
|
|
|
Gui::resetScrollableIndex();
|
2019-04-21 16:05:26 +00:00
|
|
|
g_bottomScrollEnabled = false;
|
2018-09-09 19:10:25 +00:00
|
|
|
}
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::addSelectedEntry(Gui::index());
|
2019-04-22 10:40:06 +00:00
|
|
|
Gui::updateButtons(); // Do this last
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kHeld & KEY_Y)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
|
|
|
selectionTimer++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
selectionTimer = 0;
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
if (selectionTimer > 90)
|
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-05-14 06:52:41 +00:00
|
|
|
for (size_t i = 0, sz = getTitleCount(); i < sz; i++)
|
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::addSelectedEntry(i);
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
|
|
|
selectionTimer = 0;
|
|
|
|
}
|
2017-10-14 18:26:47 +00:00
|
|
|
|
2018-05-25 17:52:44 +00:00
|
|
|
if (kHeld & KEY_B)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
|
|
|
refreshTimer++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
refreshTimer = 0;
|
|
|
|
}
|
2017-10-14 18:26:47 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
if (refreshTimer > 90)
|
|
|
|
{
|
2018-07-22 20:01:20 +00:00
|
|
|
Gui::resetIndex();
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2018-09-09 19:10:25 +00:00
|
|
|
Gui::resetScrollableIndex();
|
2018-05-14 06:52:41 +00:00
|
|
|
Threads::create((ThreadFunc)Threads::titles);
|
|
|
|
refreshTimer = 0;
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
|
|
|
if (Gui::isBackupReleased() || (kDown & KEY_L))
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
if (MS::multipleSelectionEnabled())
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
|
|
|
Gui::resetScrollableIndex();
|
2019-04-21 09:41:51 +00:00
|
|
|
std::vector<size_t> list = MS::selectedEntries();
|
2018-05-14 06:52:41 +00:00
|
|
|
for (size_t i = 0, sz = list.size(); i < sz; i++)
|
|
|
|
{
|
|
|
|
io::backup(list.at(i));
|
|
|
|
}
|
2019-04-21 09:41:51 +00:00
|
|
|
MS::clearSelectedEntries();
|
2019-04-22 10:40:06 +00:00
|
|
|
Gui::updateButtons();
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
2019-04-21 16:05:26 +00:00
|
|
|
else if (g_bottomScrollEnabled)
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
|
|
|
io::backup(Gui::index());
|
|
|
|
}
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
|
|
|
if (Gui::isRestoreReleased() || (kDown & KEY_R))
|
2018-05-14 06:52:41 +00:00
|
|
|
{
|
2019-04-21 09:41:51 +00:00
|
|
|
if (MS::multipleSelectionEnabled())
|
|
|
|
{
|
|
|
|
MS::clearSelectedEntries();
|
2019-04-22 10:40:06 +00:00
|
|
|
Gui::updateButtons();
|
2019-04-21 09:41:51 +00:00
|
|
|
}
|
2019-04-21 16:05:26 +00:00
|
|
|
else if (g_bottomScrollEnabled)
|
2019-04-21 09:41:51 +00:00
|
|
|
{
|
|
|
|
io::restore(Gui::index());
|
|
|
|
}
|
2018-05-14 06:52:41 +00:00
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2019-04-22 14:24:45 +00:00
|
|
|
if (Gui::isCheatReleased() && CheatManager::loaded())
|
2019-04-22 10:40:06 +00:00
|
|
|
{
|
2019-04-22 14:24:45 +00:00
|
|
|
if (MS::multipleSelectionEnabled())
|
|
|
|
{
|
|
|
|
MS::clearSelectedEntries();
|
|
|
|
Gui::updateButtons();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
Title title;
|
|
|
|
getTitle(title, Gui::index());
|
|
|
|
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-22 10:40:06 +00:00
|
|
|
}
|
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
Gui::updateSelector();
|
|
|
|
Gui::draw();
|
|
|
|
}
|
2018-09-09 19:10:25 +00:00
|
|
|
|
2018-05-14 06:52:41 +00:00
|
|
|
Threads::destroy();
|
|
|
|
servicesExit();
|
2018-05-26 07:36:00 +00:00
|
|
|
}
|