Merge branch 'master' into sd-card

This commit is contained in:
wheremyfoodat 2023-09-05 17:02:40 +03:00
commit 2ce58e3662
9 changed files with 3126 additions and 3099 deletions

View file

@ -87,6 +87,27 @@ FileDescriptor ExtSaveDataArchive::openFile(const FSPath& path, const FilePerms&
return FileError;
}
HorizonResult ExtSaveDataArchive::createDirectory(const FSPath& path) {
if (path.type == PathType::UTF16) {
if (!isPathSafe<PathType::UTF16>(path)) {
Helpers::panic("Unsafe path in ExtSaveData::OpenFile");
}
fs::path p = IOFile::getAppData() / backingFolder;
p += fs::path(path.utf16_string).make_preferred();
if (fs::is_directory(p)) return Result::FS::AlreadyExists;
if (fs::is_regular_file(p)) {
Helpers::panic("File path passed to ExtSaveData::CreateDirectory");
}
bool success = fs::create_directory(p);
return success ? Result::Success : Result::FS::UnexpectedFileOrDir;
} else {
Helpers::panic("Unimplemented ExtSaveData::CreateDirectory");
}
}
std::string ExtSaveDataArchive::getExtSaveDataPathFromBinary(const FSPath& path) {
// TODO: Remove punning here
const u32 mediaType = *(u32*)&path.binary[0];

View file

@ -131,16 +131,12 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
}
auto cxi = mem.getCXI();
auto hb3dsx = mem.get3DSX();
// If isCXI is true then we've loaded a CXI/3DS file, else it's 3DSX
bool isCXI = cxi != nullptr;
// Seek to file offset depending on if we're reading from RomFS, ExeFS, etc
switch (type) {
case PathType::RomFS: {
const u64 romFSSize = isCXI ? cxi->romFS.size : hb3dsx->romFSSize;
const u64 romFSOffset = isCXI ? cxi->romFS.offset : hb3dsx->romFSOffset;
const u64 romFSSize = cxi->romFS.size;
const u64 romFSOffset = cxi->romFS.offset;
if ((offset >> 32) || (offset >= romFSSize) || (offset + size >= romFSSize)) {
Helpers::panic("Tried to read from NCCH with too big of an offset");
}
@ -154,8 +150,7 @@ std::optional<u32> NCCHArchive::readFile(FileSession* file, u64 offset, u32 size
}
std::unique_ptr<u8[]> data(new u8[size]);
auto [success, bytesRead] =
isCXI ? cxi->readFromFile(mem.CXIFile, cxi->romFS, &data[0], offset, size) : hb3dsx->readRomFSBytes(&data[0], offset, size);
auto [success, bytesRead] = cxi->readFromFile(mem.CXIFile, cxi->romFS, &data[0], offset, size);
if (!success) {
Helpers::panic("Failed to read from NCCH archive");

View file

@ -71,7 +71,7 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
bool success = false;
std::size_t bytesRead = 0;
std::vector<u8> data;
std::unique_ptr<u8[]> data(new u8[size]);
if (auto cxi = mem.getCXI(); cxi != nullptr) {
IOFile& ioFile = mem.CXIFile;
@ -122,7 +122,6 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
default: Helpers::panic("Unimplemented file path type for SelfNCCH archive");
}
data.resize(size);
std::tie(success, bytesRead) = cxi->readFromFile(ioFile, fsInfo, &data[0], offset, size);
}
@ -139,7 +138,6 @@ std::optional<u32> SelfNCCHArchive::readFile(FileSession* file, u64 offset, u32
default: Helpers::panic("Unimplemented file path type for 3DSX SelfNCCH archive");
}
data.resize(size);
std::tie(success, bytesRead) = hb3dsx->readRomFSBytes(&data[0], offset, size);
}