Commit graph

85 commits

Author SHA1 Message Date
Morph
8941cdb7d2 Revert "Merge pull request #5174 from ReinUsesLisp/fs-fix"
This reverts commit 5fe55b16a1, reversing
changes made to e94dd7e2c4.
2020-12-11 20:24:22 -05:00
ReinUsesLisp
5329834376 common/file_util: Fix and deprecate CreateFullPath, add CreateDirs
Fix CreateFullPath to have its intended previous behavior (whatever
that was), and deprecate it in favor of the new CreateDirs function.

Unlike CreateDir, CreateDirs is marked as [[nodiscard]] to avoid new
code ignoring its result value.
2020-12-09 05:42:03 -03:00
Lioncash
20aad9e01a file_util: Migrate remaining file handling functions over to std::filesystem
Converts creation and deletion functions over to std::filesystem,
simplifying our file-handling code.

Notably with this, CopyDir will now function on Windows.
2020-12-09 01:24:05 -05:00
Lioncash
0e54aa17e6 file_util: Migrate Exists() and IsDirectory() over to std::filesystem
Greatly simplifies our file-handling code for these functions.
2020-12-08 18:36:53 -05:00
Lioncash
26547d3e3b General: Make ignoring a discarded return value an error
Allows our CI to catch more potential bugs. This also removes the
[[nodiscard]] attribute of IOFile's Open member function. There are
cases where a file may want to be opened, but have the status of it
checked at a later time.
2020-10-30 00:13:21 -04:00
bunnei
3d592972dc
Revert "core: Fix clang build" 2020-10-20 19:07:39 -07:00
Lioncash
be1954e04c core: Fix clang build
Recent changes to the build system that made more warnings be flagged as
errors caused building via clang to break.

Fixes #4795
2020-10-17 19:50:39 -04:00
Lioncash
c4ed791164 common/fileutil: Convert namespace to Common::FS
Migrates a remaining common file over to the Common namespace, making it
consistent with the rest of common files.

This also allows for high-traffic FS related code to alias the
filesystem function namespace as

namespace FS = Common::FS;

for more concise typing.
2020-08-16 06:52:40 -04:00
Lioncash
df72480395 common: Make use of [[nodiscard]] where applicable
Now that clang-format makes [[nodiscard]] attributes format sensibly, we
can apply them to several functions within the common library to allow
the compiler to complain about any misuses of the functions.
2020-08-15 17:17:52 -04:00
lat9nq
3848155c42 common: Add a screenshots directory
Adds a screenshots directory as a path managed by FileUtil.
2020-07-20 22:51:02 -04:00
Lioncash
e77337588e file_util: Early-exit in WriteArray and ReadArray if specified lengths are zero
It's undefined behavior to pass a null pointer to std::fread and
std::fwrite, even if the length passed in is zero, so we must perform
the precondition checking ourselves.

A common case where this can occur is when passing in the data of an
empty std::vector and size, as an empty vector will typically have a
null internal buffer.

While we're at it, we can move the implementation out of line and add
debug checks against passing in nullptr to std::fread and std::fwrite.
2020-04-15 14:43:37 -04:00
Lioncash
11e9bee91d common/file_util: Make GetCurrentDir() return a std::optional
nullptr was being returned in the error case, which, at a glance may
seem perfectly OK... until you realize that std::string has the
invariant that it may not be constructed from a null pointer. This
means that if this error case was ever hit, then the application would
most likely crash from a thrown exception in std::string's constructor.

Instead, we can change the function to return an optional value,
indicating if a failure occurred.
2019-05-23 14:24:13 -04:00
Lioncash
2b1fcc8a14 common/file_util: Make ReadFileToString and WriteStringToFile consistent
Makes the parameter ordering consistent, and also makes the filename
parameter a std::string. A std::string would be constructed anyways with
the previous code, as IOFile's only constructor with a filepath is one
taking a std::string.

We can also make WriteStringToFile's string parameter utilize a
std::string_view for the string, making use of our previous changes to
IOFile.
2019-05-23 13:52:43 -04:00
Lioncash
e3b2539986 common/file_util: Remove unnecessary c_str() calls
The file stream open functions have supported std::string overloads
since C++11, so we don't need to use c_str() here. Same behavior, less
code.
2019-05-23 13:37:47 -04:00
Lioncash
8cd3d9be26 common/file_util: Make IOFile's WriteString take a std::string_view
We don't need to force the usage of a std::string here, and can instead
use a std::string_view, which allows writing out other forms of strings
(e.g. C-style strings) without any unnecessary heap allocations.
2019-05-23 13:35:31 -04:00
ReinUsesLisp
84412591c9 file_util: Add shader directory 2019-02-06 22:20:57 -03:00
Weiyi Wang
bfe84f06f2 string_util: remove TString conversion for windows
First of all they are foundamentally broken. As our convention is that std::string is always UTF-8, these functions assume that the multi-byte character version of TString (std::string) from windows is also in UTF-8, which is almost always wrong. We are not going to build multi-byte character build, and even if we do, this dirty work should be handled by frontend framework early.
2018-10-02 16:10:20 +02:00
Zach Hilman
bd8db3f7f8 common_paths: Add Load and Dump dirs 2018-09-21 19:53:05 -04:00
fearlessTobi
63c2e32e20 Port #4182 from Citra: "Prefix all size_t with std::" 2018-09-15 15:21:06 +02:00
Zach Hilman
b70a831608 file_util: Add getter for NAND registration directory 2018-08-11 22:50:08 -04:00
Zach Hilman
2b6128fe0b file_util: Use enum instead of bool for specifing path behavior 2018-08-08 21:18:45 -04:00
Zach Hilman
3f82dad1e4 file_util: Add platform-specific slash option to SanitizePath 2018-08-08 21:18:45 -04:00
bunnei
d224eb7c39
Merge pull request #966 from lioncash/modernize
common: Convert type traits templates over to variable template versions where applicable
2018-08-08 15:28:34 -04:00
Lioncash
a7d6efc520 common: Convert type traits templates over to variable template versions where applicable
Uses the C++17 inline variable variants
2018-08-07 19:34:47 -04:00
Lioncash
0735a0c8a1 file_util: Avoid sign-conversions in WriteArray() and ReadArray()
Prevents compiler warnings.
2018-08-07 13:51:37 -04:00
Zach Hilman
150527ec19 Allow key loading from %YUZU_DIR%/keys in addition to ~/.switch 2018-08-01 00:16:54 -04:00
Zach Hilman
df5b75694f Remove files that are not used 2018-08-01 00:16:54 -04:00
Zach Hilman
59cb258409 VFS Regression and Accuracy Fixes (#776)
* Regression and Mode Fixes

* Review Fixes

* string_view correction

* Add operator& for FileSys::Mode

* Return std::string from SanitizePath

* Farming Simulator Fix

* Use != With mode operator&
2018-07-23 19:40:35 -07:00
Lioncash
398444e676 file_util, vfs: Use std::string_view where applicable
Avoids unnecessary construction of std::string instances where
applicable.
2018-07-22 03:22:21 -04:00
Lioncash
0ba7fe4ab1 file_util: Use a u64 to represent number of entries
This avoids a truncating cast on size. I doubt we'd ever traverse a
directory this large, however we also shouldn't truncate sizes away.
2018-07-21 22:42:08 -04:00
Lioncash
d66b43dadf file_util: Use an enum class for GetUserPath()
Instead of using an unsigned int as a parameter and expecting a user to
always pass in the correct values, we can just convert the enum into an
enum class and use that type as the parameter type instead, which makes
the interface more type safe.

We also get rid of the bookkeeping "NUM_" element in the enum by just
using an unordered map. This function is generally low-frequency in
terms of calls (and I'd hope so, considering otherwise would mean we're
slamming the disk with IO all the time) so I'd consider this acceptable
in this case.
2018-07-21 16:21:19 -04:00
Lioncash
63e64f0131 file_util: return string by const reference for GetExeDirectory()
This disallows modifying the internal string buffer (which shouldn't be
modified anyhow).
2018-07-19 01:27:29 -04:00
Zach Hilman
29aff8d5ab Virtual Filesystem 2: Electric Boogaloo (#676)
* Virtual Filesystem

* Fix delete bug and documentate

* Review fixes + other stuff

* Fix puyo regression
2018-07-18 18:07:11 -07:00
bunnei
913896cbd9 Revert "Virtual Filesystem (#597)"
This reverts commit 77c684c114.
2018-07-07 20:24:51 -07:00
Zach Hilman
77c684c114 Virtual Filesystem (#597)
* Add VfsFile and VfsDirectory classes

* Finish abstract Vfs classes

* Implement RealVfsFile (computer fs backend)

* Finish RealVfsFile and RealVfsDirectory

* Finished OffsetVfsFile

* More changes

* Fix import paths

* Major refactor

* Remove double const

* Use experimental/filesystem or filesystem depending on compiler

* Port partition_filesystem

* More changes

* More Overhaul

* FSP_SRV fixes

* Fixes and testing

* Try to get filesystem to compile

* Filesystem on linux

* Remove std::filesystem and document/test

* Compile fixes

* Missing include

* Bug fixes

* Fixes

* Rename v_file and v_dir

* clang-format fix

* Rename NGLOG_* to LOG_*

* Most review changes

* Fix TODO

* Guess 'main' to be Directory by filename
2018-07-06 10:51:32 -04:00
James Rowe
6269a01b4e Add configurable logging backends 2018-07-02 21:45:47 -04:00
Lioncash
e8bbafb746
file_util: Make move constructor/assignment operator and related functions noexcept
Without this, it's possible to get compilation failures in the (rare) scenario where
a container is used to store a bunch of live IOFile instances, as they may be using
std::move_if_noexcept under the hood. Given these definitely don't throw exceptions
this is also not incorrect to add either.
2018-04-29 18:34:09 -04:00
Lioncash
40d2dcabd7
file_util: Add static assertions to ReadBytes() and WriteBytes()
Ensure that the actual types being passed in are trivially copyable. The internal
call to ReadArray() and WriteArray() will always succeed, since they're passed a pointer to char*
which is always trivially copyable.
2018-04-29 18:24:12 -04:00
Lioncash
5d9ee12b1a
file_util: Remove compiler version checks around is_trivially_copyable()
The minimum clang/GCC versions we support already support this. We can also
remove is_standard_layout(), as fread and fwrite only require the type to be
trivially copyable.
2018-04-28 15:31:23 -04:00
N00byKing
75da830c13
file_util.h: Update Comment from citra to yuzu 2018-03-26 21:51:04 +02:00
James Rowe
096be16636 Format: Run the new clang format on everything 2018-01-20 16:45:11 -07:00
bunnei
707cc66362 file_util: Remove unused paths. 2016-12-21 23:29:12 -05:00
freiro
79317b63d9 Switch to AppData/Roaming 2016-11-24 16:42:31 +01:00
freiro
3d75e3cd07 Return by value and other fixes 2016-11-19 15:50:16 +01:00
freiro
29bb82cb8e Win32 move default user folder location to AppData 2016-11-19 15:49:52 +01:00
Emmanuel Gil Peyrot
ebdae19fd2 Remove empty newlines in #include blocks.
This makes clang-format useful on those.

Also add a bunch of forgotten transitive includes, which otherwise
prevented compilation.
2016-09-21 11:15:47 +09:00
Emmanuel Gil Peyrot
dc8479928c Sources: Run clang-format on everything. 2016-09-18 09:38:01 +09:00
Yuri Kunde Schlesner
d6792632f0 Fix recursive scanning of directories
ForeachDirectoryEntry didn't actually do anything with the `recursive`
parameter, and the corresponding callback parameter was shadowing the
actual recursion counters in the user functions.
2016-06-19 00:12:15 -07:00
Emmanuel Gil Peyrot
8ab6f26c09 Common: Make recursive FileUtil functions take a maximum recursion
Fixes #1115.

Also improves the performances of DiskArchive’s directory
implementation a lot, simply by not going through the entire tree
instead of just listing the first level files.

Thanks to JayRoxFox for rebasing this on current master!
2016-05-21 16:41:02 +01:00
Emmanuel Gil Peyrot
691a42fe98 VideoCore: Run include-what-you-use and fix most includes. 2016-04-30 17:02:41 +01:00