Remove usb hack, 16MB segment buffers, 2 segments for applet mode

This commit is contained in:
Huntereb 2019-12-15 20:24:16 -05:00
parent 620aee8266
commit 88be93d706
6 changed files with 18 additions and 109 deletions

View File

@ -31,7 +31,8 @@ SOFTWARE.
namespace tin::data
{
static const size_t BUFFER_SEGMENT_DATA_SIZE = 0x800000; // Approximately 8MB
static const size_t BUFFER_SEGMENT_DATA_SIZE = 0x1000000; // Approximately 16MB
extern int NUM_BUFFER_SEGMENTS;
struct BufferSegment
{
@ -40,7 +41,7 @@ namespace tin::data
u8 data[BUFFER_SEGMENT_DATA_SIZE] = {0};
};
// Receives data in a circular buffer split into 8MB segments
// Receives data in a circular buffer split into 16MB segments
class BufferedPlaceholderWriter
{
private:
@ -62,8 +63,6 @@ namespace tin::data
NcaWriter m_writer;
public:
static const int NUM_BUFFER_SEGMENTS = 4;
BufferedPlaceholderWriter(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId, size_t totalDataSize);
void AppendData(void* source, size_t length);

View File

@ -17,7 +17,7 @@ namespace inst::ui {
void onInput(u64 Down, u64 Up, u64 Held, pu::ui::Touch Pos);
Image::Ref awooImage;
private:
bool dialogAck;
bool appletThreadFinished;
TextBlock::Ref butText;
Rectangle::Ref topRect;
Rectangle::Ref botRect;

View File

@ -31,6 +31,8 @@ SOFTWARE.
namespace tin::data
{
int NUM_BUFFER_SEGMENTS;
BufferedPlaceholderWriter::BufferedPlaceholderWriter(std::shared_ptr<nx::ncm::ContentStorage>& contentStorage, NcmContentId ncaId, size_t totalDataSize) :
m_totalDataSize(totalDataSize), m_contentStorage(contentStorage), m_ncaId(ncaId), m_writer(ncaId, contentStorage)
{
@ -148,7 +150,7 @@ namespace tin::data
{
u32 numSegmentsRequired = this->CalcNumSegmentsRequired(size);
if (numSegmentsRequired > NUM_BUFFER_SEGMENTS)
if ((int)numSegmentsRequired > NUM_BUFFER_SEGMENTS)
return false;
for (unsigned int i = 0; i < numSegmentsRequired; i++)

View File

@ -93,54 +93,6 @@ namespace tin::install::nsp
return 0;
}
int USBThreadFuncNcz(void* in) // nczs corrupt with ranges over 8MB
{
USBFuncArgs* args = reinterpret_cast<USBFuncArgs*>(in);
u8* buf = (u8*)memalign(0x1000, 0x1000000);
tin::util::USBCmdHeader header;
u64 sizeRemaining = args->ncaSize;
size_t tmpSizeRead = 0;
u64 curOffset = 0;
u64 curRequestLeft = 0;
u64 reqSize = 0;
u64 readSize = 0;
try
{
while (sizeRemaining && !stopThreadsUsbNsp)
{
if (!curRequestLeft) {
reqSize = std::min(sizeRemaining, (u64)0x1000000);
header = tin::util::USBCmdManager::SendFileRangeCmd(args->nspName, args->pfs0Offset + curOffset, reqSize);
curRequestLeft = header.dataSize;
}
readSize = std::min(curRequestLeft, (u64)0x1000000);
tmpSizeRead = awoo_usbCommsRead(buf, readSize);
if (tmpSizeRead == 0) THROW_FORMAT("USB transfer timed out or failed");
curOffset += tmpSizeRead;
sizeRemaining -= tmpSizeRead;
curRequestLeft -= tmpSizeRead;
while (true)
{
if (args->bufferedPlaceholderWriter->CanAppendData(tmpSizeRead))
break;
}
args->bufferedPlaceholderWriter->AppendData(buf, tmpSizeRead);
}
}
catch (std::exception& e)
{
stopThreadsUsbNsp = true;
errorMessageUsbNsp = e.what();
}
free(buf);
return 0;
}
int USBPlaceholderWriteFunc(void* in)
{
USBFuncArgs* args = reinterpret_cast<USBFuncArgs*>(in);
@ -172,8 +124,7 @@ namespace tin::install::nsp
thrd_t writeThread;
stopThreadsUsbNsp = false;
if (m_nspName.substr(m_nspName.size() - 1, 1) == "z") thrd_create(&usbThread, USBThreadFuncNcz, &args);
else thrd_create(&usbThread, USBThreadFunc, &args);
thrd_create(&usbThread, USBThreadFunc, &args);
thrd_create(&writeThread, USBPlaceholderWriteFunc, &args);
u64 freq = armGetSystemTickFreq();

View File

@ -92,54 +92,6 @@ namespace tin::install::xci
return 0;
}
int USBThreadFuncNcz(void* in) // nczs corrupt with ranges over 8MB
{
USBFuncArgs* args = reinterpret_cast<USBFuncArgs*>(in);
u8* buf = (u8*)memalign(0x1000, 0x1000000);
tin::util::USBCmdHeader header;
u64 sizeRemaining = args->ncaSize;
size_t tmpSizeRead = 0;
u64 curOffset = 0;
u64 curRequestLeft = 0;
u64 reqSize = 0;
u64 readSize = 0;
try
{
while (sizeRemaining && !stopThreadsUsbXci)
{
if (!curRequestLeft) {
reqSize = std::min(sizeRemaining, (u64)0x1000000);
header = tin::util::USBCmdManager::SendFileRangeCmd(args->xciName, args->hfs0Offset + curOffset, reqSize);
curRequestLeft = header.dataSize;
}
readSize = std::min(curRequestLeft, (u64)0x1000000);
tmpSizeRead = awoo_usbCommsRead(buf, readSize);
if (tmpSizeRead == 0) THROW_FORMAT("USB transfer timed out or failed");
curOffset += tmpSizeRead;
sizeRemaining -= tmpSizeRead;
curRequestLeft -= tmpSizeRead;
while (true)
{
if (args->bufferedPlaceholderWriter->CanAppendData(tmpSizeRead))
break;
}
args->bufferedPlaceholderWriter->AppendData(buf, tmpSizeRead);
}
}
catch (std::exception& e)
{
stopThreadsUsbXci = true;
errorMessageUsbXci = e.what();
}
free(buf);
return 0;
}
int USBPlaceholderWriteFunc(void* in)
{
USBFuncArgs* args = reinterpret_cast<USBFuncArgs*>(in);
@ -171,8 +123,7 @@ namespace tin::install::xci
thrd_t writeThread;
stopThreadsUsbXci = false;
if (m_xciName.substr(m_xciName.size() - 1, 1) == "z") thrd_create(&usbThread, USBThreadFuncNcz, &args);
else thrd_create(&usbThread, USBThreadFunc, &args);
thrd_create(&usbThread, USBThreadFunc, &args);
thrd_create(&writeThread, USBPlaceholderWriteFunc, &args);
u64 freq = armGetSystemTickFreq();

View File

@ -5,17 +5,23 @@
#include "util/util.hpp"
#include "util/config.hpp"
#include "sigInstall.hpp"
#include "data/buffered_placeholder_writer.hpp"
#define COLOR(hex) pu::ui::Color::FromHex(hex)
namespace inst::ui {
extern MainApplication *mainApp;
bool dialogAck = false;
bool appletThreadFinished = false;
void warnAboutAppletMode() {
if (!dialogAck && mainApp->IsShown() && appletGetAppletType() == AppletType_LibraryApplet) {
inst::ui::dialogAck = true;
bool menuLoaded = mainApp->IsShown();
if (!appletThreadFinished && menuLoaded && appletGetAppletType() == AppletType_LibraryApplet) {
inst::ui::appletThreadFinished = true;
tin::data::NUM_BUFFER_SEGMENTS = 2;
mainApp->CreateShowDialog("Applet Mode not supported", "You may experience issues using Awoo Installer in Applet Mode. If you do\nhave problems, please switch to running Awoo Installer over an installed\ntitle or forwarder!", {"OK"}, true);
} else if (!appletThreadFinished && menuLoaded) {
inst::ui::appletThreadFinished = true;
tin::data::NUM_BUFFER_SEGMENTS = 4;
}
}