Checkpoint/3ds/source/main.cpp

147 lines
3.2 KiB
C++
Raw Normal View History

2017-09-29 07:45:56 +00:00
/* This file is part of Checkpoint
2018-01-17 07:53:50 +00:00
> Copyright (C) 2017/2018 Bernardo Giordano
2017-09-29 07:45:56 +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/>.
> See LICENSE for information.
*/
#include "common.h"
int main() {
servicesInit();
2017-10-04 11:19:10 +00:00
int selectionTimer = 0;
int refreshTimer = 0;
2017-09-29 07:45:56 +00:00
createThread((ThreadFunc)threadLoadTitles);
while (aptMainLoop() && !(hidKeysDown() & KEY_START)) {
hidScanInput();
if (hidKeysDown() & KEY_A)
{
2018-01-21 09:20:28 +00:00
GUI_setBottomScroll(true);
GUI_updateButtonsColor();
setEntryType(CELLS);
2017-09-29 07:45:56 +00:00
}
if (hidKeysDown() & KEY_B)
{
2018-01-21 09:20:28 +00:00
GUI_setBottomScroll(false);
GUI_updateButtonsColor();
2017-09-29 07:45:56 +00:00
setEntryType(TITLES);
2018-01-21 09:20:28 +00:00
GUI_clearSelectedEntries();
2017-09-29 07:45:56 +00:00
}
2017-09-29 20:58:55 +00:00
if (hidKeysDown() & KEY_X)
{
2018-01-21 09:20:28 +00:00
if (GUI_getBottomScroll())
2017-12-23 14:29:53 +00:00
{
bool isSaveMode = getMode() == MODE_SAVE;
2018-01-21 09:20:28 +00:00
size_t index = GUI_getScrollableIndex();
2017-12-23 14:29:53 +00:00
// avoid actions if X is pressed on "New..."
2018-01-22 07:55:32 +00:00
if (index > 0 && GUI_askForConfirmation("Delete selected backup?"))
2017-12-23 14:29:53 +00:00
{
2018-01-22 07:55:32 +00:00
Title title;
getTitle(title, GUI_getFullIndex());
std::vector<std::u16string> list = isSaveMode ? title.getDirectories() : title.getExtdatas();
std::u16string basepath = isSaveMode ? title.getBackupPath() : title.getExtdataPath();
deleteBackupFolder(basepath + u8tou16("/") + list.at(index));
refreshDirectories(title.getId());
GUI_setScrollableIndex(index - 1);
2017-12-23 14:29:53 +00:00
}
}
else
{
2018-01-21 09:20:28 +00:00
GUI_resetIndex();
2017-12-23 14:29:53 +00:00
setMode(getMode() == MODE_SAVE ? MODE_EXTDATA : MODE_SAVE);
2018-01-21 09:20:28 +00:00
GUI_clearSelectedEntries();
2017-12-23 14:29:53 +00:00
}
2017-09-29 20:58:55 +00:00
}
if (hidKeysDown() & KEY_Y)
{
2018-01-21 09:20:28 +00:00
GUI_addSelectedEntry(GUI_getFullIndex());
}
2017-10-04 11:19:10 +00:00
if (hidKeysHeld() & KEY_Y)
{
selectionTimer++;
}
else
{
selectionTimer = 0;
}
if (selectionTimer > 90)
{
2018-01-21 09:20:28 +00:00
GUI_clearSelectedEntries();
2017-10-04 11:19:10 +00:00
for (size_t i = 0, sz = getTitlesCount(); i < sz; i++)
{
2018-01-21 09:20:28 +00:00
GUI_addSelectedEntry(i);
2017-10-04 11:19:10 +00:00
}
selectionTimer = 0;
}
if (hidKeysHeld() & KEY_B)
{
refreshTimer++;
}
else
{
refreshTimer = 0;
}
if (refreshTimer > 90)
{
createThread((ThreadFunc)threadLoadTitles);
refreshTimer = 0;
}
2017-10-04 11:19:10 +00:00
2018-01-21 09:20:28 +00:00
if (GUI_isBackupReleased())
2017-09-29 07:45:56 +00:00
{
2018-01-21 09:20:28 +00:00
if (GUI_multipleSelectionEnabled())
{
2018-01-21 09:20:28 +00:00
GUI_resetDirectoryListIndex();
std::vector<size_t> list = GUI_getSelectedEntries();
for (size_t i = 0, sz = list.size(); i < sz; i++)
{
backup(list.at(i));
}
2018-01-21 09:20:28 +00:00
GUI_clearSelectedEntries();
}
else
{
2018-01-21 09:20:28 +00:00
backup(GUI_getFullIndex());
}
2017-09-29 07:45:56 +00:00
}
2018-01-21 09:20:28 +00:00
if (GUI_isRestoreReleased())
2017-09-29 07:45:56 +00:00
{
2018-01-21 09:20:28 +00:00
if (GUI_multipleSelectionEnabled())
2017-10-04 11:19:10 +00:00
{
2018-01-21 09:20:28 +00:00
GUI_clearSelectedEntries();
2017-10-04 11:19:10 +00:00
}
else
{
2018-01-21 09:20:28 +00:00
restore(GUI_getFullIndex());
2017-10-04 11:19:10 +00:00
}
2017-09-29 07:45:56 +00:00
}
2018-01-21 09:20:28 +00:00
GUI_updateSelector();
GUI_draw();
2017-09-29 07:45:56 +00:00
}
destroyThreads();
servicesExit();
}