summaryrefslogtreecommitdiff
path: root/src/common/file_util.h
AgeCommit message (Collapse)Author
2020-04-15file_util: Early-exit in WriteArray and ReadArray if specified lengths are zeroLioncash
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.
2019-05-23common/file_util: Make GetCurrentDir() return a std::optionalLioncash
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-23common/file_util: Make ReadFileToString and WriteStringToFile consistentLioncash
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-23common/file_util: Remove unnecessary c_str() callsLioncash
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-23common/file_util: Make IOFile's WriteString take a std::string_viewLioncash
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-02-06file_util: Add shader directoryReinUsesLisp
2018-10-02string_util: remove TString conversion for windowsWeiyi Wang
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-09-21common_paths: Add Load and Dump dirsZach Hilman
2018-09-15Port #4182 from Citra: "Prefix all size_t with std::"fearlessTobi
2018-08-11file_util: Add getter for NAND registration directoryZach Hilman
2018-08-08file_util: Use enum instead of bool for specifing path behaviorZach Hilman
2018-08-08file_util: Add platform-specific slash option to SanitizePathZach Hilman
2018-08-08Merge pull request #966 from lioncash/modernizebunnei
common: Convert type traits templates over to variable template versions where applicable
2018-08-07common: Convert type traits templates over to variable template versions ↵Lioncash
where applicable Uses the C++17 inline variable variants
2018-08-07file_util: Avoid sign-conversions in WriteArray() and ReadArray()Lioncash
Prevents compiler warnings.
2018-08-01Allow key loading from %YUZU_DIR%/keys in addition to ~/.switchZach Hilman
2018-08-01Remove files that are not usedZach Hilman
2018-07-23VFS Regression and Accuracy Fixes (#776)Zach Hilman
* 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-22file_util, vfs: Use std::string_view where applicableLioncash
Avoids unnecessary construction of std::string instances where applicable.
2018-07-21file_util: Use a u64 to represent number of entriesLioncash
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-21file_util: Use an enum class for GetUserPath()Lioncash
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-19file_util: return string by const reference for GetExeDirectory()Lioncash
This disallows modifying the internal string buffer (which shouldn't be modified anyhow).
2018-07-18Virtual Filesystem 2: Electric Boogaloo (#676)Zach Hilman
* Virtual Filesystem * Fix delete bug and documentate * Review fixes + other stuff * Fix puyo regression
2018-07-07Revert "Virtual Filesystem (#597)"bunnei
This reverts commit 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.
2018-07-06Virtual Filesystem (#597)Zach Hilman
* 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-02Add configurable logging backendsJames Rowe
2018-04-29file_util: Make move constructor/assignment operator and related functions ↵Lioncash
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-29file_util: Add static assertions to ReadBytes() and WriteBytes()Lioncash
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-28file_util: Remove compiler version checks around is_trivially_copyable()Lioncash
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-03-26file_util.h: Update Comment from citra to yuzuN00byKing
2018-01-20Format: Run the new clang format on everythingJames Rowe
2016-12-21file_util: Remove unused paths.bunnei
2016-11-24Switch to AppData/Roamingfreiro
2016-11-19Return by value and other fixesfreiro
2016-11-19Win32 move default user folder location to AppDatafreiro
2016-09-21Remove empty newlines in #include blocks.Emmanuel Gil Peyrot
This makes clang-format useful on those. Also add a bunch of forgotten transitive includes, which otherwise prevented compilation.
2016-09-18Sources: Run clang-format on everything.Emmanuel Gil Peyrot
2016-06-19Fix recursive scanning of directoriesYuri Kunde Schlesner
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-05-21Common: Make recursive FileUtil functions take a maximum recursionEmmanuel Gil Peyrot
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-04-30VideoCore: Run include-what-you-use and fix most includes.Emmanuel Gil Peyrot
2016-04-23Protect use of std::is_trivially_copyable to compile with GCC 4.9LittleWhite
2016-04-13file_util: In-class initialize data membersLioncash
2016-04-13file_util: const qualify IOFile's Tell and GetSize functionsLioncash
2016-04-13file_util: Don't expose IOFile internals through the APILioncash
2016-04-13file_util: Check for is_trivially_copyableLioncash
Also applies the template checks to ReadArray as well.
2016-04-13file_util: Make IOFile data members privateLioncash
2016-04-12FileUtil: Missing #include, Add const to IOFile methodsMerryMage
2015-11-27Refactor ScanDirectoryTreeAndCallback to separate errors and retvalsarchshift
ScanDirectoryTreeAndCallback, before this change, coupled error/return codes and actual return values (number of entries found). This caused confusion and difficulty interpreting the precise way the function worked. Supersedes, and closes #1255.
2015-09-30Split up FileUtil::ScanDirectoryTree to be able to use callbacks for custom ↵archshift
behavior Converted FileUtil::ScanDirectoryTree and FileUtil::DeleteDirRecursively to use the new ScanDirectoryTreeAndCallback function internally.
2015-08-17Fix building under MinGWdarkf