summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/common/fs/file.cpp4
-rw-r--r--src/common/fs/file.h12
-rw-r--r--src/common/fs/fs.cpp5
-rw-r--r--src/common/fs/fs.h30
-rw-r--r--src/common/logging/backend.cpp4
-rw-r--r--src/core/file_sys/vfs_real.cpp7
-rw-r--r--src/core/hle/service/bcat/backend/boxcat.cpp4
-rw-r--r--src/video_core/vulkan_common/nsight_aftermath_tracker.cpp2
-rw-r--r--src/yuzu/configuration/configure_per_game_addons.cpp4
-rw-r--r--src/yuzu/main.cpp24
10 files changed, 48 insertions, 48 deletions
diff --git a/src/common/fs/file.cpp b/src/common/fs/file.cpp
index 710e88b39..077f34995 100644
--- a/src/common/fs/file.cpp
+++ b/src/common/fs/file.cpp
@@ -172,7 +172,7 @@ std::string ReadStringFromFile(const std::filesystem::path& path, FileType type)
172 172
173size_t WriteStringToFile(const std::filesystem::path& path, FileType type, 173size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
174 std::string_view string) { 174 std::string_view string) {
175 if (!IsFile(path)) { 175 if (Exists(path) && !IsFile(path)) {
176 return 0; 176 return 0;
177 } 177 }
178 178
@@ -183,7 +183,7 @@ size_t WriteStringToFile(const std::filesystem::path& path, FileType type,
183 183
184size_t AppendStringToFile(const std::filesystem::path& path, FileType type, 184size_t AppendStringToFile(const std::filesystem::path& path, FileType type,
185 std::string_view string) { 185 std::string_view string) {
186 if (!IsFile(path)) { 186 if (Exists(path) && !IsFile(path)) {
187 return 0; 187 return 0;
188 } 188 }
189 189
diff --git a/src/common/fs/file.h b/src/common/fs/file.h
index 0f10b6003..588fe619d 100644
--- a/src/common/fs/file.h
+++ b/src/common/fs/file.h
@@ -49,7 +49,7 @@ void OpenFileStream(FileStream& file_stream, const Path& path, std::ios_base::op
49 49
50/** 50/**
51 * Reads an entire file at path and returns a string of the contents read from the file. 51 * Reads an entire file at path and returns a string of the contents read from the file.
52 * If the filesystem object at path is not a file, this function returns an empty string. 52 * If the filesystem object at path is not a regular file, this function returns an empty string.
53 * 53 *
54 * @param path Filesystem path 54 * @param path Filesystem path
55 * @param type File type 55 * @param type File type
@@ -72,7 +72,8 @@ template <typename Path>
72/** 72/**
73 * Writes a string to a file at path and returns the number of characters successfully written. 73 * Writes a string to a file at path and returns the number of characters successfully written.
74 * If a file already exists at path, its contents will be erased. 74 * If a file already exists at path, its contents will be erased.
75 * If the filesystem object at path is not a file, this function returns 0. 75 * If a file does not exist at path, it creates and opens a new empty file for writing.
76 * If the filesystem object at path exists and is not a regular file, this function returns 0.
76 * 77 *
77 * @param path Filesystem path 78 * @param path Filesystem path
78 * @param type File type 79 * @param type File type
@@ -95,7 +96,8 @@ template <typename Path>
95 96
96/** 97/**
97 * Appends a string to a file at path and returns the number of characters successfully written. 98 * Appends a string to a file at path and returns the number of characters successfully written.
98 * If the filesystem object at path is not a file, this function returns 0. 99 * If a file does not exist at path, it creates and opens a new empty file for appending.
100 * If the filesystem object at path exists and is not a regular file, this function returns 0.
99 * 101 *
100 * @param path Filesystem path 102 * @param path Filesystem path
101 * @param type File type 103 * @param type File type
@@ -394,11 +396,11 @@ public:
394 [[nodiscard]] size_t WriteString(std::span<const char> string) const; 396 [[nodiscard]] size_t WriteString(std::span<const char> string) const;
395 397
396 /** 398 /**
397 * Flushes any unwritten buffered data into the file. 399 * Attempts to flush any unwritten buffered data into the file and flush the file into the disk.
398 * 400 *
399 * @returns True if the flush was successful, false otherwise. 401 * @returns True if the flush was successful, false otherwise.
400 */ 402 */
401 [[nodiscard]] bool Flush() const; 403 bool Flush() const;
402 404
403 /** 405 /**
404 * Resizes the file to a given size. 406 * Resizes the file to a given size.
diff --git a/src/common/fs/fs.cpp b/src/common/fs/fs.cpp
index d3159e908..9089cad67 100644
--- a/src/common/fs/fs.cpp
+++ b/src/common/fs/fs.cpp
@@ -135,8 +135,9 @@ std::shared_ptr<IOFile> FileOpen(const fs::path& path, FileAccessMode mode, File
135 return nullptr; 135 return nullptr;
136 } 136 }
137 137
138 if (!IsFile(path)) { 138 if (Exists(path) && !IsFile(path)) {
139 LOG_ERROR(Common_Filesystem, "Filesystem object at path={} is not a file", 139 LOG_ERROR(Common_Filesystem,
140 "Filesystem object at path={} exists and is not a regular file",
140 PathToUTF8String(path)); 141 PathToUTF8String(path));
141 return nullptr; 142 return nullptr;
142 } 143 }
diff --git a/src/common/fs/fs.h b/src/common/fs/fs.h
index f6f256349..183126de3 100644
--- a/src/common/fs/fs.h
+++ b/src/common/fs/fs.h
@@ -48,18 +48,18 @@ template <typename Path>
48 * 48 *
49 * Failures occur when: 49 * Failures occur when:
50 * - Input path is not valid 50 * - Input path is not valid
51 * - Filesystem object at path is not a file 51 * - Filesystem object at path is not a regular file
52 * - Filesystem at path is read only 52 * - Filesystem at path is read only
53 * 53 *
54 * @param path Filesystem path 54 * @param path Filesystem path
55 * 55 *
56 * @returns True if file removal succeeds or file does not exist, false otherwise. 56 * @returns True if file removal succeeds or file does not exist, false otherwise.
57 */ 57 */
58[[nodiscard]] bool RemoveFile(const std::filesystem::path& path); 58bool RemoveFile(const std::filesystem::path& path);
59 59
60#ifdef _WIN32 60#ifdef _WIN32
61template <typename Path> 61template <typename Path>
62[[nodiscard]] bool RemoveFile(const Path& path) { 62bool RemoveFile(const Path& path) {
63 if constexpr (IsChar<typename Path::value_type>) { 63 if constexpr (IsChar<typename Path::value_type>) {
64 return RemoveFile(ToU8String(path)); 64 return RemoveFile(ToU8String(path));
65 } else { 65 } else {
@@ -74,7 +74,7 @@ template <typename Path>
74 * Failures occur when: 74 * Failures occur when:
75 * - One or both input path(s) is not valid 75 * - One or both input path(s) is not valid
76 * - Filesystem object at old_path does not exist 76 * - Filesystem object at old_path does not exist
77 * - Filesystem object at old_path is not a file 77 * - Filesystem object at old_path is not a regular file
78 * - Filesystem object at new_path exists 78 * - Filesystem object at new_path exists
79 * - Filesystem at either path is read only 79 * - Filesystem at either path is read only
80 * 80 *
@@ -110,8 +110,8 @@ template <typename Path1, typename Path2>
110 * 110 *
111 * Failures occur when: 111 * Failures occur when:
112 * - Input path is not valid 112 * - Input path is not valid
113 * - Filesystem object at path is not a file 113 * - Filesystem object at path exists and is not a regular file
114 * - The file is not opened 114 * - The file is not open
115 * 115 *
116 * @param path Filesystem path 116 * @param path Filesystem path
117 * @param mode File access mode 117 * @param mode File access mode
@@ -251,11 +251,11 @@ template <typename Path>
251 * 251 *
252 * @returns True if directory removal succeeds or directory does not exist, false otherwise. 252 * @returns True if directory removal succeeds or directory does not exist, false otherwise.
253 */ 253 */
254[[nodiscard]] bool RemoveDir(const std::filesystem::path& path); 254bool RemoveDir(const std::filesystem::path& path);
255 255
256#ifdef _WIN32 256#ifdef _WIN32
257template <typename Path> 257template <typename Path>
258[[nodiscard]] bool RemoveDir(const Path& path) { 258bool RemoveDir(const Path& path) {
259 if constexpr (IsChar<typename Path::value_type>) { 259 if constexpr (IsChar<typename Path::value_type>) {
260 return RemoveDir(ToU8String(path)); 260 return RemoveDir(ToU8String(path));
261 } else { 261 } else {
@@ -276,11 +276,11 @@ template <typename Path>
276 * 276 *
277 * @returns True if the directory and all of its contents are removed successfully, false otherwise. 277 * @returns True if the directory and all of its contents are removed successfully, false otherwise.
278 */ 278 */
279[[nodiscard]] bool RemoveDirRecursively(const std::filesystem::path& path); 279bool RemoveDirRecursively(const std::filesystem::path& path);
280 280
281#ifdef _WIN32 281#ifdef _WIN32
282template <typename Path> 282template <typename Path>
283[[nodiscard]] bool RemoveDirRecursively(const Path& path) { 283bool RemoveDirRecursively(const Path& path) {
284 if constexpr (IsChar<typename Path::value_type>) { 284 if constexpr (IsChar<typename Path::value_type>) {
285 return RemoveDirRecursively(ToU8String(path)); 285 return RemoveDirRecursively(ToU8String(path));
286 } else { 286 } else {
@@ -301,11 +301,11 @@ template <typename Path>
301 * 301 *
302 * @returns True if all of the directory's contents are removed successfully, false otherwise. 302 * @returns True if all of the directory's contents are removed successfully, false otherwise.
303 */ 303 */
304[[nodiscard]] bool RemoveDirContentsRecursively(const std::filesystem::path& path); 304bool RemoveDirContentsRecursively(const std::filesystem::path& path);
305 305
306#ifdef _WIN32 306#ifdef _WIN32
307template <typename Path> 307template <typename Path>
308[[nodiscard]] bool RemoveDirContentsRecursively(const Path& path) { 308bool RemoveDirContentsRecursively(const Path& path) {
309 if constexpr (IsChar<typename Path::value_type>) { 309 if constexpr (IsChar<typename Path::value_type>) {
310 return RemoveDirContentsRecursively(ToU8String(path)); 310 return RemoveDirContentsRecursively(ToU8String(path));
311 } else { 311 } else {
@@ -435,11 +435,13 @@ template <typename Path>
435#endif 435#endif
436 436
437/** 437/**
438 * Returns whether a filesystem object at path is a file. 438 * Returns whether a filesystem object at path is a regular file.
439 * A regular file is a file that stores text or binary data.
440 * It is not a directory, symlink, FIFO, socket, block device, or character device.
439 * 441 *
440 * @param path Filesystem path 442 * @param path Filesystem path
441 * 443 *
442 * @returns True if a filesystem object at path is a file, false otherwise. 444 * @returns True if a filesystem object at path is a regular file, false otherwise.
443 */ 445 */
444[[nodiscard]] bool IsFile(const std::filesystem::path& path); 446[[nodiscard]] bool IsFile(const std::filesystem::path& path);
445 447
diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp
index d5cff400f..47ce06478 100644
--- a/src/common/logging/backend.cpp
+++ b/src/common/logging/backend.cpp
@@ -159,7 +159,7 @@ FileBackend::FileBackend(const std::filesystem::path& filename) {
159 159
160 // Existence checks are done within the functions themselves. 160 // Existence checks are done within the functions themselves.
161 // We don't particularly care if these succeed or not. 161 // We don't particularly care if these succeed or not.
162 void(FS::RemoveFile(old_filename)); 162 FS::RemoveFile(old_filename);
163 void(FS::RenameFile(filename, old_filename)); 163 void(FS::RenameFile(filename, old_filename));
164 164
165 file = 165 file =
@@ -186,7 +186,7 @@ void FileBackend::Write(const Entry& entry) {
186 186
187 bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n')); 187 bytes_written += file->WriteString(FormatLogMessage(entry).append(1, '\n'));
188 if (entry.log_level >= Level::Error) { 188 if (entry.log_level >= Level::Error) {
189 void(file->Flush()); 189 file->Flush();
190 } 190 }
191} 191}
192 192
diff --git a/src/core/file_sys/vfs_real.cpp b/src/core/file_sys/vfs_real.cpp
index d0b8fd046..3dad54f49 100644
--- a/src/core/file_sys/vfs_real.cpp
+++ b/src/core/file_sys/vfs_real.cpp
@@ -24,17 +24,12 @@ constexpr FS::FileAccessMode ModeFlagsToFileAccessMode(Mode mode) {
24 case Mode::Read: 24 case Mode::Read:
25 return FS::FileAccessMode::Read; 25 return FS::FileAccessMode::Read;
26 case Mode::Write: 26 case Mode::Write:
27 return FS::FileAccessMode::Write;
28 case Mode::ReadWrite: 27 case Mode::ReadWrite:
29 return FS::FileAccessMode::ReadWrite;
30 case Mode::Append: 28 case Mode::Append:
31 return FS::FileAccessMode::Append;
32 case Mode::ReadAppend: 29 case Mode::ReadAppend:
33 return FS::FileAccessMode::ReadAppend;
34 case Mode::WriteAppend: 30 case Mode::WriteAppend:
35 return FS::FileAccessMode::Append;
36 case Mode::All: 31 case Mode::All:
37 return FS::FileAccessMode::ReadAppend; 32 return FS::FileAccessMode::ReadWrite;
38 default: 33 default:
39 return {}; 34 return {};
40 } 35 }
diff --git a/src/core/hle/service/bcat/backend/boxcat.cpp b/src/core/hle/service/bcat/backend/boxcat.cpp
index a2844ea8c..dc15cf58b 100644
--- a/src/core/hle/service/bcat/backend/boxcat.cpp
+++ b/src/core/hle/service/bcat/backend/boxcat.cpp
@@ -313,7 +313,7 @@ void SynchronizeInternal(AM::Applets::AppletManager& applet_manager, DirectoryGe
313 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res); 313 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
314 314
315 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) { 315 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
316 void(Common::FS::RemoveFile(zip_path)); 316 Common::FS::RemoveFile(zip_path);
317 } 317 }
318 318
319 HandleDownloadDisplayResult(applet_manager, res); 319 HandleDownloadDisplayResult(applet_manager, res);
@@ -445,7 +445,7 @@ std::optional<std::vector<u8>> Boxcat::GetLaunchParameter(TitleIDVersion title)
445 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res); 445 LOG_ERROR(Service_BCAT, "Boxcat synchronization failed with error '{}'!", res);
446 446
447 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) { 447 if (res == DownloadResult::NoMatchBuildId || res == DownloadResult::NoMatchTitleId) {
448 void(Common::FS::RemoveFile(bin_file_path)); 448 Common::FS::RemoveFile(bin_file_path);
449 } 449 }
450 450
451 HandleDownloadDisplayResult(applet_manager, res); 451 HandleDownloadDisplayResult(applet_manager, res);
diff --git a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
index f0ee76519..758c038ba 100644
--- a/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
+++ b/src/video_core/vulkan_common/nsight_aftermath_tracker.cpp
@@ -50,7 +50,7 @@ NsightAftermathTracker::NsightAftermathTracker() {
50 } 50 }
51 dump_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::LogDir) / "gpucrash"; 51 dump_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::LogDir) / "gpucrash";
52 52
53 void(Common::FS::RemoveDirRecursively(dump_dir)); 53 Common::FS::RemoveDirRecursively(dump_dir);
54 if (!Common::FS::CreateDir(dump_dir)) { 54 if (!Common::FS::CreateDir(dump_dir)) {
55 LOG_ERROR(Render_Vulkan, "Failed to create Nsight Aftermath dump directory"); 55 LOG_ERROR(Render_Vulkan, "Failed to create Nsight Aftermath dump directory");
56 return; 56 return;
diff --git a/src/yuzu/configuration/configure_per_game_addons.cpp b/src/yuzu/configuration/configure_per_game_addons.cpp
index 9b709d405..ebb0f411c 100644
--- a/src/yuzu/configuration/configure_per_game_addons.cpp
+++ b/src/yuzu/configuration/configure_per_game_addons.cpp
@@ -79,8 +79,8 @@ void ConfigurePerGameAddons::ApplyConfiguration() {
79 std::sort(disabled_addons.begin(), disabled_addons.end()); 79 std::sort(disabled_addons.begin(), disabled_addons.end());
80 std::sort(current.begin(), current.end()); 80 std::sort(current.begin(), current.end());
81 if (disabled_addons != current) { 81 if (disabled_addons != current) {
82 void(Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / 82 Common::FS::RemoveFile(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
83 "game_list" / fmt::format("{:016X}.pv.txt", title_id))); 83 "game_list" / fmt::format("{:016X}.pv.txt", title_id));
84 } 84 }
85 85
86 Settings::values.disabled_addons[title_id] = disabled_addons; 86 Settings::values.disabled_addons[title_id] = disabled_addons;
diff --git a/src/yuzu/main.cpp b/src/yuzu/main.cpp
index d4c7d2c0b..75ab5ef44 100644
--- a/src/yuzu/main.cpp
+++ b/src/yuzu/main.cpp
@@ -194,10 +194,10 @@ static void RemoveCachedContents() {
194 const auto offline_legal_information = cache_dir / "offline_web_applet_legal_information"; 194 const auto offline_legal_information = cache_dir / "offline_web_applet_legal_information";
195 const auto offline_system_data = cache_dir / "offline_web_applet_system_data"; 195 const auto offline_system_data = cache_dir / "offline_web_applet_system_data";
196 196
197 void(Common::FS::RemoveDirRecursively(offline_fonts)); 197 Common::FS::RemoveDirRecursively(offline_fonts);
198 void(Common::FS::RemoveDirRecursively(offline_manual)); 198 Common::FS::RemoveDirRecursively(offline_manual);
199 void(Common::FS::RemoveDirRecursively(offline_legal_information)); 199 Common::FS::RemoveDirRecursively(offline_legal_information);
200 void(Common::FS::RemoveDirRecursively(offline_system_data)); 200 Common::FS::RemoveDirRecursively(offline_system_data);
201} 201}
202 202
203GMainWindow::GMainWindow() 203GMainWindow::GMainWindow()
@@ -1743,8 +1743,8 @@ void GMainWindow::OnGameListRemoveInstalledEntry(u64 program_id, InstalledEntryT
1743 RemoveAddOnContent(program_id, entry_type); 1743 RemoveAddOnContent(program_id, entry_type);
1744 break; 1744 break;
1745 } 1745 }
1746 void(Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / 1746 Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
1747 "game_list")); 1747 "game_list");
1748 game_list->PopulateAsync(UISettings::values.game_dirs); 1748 game_list->PopulateAsync(UISettings::values.game_dirs);
1749} 1749}
1750 1750
@@ -2213,8 +2213,8 @@ void GMainWindow::OnMenuInstallToNAND() {
2213 : tr("%n file(s) failed to install\n", "", failed_files.size())); 2213 : tr("%n file(s) failed to install\n", "", failed_files.size()));
2214 2214
2215 QMessageBox::information(this, tr("Install Results"), install_results); 2215 QMessageBox::information(this, tr("Install Results"), install_results);
2216 void(Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) / 2216 Common::FS::RemoveDirRecursively(Common::FS::GetYuzuPath(Common::FS::YuzuPath::CacheDir) /
2217 "game_list")); 2217 "game_list");
2218 game_list->PopulateAsync(UISettings::values.game_dirs); 2218 game_list->PopulateAsync(UISettings::values.game_dirs);
2219 ui.action_Install_File_NAND->setEnabled(true); 2219 ui.action_Install_File_NAND->setEnabled(true);
2220} 2220}
@@ -2846,7 +2846,7 @@ void GMainWindow::MigrateConfigFiles() {
2846 LOG_INFO(Frontend, "Migrating config file from {} to {}", origin, destination); 2846 LOG_INFO(Frontend, "Migrating config file from {} to {}", origin, destination);
2847 if (!Common::FS::RenameFile(origin, destination)) { 2847 if (!Common::FS::RenameFile(origin, destination)) {
2848 // Delete the old config file if one already exists in the new location. 2848 // Delete the old config file if one already exists in the new location.
2849 void(Common::FS::RemoveFile(origin)); 2849 Common::FS::RemoveFile(origin);
2850 } 2850 }
2851 } 2851 }
2852} 2852}
@@ -3040,9 +3040,9 @@ void GMainWindow::OnReinitializeKeys(ReinitializeKeyBehavior behavior) {
3040 3040
3041 const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir); 3041 const auto keys_dir = Common::FS::GetYuzuPath(Common::FS::YuzuPath::KeysDir);
3042 3042
3043 void(Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated")); 3043 Common::FS::RemoveFile(keys_dir / "prod.keys_autogenerated");
3044 void(Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated")); 3044 Common::FS::RemoveFile(keys_dir / "console.keys_autogenerated");
3045 void(Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated")); 3045 Common::FS::RemoveFile(keys_dir / "title.keys_autogenerated");
3046 } 3046 }
3047 3047
3048 Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance(); 3048 Core::Crypto::KeyManager& keys = Core::Crypto::KeyManager::Instance();