fix gamecard install due to fs==NULL. more explicit yields for sd card transfers for file based emummc.

This commit is contained in:
ITotalJustice
2025-05-28 15:00:31 +01:00
parent 6b56b7f7c2
commit 01bfcb05cd
6 changed files with 49 additions and 6 deletions

View File

@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
set(sphaira_VERSION 0.11.1) set(sphaira_VERSION 0.11.2)
project(sphaira project(sphaira
VERSION ${sphaira_VERSION} VERSION ${sphaira_VERSION}

View File

@@ -105,6 +105,7 @@ private:
Result DumpToFile(ui::ProgressBox* pbox, fs::Fs* fs, const fs::FsPath& root, BaseSource* source, std::span<const fs::FsPath> paths) { Result DumpToFile(ui::ProgressBox* pbox, fs::Fs* fs, const fs::FsPath& root, BaseSource* source, std::span<const fs::FsPath> paths) {
constexpr s64 BIG_FILE_SIZE = 1024ULL*1024ULL*1024ULL*4ULL; constexpr s64 BIG_FILE_SIZE = 1024ULL*1024ULL*1024ULL*4ULL;
const auto is_file_based_emummc = App::IsFileBaseEmummc();
for (const auto& path : paths) { for (const auto& path : paths) {
const auto base_path = fs::AppendPath(root, path); const auto base_path = fs::AppendPath(root, path);
@@ -130,7 +131,11 @@ Result DumpToFile(ui::ProgressBox* pbox, fs::Fs* fs, const fs::FsPath& root, Bas
return source->Read(path, data, off, size, bytes_read); return source->Read(path, data, off, size, bytes_read);
}, },
[&](const void* data, s64 off, s64 size) -> Result { [&](const void* data, s64 off, s64 size) -> Result {
return file.Write(off, data, size, FsWriteOption_None); const auto rc = file.Write(off, data, size, FsWriteOption_None);
if (is_file_based_emummc) {
svcSleepThread(2e+6); // 2ms
}
return rc;
} }
)); ));
} }

View File

@@ -510,6 +510,9 @@ File::~File() {
} }
Result File::Read( s64 off, void* buf, u64 read_size, u32 option, u64* bytes_read) { Result File::Read( s64 off, void* buf, u64 read_size, u32 option, u64* bytes_read) {
*bytes_read = 0;
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
R_TRY(fsFileRead(&m_native, off, buf, read_size, option, bytes_read)); R_TRY(fsFileRead(&m_native, off, buf, read_size, option, bytes_read));
} else { } else {
@@ -534,6 +537,8 @@ Result File::Read( s64 off, void* buf, u64 read_size, u32 option, u64* bytes_rea
} }
Result File::Write(s64 off, const void* buf, u64 write_size, u32 option) { Result File::Write(s64 off, const void* buf, u64 write_size, u32 option) {
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
R_TRY(fsFileWrite(&m_native, off, buf, write_size, option)); R_TRY(fsFileWrite(&m_native, off, buf, write_size, option));
} else { } else {
@@ -554,6 +559,8 @@ Result File::Write(s64 off, const void* buf, u64 write_size, u32 option) {
} }
Result File::SetSize(s64 sz) { Result File::SetSize(s64 sz) {
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
R_TRY(fsFileSetSize(&m_native, sz)); R_TRY(fsFileSetSize(&m_native, sz));
} else { } else {
@@ -566,6 +573,8 @@ Result File::SetSize(s64 sz) {
} }
Result File::GetSize(s64* out) { Result File::GetSize(s64* out) {
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
R_TRY(fsFileGetSize(&m_native, out)); R_TRY(fsFileGetSize(&m_native, out));
} else { } else {
@@ -588,6 +597,10 @@ Result File::GetSize(s64* out) {
} }
void File::Close() { void File::Close() {
if (!m_fs) {
return;
}
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
if (serviceIsActive(&m_native.s)) { if (serviceIsActive(&m_native.s)) {
fsFileClose(&m_native); fsFileClose(&m_native);
@@ -669,6 +682,7 @@ Dir::~Dir() {
Result Dir::GetEntryCount(s64* out) { Result Dir::GetEntryCount(s64* out) {
*out = 0; *out = 0;
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
R_TRY(fsDirGetEntryCount(&m_native, out)); R_TRY(fsDirGetEntryCount(&m_native, out));
@@ -689,6 +703,7 @@ Result Dir::GetEntryCount(s64* out) {
Result Dir::ReadAll(std::vector<FsDirectoryEntry>& buf) { Result Dir::ReadAll(std::vector<FsDirectoryEntry>& buf) {
buf.clear(); buf.clear();
R_UNLESS(m_fs, 0x1);
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
s64 count; s64 count;
@@ -731,6 +746,10 @@ Result Dir::ReadAll(std::vector<FsDirectoryEntry>& buf) {
} }
void Dir::Close() { void Dir::Close() {
if (!m_fs) {
return;
}
if (m_fs->IsNative()) { if (m_fs->IsNative()) {
if (serviceIsActive(&m_native.s)) { if (serviceIsActive(&m_native.s)) {
fsDirClose(&m_native); fsDirClose(&m_native);

View File

@@ -1,4 +1,5 @@
#include "hasher.hpp" #include "hasher.hpp"
#include "app.hpp"
#include <mbedtls/md5.h> #include <mbedtls/md5.h>
namespace sphaira::hash { namespace sphaira::hash {
@@ -11,6 +12,7 @@ consteval auto CalculateHashStrLen(s64 buf_size) {
struct FileSource final : BaseSource { struct FileSource final : BaseSource {
FileSource(fs::Fs* fs, const fs::FsPath& path) : m_fs{fs} { FileSource(fs::Fs* fs, const fs::FsPath& path) : m_fs{fs} {
m_open_result = m_fs->OpenFile(path, FsOpenMode_Read, std::addressof(m_file)); m_open_result = m_fs->OpenFile(path, FsOpenMode_Read, std::addressof(m_file));
m_is_file_based_emummc = App::IsFileBaseEmummc();
} }
Result Size(s64* out) { Result Size(s64* out) {
@@ -18,13 +20,18 @@ struct FileSource final : BaseSource {
} }
Result Read(void* buf, s64 off, s64 size, u64* bytes_read) { Result Read(void* buf, s64 off, s64 size, u64* bytes_read) {
return m_file.Read(off, buf, size, 0, bytes_read); const auto rc = m_file.Read(off, buf, size, 0, bytes_read);
if (m_fs->IsNative() && m_is_file_based_emummc) {
svcSleepThread(2e+6); // 2ms
}
return rc;
} }
private: private:
fs::Fs* m_fs{}; fs::Fs* m_fs{};
fs::File m_file{}; fs::File m_file{};
Result m_open_result{}; Result m_open_result{};
bool m_is_file_based_emummc{};
}; };
struct HashSource { struct HashSource {

View File

@@ -946,6 +946,7 @@ void FsView::UploadFiles() {
const auto loc = network_locations[*op_index]; const auto loc = network_locations[*op_index];
App::Push(std::make_shared<ProgressBox>(0, "Uploading"_i18n, "", [this, loc](auto pbox) -> Result { App::Push(std::make_shared<ProgressBox>(0, "Uploading"_i18n, "", [this, loc](auto pbox) -> Result {
auto targets = GetSelectedEntries(); auto targets = GetSelectedEntries();
const auto is_file_based_emummc = App::IsFileBaseEmummc();
const auto file_add = [&](s64 file_size, const fs::FsPath& file_path, const char* name) -> Result { const auto file_add = [&](s64 file_size, const fs::FsPath& file_path, const char* name) -> Result {
// the file name needs to be relative to the current directory. // the file name needs to be relative to the current directory.
@@ -958,7 +959,11 @@ void FsView::UploadFiles() {
return thread::TransferPull(pbox, file_size, return thread::TransferPull(pbox, file_size,
[&](void* data, s64 off, s64 size, u64* bytes_read) -> Result { [&](void* data, s64 off, s64 size, u64* bytes_read) -> Result {
return f.Read(off, data, size, FsReadOption_None, bytes_read); const auto rc = f.Read(off, data, size, FsReadOption_None, bytes_read);
if (m_fs->IsNative() && is_file_based_emummc) {
svcSleepThread(2e+6); // 2ms
}
return rc;
}, },
[&](thread::PullCallback pull) -> Result { [&](thread::PullCallback pull) -> Result {
s64 offset{}; s64 offset{};

View File

@@ -186,7 +186,9 @@ private:
}; };
struct NspSource final : dump::BaseSource { struct NspSource final : dump::BaseSource {
NspSource(const std::vector<NspEntry>& entries) : m_entries{entries} { } NspSource(const std::vector<NspEntry>& entries) : m_entries{entries} {
m_is_file_based_emummc = App::IsFileBaseEmummc();
}
Result Read(const std::string& path, void* buf, s64 off, s64 size, u64* bytes_read) override { Result Read(const std::string& path, void* buf, s64 off, s64 size, u64* bytes_read) override {
const auto it = std::ranges::find_if(m_entries, [&path](auto& e){ const auto it = std::ranges::find_if(m_entries, [&path](auto& e){
@@ -194,7 +196,11 @@ struct NspSource final : dump::BaseSource {
}); });
R_UNLESS(it != m_entries.end(), 0x1); R_UNLESS(it != m_entries.end(), 0x1);
return it->Read(buf, off, size, bytes_read); const auto rc = it->Read(buf, off, size, bytes_read);
if (m_is_file_based_emummc) {
svcSleepThread(2e+6); // 2ms
}
return rc;
} }
auto GetName(const std::string& path) const -> std::string { auto GetName(const std::string& path) const -> std::string {
@@ -235,6 +241,7 @@ struct NspSource final : dump::BaseSource {
private: private:
std::vector<NspEntry> m_entries{}; std::vector<NspEntry> m_entries{};
bool m_is_file_based_emummc{};
}; };
Result Notify(Result rc, const std::string& error_message) { Result Notify(Result rc, const std::string& error_message) {