From 5ce5fce2e723d813d20644092d24f48e408e8150 Mon Sep 17 00:00:00 2001 From: pineappleEA Date: Tue, 18 May 2021 20:58:12 +0200 Subject: [PATCH] early-access version 1695 --- README.md | 2 +- src/common/fs/file.cpp | 8 ------ src/common/fs/path_util.cpp | 8 ------ src/core/hle/kernel/k_transfer_memory.h | 2 +- .../hle/service/filesystem/filesystem.cpp | 19 +++++++------ .../renderer_opengl/gl_shader_disk_cache.cpp | 28 +------------------ src/yuzu/configuration/config.cpp | 9 +++--- src/yuzu/game_list_worker.cpp | 1 - src/yuzu/main.cpp | 11 ++++---- src/yuzu_cmd/config.cpp | 7 +++-- 10 files changed, 27 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 6a0623868..fd500d7cd 100755 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ yuzu emulator early access ============= -This is the source code for early-access 1694. +This is the source code for early-access 1695. ## Legal Notice diff --git a/src/common/fs/file.cpp b/src/common/fs/file.cpp index 10e636275..37aa9f46e 100755 --- a/src/common/fs/file.cpp +++ b/src/common/fs/file.cpp @@ -252,18 +252,14 @@ void IOFile::Open(const fs::path& path, FileAccessMode mode, FileType type, File errno = 0; #ifdef _WIN32 - if (flag != FileShareFlag::ShareNone) { file = _wfsopen(path.wstring().c_str(), AccessModeToWStr(mode, type), ToWindowsFileShareFlag(flag)); } else { _wfopen_s(&file, path.wstring().c_str(), AccessModeToWStr(mode, type)); } - #else - file = std::fopen(PathToUTF8String(path).c_str(), AccessModeToStr(mode, type)); - #endif if (!IsOpen()) { @@ -334,13 +330,9 @@ bool IOFile::SetSize(u64 size) const { errno = 0; #ifdef _WIN32 - const auto set_size_result = _chsize_s(fileno(file), static_cast(size)) == 0; - #else - const auto set_size_result = ftruncate(fileno(file), static_cast(size)) == 0; - #endif if (!set_size_result) { diff --git a/src/common/fs/path_util.cpp b/src/common/fs/path_util.cpp index 8bf003b88..8b732a21c 100755 --- a/src/common/fs/path_util.cpp +++ b/src/common/fs/path_util.cpp @@ -83,7 +83,6 @@ public: private: PathManagerImpl() { #ifdef _WIN32 - auto yuzu_path = GetExeDirectory() / PORTABLE_DIR; if (!IsDir(yuzu_path)) { @@ -93,9 +92,7 @@ private: GenerateYuzuPath(YuzuPath::YuzuDir, yuzu_path); GenerateYuzuPath(YuzuPath::CacheDir, yuzu_path / CACHE_DIR); GenerateYuzuPath(YuzuPath::ConfigDir, yuzu_path / CONFIG_DIR); - #else - auto yuzu_path = GetCurrentDir() / PORTABLE_DIR; if (Exists(yuzu_path) && IsDir(yuzu_path)) { @@ -109,7 +106,6 @@ private: GenerateYuzuPath(YuzuPath::CacheDir, GetDataDirectory("XDG_CACHE_HOME") / YUZU_DIR); GenerateYuzuPath(YuzuPath::ConfigDir, GetDataDirectory("XDG_CONFIG_HOME") / YUZU_DIR); } - #endif GenerateYuzuPath(YuzuPath::DumpDir, yuzu_path / DUMP_DIR); @@ -146,19 +142,15 @@ bool ValidatePath(const fs::path& path) { } #ifdef _WIN32 - if (path.u16string().size() >= MAX_PATH) { LOG_ERROR(Common_Filesystem, "Input path is too long, path={}", PathToUTF8String(path)); return false; } - #else - if (path.u8string().size() >= MAX_PATH) { LOG_ERROR(Common_Filesystem, "Input path is too long, path={}", PathToUTF8String(path)); return false; } - #endif return true; diff --git a/src/core/hle/kernel/k_transfer_memory.h b/src/core/hle/kernel/k_transfer_memory.h index 838fd2b18..c2d0f1eaf 100755 --- a/src/core/hle/kernel/k_transfer_memory.h +++ b/src/core/hle/kernel/k_transfer_memory.h @@ -52,7 +52,7 @@ public: } size_t GetSize() const { - return is_initialized ? size * PageSize : 0; + return is_initialized ? size : 0; } private: diff --git a/src/core/hle/service/filesystem/filesystem.cpp b/src/core/hle/service/filesystem/filesystem.cpp index 0031105c5..921f8fa32 100755 --- a/src/core/hle/service/filesystem/filesystem.cpp +++ b/src/core/hle/service/filesystem/filesystem.cpp @@ -728,14 +728,17 @@ void FileSystemController::CreateFactories(FileSys::VfsFilesystem& vfs, bool ove sdmc_factory = nullptr; } - auto nand_directory = vfs.OpenDirectory( - Common::FS::GetYuzuPathString(Common::FS::YuzuPath::NANDDir), FileSys::Mode::ReadWrite); - auto sd_directory = vfs.OpenDirectory( - Common::FS::GetYuzuPathString(Common::FS::YuzuPath::SDMCDir), FileSys::Mode::ReadWrite); - auto load_directory = vfs.OpenDirectory( - Common::FS::GetYuzuPathString(Common::FS::YuzuPath::LoadDir), FileSys::Mode::ReadWrite); - auto dump_directory = vfs.OpenDirectory( - Common::FS::GetYuzuPathString(Common::FS::YuzuPath::DumpDir), FileSys::Mode::ReadWrite); + using YuzuPath = Common::FS::YuzuPath; + const auto rw_mode = FileSys::Mode::ReadWrite; + + auto nand_directory = + vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::NANDDir), rw_mode); + auto sd_directory = + vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::SDMCDir), rw_mode); + auto load_directory = + vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::LoadDir), rw_mode); + auto dump_directory = + vfs.OpenDirectory(Common::FS::GetYuzuPathString(YuzuPath::DumpDir), rw_mode); if (bis_factory == nullptr) { bis_factory = diff --git a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp index 433b9e2bc..0deb86517 100755 --- a/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp +++ b/src/video_core/renderer_opengl/gl_shader_disk_cache.cpp @@ -76,21 +76,16 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { if (!file.ReadObject(type)) { return false; } - u32 code_size; u32 code_size_b; - if (!file.ReadObject(code_size) || !file.ReadObject(code_size_b)) { return false; } - code.resize(code_size); code_b.resize(code_size_b); - if (file.Read(code) != code_size) { return false; } - if (HasProgramA() && file.Read(code_b) != code_size_b) { return false; } @@ -101,7 +96,6 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { u32 num_bound_samplers; u32 num_separate_samplers; u32 num_bindless_samplers; - if (!file.ReadObject(unique_identifier) || !file.ReadObject(bound_buffer) || !file.ReadObject(is_texture_handler_size_known) || !file.ReadObject(texture_handler_size_value) || !file.ReadObject(graphics_info) || @@ -110,7 +104,6 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { !file.ReadObject(num_bindless_samplers)) { return false; } - if (is_texture_handler_size_known) { texture_handler_size = texture_handler_size_value; } @@ -119,29 +112,24 @@ bool ShaderDiskCacheEntry::Load(Common::FS::IOFile& file) { std::vector flat_bound_samplers(num_bound_samplers); std::vector flat_separate_samplers(num_separate_samplers); std::vector flat_bindless_samplers(num_bindless_samplers); - if (file.Read(flat_keys) != flat_keys.size() || file.Read(flat_bound_samplers) != flat_bound_samplers.size() || file.Read(flat_separate_samplers) != flat_separate_samplers.size() || file.Read(flat_bindless_samplers) != flat_bindless_samplers.size()) { return false; } - for (const auto& entry : flat_keys) { keys.insert({{entry.cbuf, entry.offset}, entry.value}); } - for (const auto& entry : flat_bound_samplers) { bound_samplers.emplace(entry.offset, entry.sampler); } - for (const auto& entry : flat_separate_samplers) { SeparateSamplerKey key; key.buffers = {entry.cbuf1, entry.cbuf2}; key.offsets = {entry.offset1, entry.offset2}; separate_samplers.emplace(key, entry.sampler); } - for (const auto& entry : flat_bindless_samplers) { bindless_samplers.insert({{entry.cbuf, entry.offset}, entry.sampler}); } @@ -155,11 +143,9 @@ bool ShaderDiskCacheEntry::Save(Common::FS::IOFile& file) const { !file.WriteObject(static_cast(code_b.size()))) { return false; } - if (file.Write(code) != code.size()) { return false; } - if (HasProgramA() && file.Write(code_b) != code_b.size()) { return false; } @@ -226,7 +212,6 @@ std::optional> ShaderDiskCacheOpenGL::LoadTran Common::FS::IOFile file{GetTransferablePath(), Common::FS::FileAccessMode::Read, Common::FS::FileType::BinaryFile}; - if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No transferable shader cache found"); is_usable = true; @@ -234,7 +219,6 @@ std::optional> ShaderDiskCacheOpenGL::LoadTran } u32 version{}; - if (!file.ReadObject(version)) { LOG_ERROR(Render_OpenGL, "Failed to get transferable cache version, skipping it"); return std::nullopt; @@ -274,7 +258,6 @@ std::vector ShaderDiskCacheOpenGL::LoadPrecompiled() Common::FS::IOFile file{GetPrecompiledPath(), Common::FS::FileAccessMode::Read, Common::FS::FileType::BinaryFile}; - if (!file.IsOpen()) { LOG_INFO(Render_OpenGL, "No precompiled shader cache found"); return {}; @@ -294,11 +277,9 @@ std::optional> ShaderDiskCacheOpenGL::Lo Common::FS::IOFile& file) { // Read compressed file from disk and decompress to virtual precompiled cache file std::vector compressed(file.GetSize()); - if (file.Read(compressed) != file.GetSize()) { return std::nullopt; } - const std::vector decompressed = Common::Compression::DecompressDataZSTD(compressed); SaveArrayToPrecompiled(decompressed.data(), decompressed.size()); precompiled_cache_virtual_file_offset = 0; @@ -337,7 +318,6 @@ void ShaderDiskCacheOpenGL::InvalidateTransferable() { LOG_ERROR(Render_OpenGL, "Failed to invalidate transferable file={}", Common::FS::PathToUTF8String(GetTransferablePath())); } - InvalidatePrecompiled(); } @@ -363,11 +343,9 @@ void ShaderDiskCacheOpenGL::SaveEntry(const ShaderDiskCacheEntry& entry) { } Common::FS::IOFile file = AppendTransferableFile(); - if (!file.IsOpen()) { return; } - if (!entry.Save(file)) { LOG_ERROR(Render_OpenGL, "Failed to save raw transferable cache entry, removing"); file.Close(); @@ -411,18 +389,16 @@ Common::FS::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { return {}; } - const auto transferable_path = GetTransferablePath(); + const auto transferable_path{GetTransferablePath()}; const bool existed = Common::FS::Exists(transferable_path); Common::FS::IOFile file{transferable_path, Common::FS::FileAccessMode::Append, Common::FS::FileType::BinaryFile}; - if (!file.IsOpen()) { LOG_ERROR(Render_OpenGL, "Failed to open transferable cache in path={}", Common::FS::PathToUTF8String(transferable_path)); return {}; } - if (!existed || file.GetSize() == 0) { // If the file didn't exist, write its version if (!file.WriteObject(NativeVersion)) { @@ -431,7 +407,6 @@ Common::FS::IOFile ShaderDiskCacheOpenGL::AppendTransferableFile() const { return {}; } } - return file; } @@ -459,7 +434,6 @@ void ShaderDiskCacheOpenGL::SaveVirtualPrecompiledFile() { Common::FS::PathToUTF8String(precompiled_path)); return; } - if (file.Write(compressed) != compressed.size()) { LOG_ERROR(Render_OpenGL, "Failed to write precompiled cache version in path={}", Common::FS::PathToUTF8String(precompiled_path)); diff --git a/src/yuzu/configuration/config.cpp b/src/yuzu/configuration/config.cpp index ec859c9d3..6c1592a87 100755 --- a/src/yuzu/configuration/config.cpp +++ b/src/yuzu/configuration/config.cpp @@ -244,26 +244,25 @@ const std::array Config::default_hotkeys{{ void Config::Initialize(const std::string& config_name) { const auto fs_config_loc = FS::GetYuzuPath(FS::YuzuPath::ConfigDir); + const auto config_file = fmt::format("{}.ini", config_name); switch (type) { case ConfigType::GlobalConfig: - qt_config_loc = FS::PathToUTF8String(fs_config_loc / fmt::format("{}.ini", config_name)); + qt_config_loc = FS::PathToUTF8String(fs_config_loc / config_file); void(FS::CreateParentDir(qt_config_loc)); qt_config = std::make_unique(QString::fromStdString(qt_config_loc), QSettings::IniFormat); Reload(); break; case ConfigType::PerGameConfig: - qt_config_loc = - FS::PathToUTF8String(fs_config_loc / "custom" / fmt::format("{}.ini", config_name)); + qt_config_loc = FS::PathToUTF8String(fs_config_loc / "custom" / config_file); void(FS::CreateParentDir(qt_config_loc)); qt_config = std::make_unique(QString::fromStdString(qt_config_loc), QSettings::IniFormat); Reload(); break; case ConfigType::InputProfile: - qt_config_loc = - FS::PathToUTF8String(fs_config_loc / "input" / fmt::format("{}.ini", config_name)); + qt_config_loc = FS::PathToUTF8String(fs_config_loc / "input" / config_file); void(FS::CreateParentDir(qt_config_loc)); qt_config = std::make_unique(QString::fromStdString(qt_config_loc), QSettings::IniFormat); diff --git a/src/yuzu/game_list_worker.cpp b/src/yuzu/game_list_worker.cpp index 1028f382b..485045334 100755 --- a/src/yuzu/game_list_worker.cpp +++ b/src/yuzu/game_list_worker.cpp @@ -297,7 +297,6 @@ void GameListWorker::ScanFileSystem(ScanTarget target, const std::string& dir_pa } const auto physical_name = Common::FS::PathToUTF8String(path); - const auto is_dir = Common::FS::IsDir(path); if (!is_dir && diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp index d3398a93f..f45180a00 100755 --- a/src/yuzu/main.cpp +++ b/src/yuzu/main.cpp @@ -2953,12 +2953,11 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) { if (res == QMessageBox::Cancel) return; - void(Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir) / - "prod.keys_autogenerated")); - void(Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir) / - "console.keys_autogenerated")); - void(Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir) / - "title.keys_autogenerated")); + const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); + + void(Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated")); + void(Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated")); + void(Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated")); } Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance(); diff --git a/src/yuzu_cmd/config.cpp b/src/yuzu_cmd/config.cpp index 7ad125a35..a2ab69cdd 100755 --- a/src/yuzu_cmd/config.cpp +++ b/src/yuzu_cmd/config.cpp @@ -41,22 +41,23 @@ Config::Config() { Config::~Config() = default; bool Config::LoadINI(const std::string& default_contents, bool retry) { + const auto config_loc_str = FS::PathToUTF8String(sdl2_config_loc); if (sdl2_config->ParseError() < 0) { if (retry) { LOG_WARNING(Config, "Failed to load {}. Creating file from defaults...", - FS::PathToUTF8String(sdl2_config_loc)); + config_loc_str); void(FS::CreateParentDir(sdl2_config_loc)); void(FS::WriteStringToFile(sdl2_config_loc, FS::FileType::TextFile, default_contents)); - sdl2_config = std::make_unique(FS::PathToUTF8String(sdl2_config_loc)); + sdl2_config = std::make_unique(config_loc_str); return LoadINI(default_contents, false); } LOG_ERROR(Config, "Failed."); return false; } - LOG_INFO(Config, "Successfully loaded {}", FS::PathToUTF8String(sdl2_config_loc)); + LOG_INFO(Config, "Successfully loaded {}", config_loc_str); return true; }