diff --git a/sphaira/include/fs.hpp b/sphaira/include/fs.hpp index f2fccf3..07b6528 100644 --- a/sphaira/include/fs.hpp +++ b/sphaira/include/fs.hpp @@ -171,39 +171,39 @@ static_assert(FsPath::TestFrom(FsPath{"abc"})); FsPath AppendPath(const fs::FsPath& root_path, const fs::FsPath& file_path); -Result CreateFile(FsFileSystem* fs, const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = false); -Result CreateDirectory(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result CreateDirectoryRecursively(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result CreateDirectoryRecursivelyWithPath(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result DeleteFile(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result DeleteDirectory(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result DeleteDirectoryRecursively(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = false); -Result RenameFile(FsFileSystem* fs, const FsPath& src, const FsPath& dst, bool ignore_read_only = false); -Result RenameDirectory(FsFileSystem* fs, const FsPath& src, const FsPath& dst, bool ignore_read_only = false); +Result CreateFile(FsFileSystem* fs, const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = true); +Result CreateDirectory(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result CreateDirectoryRecursively(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result CreateDirectoryRecursivelyWithPath(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result DeleteFile(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result DeleteDirectory(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result DeleteDirectoryRecursively(FsFileSystem* fs, const FsPath& path, bool ignore_read_only = true); +Result RenameFile(FsFileSystem* fs, const FsPath& src, const FsPath& dst, bool ignore_read_only = true); +Result RenameDirectory(FsFileSystem* fs, const FsPath& src, const FsPath& dst, bool ignore_read_only = true); Result GetEntryType(FsFileSystem* fs, const FsPath& path, FsDirEntryType* out); Result GetFileTimeStampRaw(FsFileSystem* fs, const FsPath& path, FsTimeStampRaw *out); bool FileExists(FsFileSystem* fs, const FsPath& path); bool DirExists(FsFileSystem* fs, const FsPath& path); Result read_entire_file(FsFileSystem* fs, const FsPath& path, std::vector& out); -Result write_entire_file(FsFileSystem* fs, const FsPath& path, const std::vector& in, bool ignore_read_only = false); -Result copy_entire_file(FsFileSystem* fs, const FsPath& dst, const FsPath& src, bool ignore_read_only = false); +Result write_entire_file(FsFileSystem* fs, const FsPath& path, const std::vector& in, bool ignore_read_only = true); +Result copy_entire_file(FsFileSystem* fs, const FsPath& dst, const FsPath& src, bool ignore_read_only = true); -Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = false); -Result CreateDirectory(const FsPath& path, bool ignore_read_only = false); -Result CreateDirectoryRecursively(const FsPath& path, bool ignore_read_only = false); -Result CreateDirectoryRecursivelyWithPath(const FsPath& path, bool ignore_read_only = false); -Result DeleteFile(const FsPath& path, bool ignore_read_only = false); -Result DeleteDirectory(const FsPath& path, bool ignore_read_only = false); -Result DeleteDirectoryRecursively(const FsPath& path, bool ignore_read_only = false); -Result RenameFile(const FsPath& src, const FsPath& dst, bool ignore_read_only = false); -Result RenameDirectory(const FsPath& src, const FsPath& dst, bool ignore_read_only = false); +Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = true); +Result CreateDirectory(const FsPath& path, bool ignore_read_only = true); +Result CreateDirectoryRecursively(const FsPath& path, bool ignore_read_only = true); +Result CreateDirectoryRecursivelyWithPath(const FsPath& path, bool ignore_read_only = true); +Result DeleteFile(const FsPath& path, bool ignore_read_only = true); +Result DeleteDirectory(const FsPath& path, bool ignore_read_only = true); +Result DeleteDirectoryRecursively(const FsPath& path, bool ignore_read_only = true); +Result RenameFile(const FsPath& src, const FsPath& dst, bool ignore_read_only = true); +Result RenameDirectory(const FsPath& src, const FsPath& dst, bool ignore_read_only = true); Result GetEntryType(const FsPath& path, FsDirEntryType* out); Result GetFileTimeStampRaw(const FsPath& path, FsTimeStampRaw *out); bool FileExists(const FsPath& path); bool DirExists(const FsPath& path); Result read_entire_file(const FsPath& path, std::vector& out); -Result write_entire_file(const FsPath& path, const std::vector& in, bool ignore_read_only = false); -Result copy_entire_file(const FsPath& dst, const FsPath& src, bool ignore_read_only = false); +Result write_entire_file(const FsPath& path, const std::vector& in, bool ignore_read_only = true); +Result copy_entire_file(const FsPath& dst, const FsPath& src, bool ignore_read_only = true); struct Fs { static constexpr inline u32 FsModule = 505; @@ -222,51 +222,64 @@ struct Fs { static constexpr inline Result ResultUnknownStdioError = MAKERESULT(FsModule, 13); static constexpr inline Result ResultReadOnly = MAKERESULT(FsModule, 14); - virtual Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = false) = 0; - virtual Result CreateDirectory(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result CreateDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result CreateDirectoryRecursivelyWithPath(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result DeleteFile(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result DeleteDirectory(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result DeleteDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) = 0; - virtual Result RenameFile(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) = 0; - virtual Result RenameDirectory(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) = 0; + Fs(bool ignore_read_only = true) : m_ignore_read_only{ignore_read_only} {} + virtual ~Fs() = default; + + virtual Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0) = 0; + virtual Result CreateDirectory(const FsPath& path) = 0; + virtual Result CreateDirectoryRecursively(const FsPath& path) = 0; + virtual Result CreateDirectoryRecursivelyWithPath(const FsPath& path) = 0; + virtual Result DeleteFile(const FsPath& path) = 0; + virtual Result DeleteDirectory(const FsPath& path) = 0; + virtual Result DeleteDirectoryRecursively(const FsPath& path) = 0; + virtual Result RenameFile(const FsPath& src, const FsPath& dst) = 0; + virtual Result RenameDirectory(const FsPath& src, const FsPath& dst) = 0; virtual Result GetEntryType(const FsPath& path, FsDirEntryType* out) = 0; virtual Result GetFileTimeStampRaw(const FsPath& path, FsTimeStampRaw *out) = 0; virtual bool FileExists(const FsPath& path) = 0; virtual bool DirExists(const FsPath& path) = 0; virtual Result read_entire_file(const FsPath& path, std::vector& out) = 0; - virtual Result write_entire_file(const FsPath& path, const std::vector& in, bool ignore_read_only = false) = 0; - virtual Result copy_entire_file(const FsPath& dst, const FsPath& src, bool ignore_read_only = false) = 0; + virtual Result write_entire_file(const FsPath& path, const std::vector& in) = 0; + virtual Result copy_entire_file(const FsPath& dst, const FsPath& src) = 0; + + void SetIgnoreReadOnly(bool enable) { + m_ignore_read_only = enable; + } + +protected: + bool m_ignore_read_only; }; struct FsStdio : Fs { - Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = false) override { - return fs::CreateFile(path, size, option, ignore_read_only); + FsStdio(bool ignore_read_only = true) : Fs{ignore_read_only} {} + virtual ~FsStdio() = default; + + Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0) override { + return fs::CreateFile(path, size, option, m_ignore_read_only); } - Result CreateDirectory(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectory(path, ignore_read_only); + Result CreateDirectory(const FsPath& path) override { + return fs::CreateDirectory(path, m_ignore_read_only); } - Result CreateDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectoryRecursively(path, ignore_read_only); + Result CreateDirectoryRecursively(const FsPath& path) override { + return fs::CreateDirectoryRecursively(path, m_ignore_read_only); } - Result CreateDirectoryRecursivelyWithPath(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectoryRecursivelyWithPath(path, ignore_read_only); + Result CreateDirectoryRecursivelyWithPath(const FsPath& path) override { + return fs::CreateDirectoryRecursivelyWithPath(path, m_ignore_read_only); } - Result DeleteFile(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteFile(path, ignore_read_only); + Result DeleteFile(const FsPath& path) override { + return fs::DeleteFile(path, m_ignore_read_only); } - Result DeleteDirectory(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteDirectory(path, ignore_read_only); + Result DeleteDirectory(const FsPath& path) override { + return fs::DeleteDirectory(path, m_ignore_read_only); } - Result DeleteDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteDirectoryRecursively(path, ignore_read_only); + Result DeleteDirectoryRecursively(const FsPath& path) override { + return fs::DeleteDirectoryRecursively(path, m_ignore_read_only); } - Result RenameFile(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) override { - return fs::RenameFile(src, dst, ignore_read_only); + Result RenameFile(const FsPath& src, const FsPath& dst) override { + return fs::RenameFile(src, dst, m_ignore_read_only); } - Result RenameDirectory(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) override { - return fs::RenameDirectory(src, dst, ignore_read_only); + Result RenameDirectory(const FsPath& src, const FsPath& dst) override { + return fs::RenameDirectory(src, dst, m_ignore_read_only); } Result GetEntryType(const FsPath& path, FsDirEntryType* out) override { return fs::GetEntryType(path, out); @@ -283,17 +296,17 @@ struct FsStdio : Fs { Result read_entire_file(const FsPath& path, std::vector& out) override { return fs::read_entire_file(path, out); } - Result write_entire_file(const FsPath& path, const std::vector& in, bool ignore_read_only = false) override { - return fs::write_entire_file(path, in, ignore_read_only); + Result write_entire_file(const FsPath& path, const std::vector& in) override { + return fs::write_entire_file(path, in, m_ignore_read_only); } - Result copy_entire_file(const FsPath& dst, const FsPath& src, bool ignore_read_only = false) override { - return fs::copy_entire_file(dst, src, ignore_read_only); + Result copy_entire_file(const FsPath& dst, const FsPath& src) override { + return fs::copy_entire_file(dst, src, m_ignore_read_only); } }; struct FsNative : Fs { - FsNative() = default; - FsNative(FsFileSystem* fs, bool own) : m_fs{*fs}, m_own{own} {} + explicit FsNative(bool ignore_read_only = true) : Fs{ignore_read_only} {} + explicit FsNative(FsFileSystem* fs, bool own, bool ignore_read_only = true) : Fs{ignore_read_only}, m_fs{*fs}, m_own{own} {} virtual ~FsNative() { if (m_own) { @@ -355,32 +368,32 @@ struct FsNative : Fs { return m_open_result; } - Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0, bool ignore_read_only = false) override { - return fs::CreateFile(&m_fs, path, size, option, ignore_read_only); + Result CreateFile(const FsPath& path, u64 size = 0, u32 option = 0) override { + return fs::CreateFile(&m_fs, path, size, option, m_ignore_read_only); } - Result CreateDirectory(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectory(&m_fs, path, ignore_read_only); + Result CreateDirectory(const FsPath& path) override { + return fs::CreateDirectory(&m_fs, path, m_ignore_read_only); } - Result CreateDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectoryRecursively(&m_fs, path, ignore_read_only); + Result CreateDirectoryRecursively(const FsPath& path) override { + return fs::CreateDirectoryRecursively(&m_fs, path, m_ignore_read_only); } - Result CreateDirectoryRecursivelyWithPath(const FsPath& path, bool ignore_read_only = false) override { - return fs::CreateDirectoryRecursivelyWithPath(&m_fs, path, ignore_read_only); + Result CreateDirectoryRecursivelyWithPath(const FsPath& path) override { + return fs::CreateDirectoryRecursivelyWithPath(&m_fs, path, m_ignore_read_only); } - Result DeleteFile(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteFile(&m_fs, path, ignore_read_only); + Result DeleteFile(const FsPath& path) override { + return fs::DeleteFile(&m_fs, path, m_ignore_read_only); } - Result DeleteDirectory(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteDirectory(&m_fs, path, ignore_read_only); + Result DeleteDirectory(const FsPath& path) override { + return fs::DeleteDirectory(&m_fs, path, m_ignore_read_only); } - Result DeleteDirectoryRecursively(const FsPath& path, bool ignore_read_only = false) override { - return fs::DeleteDirectoryRecursively(&m_fs, path, ignore_read_only); + Result DeleteDirectoryRecursively(const FsPath& path) override { + return fs::DeleteDirectoryRecursively(&m_fs, path, m_ignore_read_only); } - Result RenameFile(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) override { - return fs::RenameFile(&m_fs, src, dst, ignore_read_only); + Result RenameFile(const FsPath& src, const FsPath& dst) override { + return fs::RenameFile(&m_fs, src, dst, m_ignore_read_only); } - Result RenameDirectory(const FsPath& src, const FsPath& dst, bool ignore_read_only = false) override { - return fs::RenameDirectory(&m_fs, src, dst, ignore_read_only); + Result RenameDirectory(const FsPath& src, const FsPath& dst) override { + return fs::RenameDirectory(&m_fs, src, dst, m_ignore_read_only); } Result GetEntryType(const FsPath& path, FsDirEntryType* out) override { return fs::GetEntryType(&m_fs, path, out); @@ -397,11 +410,11 @@ struct FsNative : Fs { Result read_entire_file(const FsPath& path, std::vector& out) override { return fs::read_entire_file(&m_fs, path, out); } - Result write_entire_file(const FsPath& path, const std::vector& in, bool ignore_read_only = false) override { - return fs::write_entire_file(&m_fs, path, in, ignore_read_only); + Result write_entire_file(const FsPath& path, const std::vector& in) override { + return fs::write_entire_file(&m_fs, path, in, m_ignore_read_only); } - Result copy_entire_file(const FsPath& dst, const FsPath& src, bool ignore_read_only = false) override { - return fs::copy_entire_file(&m_fs, dst, src, ignore_read_only); + Result copy_entire_file(const FsPath& dst, const FsPath& src) override { + return fs::copy_entire_file(&m_fs, dst, src, m_ignore_read_only); } FsFileSystem m_fs{}; @@ -417,43 +430,28 @@ struct FsNativeSd final : FsNative { }; #else struct FsNativeSd final : FsNative { - FsNativeSd() : FsNative{fsdevGetDeviceFileSystem("sdmc:"), false} { + FsNativeSd(bool ignore_read_only = true) : FsNative{fsdevGetDeviceFileSystem("sdmc:"), false, ignore_read_only} { m_open_result = 0; } }; #endif struct FsNativeBis final : FsNative { - FsNativeBis(FsBisPartitionId id, const FsPath& string) { + FsNativeBis(FsBisPartitionId id, const FsPath& string, bool ignore_read_only = true) : FsNative{ignore_read_only} { m_open_result = fsOpenBisFileSystem(&m_fs, id, string); } }; struct FsNativeImage final : FsNative { - FsNativeImage(FsImageDirectoryId id) { + FsNativeImage(FsImageDirectoryId id, bool ignore_read_only = true) : FsNative{ignore_read_only} { m_open_result = fsOpenImageDirectoryFileSystem(&m_fs, id); } }; struct FsNativeContentStorage final : FsNative { - FsNativeContentStorage(FsContentStorageId id) { + FsNativeContentStorage(FsContentStorageId id, bool ignore_read_only = true) : FsNative{ignore_read_only} { m_open_result = fsOpenContentStorageFileSystem(&m_fs, id); } }; -// auto file_exists(const FsPath& path) -> bool; -// auto create_file(const FsPath& path, u64 size = 0) -> Result; -// auto delete_file(const FsPath& path) -> Result; -// auto create_directory(const FsPath& path) -> Result; -// auto create_directory_recursively(const FsPath& path) -> Result; -// auto delete_directory(const FsPath& path) -> Result; -// auto delete_directory_recursively(const FsPath& path) -> Result; -// auto rename_file(const FsPath& src, const FsPath& dst) -> Result; -// auto rename_directory(const FsPath& src, const FsPath& dst) -> Result; - -// auto read_entire_file(const FsPath& path, std::vector& out) -> Result; -// auto write_entire_file(const FsPath& path, const std::vector& in) -> Result; -// // single threaded one shot copy, only use for very small files! -// auto copy_entire_file(const FsPath& dst, const FsPath& src) -> Result; - } // namespace fs diff --git a/sphaira/include/ui/menus/filebrowser.hpp b/sphaira/include/ui/menus/filebrowser.hpp index a62f535..9bda87a 100644 --- a/sphaira/include/ui/menus/filebrowser.hpp +++ b/sphaira/include/ui/menus/filebrowser.hpp @@ -256,10 +256,7 @@ private: option::OptionBool m_show_hidden{INI_SECTION, "show_hidden", false}; option::OptionBool m_folders_first{INI_SECTION, "folders_first", true}; option::OptionBool m_hidden_last{INI_SECTION, "hidden_last", false}; - - option::OptionBool m_search_show_files{INI_SECTION, "search_show_files", true}; - option::OptionBool m_search_show_folders{INI_SECTION, "search_show_folders", true}; - option::OptionBool m_search_recursive{INI_SECTION, "search_recursive", false}; + option::OptionBool m_ignore_read_only{INI_SECTION, "ignore_read_only", false}; bool m_loaded_assoc_entries{}; bool m_is_update_folder{}; diff --git a/sphaira/source/app.cpp b/sphaira/source/app.cpp index 187798a..dbf47ee 100644 --- a/sphaira/source/app.cpp +++ b/sphaira/source/app.cpp @@ -520,7 +520,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { if (R_SUCCEEDED(rc) && !std::strcmp(sphaira_nacp.lang[0].name, "sphaira")) { if (std::strcmp(sphaira_nacp.display_version, hbmenu_nacp.display_version) < 0) { - if (R_FAILED(rc = fs.copy_entire_file(sphaira_path, "/hbmenu.nro", true))) { + if (R_FAILED(rc = fs.copy_entire_file(sphaira_path, "/hbmenu.nro"))) { log_write("failed to copy entire file: %s 0x%X module: %u desc: %u\n", sphaira_path, rc, R_MODULE(rc), R_DESCRIPTION(rc)); } else { log_write("success with updating hbmenu!\n"); @@ -530,13 +530,13 @@ void App::SetReplaceHbmenuEnable(bool enable) { // sphaira doesn't yet exist, create a new file. sphaira_path = "/switch/sphaira/sphaira.nro"; fs.CreateDirectoryRecursively("/switch/sphaira/"); - fs.copy_entire_file(sphaira_path, "/hbmenu.nro", true); + fs.copy_entire_file(sphaira_path, "/hbmenu.nro"); } // this should never fail, if it does, well then the sd card is fucked. - if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", "/switch/hbmenu.nro", true))) { + if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", "/switch/hbmenu.nro"))) { // try and restore sphaira in a last ditch effort. - if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", sphaira_path, true))) { + if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", sphaira_path))) { App::Push(std::make_shared(rc, "Failed to restore hbmenu, please re-download hbmenu"_i18n )); @@ -550,7 +550,7 @@ void App::SetReplaceHbmenuEnable(bool enable) { } // don't need this any more. - fs.DeleteFile("/switch/hbmenu.nro", true); + fs.DeleteFile("/switch/hbmenu.nro"); // if we were hbmenu, exit now (as romfs is gone). if (IsHbmenu()) { @@ -1260,14 +1260,14 @@ App::~App() { if (R_SUCCEEDED(rc = nro_get_nacp("/hbmenu.nro", hbmenu_nacp)) && std::strcmp(hbmenu_nacp.lang[0].name, "sphaira")) { log_write("backing up hbmenu.nro\n"); - if (R_FAILED(rc = fs.copy_entire_file("/switch/hbmenu.nro", "/hbmenu.nro", true))) { + if (R_FAILED(rc = fs.copy_entire_file("/switch/hbmenu.nro", "/hbmenu.nro"))) { log_write("failed to backup hbmenu.nro\n"); } } else { log_write("not backing up\n"); } - if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", GetExePath(), true))) { + if (R_FAILED(rc = fs.copy_entire_file("/hbmenu.nro", GetExePath()))) { log_write("failed to copy entire file: %s 0x%X module: %u desc: %u\n", GetExePath(), rc, R_MODULE(rc), R_DESCRIPTION(rc)); } else { log_write("success with copying over root file!\n"); @@ -1292,7 +1292,7 @@ App::~App() { // found sphaira, now lets get compare version if (R_SUCCEEDED(rc) && !std::strcmp(sphaira_nacp.lang[0].name, "sphaira")) { if (std::strcmp(hbmenu_nacp.display_version, sphaira_nacp.display_version) < 0) { - if (R_FAILED(rc = fs.copy_entire_file(GetExePath(), sphaira_path, true))) { + if (R_FAILED(rc = fs.copy_entire_file(GetExePath(), sphaira_path))) { log_write("failed to copy entire file: %s 0x%X module: %u desc: %u\n", sphaira_path, rc, R_MODULE(rc), R_DESCRIPTION(rc)); } else { log_write("success with updating hbmenu!\n"); diff --git a/sphaira/source/download.cpp b/sphaira/source/download.cpp index bf72481..e49d3a6 100644 --- a/sphaira/source/download.cpp +++ b/sphaira/source/download.cpp @@ -454,9 +454,9 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { if (has_file) { GetDownloadTempPath(tmp_buf); - fs.CreateDirectoryRecursivelyWithPath(tmp_buf, true); + fs.CreateDirectoryRecursivelyWithPath(tmp_buf); - if (auto rc = fs.CreateFile(tmp_buf, 0, 0, true); R_FAILED(rc) && rc != FsError_PathAlreadyExists) { + if (auto rc = fs.CreateFile(tmp_buf, 0, 0); R_FAILED(rc) && rc != FsError_PathAlreadyExists) { log_write("failed to create file: %s\n", tmp_buf); return {}; } @@ -537,7 +537,7 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &http_code); if (has_file) { - ON_SCOPE_EXIT( fs.DeleteFile(tmp_buf, true) ); + ON_SCOPE_EXIT( fs.DeleteFile(tmp_buf) ); if (res == CURLE_OK && chunk.offset) { fsFileWrite(&chunk.f, chunk.file_offset, chunk.data.data(), chunk.offset, FsWriteOption_None); } @@ -553,9 +553,9 @@ auto DownloadInternal(CURL* curl, const Api& e) -> ApiResult { g_cache.set(e.m_path, header_out); } - fs.DeleteFile(e.m_path, true); - fs.CreateDirectoryRecursivelyWithPath(e.m_path, true); - if (R_FAILED(fs.RenameFile(tmp_buf, e.m_path, true))) { + fs.DeleteFile(e.m_path); + fs.CreateDirectoryRecursivelyWithPath(e.m_path); + if (R_FAILED(fs.RenameFile(tmp_buf, e.m_path))) { success = false; } } diff --git a/sphaira/source/fs.cpp b/sphaira/source/fs.cpp index 8c2cd47..301f791 100644 --- a/sphaira/source/fs.cpp +++ b/sphaira/source/fs.cpp @@ -248,10 +248,10 @@ Result read_entire_file(FsFileSystem* _fs, const FsPath& path, std::vector& Result write_entire_file(FsFileSystem* _fs, const FsPath& path, const std::vector& in, bool ignore_read_only) { R_UNLESS(ignore_read_only || !is_read_only(path), Fs::ResultReadOnly); - FsNative fs{_fs, false}; + FsNative fs{_fs, false, ignore_read_only}; R_TRY(fs.GetFsOpenResult()); - if (auto rc = fs.CreateFile(path, in.size(), 0, ignore_read_only); R_FAILED(rc) && rc != FsError_PathAlreadyExists) { + if (auto rc = fs.CreateFile(path, in.size(), 0); R_FAILED(rc) && rc != FsError_PathAlreadyExists) { return rc; } diff --git a/sphaira/source/ui/menus/appstore.cpp b/sphaira/source/ui/menus/appstore.cpp index bb38d8e..123af1a 100644 --- a/sphaira/source/ui/menus/appstore.cpp +++ b/sphaira/source/ui/menus/appstore.cpp @@ -522,10 +522,10 @@ auto InstallApp(ProgressBox* pbox, const Entry& entry) -> bool { } // create directories - fs.CreateDirectoryRecursivelyWithPath(output, true); + fs.CreateDirectoryRecursivelyWithPath(output); Result rc; - if (R_FAILED(rc = fs.CreateFile(output, info.uncompressed_size, 0, true)) && rc != FsError_PathAlreadyExists) { + if (R_FAILED(rc = fs.CreateFile(output, info.uncompressed_size, 0)) && rc != FsError_PathAlreadyExists) { log_write("failed to create file: %s 0x%04X\n", output, rc); return false; } @@ -614,7 +614,7 @@ auto InstallApp(ProgressBox* pbox, const Entry& entry) -> bool { if (!found) { const auto safe_buf = fs::AppendPath("/", old_entry.path); // std::strcat(safe_buf, old_entry.path); - if (R_FAILED(fs.DeleteFile(safe_buf, true))) { + if (R_FAILED(fs.DeleteFile(safe_buf))) { log_write("failed to delete: %s\n", safe_buf); } else { log_write("deleted file: %s\n", safe_buf); diff --git a/sphaira/source/ui/menus/filebrowser.cpp b/sphaira/source/ui/menus/filebrowser.cpp index 5124d1b..81b4099 100644 --- a/sphaira/source/ui/menus/filebrowser.cpp +++ b/sphaira/source/ui/menus/filebrowser.cpp @@ -533,11 +533,16 @@ Menu::Menu(const std::vector& nro_entries) : MenuBase{"FileBrowser"_i1 })); } } + + options->Add(std::make_shared("Ignore read only"_i18n, m_ignore_read_only.Get(), [this](bool& v_out){ + m_ignore_read_only.Set(v_out); + m_fs->SetIgnoreReadOnly(v_out); + }, "Yes"_i18n, "No"_i18n)); })); }}) ); - m_fs = std::make_unique(); + m_fs = std::make_unique(m_ignore_read_only.Get()); fs::FsPath buf; ini_gets("paths", "last_path", "/", buf, sizeof(buf), App::CONFIG_PATH); m_path = buf; diff --git a/sphaira/source/ui/menus/ghdl.cpp b/sphaira/source/ui/menus/ghdl.cpp index e1c96b9..b897c91 100644 --- a/sphaira/source/ui/menus/ghdl.cpp +++ b/sphaira/source/ui/menus/ghdl.cpp @@ -154,17 +154,17 @@ auto DownloadApp(ProgressBox* pbox, const GhApiAsset& gh_asset, const AssetEntry Result rc; if (file_path[strlen(file_path) -1] == '/') { - if (R_FAILED(rc = fs.CreateDirectoryRecursively(file_path, true)) && rc != FsError_PathAlreadyExists) { + if (R_FAILED(rc = fs.CreateDirectoryRecursively(file_path)) && rc != FsError_PathAlreadyExists) { log_write("failed to create folder: %s 0x%04X\n", file_path, rc); return false; } } else { - if (R_FAILED(rc = fs.CreateDirectoryRecursivelyWithPath(file_path, true)) && rc != FsError_PathAlreadyExists) { + if (R_FAILED(rc = fs.CreateDirectoryRecursivelyWithPath(file_path)) && rc != FsError_PathAlreadyExists) { log_write("failed to create folder: %s 0x%04X\n", file_path, rc); return false; } - if (R_FAILED(rc = fs.CreateFile(file_path, info.uncompressed_size, 0, true)) && rc != FsError_PathAlreadyExists) { + if (R_FAILED(rc = fs.CreateFile(file_path, info.uncompressed_size, 0)) && rc != FsError_PathAlreadyExists) { log_write("failed to create file: %s 0x%04X\n", file_path, rc); return false; } @@ -201,9 +201,9 @@ auto DownloadApp(ProgressBox* pbox, const GhApiAsset& gh_asset, const AssetEntry } } } else { - fs.CreateDirectoryRecursivelyWithPath(root_path, true); + fs.CreateDirectoryRecursivelyWithPath(root_path); fs.DeleteFile(root_path); - if (R_FAILED(fs.RenameFile(temp_file, root_path, true))) { + if (R_FAILED(fs.RenameFile(temp_file, root_path))) { log_write("failed to rename file: %s -> %s\n", temp_file.s, root_path.s); } }