summaryrefslogtreecommitdiffstats
path: root/src/common/file_util.cpp (unfollow)
Commit message (Collapse)AuthorFilesLines
2020-12-12Revert "Merge pull request #5173 from lioncash/common-fs"Morph1-89/+350
This reverts commit ce5fcb6bb2c358b0251a2ce87945bda52789a76d, reversing changes made to 6f41763061082d5fa2ab039c554427152243cb46.
2020-12-12Revert "Merge pull request #5174 from ReinUsesLisp/fs-fix"Morph1-28/+2
This reverts commit 5fe55b16a11d9ec607fb8a3fdddc77a4393cd96a, reversing changes made to e94dd7e2c4fc3f7ca2c15c01bdc301be2b8a4c1b.
2020-12-12Revert "Merge pull request #5179 from ReinUsesLisp/fs-path"Morph1-1/+1
This reverts commit 4e94d0d53af2cdb7b03ef9de23cc29f3565df97a, reversing changes made to 6d6115475b4edccdf1bb4e96ecc3d3b1be319e76.
2020-12-12Revert "Merge pull request #5181 from Morph1984/5174-review"Morph1-3/+9
This reverts commit cdb36aef9ec9d30bdef1953f9ed46776ae2f12af, reversing changes made to 5e9b77129f2cf8c039a8d98033cae4ac0f93f515.
2020-12-10common/file_util: Simplify the behavior of CreateFullPathMorph1-9/+3
2020-12-09common/file_util: Let std::filesystem cast from UTF16 to std::stringReinUsesLisp1-1/+1
Fix invalid encoding paths when iterating over a directory on Windows.
2020-12-09common/file_util: Fix and deprecate CreateFullPath, add CreateDirsReinUsesLisp1-2/+23
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-09common/file_util: Succeed on CreateDir when the directory existsReinUsesLisp1-0/+5
2020-12-09file_util: Migrate remaining file handling functions over to std::filesystemLioncash1-297/+81
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-09file_util: Migrate Exists() and IsDirectory() over to std::filesystemLioncash1-53/+8
Greatly simplifies our file-handling code for these functions.
2020-11-02common: Enable warnings as errorsLioncash1-13/+18
Cleans up common so that we can enable warnings as errors.
2020-08-16common/fileutil: Convert namespace to Common::FSLioncash1-28/+36
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-16common: Silence two discarded result warningsLioncash1-2/+2
These are intentionally discarded internally, since the rest of the public API allows querying success. We want all non-internal uses of these functions to be explicitly checked, so we can signify that we intentionally want to discard the return values here.
2020-07-21common: Add a screenshots directorylat9nq1-0/+1
Adds a screenshots directory as a path managed by FileUtil.
2020-04-15file_util: Early-exit in WriteArray and ReadArray if specified lengths are zeroLioncash1-0/+28
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-09common/file_util: Allow access to files on network sharesBen Russell1-1/+8
On Windows, network shares use paths like \\server\share\file which were being broken by FileUtil::SanitizePath() removing double slashes. Changed the code in SanitizePath to permit a double-backslash if it occurs at the start of a filepath (on Windows only).
2020-04-01common: Port some changes from dolphin (#5127)Vitor K1-9/+13
* IOFile: Make the move constructor and move assignment operator noexcept Certain parts of the standard library try to determine whether or not a transfer operation should either be a copy or a move. The prevalent notion of move constructors/assignment operators is that they should not throw, they simply move an already existing resource somewhere else. This is typically done with 'std::move_if_noexcept'. Like the name says, if a type's move constructor is noexcept, then the functions retrieves an r-value reference (for move semantics), or an l-value (for copy semantics) if it is not noexcept. As IOFile deletes the copy constructor and copy assignment operators, using IOFile with certain parts of the standard library can fail in unexcepted ways (especially when used with various container implementations). This prevents that. * fix various instances of -1 being assigned to unsigned types * do not assign in conditional statements * File/IOFile: Check _tfopen_s properly * common/file_util.cpp: address review comments Co-authored-by: Lioncash <mathew1800@gmail.com> Co-authored-by: Shawn Hoffman <godisgovernment@gmail.com> Co-authored-by: Sepalani <sepalani@hotmail.fr>
2019-10-05common/file_util: Silence -WswitchReinUsesLisp1-1/+2
2019-05-23common/file_util: Remove unnecessary return at end of void StripTailDirSlashes()Lioncash1-6/+8
While we're at it, also invert the conditional into a guard clause.
2019-05-23common/file_util: Make GetCurrentDir() return a std::optionalLioncash1-2/+2
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: Remove duplicated documentation commentsLioncash1-25/+0
These are already present within the header, so they don't need to be repeated in the cpp file.
2019-05-23common/file_util: Make ReadFileToString and WriteStringToFile consistentLioncash1-3/+3
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-02-07file_util: Add shader directoryReinUsesLisp1-0/+1
2018-10-23only redefine 64 bit file operation for MSVCWeiyi Wang1-5/+8
MinGW provides POSIX functions
2018-09-22common_paths: Add Load and Dump dirsZach Hilman1-0/+2
2018-09-15Port #4182 from Citra: "Prefix all size_t with std::"fearlessTobi1-8/+8
2018-08-24file_util: Correct return value in early exit of ReadFileToString()Lioncash1-1/+1
While still essentially being zero, we should be returning a numeric value here, not a boolean typed value.
2018-08-12file_util: Add getter for NAND registration directoryZach Hilman1-0/+6
2018-08-09file_util: Use enum instead of bool for specifing path behaviorZach Hilman1-4/+4
2018-08-09file_util: Add platform-specific slash option to SanitizePathZach Hilman1-3/+13
2018-08-01Allow key loading from %YUZU_DIR%/keys in addition to ~/.switchZach Hilman1-0/+1
2018-08-01Use SHGetKnownFolderPath instead of SHGetFolderPathAZach Hilman1-3/+4
2018-08-01Extract mbedtls to cpp fileZach Hilman1-1/+1
2018-08-01Remove files that are not usedZach Hilman1-0/+12
2018-07-24VFS Regression and Accuracy Fixes (#776)Zach Hilman1-1/+10
* 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 applicableLioncash1-34/+48
Avoids unnecessary construction of std::string instances where applicable.
2018-07-22file_util: Remove goto usages from Copy()Lioncash1-24/+14
We can just leverage std::unique_ptr to automatically close these for us in error cases instead of jumping to the end of the function to call fclose on them.
2018-07-22file_util: Use a u64 to represent number of entriesLioncash1-9/+9
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-22file_util: std::move FST entries in ScanDirectoryTree()Lioncash1-1/+1
Avoids unnecessary copies when building up the FST entries.
2018-07-21file_util: Use an enum class for GetUserPath()Lioncash1-33/+35
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-21file_util: Remove explicit type from std::min() in GetPathWithoutTop()Lioncash1-1/+1
Given both operands are the same type, there won't be an issue with overload selection that requires making this explicit.
2018-07-21file_util: Remove redundant duplicate return in GetPathWithoutTop()Lioncash1-1/+0
2018-07-19file_util: return string by const reference for GetExeDirectory()Lioncash1-1/+1
This disallows modifying the internal string buffer (which shouldn't be modified anyhow).
2018-07-19Virtual Filesystem 2: Electric Boogaloo (#676)Zach Hilman1-26/+81
* Virtual Filesystem * Fix delete bug and documentate * Review fixes + other stuff * Fix puyo regression
2018-07-08Revert "Virtual Filesystem (#597)"bunnei1-67/+26
This reverts commit 77c684c1140f6bf3fb7d4560d06d2efb1a2ee5e2.
2018-07-06Virtual Filesystem (#597)Zach Hilman1-26/+67
* 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-06Remove some references to CitrafearlessTobi1-1/+1
2018-07-03Add configurable logging backendsJames Rowe1-5/+12
2018-07-03Update clang formatJames Rowe1-10/+8
2018-07-03Rename logging macro back to LOG_*James Rowe1-40/+40
2018-04-30file_util: Make move constructor/assignment operator and related functions noexceptLioncash1-3/+3
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-27general: Convert assertion macros over to be fmt-compatibleLioncash1-3/+3
2018-04-27common: Move logging macros over to new fmt-capable macros where applicableLioncash1-48/+48
2018-01-21Format: Run the new clang format on everythingJames Rowe1-9/+8
2017-03-11file_util: Log when using local user directorywwylele1-0/+2
2017-03-08file_util: lower logging level for harmless caseswwylele1-9/+7
2017-01-31file_util: Fixed implicit type conversion warning (#2503)noah the goodra1-2/+2
2016-12-23file_util: fix missing sysdata pathwwylele1-3/+1
2016-12-22file_util: Remove unused paths.bunnei1-49/+3
2016-12-13Common: Fix gcc build on macOSJeffrey Pfau1-0/+11
2016-11-30WINVER definition moved to CMake and cleanupfreiro1-3/+0
2016-11-26Removed /user/ from pathfreiro1-2/+1
2016-11-24Switch to AppData/Roamingfreiro1-3/+3
2016-11-19Return by value and other fixesfreiro1-13/+7
2016-11-19Win32 move default user folder location to AppDatafreiro1-0/+23
2016-10-28common: convert to standard stat()/fstat() interfacesAnthony J. Bentley1-15/+10
Most modern Unix environments use 64-bit off_t by default: OpenBSD, FreeBSD, OS X, and Linux libc implementations such as Musl. glibc is the lone exception; it can default to 32 bits but this is configurable by setting _FILE_OFFSET_BITS. Avoiding the stat64()/fstat64() interfaces is desirable because they are nonstandard and not implemented on many systems (including OpenBSD and FreeBSD), and using 64 bits for stat()/fstat() is either the default or trivial to set up.
2016-10-28common: stat64 is non-standard, hide on a random UnixJan Beich1-1/+1
src/common/file_util.cpp:79:19: error: variable has incomplete type 'struct stat64' struct stat64 file_info; ^ src/common/file_util.cpp:79:12: note: forward declaration of 'stat64' struct stat64 file_info; ^ src/common/file_util.cpp:99:19: error: variable has incomplete type 'struct stat64' struct stat64 file_info; ^ src/common/file_util.cpp:99:12: note: forward declaration of 'stat64' struct stat64 file_info; ^ src/common/file_util.cpp:342:19: error: variable has incomplete type 'struct stat64' struct stat64 buf; ^ src/common/file_util.cpp:342:12: note: forward declaration of 'stat64' struct stat64 buf; ^ src/common/file_util.cpp:359:19: error: variable has incomplete type 'struct stat64' struct stat64 buf; ^ src/common/file_util.cpp:359:12: note: forward declaration of 'stat64' struct stat64 buf; ^ 4 errors generated.
2016-09-21Remove special rules for Windows.h and library includesYuri Kunde Schlesner1-0/+1
2016-09-21Use negative priorities to avoid special-casing the self-includeYuri Kunde Schlesner1-1/+1
2016-09-21Remove empty newlines in #include blocks.Emmanuel Gil Peyrot1-1/+0
This makes clang-format useful on those. Also add a bunch of forgotten transitive includes, which otherwise prevented compilation.
2016-09-19Manually tweak source formatting and then re-run clang-formatYuri Kunde Schlesner1-2/+1
2016-09-18Sources: Run clang-format on everything.Emmanuel Gil Peyrot1-292/+223
2016-09-13Common: readdir_r() is deprecated, switch to readdir().Emmanuel Gil Peyrot1-6/+2
2016-06-19Fix recursive scanning of directoriesYuri Kunde Schlesner1-12/+10
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 Peyrot1-20/+28
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-15fix driver root identification on Windowswwylele1-3/+12
2016-04-14file_util: In-class initialize data membersLioncash1-4/+2
2016-04-14file_util: const qualify IOFile's Tell and GetSize functionsLioncash1-6/+6
2016-04-14file_util: Don't expose IOFile internals through the APILioncash1-22/+3
2016-03-31remove debug codeLFsWang1-1/+1
2016-03-31fix unicode url problem on windowsLFsWang1-6/+18
2016-03-31Fix encode problem On WindowsLFsWang1-12/+17
2016-01-16DiskDirectory: Initialize the directory member with valid info.Subv1-1/+1
2015-12-23Add missing return values in ForeachDirectoryEntryLFsWang1-4/+14
ForeachDirectoryEntry is changed by #1256 ,but return value at last line was missing.
2015-11-27Refactor ScanDirectoryTreeAndCallback to separate errors and retvalsarchshift1-37/+35
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-10-01Split up FileUtil::ScanDirectoryTree to be able to use callbacks for custom behaviorarchshift1-100/+60
Converted FileUtil::ScanDirectoryTree and FileUtil::DeleteDirRecursively to use the new ScanDirectoryTreeAndCallback function internally.
2015-09-16general: Silence some warnings when using clangLioncash1-2/+2
2015-06-28Common: Fix FileUtil includes, and everything relying on those.Emmanuel Gil Peyrot1-2/+9
2015-05-29Remove every trailing whitespace from the project (but externals).Emmanuel Gil Peyrot1-1/+1
2015-05-07Common: Remove common.hYuri Kunde Schlesner1-2/+4
2015-05-07Common: Move IO-specific compatibility macros to file_util.cppYuri Kunde Schlesner1-18/+26
2015-05-07Common: Remove many unnecessary cross-platform compatibility macrosYuri Kunde Schlesner1-2/+2
2015-02-25Common: Switch to the XDG Base Directory Specification for directory selection.Emmanuel Gil Peyrot1-9/+68
This allows for easily movable and independent configuration and data directories, using standardized paths.
2015-02-20Common: Change names containing “Dolphin” or “PPSSPP” to something more generic.Emmanuel Gil Peyrot1-7/+7
2015-01-04Archives: Changed the way paths are built for the archives.Subv1-10/+2
Each archive now takes a mount point of either NAND or SDMC, and builds its own directory structure there, trying to simulate an HLE-friendly hardware layout
2015-01-03Archives: Change the folder layout of some archives.Subv1-0/+2
This is to better represent the hardware layout, they are still aren't quite accurate, but this better and will help a bit when implementing the other archives like NAND-RO and NAND-RW
2015-01-03Archives: Reduced duplicate code in RomFS and SaveCheck.Subv1-0/+2
Fixed a few warnings and cleaned up the code
2014-12-30Archives: Implemented ExtSaveData and SharedExtSaveDataSubv1-0/+2
They will be stored in /extsavedata/SDMC and /extsavedata/NAND respectively. Also redirect some APT_A functions to their APT_U equivalents. Implemented the gamecoin.dat file in SharedExtSaveData in the PTM module. Implemented formatting the savegame. Retake a previous savegame if it exists instead of reporting them as not formatted every time a game is loaded.
2014-12-21License changepurpasmart961-2/+2
2014-12-18SaveData: Implemented the SystemSaveData archive.Subv1-0/+2
It will be stored in the /syssavedata folder. This archive is user by various Services and possibly games via the FS:U service.
2014-12-18Filesystem/Archives: Implemented the SaveData archiveSubv1-0/+2
The savedata for each game is stored in /savedata/<ProgramID> for NCCH files. ELF files and 3DSX files use the folder 0 because they have no ID information Got rid of the code duplication in File and Directory Files that deal with the host machine's file system now live in DiskFile, similarly for directories and DiskDirectory and archives with DiskArchive. FS_U: Use the correct error code when a file wasn't found
2014-12-13Convert old logging calls to new logging macrosYuri Kunde Schlesner1-42/+42
2014-12-12Common: Add "sysdata" to GetUserPath and cleanup.bunnei1-13/+1
2014-12-03Change NULLs to nullptrs.Rohit Nirmal1-12/+12
2014-11-19Remove trailing spaces in every file but the ones imported from SkyEye, AOSP or generatedEmmanuel Gil Peyrot1-31/+31
2014-10-23Use std sized types instead of platform specific typedefsYuri Kunde Schlesner1-0/+1
2014-10-23Common: Return from CreateFullPath early if the directory creation failsarchshift1-2/+4
2014-10-08Added configuration file system.archshift1-36/+36
Uses QSettings on citra-qt, and inih on citra-cli.
2014-10-06Common: Add a helper function to generate a 8.3 filename from a long one.Emmanuel Gil Peyrot1-0/+42
Core: Fix the SDMC Directory implementation to make blargSnes work.
2014-09-28Fix warnings in core and commonLioncash1-2/+2
2014-09-21Use the citra user path for the sdmc directoryarchshift1-0/+2
2014-09-17Common: Rename the File namespace to FileUtil, to match the filename and prevent collisions.Emmanuel Gil Peyrot1-19/+19
2014-09-09common: Prune all redundant includesarchshift1-7/+0
2014-09-09Added string_util to common, small changes in loader.cpparchshift1-13/+13
2014-08-17Common: Move remaining C header includes over to their C++ equivalentLioncash1-2/+2
2014-04-23fixes to build on linuxbunnei1-1/+1
2014-04-09fixed project includes to use new directory structurebunnei1-5/+5
2014-04-09got rid of 'src' folders in each sub-projectbunnei1-0/+0
2014-04-02convert tabs to spacesbunnei1-572/+572
2013-09-09fixed some code warningsShizZy1-1/+1
2013-09-09 removed unneeded dolphin paths code, fixed linker problems with common.libShizZy1-117/+105
2013-09-05replaced common code with dolphin commonShizZy1-0/+922