From 5106f251cf27211810f1e1339d1b6481f8df7c93 Mon Sep 17 00:00:00 2001 From: wheremyfoodat <44909372+wheremyfoodat@users.noreply.github.com> Date: Sun, 20 Aug 2023 16:53:06 +0300 Subject: [PATCH] [SDMC] Handle ASCII paths for CreateDirectory --- src/core/fs/archive_sdmc.cpp | 45 +++++++++++++++++----------- src/core/renderer_gl/renderer_gl.cpp | 8 ++++- 2 files changed, 35 insertions(+), 18 deletions(-) diff --git a/src/core/fs/archive_sdmc.cpp b/src/core/fs/archive_sdmc.cpp index ee5c8ffb..8e6010eb 100644 --- a/src/core/fs/archive_sdmc.cpp +++ b/src/core/fs/archive_sdmc.cpp @@ -64,28 +64,39 @@ FileDescriptor SDMCArchive::openFile(const FSPath& path, const FilePerms& perms) } HorizonResult SDMCArchive::createDirectory(const FSPath& path) { - if (path.type == PathType::UTF16) { - if (!isPathSafe(path)) { - Helpers::panic("Unsafe path in SDMCArchive::OpenFile"); - } + std::filesystem::path p = IOFile::getAppData() / "SDMC"; - fs::path p = IOFile::getAppData() / "SDMC"; - p += fs::path(path.utf16_string).make_preferred(); + switch (path.type) { + case PathType::ASCII: + if (!isPathSafe(path)) { + Helpers::panic("Unsafe path in SDMCArchive::OpenFile"); + } - if (fs::is_directory(p)) { - return Result::FS::AlreadyExists; - } + p += fs::path(path.string).make_preferred(); + break; - if (fs::is_regular_file(p)) { - Helpers::panic("File path passed to SDMCArchive::CreateDirectory"); - } + case PathType::UTF16: + if (!isPathSafe(path)) { + Helpers::panic("Unsafe path in SDMCArchive::OpenFile"); + } - std::error_code ec; - bool success = fs::create_directory(p, ec); - return success ? Result::Success : Result::FS::UnexpectedFileOrDir; - } else { - Helpers::panic("Unimplemented SDMC::CreateDirectory path type"); + p += fs::path(path.utf16_string).make_preferred(); + break; + + default: Helpers::panic("SDMCArchive::CreateDirectory: Failed. Path type: %d", path.type); return Result::FailurePlaceholder; } + + if (fs::is_directory(p)) { + return Result::FS::AlreadyExists; + } + + if (fs::is_regular_file(p)) { + Helpers::panic("File path passed to SDMCArchive::CreateDirectory"); + } + + std::error_code ec; + bool success = fs::create_directory(p, ec); + return success ? Result::Success : Result::FS::UnexpectedFileOrDir; } Rust::Result SDMCArchive::openDirectory(const FSPath& path) { diff --git a/src/core/renderer_gl/renderer_gl.cpp b/src/core/renderer_gl/renderer_gl.cpp index 6d29e7d3..f904dc37 100644 --- a/src/core/renderer_gl/renderer_gl.cpp +++ b/src/core/renderer_gl/renderer_gl.cpp @@ -695,6 +695,7 @@ void RendererGL::textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 if (inputGap != 0 || outputGap != 0) { // Helpers::warn("Strided texture copy\n"); } + if (inputWidth != outputWidth) { Helpers::warn("Input width does not match output width, cannot accelerate texture copy!"); return; @@ -716,7 +717,12 @@ void RendererGL::textureCopy(u32 inputAddr, u32 outputAddr, u32 totalBytes, u32 // inputHeight/outputHeight are typically set to zero so they cannot be used to get the height of the copy region // in contrast to display transfer. Compute height manually by dividing the copy size with the copy width. The result // is the number of vertical tiles so multiply that by eight to get the actual copy height. - const u32 copyHeight = (copySize / inputWidth) * 8; + u32 copyHeight; + if (inputWidth != 0) [[likely]] { + copyHeight = (copySize / inputWidth) * 8; + } else { + copyHeight = 0; + } // Find the source surface. auto srcFramebuffer = getColourBuffer(inputAddr, PICA::ColorFmt::RGBA8, copyStride, copyHeight, false);