USB waiting threading so we can increase buffer timeouts
This commit is contained in:
parent
d1dde4df5d
commit
7ed1f78234
@ -12,8 +12,8 @@ namespace inst::ui {
|
||||
void startUsb();
|
||||
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
|
||||
TextBlock::Ref pageInfoText;
|
||||
private:
|
||||
std::vector<std::string> ourTitles;
|
||||
private:
|
||||
std::vector<std::string> selectedTitles;
|
||||
std::string lastUrl;
|
||||
std::string lastFileID;
|
||||
@ -27,5 +27,6 @@ namespace inst::ui {
|
||||
Image::Ref infoImage;
|
||||
void drawMenuItems(bool clearItems);
|
||||
void selectTitle(int selectedIndex);
|
||||
void waitForList();
|
||||
};
|
||||
}
|
3
include/usbInstall.hpp
Normal file → Executable file
3
include/usbInstall.hpp
Normal file → Executable file
@ -3,6 +3,7 @@
|
||||
#include <string>
|
||||
|
||||
namespace usbInstStuff {
|
||||
std::vector<std::string> OnSelected();
|
||||
int OnSelected(void* in);
|
||||
void installTitleUsb(std::vector<std::string> ourNspList, int ourStorage);
|
||||
extern bool stopThread;
|
||||
}
|
@ -43,7 +43,7 @@ namespace tin::install::nsp
|
||||
while (sizeRemaining)
|
||||
{
|
||||
tmpSizeRead = usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000));
|
||||
if (tmpSizeRead == 0) THROW_FORMAT("USB error");
|
||||
if (tmpSizeRead == 0) THROW_FORMAT("USB transfer timed out or failed");
|
||||
sizeRemaining -= tmpSizeRead;
|
||||
|
||||
while (true)
|
||||
@ -156,7 +156,7 @@ namespace tin::install::nsp
|
||||
LOG_DEBUG("buffering 0x%lx-0x%lx", offset, offset + size);
|
||||
tin::util::USBCmdHeader header = tin::util::USBCmdManager::SendFileRangeCmd(m_nspName, offset, size);
|
||||
u8* ourBuffer = (u8*)memalign(0x1000, header.dataSize);
|
||||
if (tin::util::USBRead(ourBuffer, header.dataSize) == 0) THROW_FORMAT("USB error");
|
||||
if (tin::util::USBRead(ourBuffer, header.dataSize) == 0) THROW_FORMAT("USB transfer timed out or failed");
|
||||
memcpy(buf, ourBuffer, header.dataSize);
|
||||
}
|
||||
}
|
@ -43,7 +43,7 @@ namespace tin::install::xci
|
||||
while (sizeRemaining)
|
||||
{
|
||||
tmpSizeRead = usbCommsRead(buf, std::min(sizeRemaining, (u64)0x800000));
|
||||
if (tmpSizeRead == 0) THROW_FORMAT("USB error");
|
||||
if (tmpSizeRead == 0) THROW_FORMAT("USB transfer timed out or failed");
|
||||
sizeRemaining -= tmpSizeRead;
|
||||
|
||||
while (true)
|
||||
@ -156,7 +156,7 @@ namespace tin::install::xci
|
||||
LOG_DEBUG("buffering 0x%lx-0x%lx", offset, offset + size);
|
||||
tin::util::USBCmdHeader header = tin::util::USBCmdManager::SendFileRangeCmd(m_xciName, offset, size);
|
||||
u8* ourBuffer = (u8*)memalign(0x1000, header.dataSize);
|
||||
if (tin::util::USBRead(ourBuffer, header.dataSize) == 0) THROW_FORMAT("USB error");
|
||||
if (tin::util::USBRead(ourBuffer, header.dataSize) == 0) THROW_FORMAT("USB transfer timed out or failed");
|
||||
memcpy(buf, ourBuffer, header.dataSize);
|
||||
}
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
#include <threads.h>
|
||||
#include "ui/usbInstPage.hpp"
|
||||
#include "ui/MainApplication.hpp"
|
||||
#include "util/util.hpp"
|
||||
@ -64,16 +65,22 @@ namespace inst::ui {
|
||||
this->drawMenuItems(false);
|
||||
}
|
||||
|
||||
void usbInstPage::startUsb() {
|
||||
this->pageInfoText->SetText("USB connection successful! Waiting for list of files to be sent...");
|
||||
this->butText->SetText("\ue0e2 Help \ue0e1 Cancel ");
|
||||
this->menu->SetVisible(false);
|
||||
this->menu->ClearItems();
|
||||
this->infoImage->SetVisible(true);
|
||||
mainApp->LoadLayout(mainApp->usbinstPage);
|
||||
mainApp->CallForRender();
|
||||
this->ourTitles = usbInstStuff::OnSelected();
|
||||
if (!this->ourTitles.size()) {
|
||||
void usbInstPage::waitForList() {
|
||||
thrd_t usbThread;
|
||||
thrd_create(&usbThread, usbInstStuff::OnSelected, 0);
|
||||
while(!this->ourTitles.size()) {
|
||||
hidScanInput();
|
||||
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
if (kDown & KEY_B) {
|
||||
usbInstStuff::stopThread = true;
|
||||
thrd_join(usbThread, NULL);
|
||||
mainApp->LoadLayout(mainApp->mainPage);
|
||||
return;
|
||||
};
|
||||
if (kDown & KEY_X) inst::ui::mainApp->CreateShowDialog("Help", "Files can be installed over USB from other devices using tools such as\nns-usbloader in Tinfoil mode. To send files to your Switch, open one of\nthese pieces of software on your PC, select your files, then upload to\nyour console!\n\nUnfortunately USB installations require a specific setup on some\nplatforms, and can be rather buggy at times. If you can't figure it out,\ngive LAN/internet installs a try, or copy your files to your SD card and\ntry the \"Install from SD Card\" option on the main menu!", {"OK"}, true);
|
||||
}
|
||||
|
||||
if (this->ourTitles[0] == "errorOccured") {
|
||||
mainApp->LoadLayout(mainApp->mainPage);
|
||||
return;
|
||||
} else {
|
||||
@ -87,6 +94,18 @@ namespace inst::ui {
|
||||
return;
|
||||
}
|
||||
|
||||
void usbInstPage::startUsb() {
|
||||
this->ourTitles = {};
|
||||
this->pageInfoText->SetText("USB connection successful! Waiting for list of files to be sent...");
|
||||
this->butText->SetText("\ue0e2 Help \ue0e1 Cancel ");
|
||||
this->menu->SetVisible(false);
|
||||
this->menu->ClearItems();
|
||||
this->infoImage->SetVisible(true);
|
||||
mainApp->LoadLayout(mainApp->usbinstPage);
|
||||
mainApp->CallForRender();
|
||||
this->waitForList();
|
||||
}
|
||||
|
||||
void usbInstPage::startInstall() {
|
||||
int dialogResult = -1;
|
||||
if (this->selectedTitles.size() == 1) dialogResult = mainApp->CreateShowDialog("Where should " + inst::util::shortenString(inst::util::formatUrlString(this->selectedTitles[0]), 32, true) + " be installed to?", "Press B to cancel", {"SD Card", "Internal Storage"}, false);
|
||||
|
@ -20,9 +20,15 @@ namespace inst::ui {
|
||||
mainApp->usbinstPage->pageInfoText->SetText(ourText);
|
||||
mainApp->CallForRender();
|
||||
}
|
||||
|
||||
void setUsbTitleList(std::vector<std::string> ourText){
|
||||
mainApp->usbinstPage->ourTitles = ourText;
|
||||
}
|
||||
}
|
||||
|
||||
namespace usbInstStuff {
|
||||
bool stopThread;
|
||||
|
||||
struct TUSHeader
|
||||
{
|
||||
u32 magic; // TUL0 (Tinfoil Usb List 0)
|
||||
@ -30,27 +36,22 @@ namespace usbInstStuff {
|
||||
u64 padding;
|
||||
} PACKED;
|
||||
|
||||
std::vector<std::string> OnSelected() {
|
||||
Result rc = 0;
|
||||
|
||||
while(true) {
|
||||
rc = usbDsWaitReady(1000000);
|
||||
if (R_SUCCEEDED(rc)) break;
|
||||
else if ((rc & 0x3FFFFF) != 0xEA01)
|
||||
return {};
|
||||
}
|
||||
int OnSelected(void* in) {
|
||||
usbInstStuff::stopThread = false;
|
||||
|
||||
TUSHeader header;
|
||||
while(true) {
|
||||
if (tin::util::USBRead(&header, sizeof(TUSHeader)) != 0) break;
|
||||
hidScanInput();
|
||||
u64 kDown = hidKeysDown(CONTROLLER_P1_AUTO);
|
||||
if (kDown & KEY_B) return {};
|
||||
if (kDown & KEY_X) inst::ui::mainApp->CreateShowDialog("Help", "Files can be installed over USB from other devices using tools such as\nns-usbloader in Tinfoil mode. To send files to your Switch, open one of\nthese pieces of software on your PC, select your files, then upload to\nyour console!\n\nUnfortunately USB installations require a specific setup on some\nplatforms, and can be rather buggy at times. If you can't figure it out,\ngive LAN/internet installs a try, or copy your files to your SD card and\ntry the \"Install from SD Card\" option on the main menu!", {"OK"}, true);
|
||||
if (inst::util::getUsbState() != 5) return {};
|
||||
if (inst::util::getUsbState() != 5 || usbInstStuff::stopThread) {
|
||||
inst::ui::setUsbTitleList({"errorOccured"});
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (header.magic != 0x304C5554) return {};
|
||||
if (header.magic != 0x304C5554) {
|
||||
inst::ui::setUsbTitleList({"errorOccured"});
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto titleListBuf = std::make_unique<char[]>(header.titleListSize+1);
|
||||
std::vector<std::string> titleNames;
|
||||
@ -65,7 +66,8 @@ namespace usbInstStuff {
|
||||
titleNames.push_back(segment);
|
||||
}
|
||||
|
||||
return titleNames;
|
||||
inst::ui::setUsbTitleList(titleNames);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void installTitleUsb(std::vector<std::string> ourTitleList, int ourStorage)
|
||||
|
Reference in New Issue
Block a user