diff --git a/Utilities/AutoPause.cpp b/Utilities/AutoPause.cpp index 0193fb8e3c..8ef5af6627 100644 --- a/Utilities/AutoPause.cpp +++ b/Utilities/AutoPause.cpp @@ -2,7 +2,7 @@ #include "rpcs3/Ini.h" #include "AutoPause.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Emu/System.h" using namespace Debug; @@ -44,14 +44,14 @@ AutoPause::~AutoPause(void) //This would be able to create in a GUI window. void AutoPause::Reload(void) { - if (rIsFile("pause.bin")) + if (fs::is_file("pause.bin")) { m_pause_function.clear(); m_pause_function.reserve(16); m_pause_syscall.clear(); m_pause_syscall.reserve(16); - rfile_t list("pause.bin"); + fs::file list("pause.bin"); //System calls ID and Function calls ID are all u32 iirc. u32 num; size_t fmax = list.size(); diff --git a/Utilities/rFile.cpp b/Utilities/File.cpp similarity index 83% rename from Utilities/rFile.cpp rename to Utilities/File.cpp index 9c7b180ae5..b96d00f187 100644 --- a/Utilities/rFile.cpp +++ b/Utilities/File.cpp @@ -5,7 +5,7 @@ #pragma warning(disable : 4996) #include #pragma warning(pop) -#include "rFile.h" +#include "File.h" #ifdef _WIN32 #include @@ -92,7 +92,7 @@ bool truncate_file(const std::string& file, uint64_t length) #endif -bool get_file_info(const std::string& path, FileInfo& info) +bool fs::stat(const std::string& path, stat_t& info) { #ifdef _WIN32 WIN32_FILE_ATTRIBUTE_DATA attrs; @@ -103,8 +103,8 @@ bool get_file_info(const std::string& path, FileInfo& info) } info.exists = true; - info.isDirectory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info.isWritable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0; + info.is_directory = (attrs.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + info.is_writable = (attrs.dwFileAttributes & FILE_ATTRIBUTE_READONLY) == 0; info.size = (uint64_t)attrs.nFileSizeLow | ((uint64_t)attrs.nFileSizeHigh << 32); info.atime = to_time_t(attrs.ftLastAccessTime); info.mtime = to_time_t(attrs.ftLastWriteTime); @@ -118,8 +118,8 @@ bool get_file_info(const std::string& path, FileInfo& info) } info.exists = true; - info.isDirectory = S_ISDIR(file_info.st_mode); - info.isWritable = file_info.st_mode & 0200; // HACK: approximation + info.is_directory = S_ISDIR(file_info.st_mode); + info.is_writable = file_info.st_mode & 0200; // HACK: approximation info.size = file_info.st_size; info.atime = file_info.st_atime; info.mtime = file_info.st_mtime; @@ -128,7 +128,7 @@ bool get_file_info(const std::string& path, FileInfo& info) return true; } -bool rExists(const std::string& path) +bool fs::exists(const std::string& path) { #ifdef _WIN32 return GetFileAttributesW(ConvertUTF8ToWChar(path).get()) != 0xFFFFFFFF; @@ -138,7 +138,7 @@ bool rExists(const std::string& path) #endif } -bool rIsFile(const std::string& file) +bool fs::is_file(const std::string& file) { #ifdef _WIN32 DWORD attrs; @@ -159,7 +159,7 @@ bool rIsFile(const std::string& file) #endif } -bool rIsDir(const std::string& dir) +bool fs::is_dir(const std::string& dir) { #ifdef _WIN32 DWORD attrs; @@ -180,7 +180,7 @@ bool rIsDir(const std::string& dir) #endif } -bool rMkDir(const std::string& dir) +bool fs::create_dir(const std::string& dir) { #ifdef _WIN32 if (!CreateDirectoryW(ConvertUTF8ToWChar(dir).get(), NULL)) @@ -195,7 +195,7 @@ bool rMkDir(const std::string& dir) return true; } -bool rMkPath(const std::string& path) +bool fs::create_path(const std::string& path) { size_t start = 0; @@ -218,10 +218,10 @@ bool rMkPath(const std::string& path) continue; } - if (!rIsDir(dir)) + if (!is_dir(dir)) { // if doesn't exist or not a dir - if (!rMkDir(dir)) + if (!create_dir(dir)) { // if creating failed return false; @@ -237,7 +237,7 @@ bool rMkPath(const std::string& path) return true; } -bool rRmDir(const std::string& dir) +bool fs::remove_dir(const std::string& dir) { #ifdef _WIN32 if (!RemoveDirectoryW(ConvertUTF8ToWChar(dir).get())) @@ -252,7 +252,7 @@ bool rRmDir(const std::string& dir) return true; } -bool rRename(const std::string& from, const std::string& to) +bool fs::rename(const std::string& from, const std::string& to) { // TODO: Deal with case-sensitivity #ifdef _WIN32 @@ -304,7 +304,7 @@ int OSCopyFile(const char* source, const char* destination, bool overwrite) } #endif -bool rCopy(const std::string& from, const std::string& to, bool overwrite) +bool fs::copy_file(const std::string& from, const std::string& to, bool overwrite) { #ifdef _WIN32 if (!CopyFileW(ConvertUTF8ToWChar(from).get(), ConvertUTF8ToWChar(to).get(), !overwrite)) @@ -319,7 +319,7 @@ bool rCopy(const std::string& from, const std::string& to, bool overwrite) return true; } -bool rRemoveFile(const std::string& file) +bool fs::remove_file(const std::string& file) { #ifdef _WIN32 if (!DeleteFileW(ConvertUTF8ToWChar(file).get())) @@ -334,10 +334,10 @@ bool rRemoveFile(const std::string& file) return true; } -bool rTruncate(const std::string& file, uint64_t length) +bool fs::truncate_file(const std::string& file, uint64_t length) { #ifdef _WIN32 - if (!truncate_file(file, length)) + if (!::truncate_file(file, length)) #else if (truncate64(file.c_str(), length)) #endif @@ -349,7 +349,7 @@ bool rTruncate(const std::string& file, uint64_t length) return true; } -rfile_t::rfile_t() +fs::file::file() #ifdef _WIN32 : fd(INVALID_HANDLE_VALUE) #else @@ -358,7 +358,7 @@ rfile_t::rfile_t() { } -rfile_t::~rfile_t() +fs::file::~file() { #ifdef _WIN32 if (fd != INVALID_HANDLE_VALUE) @@ -373,7 +373,7 @@ rfile_t::~rfile_t() #endif } -rfile_t::rfile_t(const std::string& filename, u32 mode) +fs::file::file(const std::string& filename, u32 mode) #ifdef _WIN32 : fd(INVALID_HANDLE_VALUE) #else @@ -383,7 +383,7 @@ rfile_t::rfile_t(const std::string& filename, u32 mode) open(filename, mode); } -rfile_t::operator bool() const +fs::file::operator bool() const { #ifdef _WIN32 return fd != INVALID_HANDLE_VALUE; @@ -392,15 +392,15 @@ rfile_t::operator bool() const #endif } -void rfile_t::import(handle_type handle) +void fs::file::import(handle_type handle) { - this->~rfile_t(); + this->~file(); fd = handle; } -bool rfile_t::open(const std::string& filename, u32 mode) +bool fs::file::open(const std::string& filename, u32 mode) { - this->~rfile_t(); + this->~file(); #ifdef _WIN32 DWORD access = 0; @@ -414,7 +414,7 @@ bool rfile_t::open(const std::string& filename, u32 mode) case o_read | o_write | o_append: access |= GENERIC_READ | FILE_APPEND_DATA; break; default: { - LOG_ERROR(GENERAL, "rfile_t::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode); + LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode); return false; } } @@ -432,7 +432,7 @@ bool rfile_t::open(const std::string& filename, u32 mode) if (!disp || (mode & ~(o_read | o_write | o_append | o_create | o_trunc | o_excl))) { - LOG_ERROR(GENERAL, "rfile_t::open('%s') failed: unknown mode specified (0x%x)", filename, mode); + LOG_ERROR(GENERAL, "fs::file::open('%s') failed: unknown mode specified (0x%x)", filename, mode); return false; } @@ -447,7 +447,7 @@ bool rfile_t::open(const std::string& filename, u32 mode) case o_read | o_write: flags |= O_RDWR; break; default: { - LOG_ERROR(GENERAL, "rfile_t::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode); + LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode); return false; } } @@ -459,26 +459,26 @@ bool rfile_t::open(const std::string& filename, u32 mode) if (((mode & o_excl) && !(mode & o_create)) || (mode & ~(o_read | o_write | o_append | o_create | o_trunc | o_excl))) { - LOG_ERROR(GENERAL, "rfile_t::open('%s') failed: unknown mode specified (0x%x)", filename, mode); + LOG_ERROR(GENERAL, "fs::file::open('%s') failed: unknown mode specified (0x%x)", filename, mode); return false; } if ((fd = ::open(filename.c_str(), flags, 0666)) == -1) #endif { - LOG_WARNING(GENERAL, "rfile_t::open('%s', 0x%x) failed: error 0x%llx", filename, mode, GET_API_ERROR); + LOG_WARNING(GENERAL, "fs::file::open('%s', 0x%x) failed: error 0x%llx", filename, mode, GET_API_ERROR); return false; } return true; } -bool rfile_t::is_opened() const +bool fs::file::is_opened() const { return *this; } -bool rfile_t::trunc(u64 size) const +bool fs::file::trunc(u64 size) const { #ifdef _WIN32 LARGE_INTEGER old, pos; @@ -499,7 +499,7 @@ bool rfile_t::trunc(u64 size) const #endif } -bool rfile_t::stat(FileInfo& info) const +bool fs::file::stat(stat_t& info) const { #ifdef _WIN32 FILE_BASIC_INFO basic_info; @@ -512,8 +512,8 @@ bool rfile_t::stat(FileInfo& info) const } info.exists = true; - info.isDirectory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; - info.isWritable = (basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY) == 0; + info.is_directory = (basic_info.FileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0; + info.is_writable = (basic_info.FileAttributes & FILE_ATTRIBUTE_READONLY) == 0; info.size = this->size(); info.atime = to_time_t(basic_info.LastAccessTime); info.mtime = to_time_t(basic_info.ChangeTime); @@ -527,8 +527,8 @@ bool rfile_t::stat(FileInfo& info) const } info.exists = true; - info.isDirectory = S_ISDIR(file_info.st_mode); - info.isWritable = file_info.st_mode & 0200; // HACK: approximation + info.is_directory = S_ISDIR(file_info.st_mode); + info.is_writable = file_info.st_mode & 0200; // HACK: approximation info.size = file_info.st_size; info.atime = file_info.st_atime; info.mtime = file_info.st_mtime; @@ -537,7 +537,7 @@ bool rfile_t::stat(FileInfo& info) const return true; } -bool rfile_t::close() +bool fs::file::close() { #ifdef _WIN32 if (CloseHandle(fd)) @@ -558,7 +558,7 @@ bool rfile_t::close() return false; } -u64 rfile_t::read(void* buffer, u64 count) const +u64 fs::file::read(void* buffer, u64 count) const { #ifdef _WIN32 DWORD nread; @@ -573,7 +573,7 @@ u64 rfile_t::read(void* buffer, u64 count) const #endif } -u64 rfile_t::write(const void* buffer, u64 count) const +u64 fs::file::write(const void* buffer, u64 count) const { #ifdef _WIN32 DWORD nwritten; @@ -588,7 +588,7 @@ u64 rfile_t::write(const void* buffer, u64 count) const #endif } -u64 rfile_t::seek(u64 offset, u32 mode) const +u64 fs::file::seek(u64 offset, u32 mode) const { assert(mode < 3); @@ -607,7 +607,7 @@ u64 rfile_t::seek(u64 offset, u32 mode) const #endif } -u64 rfile_t::size() const +u64 fs::file::size() const { #ifdef _WIN32 LARGE_INTEGER size; diff --git a/Utilities/File.h b/Utilities/File.h new file mode 100644 index 0000000000..166c0b14e1 --- /dev/null +++ b/Utilities/File.h @@ -0,0 +1,97 @@ +#pragma once + +enum file_seek_mode : u32 +{ + from_begin, + from_cur, + from_end, +}; + +enum file_open_mode : u32 +{ + o_read = 1 << 0, + o_write = 1 << 1, + o_append = 1 << 2, + o_create = 1 << 3, + o_trunc = 1 << 4, + o_excl = 1 << 5, +}; + +namespace fs +{ + struct stat_t + { + bool exists; + bool is_directory; + bool is_writable; + uint64_t size; + time_t atime; + time_t mtime; + time_t ctime; + }; + + bool stat(const std::string& path, stat_t& info); + bool exists(const std::string& path); + bool is_file(const std::string& file); + bool is_dir(const std::string& dir); + bool remove_dir(const std::string& dir); + bool create_dir(const std::string& dir); + bool create_path(const std::string& path); + bool rename(const std::string& from, const std::string& to); + bool copy_file(const std::string& from, const std::string& to, bool overwrite); + bool remove_file(const std::string& file); + bool truncate_file(const std::string& file, uint64_t length); + + struct file final + { +#ifdef _WIN32 + using handle_type = void*; +#else + using handle_type = intptr_t; +#endif + + private: + handle_type fd; + + public: + file(); + ~file(); + explicit file(const std::string& filename, u32 mode = o_read); + + file(const file&) = delete; + file(file&&) = delete; // possibly TODO + + file& operator =(const file&) = delete; + file& operator =(file&&) = delete; // possibly TODO + + operator bool() const; // check is_opened() + + void import(handle_type fd); // replace file handle + + bool open(const std::string& filename, u32 mode = o_read); + bool is_opened() const; // check whether the file is opened + bool trunc(u64 size) const; // change file size (possibly appending zero bytes) + bool stat(stat_t& info) const; // get file info + bool close(); + + u64 read(void* buffer, u64 count) const; + u64 write(const void* buffer, u64 count) const; + u64 seek(u64 offset, u32 mode = from_begin) const; + u64 size() const; + }; +} + +struct rDir +{ + rDir(); + ~rDir(); + rDir(const rDir& other) = delete; + rDir(const std::string &path); + bool Open(const std::string& path); + bool IsOpened() const; + static bool Exists(const std::string &path); + bool GetFirst(std::string *filename) const; + bool GetNext(std::string *filename) const; + + void *handle; +}; diff --git a/Utilities/Log.cpp b/Utilities/Log.cpp index 9add021af4..98d06b5c52 100644 --- a/Utilities/Log.cpp +++ b/Utilities/Log.cpp @@ -5,7 +5,7 @@ #include #include #include "Thread.h" -#include "rFile.h" +#include "File.h" using namespace Log; @@ -90,7 +90,7 @@ struct CoutListener : LogListener struct FileListener : LogListener { - rfile_t mFile; + fs::file mFile; bool mPrependChannelName; FileListener(const std::string& name = _PRGNAME_, bool prependChannel = true) diff --git a/Utilities/rFile.h b/Utilities/rFile.h deleted file mode 100644 index 41dbaca396..0000000000 --- a/Utilities/rFile.h +++ /dev/null @@ -1,94 +0,0 @@ -#pragma once - -struct FileInfo -{ - bool exists; - bool isDirectory; - bool isWritable; - uint64_t size; - time_t atime; - time_t mtime; - time_t ctime; -}; - -bool get_file_info(const std::string& path, FileInfo& fileInfo); -bool rExists(const std::string& path); -bool rIsFile(const std::string& file); -bool rIsDir(const std::string& dir); -bool rRmDir(const std::string& dir); -bool rMkDir(const std::string& dir); -bool rMkPath(const std::string& path); -bool rRename(const std::string& from, const std::string& to); -bool rCopy(const std::string& from, const std::string& to, bool overwrite); -bool rRemoveFile(const std::string& file); -bool rTruncate(const std::string& file, uint64_t length); - -enum rfile_seek_mode : u32 -{ - from_begin, - from_cur, - from_end, -}; - -enum rfile_open_mode : u32 -{ - o_read = 1 << 0, - o_write = 1 << 1, - o_append = 1 << 2, - o_create = 1 << 3, - o_trunc = 1 << 4, - o_excl = 1 << 5, -}; - -struct rfile_t final -{ -#ifdef _WIN32 - using handle_type = void*; -#else - using handle_type = intptr_t; -#endif - -private: - handle_type fd; - -public: - rfile_t(); - ~rfile_t(); - explicit rfile_t(const std::string& filename, u32 mode = o_read); - - rfile_t(const rfile_t&) = delete; - rfile_t(rfile_t&&) = delete; // possibly TODO - - rfile_t& operator =(const rfile_t&) = delete; - rfile_t& operator =(rfile_t&&) = delete; // possibly TODO - - operator bool() const; // check is_opened() - - void import(handle_type fd); // replace file handle - - bool open(const std::string& filename, u32 mode = o_read); - bool is_opened() const; // check whether the file is opened - bool trunc(u64 size) const; // change file size (possibly appending zero bytes) - bool stat(FileInfo& info) const; // get file info - bool close(); - - u64 read(void* buffer, u64 count) const; - u64 write(const void* buffer, u64 count) const; - u64 seek(u64 offset, u32 mode = from_begin) const; - u64 size() const; -}; - -struct rDir -{ - rDir(); - ~rDir(); - rDir(const rDir& other) = delete; - rDir(const std::string &path); - bool Open(const std::string& path); - bool IsOpened() const; - static bool Exists(const std::string &path); - bool GetFirst(std::string *filename) const; - bool GetNext(std::string *filename) const; - - void *handle; -}; diff --git a/rpcs3/Crypto/unedat.cpp b/rpcs3/Crypto/unedat.cpp index c7d89b4346..9bfaa000e7 100644 --- a/rpcs3/Crypto/unedat.cpp +++ b/rpcs3/Crypto/unedat.cpp @@ -2,7 +2,7 @@ #include "key_vault.h" #include "unedat.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" void generate_key(int crypto_mode, int version, unsigned char *key_final, unsigned char *iv_final, unsigned char *key, unsigned char *iv) { @@ -136,7 +136,7 @@ unsigned char* get_block_key(int block, NPD_HEADER *npd) } // EDAT/SDAT decryption. -int decrypt_data(const rfile_t *in, const rfile_t *out, EDAT_HEADER *edat, NPD_HEADER *npd, unsigned char* crypt_key, bool verbose) +int decrypt_data(const fs::file* in, const fs::file* out, EDAT_HEADER *edat, NPD_HEADER *npd, unsigned char* crypt_key, bool verbose) { // Get metadata info and setup buffers. int block_num = (int)((edat->file_size + edat->block_size - 1) / edat->block_size); @@ -340,7 +340,7 @@ int decrypt_data(const rfile_t *in, const rfile_t *out, EDAT_HEADER *edat, NPD_H return 0; } -int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const rfile_t *f, bool verbose) +int check_data(unsigned char *key, EDAT_HEADER *edat, NPD_HEADER *npd, const fs::file* f, bool verbose) { f->seek(0); unsigned char header[0xA0]; @@ -639,7 +639,7 @@ int validate_npd_hashes(const char* file_name, unsigned char *klicensee, NPD_HEA return (title_hash_result && dev_hash_result); } -bool extract_data(const rfile_t *input, const rfile_t *output, const char* input_file_name, unsigned char* devklic, unsigned char* rifkey, bool verbose) +bool extract_data(const fs::file* input, const fs::file* output, const char* input_file_name, unsigned char* devklic, unsigned char* rifkey, bool verbose) { // Setup NPD and EDAT/SDAT structs. NPD_HEADER *NPD = new NPD_HEADER(); @@ -812,9 +812,9 @@ bool extract_data(const rfile_t *input, const rfile_t *output, const char* input int DecryptEDAT(const std::string& input_file_name, const std::string& output_file_name, int mode, const std::string& rap_file_name, unsigned char *custom_klic, bool verbose) { // Prepare the files. - rfile_t input(input_file_name); - rfile_t output(output_file_name, o_write | o_create | o_trunc); - rfile_t rap(rap_file_name); + fs::file input(input_file_name); + fs::file output(output_file_name, o_write | o_create | o_trunc); + fs::file rap(rap_file_name); // Set keys (RIF and DEVKLIC). unsigned char rifkey[0x10]; @@ -887,7 +887,7 @@ int DecryptEDAT(const std::string& input_file_name, const std::string& output_fi if (extract_data(&input, &output, input_file_name.c_str(), devklic, rifkey, verbose)) { output.close(); - rRemoveFile(output_file_name); + fs::remove_file(output_file_name); return -1; } diff --git a/rpcs3/Crypto/unpkg.cpp b/rpcs3/Crypto/unpkg.cpp index 0a7b377737..fdc99b2e99 100644 --- a/rpcs3/Crypto/unpkg.cpp +++ b/rpcs3/Crypto/unpkg.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "utils.h" #include "aes.h" #include "sha1.h" @@ -15,7 +15,7 @@ #include "define_new_memleakdetect.h" // Decryption. -bool CheckHeader(const rfile_t& pkg_f, PKGHeader* m_header) +bool CheckHeader(const fs::file& pkg_f, PKGHeader* m_header) { if (m_header->pkg_magic != 0x7F504B47) { @@ -66,7 +66,7 @@ bool CheckHeader(const rfile_t& pkg_f, PKGHeader* m_header) return true; } -bool LoadHeader(const rfile_t& pkg_f, PKGHeader* m_header) +bool LoadHeader(const fs::file& pkg_f, PKGHeader* m_header) { pkg_f.seek(0); @@ -82,7 +82,7 @@ bool LoadHeader(const rfile_t& pkg_f, PKGHeader* m_header) return true; } -int Decrypt(const rfile_t& pkg_f, const rfile_t& dec_pkg_f, PKGHeader* m_header) +int Decrypt(const fs::file& pkg_f, const fs::file& dec_pkg_f, PKGHeader* m_header) { if (!LoadHeader(pkg_f, m_header)) { @@ -157,7 +157,7 @@ int Decrypt(const rfile_t& pkg_f, const rfile_t& dec_pkg_f, PKGHeader* m_header) } // Unpacking. -bool LoadEntries(const rfile_t& dec_pkg_f, PKGHeader* m_header, PKGEntry* m_entries) +bool LoadEntries(const fs::file& dec_pkg_f, PKGHeader* m_header, PKGEntry* m_entries) { dec_pkg_f.seek(0); dec_pkg_f.read(m_entries, sizeof(PKGEntry) * m_header->file_count); @@ -171,7 +171,7 @@ bool LoadEntries(const rfile_t& dec_pkg_f, PKGHeader* m_header, PKGEntry* m_entr return true; } -bool UnpackEntry(const rfile_t& dec_pkg_f, const PKGEntry& entry, std::string dir) +bool UnpackEntry(const fs::file& dec_pkg_f, const PKGEntry& entry, std::string dir) { char buf[BUF_SIZE]; @@ -186,26 +186,31 @@ bool UnpackEntry(const rfile_t& dec_pkg_f, const PKGEntry& entry, std::string di case PKG_FILE_ENTRY_SDAT: case PKG_FILE_ENTRY_REGULAR: { - auto path = dir + std::string(buf, entry.name_size); + const std::string path = dir + std::string(buf, entry.name_size); - if (rIsFile(path)) + if (fs::is_file(path)) { LOG_WARNING(LOADER, "PKG Loader: '%s' is overwritten", path); } - rfile_t out; + fs::file out(path, o_write | o_create | o_trunc); - if (out.open(path, o_write | o_create | o_trunc)) + if (out) { dec_pkg_f.seek(entry.file_offset); for (u64 size = 0; size < entry.file_size;) { size += dec_pkg_f.read(buf, BUF_SIZE); + if (size > entry.file_size) + { out.write(buf, BUF_SIZE - (size - entry.file_size)); + } else + { out.write(buf, BUF_SIZE); + } } return true; @@ -219,10 +224,11 @@ bool UnpackEntry(const rfile_t& dec_pkg_f, const PKGEntry& entry, std::string di case PKG_FILE_ENTRY_FOLDER: { - auto path = dir + std::string(buf, entry.name_size); - if (!rIsDir(path) && !rMkPath(path)) + const std::string path = dir + std::string(buf, entry.name_size); + + if (!fs::is_dir(path) && !fs::create_dir(path)) { - LOG_ERROR(LOADER, "PKG Loader: Could not create directory: %s", path.c_str()); + LOG_ERROR(LOADER, "PKG Loader: Could not create directory: %s", path); return false; } @@ -237,14 +243,14 @@ bool UnpackEntry(const rfile_t& dec_pkg_f, const PKGEntry& entry, std::string di } } -int Unpack(const rfile_t& pkg_f, std::string src, std::string dst) +int Unpack(const fs::file& pkg_f, std::string src, std::string dst) { PKGHeader* m_header = (PKGHeader*) malloc (sizeof(PKGHeader)); // TODO: This shouldn't use current dir std::string decryptedFile = "./dev_hdd1/" + src + ".dec"; - rfile_t dec_pkg_f(decryptedFile, o_read | o_write | o_create | o_trunc); + fs::file dec_pkg_f(decryptedFile, o_read | o_write | o_create | o_trunc); if (Decrypt(pkg_f, dec_pkg_f, m_header) < 0) { @@ -274,7 +280,7 @@ int Unpack(const rfile_t& pkg_f, std::string src, std::string dst) pdlg.Update(m_entries.size()); dec_pkg_f.close(); - rRemoveFile(decryptedFile); + fs::remove_file(decryptedFile); return 0; } diff --git a/rpcs3/Crypto/unpkg.h b/rpcs3/Crypto/unpkg.h index 8e516fd56c..62a18a4bef 100644 --- a/rpcs3/Crypto/unpkg.h +++ b/rpcs3/Crypto/unpkg.h @@ -56,6 +56,6 @@ struct PKGEntry be_t pad; // Padding (zeros) }; -struct rfile_t; +struct fs::file; -int Unpack(const rfile_t& dec_pkg_f, std::string src, std::string dst); +int Unpack(const fs::file& dec_pkg_f, std::string src, std::string dst); diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 198eaf8546..1f6645bdd0 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "aes.h" #include "sha1.h" #include "utils.h" @@ -67,7 +67,7 @@ __forceinline void Write8(vfsStream& f, const u8 data) f.Write(&data, sizeof(data)); } -__forceinline void Write8(const rfile_t& f, const u8 data) +__forceinline void Write8(const fs::file& f, const u8 data) { f.write(&data, sizeof(data)); } @@ -77,7 +77,7 @@ __forceinline void Write16LE(vfsStream& f, const u16 data) f.Write(&data, sizeof(data)); } -__forceinline void Write16LE(const rfile_t& f, const u16 data) +__forceinline void Write16LE(const fs::file& f, const u16 data) { f.write(&data, sizeof(data)); } @@ -87,7 +87,7 @@ __forceinline void Write32LE(vfsStream& f, const u32 data) f.Write(&data, sizeof(data)); } -__forceinline void Write32LE(const rfile_t& f, const u32 data) +__forceinline void Write32LE(const fs::file& f, const u32 data) { f.write(&data, sizeof(data)); } @@ -97,7 +97,7 @@ __forceinline void Write64LE(vfsStream& f, const u64 data) f.Write(&data, sizeof(data)); } -__forceinline void Write64LE(const rfile_t& f, const u64 data) +__forceinline void Write64LE(const fs::file& f, const u64 data) { f.write(&data, sizeof(data)); } @@ -107,7 +107,7 @@ __forceinline void Write16(vfsStream& f, const u16 data) Write16LE(f, re16(data)); } -__forceinline void Write16(const rfile_t& f, const u16 data) +__forceinline void Write16(const fs::file& f, const u16 data) { Write16LE(f, re16(data)); } @@ -117,7 +117,7 @@ __forceinline void Write32(vfsStream& f, const u32 data) Write32LE(f, re32(data)); } -__forceinline void Write32(const rfile_t& f, const u32 data) +__forceinline void Write32(const fs::file& f, const u32 data) { Write32LE(f, re32(data)); } @@ -127,12 +127,12 @@ __forceinline void Write64(vfsStream& f, const u64 data) Write64LE(f, re64(data)); } -__forceinline void Write64(const rfile_t& f, const u64 data) +__forceinline void Write64(const fs::file& f, const u64 data) { Write64LE(f, re64(data)); } -void WriteEhdr(const rfile_t& f, Elf64_Ehdr& ehdr) +void WriteEhdr(const fs::file& f, Elf64_Ehdr& ehdr) { Write32(f, ehdr.e_magic); Write8(f, ehdr.e_class); @@ -155,7 +155,7 @@ void WriteEhdr(const rfile_t& f, Elf64_Ehdr& ehdr) Write16(f, ehdr.e_shstrndx); } -void WritePhdr(const rfile_t& f, Elf64_Phdr& phdr) +void WritePhdr(const fs::file& f, Elf64_Phdr& phdr) { Write32(f, phdr.p_type); Write32(f, phdr.p_flags); @@ -167,7 +167,7 @@ void WritePhdr(const rfile_t& f, Elf64_Phdr& phdr) Write64(f, phdr.p_align); } -void WriteShdr(const rfile_t& f, Elf64_Shdr& shdr) +void WriteShdr(const fs::file& f, Elf64_Shdr& shdr) { Write32(f, shdr.sh_name); Write32(f, shdr.sh_type); @@ -181,7 +181,7 @@ void WriteShdr(const rfile_t& f, Elf64_Shdr& shdr) Write64(f, shdr.sh_entsize); } -void WriteEhdr(const rfile_t& f, Elf32_Ehdr& ehdr) +void WriteEhdr(const fs::file& f, Elf32_Ehdr& ehdr) { Write32(f, ehdr.e_magic); Write8(f, ehdr.e_class); @@ -204,7 +204,7 @@ void WriteEhdr(const rfile_t& f, Elf32_Ehdr& ehdr) Write16(f, ehdr.e_shstrndx); } -void WritePhdr(const rfile_t& f, Elf32_Phdr& phdr) +void WritePhdr(const fs::file& f, Elf32_Phdr& phdr) { Write32(f, phdr.p_type); Write32(f, phdr.p_offset); @@ -216,7 +216,7 @@ void WritePhdr(const rfile_t& f, Elf32_Phdr& phdr) Write32(f, phdr.p_align); } -void WriteShdr(const rfile_t& f, Elf32_Shdr& shdr) +void WriteShdr(const fs::file& f, Elf32_Shdr& shdr) { Write32(f, shdr.sh_name); Write32(f, shdr.sh_type); @@ -1076,7 +1076,7 @@ bool SELFDecrypter::DecryptData() bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32) { // Create a new ELF file. - rfile_t e(elf, o_write | o_create | o_trunc); + fs::file e(elf, o_write | o_create | o_trunc); if(!e) { LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str()); @@ -1195,14 +1195,14 @@ bool SELFDecrypter::GetKeyFromRap(u8 *content_id, u8 *npdrm_key) std::string rap_path("dev_hdd0/home/" + pf_str + "/exdata/" + ci_str + ".rap"); // Check if we have a valid RAP file. - if (!rIsFile(rap_path)) + if (!fs::is_file(rap_path)) { LOG_ERROR(LOADER, "This application requires a valid RAP file for decryption!"); return false; } // Open the RAP file and read the key. - rfile_t rap_file(rap_path); + fs::file rap_file(rap_path); if (!rap_file) { @@ -1255,7 +1255,7 @@ bool IsSelfElf32(const std::string& path) bool CheckDebugSelf(const std::string& self, const std::string& elf) { // Open the SELF file. - rfile_t s(self); + fs::file s(self); if(!s) { @@ -1283,7 +1283,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf) s.seek(elf_offset); // Write the real ELF file back. - rfile_t e(elf, o_write | o_create | o_trunc); + fs::file e(elf, o_write | o_create | o_trunc); if(!e) { LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str()); diff --git a/rpcs3/Emu/Audio/AudioDumper.h b/rpcs3/Emu/Audio/AudioDumper.h index 54c8f00edf..fa629b254d 100644 --- a/rpcs3/Emu/Audio/AudioDumper.h +++ b/rpcs3/Emu/Audio/AudioDumper.h @@ -1,6 +1,5 @@ #pragma once - -#include "Utilities/rFile.h" +#include "Utilities/File.h" struct WAVHeader { @@ -56,7 +55,7 @@ struct WAVHeader class AudioDumper { WAVHeader m_header; - rfile_t m_output; + fs::file m_output; bool m_init; public: diff --git a/rpcs3/Emu/Cell/PPUProgramCompiler.cpp b/rpcs3/Emu/Cell/PPUProgramCompiler.cpp index 532b26d36a..3ce377834d 100644 --- a/rpcs3/Emu/Cell/PPUProgramCompiler.cpp +++ b/rpcs3/Emu/Cell/PPUProgramCompiler.cpp @@ -1,6 +1,6 @@ #include "stdafx_gui.h" #include "PPUProgramCompiler.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" /* using namespace PPU_instr; diff --git a/rpcs3/Emu/Cell/SPURecompilerCore.cpp b/rpcs3/Emu/Cell/SPURecompilerCore.cpp index ed8418fa79..10329f727f 100644 --- a/rpcs3/Emu/Cell/SPURecompilerCore.cpp +++ b/rpcs3/Emu/Cell/SPURecompilerCore.cpp @@ -2,7 +2,7 @@ #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Emu/SysCalls/lv2/sys_time.h" @@ -147,22 +147,22 @@ void SPURecompilerCore::Compile(u16 pos) entry[start].pointer = compiler.make(); compiler.setLogger(nullptr); // crashes without it - //rFile log; - //log.Open(fmt::Format("SPUjit_%d.log", GetCurrentSPUThread().GetId()), first ? rFile::write : rFile::write_append); - //log.Write(fmt::Format("========== START POSITION 0x%x ==========\n\n", start * 4)); - //log.Write(std::string(stringLogger.getString())); + //std::string log = fmt::format("========== START POSITION 0x%x ==========\n\n", start * 4); + //log += stringLogger.getString(); //if (!entry[start].pointer) //{ // LOG_ERROR(Log::SPU, "SPURecompilerCore::Compile(pos=0x%x) failed", start * sizeof(u32)); - // log.Write("========== FAILED ============\n\n"); + // log += "========== FAILED ============\n\n"; // Emu.Pause(); //} //else //{ - // log.Write(fmt::Format("========== COMPILED %d (excess %d), time: [start=%lld (decoding=%lld), finalize=%lld]\n\n", - // entry[start].count, excess, stamp1 - stamp0, time0, get_system_time() - stamp1)); + // log += fmt::format("========== COMPILED %d (excess %d), time: [start=%lld (decoding=%lld), finalize=%lld]\n\n", + // entry[start].count, excess, stamp1 - stamp0, time0, get_system_time() - stamp1); //} - //log.Close(); + + //fs::file(fmt::Format("SPUjit_%d.log", this->CPU.GetId()), o_write | o_create | (first ? o_trunc : o_append)).write(log.c_str(), log.size()); + m_enc->compiler = nullptr; first = false; } diff --git a/rpcs3/Emu/FS/VFS.cpp b/rpcs3/Emu/FS/VFS.cpp index 7e97a997f0..27c0eedfea 100644 --- a/rpcs3/Emu/FS/VFS.cpp +++ b/rpcs3/Emu/FS/VFS.cpp @@ -185,7 +185,7 @@ bool VFS::CreatePath(const std::string& ps3_path) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - return rMkPath(path); + return fs::create_path(path); } return false; @@ -307,7 +307,7 @@ bool VFS::CopyFile(const std::string& ps3_path_from, const std::string& ps3_path { if (vfsDevice* dev_ = GetDevice(ps3_path_to, path_to)) { - return rCopy(path_from, path_to, overwrite); + return fs::copy_file(path_from, path_to, overwrite); } } @@ -320,7 +320,7 @@ bool VFS::TruncateFile(const std::string& ps3_path, u64 length) const if (vfsDevice* dev = GetDevice(ps3_path, path)) { - return rTruncate(path, length); + return fs::truncate_file(path, length); } return false; @@ -514,14 +514,9 @@ void VFS::SaveLoadDevices(std::vector& res, bool is_load) Ini.SysEmulationDirPath.SetValue(Emu.GetEmulatorPath()); } - FileInfo info; - if (!get_file_info(dir, info) || !info.exists) + if (!fs::is_dir(dir)) { - LOG_ERROR(GENERAL, "Custom EmulationDir: '%s' not found", dir); - } - else if (!info.isDirectory) - { - LOG_ERROR(GENERAL, "Custom EmulationDir: '%s' is not a valid directory", dir); + LOG_ERROR(GENERAL, "Custom EmulationDir: directory '%s' not found", dir); } else { diff --git a/rpcs3/Emu/FS/vfsDirBase.cpp b/rpcs3/Emu/FS/vfsDirBase.cpp index 58bd1d2ff4..4a001e43fe 100644 --- a/rpcs3/Emu/FS/vfsDirBase.cpp +++ b/rpcs3/Emu/FS/vfsDirBase.cpp @@ -1,5 +1,5 @@ #include "stdafx.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "vfsDirBase.h" vfsDirBase::vfsDirBase(vfsDevice* device) diff --git a/rpcs3/Emu/FS/vfsLocalDir.cpp b/rpcs3/Emu/FS/vfsLocalDir.cpp index f9d456f868..822fe4f051 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.cpp +++ b/rpcs3/Emu/FS/vfsLocalDir.cpp @@ -21,16 +21,16 @@ bool vfsLocalDir::Open(const std::string& path) for (bool is_ok = dir.GetFirst(&name); is_ok; is_ok = dir.GetNext(&name)) { - FileInfo file_info; - get_file_info(path + "/" + name, file_info); + fs::stat_t file_info; + fs::stat(path + "/" + name, file_info); m_entries.emplace_back(); DirEntryInfo& info = m_entries.back(); info.name = name; - info.flags |= file_info.isDirectory ? DirEntry_TypeDir | DirEntry_PermExecutable : DirEntry_TypeFile; - info.flags |= file_info.isWritable ? DirEntry_PermWritable | DirEntry_PermReadable : DirEntry_PermReadable; + info.flags |= file_info.is_directory ? DirEntry_TypeDir | DirEntry_PermExecutable : DirEntry_TypeFile; + info.flags |= file_info.is_writable ? DirEntry_PermWritable | DirEntry_PermReadable : DirEntry_PermReadable; info.size = file_info.size; info.access_time = file_info.atime; info.modify_time = file_info.mtime; @@ -42,22 +42,22 @@ bool vfsLocalDir::Open(const std::string& path) bool vfsLocalDir::Create(const std::string& path) { - return rMkDir(path); + return fs::create_dir(path); } bool vfsLocalDir::IsExists(const std::string& path) const { - return rIsDir(path); + return fs::is_dir(path); } bool vfsLocalDir::Rename(const std::string& from, const std::string& to) { - return rRename(from, to); + return fs::rename(from, to); } bool vfsLocalDir::Remove(const std::string& path) { - return rRmDir(path); + return fs::remove_dir(path); } bool vfsLocalDir::IsOpened() const diff --git a/rpcs3/Emu/FS/vfsLocalDir.h b/rpcs3/Emu/FS/vfsLocalDir.h index c2174f3658..1c6e5ee6ae 100644 --- a/rpcs3/Emu/FS/vfsLocalDir.h +++ b/rpcs3/Emu/FS/vfsLocalDir.h @@ -1,6 +1,6 @@ #pragma once #include "vfsDirBase.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" class vfsLocalDir : public vfsDirBase { diff --git a/rpcs3/Emu/FS/vfsLocalFile.cpp b/rpcs3/Emu/FS/vfsLocalFile.cpp index 8d1ea4c405..c0a1d57935 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.cpp +++ b/rpcs3/Emu/FS/vfsLocalFile.cpp @@ -50,15 +50,15 @@ bool vfsLocalFile::IsOpened() const bool vfsLocalFile::Exists(const std::string& path) { - return rIsFile(path); + return fs::is_file(path); } bool vfsLocalFile::Rename(const std::string& from, const std::string& to) { - return rRename(from, to); + return fs::rename(from, to); } bool vfsLocalFile::Remove(const std::string& path) { - return rRemoveFile(path); + return fs::remove_file(path); } diff --git a/rpcs3/Emu/FS/vfsLocalFile.h b/rpcs3/Emu/FS/vfsLocalFile.h index 902932949b..d6e0b5c493 100644 --- a/rpcs3/Emu/FS/vfsLocalFile.h +++ b/rpcs3/Emu/FS/vfsLocalFile.h @@ -4,7 +4,7 @@ class vfsLocalFile : public vfsFileBase { private: - rfile_t m_file; + fs::file m_file; public: vfsLocalFile(vfsDevice* device); @@ -25,8 +25,5 @@ public: virtual bool IsOpened() const override; - virtual const rfile_t& GetFile() const - { - return m_file; - } + virtual const fs::file& GetFile() const { return m_file; } }; diff --git a/rpcs3/Emu/FS/vfsStream.h b/rpcs3/Emu/FS/vfsStream.h index e49848c788..28e775c2cd 100644 --- a/rpcs3/Emu/FS/vfsStream.h +++ b/rpcs3/Emu/FS/vfsStream.h @@ -1,5 +1,5 @@ #pragma once -#include "Utilities/rFile.h" +#include "Utilities/File.h" struct vfsStream { diff --git a/rpcs3/Emu/HDD/HDD.cpp b/rpcs3/Emu/HDD/HDD.cpp index 1a661ebd6a..c16127fb75 100644 --- a/rpcs3/Emu/HDD/HDD.cpp +++ b/rpcs3/Emu/HDD/HDD.cpp @@ -21,7 +21,7 @@ void vfsHDDManager::CreateEntry(vfsHDD_Entry& entry) void vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size) { - rfile_t f(path, o_write | o_create | o_trunc); + fs::file f(path, o_write | o_create | o_trunc); static const u64 cur_dir_block = 1; diff --git a/rpcs3/Emu/RSX/CgBinaryProgram.h b/rpcs3/Emu/RSX/CgBinaryProgram.h index 15bdd5c50a..ff64e96e94 100644 --- a/rpcs3/Emu/RSX/CgBinaryProgram.h +++ b/rpcs3/Emu/RSX/CgBinaryProgram.h @@ -1,7 +1,6 @@ #pragma once - #include -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/RSX/GL/GLVertexProgram.h" @@ -182,9 +181,8 @@ public: , m_arb_shader("") , m_dst_reg_name("") { - rfile_t f(path); - if (!f) - return; + fs::file f(path); + if (!f) return; m_buffer_size = f.size(); m_buffer = new u8[m_buffer_size]; @@ -314,10 +312,8 @@ public: { u32 ptr; { - rfile_t f(m_path); - - if (!f) - return; + fs::file f(m_path); + if (!f) return; size_t size = f.size(); vm::ps3::init(); diff --git a/rpcs3/Emu/RSX/GL/GLGSRender.cpp b/rpcs3/Emu/RSX/GL/GLGSRender.cpp index 9a72e08aeb..317613183a 100644 --- a/rpcs3/Emu/RSX/GL/GLGSRender.cpp +++ b/rpcs3/Emu/RSX/GL/GLGSRender.cpp @@ -1,7 +1,7 @@ #include "stdafx.h" #include "rpcs3/Ini.h" #include "Utilities/rPlatform.h" // only for rImage -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Utilities/Log.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" @@ -580,7 +580,7 @@ void GLTexture::Save(RSXTexture& tex, const std::string& name) return; } - rfile_t(name + ".raw", o_write | o_create | o_trunc).write(alldata, texPixelCount * 4); + fs::file(name + ".raw", o_write | o_create | o_trunc).write(alldata, texPixelCount * 4); u8* data = new u8[texPixelCount * 3]; u8* alpha = new u8[texPixelCount]; @@ -610,10 +610,10 @@ void GLTexture::Save(RSXTexture& tex) static const std::string& dir_path = "textures"; static const std::string& file_fmt = dir_path + "/" + "tex[%d].png"; - if (!rIsDir(dir_path)) rMkDir(dir_path); + if (!fs::exists(dir_path)) fs::create_dir(dir_path); u32 count = 0; - while (rIsFile(fmt::Format(file_fmt.c_str(), count))) count++; + while (fs::exists(fmt::Format(file_fmt.c_str(), count))) count++; Save(tex, fmt::Format(file_fmt.c_str(), count)); } @@ -1134,7 +1134,7 @@ bool GLGSRender::LoadProgram() checkForGlError("m_fragment_prog.Compile"); // TODO: This shouldn't use current dir - rfile_t("./FragmentProgram.txt", o_write | o_create | o_trunc).write(m_fragment_prog.shader.c_str(), m_fragment_prog.shader.size()); + fs::file("./FragmentProgram.txt", o_write | o_create | o_trunc).write(m_fragment_prog.shader.c_str(), m_fragment_prog.shader.size()); } if (m_vp_buf_num == -1) @@ -1145,7 +1145,7 @@ bool GLGSRender::LoadProgram() checkForGlError("m_vertex_prog.Compile"); // TODO: This shouldn't use current dir - rfile_t("./VertexProgram.txt", o_write | o_create | o_trunc).write(m_vertex_prog.shader.c_str(), m_vertex_prog.shader.size()); + fs::file("./VertexProgram.txt", o_write | o_create | o_trunc).write(m_vertex_prog.shader.c_str(), m_vertex_prog.shader.size()); } if (m_fp_buf_num != -1 && m_vp_buf_num != -1) diff --git a/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp b/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp index c42b02c802..1c2a7520d4 100644 --- a/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp +++ b/rpcs3/Emu/SysCalls/Modules/cellSaveData.cpp @@ -7,7 +7,7 @@ #include "Emu/FS/VFS.h" #include "Emu/FS/vfsFile.h" #include "Emu/FS/vfsDir.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Loader/PSF.h" #include "cellSaveData.h" @@ -373,9 +373,8 @@ __noinline s32 savedata_op( Emu.GetVFS().GetDevice(dir_path, dir_local_path); - FileInfo dir_info = {}; - - get_file_info(dir_local_path, dir_info); + fs::stat_t dir_info; + fs::stat(dir_local_path, dir_info); statGet->hddFreeSizeKB = 40 * 1024 * 1024; // 40 GB statGet->isNewData = save_entry.isNew = !psf; @@ -577,7 +576,7 @@ __noinline s32 savedata_op( { case CELL_SAVEDATA_FILEOP_READ: { - rfile_t file(local_path, o_read); + fs::file file(local_path, o_read); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast(file.read(fileSet->fileBuf.get_ptr(), std::min(fileSet->fileSize, fileSet->fileBufSize))); break; @@ -585,7 +584,7 @@ __noinline s32 savedata_op( case CELL_SAVEDATA_FILEOP_WRITE: { - rfile_t file(local_path, o_write | o_create); + fs::file file(local_path, o_write | o_create); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast(file.write(fileSet->fileBuf.get_ptr(), std::min(fileSet->fileSize, fileSet->fileBufSize))); file.trunc(file.seek(0, from_cur)); // truncate @@ -594,14 +593,14 @@ __noinline s32 savedata_op( case CELL_SAVEDATA_FILEOP_DELETE: { - rRemoveFile(local_path); + fs::remove_file(local_path); fileGet->excSize = 0; break; } case CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC: { - rfile_t file(local_path, o_write | o_create); + fs::file file(local_path, o_write | o_create); file.seek(fileSet->fileOffset); fileGet->excSize = static_cast(file.write(fileSet->fileBuf.get_ptr(), std::min(fileSet->fileSize, fileSet->fileBufSize))); break; diff --git a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp index 82b7f305fe..20367f4c82 100644 --- a/rpcs3/Emu/SysCalls/Modules/sceNp.cpp +++ b/rpcs3/Emu/SysCalls/Modules/sceNp.cpp @@ -5,7 +5,7 @@ #include "Emu/SysCalls/lv2/sys_process.h" #include "Emu/FS/VFS.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Emu/FS/vfsDir.h" #include "Crypto/unedat.h" #include "sceNp.h" @@ -140,8 +140,8 @@ int npDrmIsAvailable(u32 k_licensee_addr, vm::ptr drm_path) if (DecryptEDAT(enc_drm_path_local, dec_drm_path_local, 8, rap_path_local, k_licensee, false) >= 0) { // If decryption succeeds, replace the encrypted file with it. - rRemoveFile(enc_drm_path_local); - rRename(dec_drm_path_local, enc_drm_path_local); + fs::remove_file(enc_drm_path_local); + fs::rename(dec_drm_path_local, enc_drm_path_local); } return CELL_OK; diff --git a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp index 0a9c422ad0..d538425152 100644 --- a/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp +++ b/rpcs3/Emu/SysCalls/lv2/sys_fs.cpp @@ -43,7 +43,7 @@ s32 sys_fs_open(vm::ptr path, s32 flags, vm::ptr fd, s32 mode, // TODO: other checks for path - if (rIsDir(local_path)) + if (fs::is_dir(local_path)) { sys_fs.Error("sys_fs_open('%s') failed: path is a directory", path.get_ptr()); return CELL_FS_EISDIR; @@ -247,15 +247,15 @@ s32 sys_fs_stat(vm::ptr path, vm::ptr sb) return CELL_FS_ENOTMOUNTED; } - FileInfo info; + fs::stat_t info; - if (!get_file_info(local_path, info) || !info.exists) + if (!fs::stat(local_path, info) || !info.exists) { sys_fs.Error("sys_fs_stat('%s') failed: not found", path.get_ptr()); return CELL_FS_ENOENT; } - sb->mode = info.isDirectory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; + sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; sb->uid = 1; // ??? sb->gid = 1; // ??? sb->atime = info.atime; @@ -288,14 +288,14 @@ s32 sys_fs_fstat(u32 fd, vm::ptr sb) return CELL_FS_ENOTSUP; } - FileInfo info; + fs::stat_t info; if (!local_file->GetFile().stat(info)) { return CELL_FS_EIO; // ??? } - sb->mode = info.isDirectory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; + sb->mode = info.is_directory ? CELL_FS_S_IFDIR | 0777 : CELL_FS_S_IFREG | 0666; sb->uid = 1; // ??? sb->gid = 1; // ??? sb->atime = info.atime; diff --git a/rpcs3/Emu/System.cpp b/rpcs3/Emu/System.cpp index eee6d1025b..fe7578ab0a 100644 --- a/rpcs3/Emu/System.cpp +++ b/rpcs3/Emu/System.cpp @@ -1,6 +1,6 @@ #include "stdafx.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" @@ -152,7 +152,7 @@ bool Emulator::BootGame(const std::string& path, bool direct) if (direct) { - if (rfile_t(curpath)) + if (fs::is_file(curpath)) { SetPath(curpath); Load(); @@ -165,7 +165,7 @@ bool Emulator::BootGame(const std::string& path, bool direct) { curpath = path + elf_path[i]; - if (rfile_t(curpath)) + if (fs::is_file(curpath)) { SetPath(curpath); Load(); @@ -181,7 +181,7 @@ void Emulator::Load() { GetModuleManager().Init(); - if (!rIsFile(m_path)) return; + if (!fs::is_file(m_path)) return; const std::string elf_dir = m_path.substr(0, m_path.find_last_of("/\\", std::string::npos, 2) + 1); @@ -233,7 +233,7 @@ void Emulator::Load() Emu.GetVFS().Mount("/dev_bdvd/", bdvd, new vfsDeviceLocalFile()); } - else if (rIsFile(elf_dir + "../../PS3_DISC.SFB")) // guess loading disc game + else if (fs::is_file(elf_dir + "../../PS3_DISC.SFB")) // guess loading disc game { const auto dir_list = fmt::split(elf_dir, { "/", "\\" }); @@ -436,7 +436,7 @@ void Emulator::SavePoints(const std::string& path) void Emulator::LoadPoints(const std::string& path) { - if (!rIsFile(path)) return; + if (!fs::is_file(path)) return; std::ifstream f(path, std::ios::binary); if (!f.is_open()) return; diff --git a/rpcs3/Gui/AutoPauseManager.cpp b/rpcs3/Gui/AutoPauseManager.cpp index 66f86355b8..732b57f4f1 100644 --- a/rpcs3/Gui/AutoPauseManager.cpp +++ b/rpcs3/Gui/AutoPauseManager.cpp @@ -4,7 +4,7 @@ #include #include #include "Utilities/Log.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" enum { @@ -71,9 +71,10 @@ void AutoPauseManagerDialog::LoadEntries(void) m_entries.clear(); m_entries.reserve(16); - if (rIsFile("pause.bin")) + fs::file list("pause.bin"); + + if (list) { - rfile_t list("pause.bin"); //System calls ID and Function calls ID are all u32 iirc. u32 num; size_t fmax = list.size(); @@ -95,7 +96,7 @@ void AutoPauseManagerDialog::LoadEntries(void) //This would always use a 0xFFFFFFFF as end of the pause.bin void AutoPauseManagerDialog::SaveEntries(void) { - rfile_t list("pause.bin", o_write | o_create | o_trunc); + fs::file list("pause.bin", o_write | o_create | o_trunc); //System calls ID and Function calls ID are all u32 iirc. u32 num = 0; list.seek(0); diff --git a/rpcs3/Gui/GameViewer.cpp b/rpcs3/Gui/GameViewer.cpp index 4ac4c1f87e..f2527a1d35 100644 --- a/rpcs3/Gui/GameViewer.cpp +++ b/rpcs3/Gui/GameViewer.cpp @@ -1,7 +1,7 @@ #include "stdafx_gui.h" #include "Utilities/AutoPause.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" +//#include "Utilities/File.h" #include "Emu/Memory/Memory.h" #include "Emu/System.h" #include "Emu/FS/VFS.h" diff --git a/rpcs3/Gui/MainFrame.cpp b/rpcs3/Gui/MainFrame.cpp index 665cc25d02..f724cc3513 100644 --- a/rpcs3/Gui/MainFrame.cpp +++ b/rpcs3/Gui/MainFrame.cpp @@ -246,9 +246,9 @@ void MainFrame::InstallPkg(wxCommandEvent& WXUNUSED(event)) Emu.Stop(); // Open and install PKG file - rfile_t pkg_f(ctrl.GetPath().ToStdString(), o_read); + fs::file pkg_f(ctrl.GetPath().ToStdString(), o_read); - if(pkg_f) + if (pkg_f) { PKGLoader::Install(pkg_f, "/dev_hdd0/game/"); diff --git a/rpcs3/Gui/SaveDataUtility.cpp b/rpcs3/Gui/SaveDataUtility.cpp index 534188d076..517f03642a 100644 --- a/rpcs3/Gui/SaveDataUtility.cpp +++ b/rpcs3/Gui/SaveDataUtility.cpp @@ -3,7 +3,7 @@ #include #include #include "Utilities/Log.h" -#include "Utilities/rFile.h" +//#include "Utilities/File.h" //Cause i can not decide what struct to be used to fill those. Just use no real data now. //Currently variable info isn't used. it supposed to be a container for the information passed by other. diff --git a/rpcs3/Loader/ELF32.cpp b/rpcs3/Loader/ELF32.cpp index 0135b3a0a5..6ef662b641 100644 --- a/rpcs3/Loader/ELF32.cpp +++ b/rpcs3/Loader/ELF32.cpp @@ -1,7 +1,6 @@ #include "stdafx.h" #include "Ini.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" #include "Emu/FS/vfsStream.h" #include "Emu/Memory/Memory.h" #include "ELF32.h" diff --git a/rpcs3/Loader/ELF64.cpp b/rpcs3/Loader/ELF64.cpp index 56999154e1..30fbd4d5ba 100644 --- a/rpcs3/Loader/ELF64.cpp +++ b/rpcs3/Loader/ELF64.cpp @@ -1,6 +1,5 @@ #include "stdafx.h" #include "Utilities/Log.h" -#include "Utilities/rFile.h" #include "Emu/FS/vfsStream.h" #include "Emu/FS/vfsFile.h" #include "Emu/FS/vfsDir.h" diff --git a/rpcs3/Loader/PKG.cpp b/rpcs3/Loader/PKG.cpp index a87f7af6c3..e484e2afa0 100644 --- a/rpcs3/Loader/PKG.cpp +++ b/rpcs3/Loader/PKG.cpp @@ -1,11 +1,11 @@ #include "stdafx.h" #include "Utilities/Log.h" #include "Utilities/rMsgBox.h" -#include "Utilities/rFile.h" +#include "Utilities/File.h" #include "PKG.h" #include "../Crypto/unpkg.h" -bool PKGLoader::Install(const rfile_t& pkg_f, std::string dest) +bool PKGLoader::Install(const fs::file& pkg_f, std::string dest) { // Initial checks if (!pkg_f) @@ -27,7 +27,7 @@ bool PKGLoader::Install(const rfile_t& pkg_f, std::string dest) std::string titleID = std::string(title_id).substr(7, 9); - if (rIsDir(dest + titleID)) + if (fs::is_dir(dest + titleID)) { if (rMessageDialog(NULL, "Another installation found. Do you want to overwrite it?", "PKG Decrypter / Installer", rYES_NO | rCENTRE).ShowModal() != rID_YES) { @@ -35,7 +35,7 @@ bool PKGLoader::Install(const rfile_t& pkg_f, std::string dest) return false; } } - else if (!rMkDir(dest + titleID)) + else if (!fs::create_dir(dest + titleID)) { LOG_ERROR(LOADER, "PKG Loader: Could not create the installation directory: %s", titleID.c_str()); return false; diff --git a/rpcs3/Loader/PKG.h b/rpcs3/Loader/PKG.h index d72fdd03db..17e55e2347 100644 --- a/rpcs3/Loader/PKG.h +++ b/rpcs3/Loader/PKG.h @@ -1,8 +1,8 @@ #pragma once -struct rfile_t; +struct fs::file; struct PKGLoader { - static bool Install(const rfile_t& pkg_f, std::string dest); + static bool Install(const fs::file& pkg_f, std::string dest); }; diff --git a/rpcs3/emucore.vcxproj b/rpcs3/emucore.vcxproj index 22323e0905..5b35d41c97 100644 --- a/rpcs3/emucore.vcxproj +++ b/rpcs3/emucore.vcxproj @@ -29,7 +29,7 @@ - + @@ -311,7 +311,7 @@ - + diff --git a/rpcs3/emucore.vcxproj.filters b/rpcs3/emucore.vcxproj.filters index d1cea17c07..facf1494db 100644 --- a/rpcs3/emucore.vcxproj.filters +++ b/rpcs3/emucore.vcxproj.filters @@ -599,9 +599,6 @@ Utilities - - Utilities - Utilities @@ -863,6 +860,9 @@ Emu\CPU\Cell + + Utilities + @@ -1402,9 +1402,6 @@ Utilities - - Utilities - Utilities @@ -1549,5 +1546,8 @@ Emu\CPU\Cell + + Utilities + \ No newline at end of file