Files
sphaira/sphaira/include/yati/source/usb.hpp
ITotalJustice fe2a1a3a80 add support for streamed usb upload, multi thread usb uploads / dumps.
Some notes i made when adding stream support:
The tinfoil API makes it hard / impossible to multi thread the file upload because each data transfer passes the the file name and offset, meaning that it can and will change files and offset in the middle of a transfer
So that prevents the read thread from running freely in the background and the pull thread pulling data when requested.
The extension adds a flag to the usb header which if set, enables stream mode (same as ftp installs). This removes random access, but allows for multi threading as the data will be requested in order.
2025-05-21 13:19:46 +01:00

53 lines
1.3 KiB
C++

#pragma once
#include "base.hpp"
#include "fs.hpp"
#include "usb/usbds.hpp"
#include <string>
#include <memory>
#include <switch.h>
namespace sphaira::yati::source {
struct Usb final : Base {
enum { USBModule = 523 };
enum : Result {
Result_BadMagic = MAKERESULT(USBModule, 0),
Result_BadVersion = MAKERESULT(USBModule, 1),
Result_BadCount = MAKERESULT(USBModule, 2),
Result_BadTransferSize = MAKERESULT(USBModule, 3),
Result_BadTotalSize = MAKERESULT(USBModule, 4),
};
Usb(u64 transfer_timeout);
~Usb();
bool IsStream() const override;
Result Read(void* buf, s64 off, s64 size, u64* bytes_read) override;
Result Finished(u64 timeout);
Result IsUsbConnected(u64 timeout) {
return m_usb->IsUsbConnected(timeout);
}
Result WaitForConnection(u64 timeout, std::vector<std::string>& out_names);
void SetFileNameForTranfser(const std::string& name);
void SignalCancel() override {
m_usb->Cancel();
}
private:
Result SendCmdHeader(u32 cmdId, size_t dataSize, u64 timeout);
Result SendFileRangeCmd(u64 offset, u64 size, u64 timeout);
private:
std::unique_ptr<usb::UsbDs> m_usb;
std::string m_transfer_file_name{};
u8 m_flags{};
};
} // namespace sphaira::yati::source