139 lines
6.0 KiB
C++
139 lines
6.0 KiB
C++
#include <MainApplication.hpp>
|
|
#include <stdio.h>
|
|
#include <main.hpp>
|
|
#include <const.h>
|
|
#include <client.hpp>
|
|
#include <server.hpp>
|
|
#include <TransferOverlay.hpp>
|
|
|
|
static std::vector<uint64_t> accSids, devSids, bcatSids, cacheSids;
|
|
|
|
namespace ui {
|
|
extern MainApplication *mainApp;
|
|
void TitlesLayout::InitTitles() {
|
|
Logger::getInstance().log(Logger::INFO, "InitTitles");
|
|
|
|
auto it = this->menuCache.find(g_currentUId);
|
|
if (it != this->menuCache.end()) {
|
|
this->titlesMenu = it->second;
|
|
} else {
|
|
auto menu = pu::ui::elm::Menu::New(0, 0, 1280, COLOR("#67000000"), COLOR("#170909FF"), 94, 7);
|
|
for (size_t i = 0; i < getTitleCount(g_currentUId); i++) {
|
|
Title title;
|
|
getTitle(title, g_currentUId, i);
|
|
auto titleItem = pu::ui::elm::MenuItem::New(title.name().c_str());
|
|
titleItem->SetColor(COLOR("#FFFFFFFF"));
|
|
menu->AddItem(titleItem);
|
|
}
|
|
this->menuCache.emplace(g_currentUId, menu);
|
|
this->titlesMenu = menu;
|
|
}
|
|
|
|
this->Clear();
|
|
this->Add(this->titlesMenu);
|
|
|
|
this->SetBackgroundColor(BACKGROUND_COLOR);
|
|
}
|
|
|
|
void TitlesLayout::onInput(u64 Down, u64 Up, u64 Held, pu::ui::TouchPoint Pos) {
|
|
if (m_inputLocked) return;
|
|
|
|
if (Down & HidNpadButton_B) {
|
|
mainApp->LoadLayout(mainApp->usersLayout);
|
|
return;
|
|
}
|
|
|
|
if (Down & HidNpadButton_Plus) {
|
|
cancelClientTransfer();
|
|
cancelServerTransfer();
|
|
mainApp->Close();
|
|
return;
|
|
}
|
|
|
|
if (Down & HidNpadButton_A) {
|
|
auto index = this->titlesMenu->GetSelectedIndex();
|
|
Title title;
|
|
getTitle(title, g_currentUId, index);
|
|
printf("userid is 0x%lX%lX\n", title.userId().uid[1], title.userId().uid[0]);
|
|
// printf("current game index is %i\n", index);
|
|
int opt = mainApp->CreateShowDialog(title.name().c_str(), "What do you want?", { "Transfer", "Receive" }, false);
|
|
printf("opt is %i\n", opt);
|
|
switch (opt) {
|
|
case 0: {
|
|
// Transfer selected
|
|
{
|
|
auto ovl = TransferOverlay::New("Transferring save data...");
|
|
this->titlesMenu->SetVisible(false);
|
|
mainApp->StartOverlay(ovl);
|
|
this->LockInput();
|
|
if (transfer_files(index, g_currentUId) != 0) {
|
|
mainApp->EndOverlay();
|
|
this->titlesMenu->SetVisible(true);
|
|
this->UnlockInput();
|
|
mainApp->CreateShowDialog("Transfer", "Failed to start transfer.", {"OK"}, true);
|
|
break;
|
|
}
|
|
while (!isClientTransferDone()) {
|
|
ovl->SetStatus(getClientStatusText());
|
|
ovl->SetProgressVisible(isClientProgressKnown());
|
|
ovl->SetProgress(getClientProgress());
|
|
mainApp->CallForRender();
|
|
if (mainApp->GetButtonsDown() & HidNpadButton_B) {
|
|
cancelClientTransfer();
|
|
}
|
|
svcSleepThread(16666666LL);
|
|
}
|
|
mainApp->EndOverlay();
|
|
this->titlesMenu->SetVisible(true);
|
|
this->UnlockInput();
|
|
}
|
|
if (isClientConnectionFailed()) {
|
|
mainApp->CreateShowDialog("Transfer", getClientFailReason(), {"OK"}, true);
|
|
} else if (isClientTransferCancelled()) {
|
|
mainApp->CreateShowDialog("Transfer", "Transfer cancelled.", {"OK"}, true);
|
|
} else {
|
|
mainApp->CreateShowDialog("Transfer", "Save data sent successfully!", {"OK"}, true);
|
|
}
|
|
break;
|
|
}
|
|
case 1: {
|
|
// Receive selected
|
|
if (startSendingThread() != 0) {
|
|
mainApp->CreateShowDialog("Receive", "Failed to start receiver.\nCheck network connection.", {"OK"}, true);
|
|
break;
|
|
}
|
|
{
|
|
auto ovl = TransferOverlay::New("Receiving save data...");
|
|
this->titlesMenu->SetVisible(false);
|
|
mainApp->StartOverlay(ovl);
|
|
this->LockInput();
|
|
while (!isServerTransferDone()) {
|
|
ovl->SetStatus(getServerStatusText());
|
|
ovl->SetProgress(getServerProgress());
|
|
mainApp->CallForRender();
|
|
if (mainApp->GetButtonsDown() & HidNpadButton_B) {
|
|
cancelServerTransfer();
|
|
}
|
|
svcSleepThread(16666666LL);
|
|
}
|
|
mainApp->EndOverlay();
|
|
this->titlesMenu->SetVisible(true);
|
|
this->UnlockInput();
|
|
}
|
|
if (isServerTransferCancelled()) {
|
|
mainApp->CreateShowDialog("Receive", "Transfer cancelled.", {"OK"}, true);
|
|
break;
|
|
}
|
|
auto restoreResult = io::restore(index, g_currentUId, 0, title.name());
|
|
if (std::get<0>(restoreResult)) {
|
|
mainApp->CreateShowDialog("Receive", "Save data received and restored successfully!", {"OK"}, true);
|
|
} else {
|
|
mainApp->CreateShowDialog("Receive", "Restore failed:\n" + std::get<2>(restoreResult), {"OK"}, true);
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|