mirror of
https://github.com/RPCS3/rpcs3.git
synced 2024-11-22 10:42:36 +01:00
fs:: const renaming, fs::g_tls_error stub
This commit is contained in:
parent
c2897cddd6
commit
73b108765e
@ -114,8 +114,12 @@ bool truncate_file(const std::string& file, u64 length)
|
||||
|
||||
#endif
|
||||
|
||||
thread_local fse fs::g_tls_error = fse::ok;
|
||||
|
||||
bool fs::stat(const std::string& path, stat_t& info)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
WIN32_FILE_ATTRIBUTE_DATA attrs;
|
||||
if (!GetFileAttributesExW(to_wchar(path).get(), GetFileExInfoStandard, &attrs))
|
||||
@ -149,6 +153,8 @@ bool fs::stat(const std::string& path, stat_t& info)
|
||||
|
||||
bool fs::exists(const std::string& path)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
return GetFileAttributesW(to_wchar(path).get()) != 0xFFFFFFFF;
|
||||
#else
|
||||
@ -159,6 +165,8 @@ bool fs::exists(const std::string& path)
|
||||
|
||||
bool fs::is_file(const std::string& file)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD attrs;
|
||||
if ((attrs = GetFileAttributesW(to_wchar(file).get())) == INVALID_FILE_ATTRIBUTES)
|
||||
@ -180,6 +188,8 @@ bool fs::is_file(const std::string& file)
|
||||
|
||||
bool fs::is_dir(const std::string& dir)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD attrs;
|
||||
if ((attrs = GetFileAttributesW(to_wchar(dir).get())) == INVALID_FILE_ATTRIBUTES)
|
||||
@ -201,6 +211,8 @@ bool fs::is_dir(const std::string& dir)
|
||||
|
||||
bool fs::create_dir(const std::string& dir)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!CreateDirectoryW(to_wchar(dir).get(), NULL))
|
||||
#else
|
||||
@ -216,6 +228,8 @@ bool fs::create_dir(const std::string& dir)
|
||||
|
||||
bool fs::create_path(const std::string& path)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
size_t start = 0;
|
||||
|
||||
while (true)
|
||||
@ -258,6 +272,8 @@ bool fs::create_path(const std::string& path)
|
||||
|
||||
bool fs::remove_dir(const std::string& dir)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!RemoveDirectoryW(to_wchar(dir).get()))
|
||||
#else
|
||||
@ -273,6 +289,8 @@ bool fs::remove_dir(const std::string& dir)
|
||||
|
||||
bool fs::rename(const std::string& from, const std::string& to)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!MoveFileW(to_wchar(from).get(), to_wchar(to).get()))
|
||||
#else
|
||||
@ -324,6 +342,8 @@ int OSCopyFile(const char* source, const char* destination, bool overwrite)
|
||||
|
||||
bool fs::copy_file(const std::string& from, const std::string& to, bool overwrite)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!CopyFileW(to_wchar(from).get(), to_wchar(to).get(), !overwrite))
|
||||
#else
|
||||
@ -339,6 +359,8 @@ bool fs::copy_file(const std::string& from, const std::string& to, bool overwrit
|
||||
|
||||
bool fs::remove_file(const std::string& file)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!DeleteFileW(to_wchar(file).get()))
|
||||
#else
|
||||
@ -354,6 +376,8 @@ bool fs::remove_file(const std::string& file)
|
||||
|
||||
bool fs::truncate_file(const std::string& file, u64 length)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
if (!::truncate_file(file, length))
|
||||
#else
|
||||
@ -383,62 +407,64 @@ bool fs::file::open(const std::string& filename, u32 mode)
|
||||
{
|
||||
this->close();
|
||||
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
DWORD access = 0;
|
||||
switch (mode & (o_read | o_write | o_append))
|
||||
switch (mode & (fom::read | fom::write | fom::append))
|
||||
{
|
||||
case o_read: access |= GENERIC_READ; break;
|
||||
case o_read | o_append: access |= GENERIC_READ; break;
|
||||
case o_write: access |= GENERIC_WRITE; break;
|
||||
case o_write | o_append: access |= FILE_APPEND_DATA; break;
|
||||
case o_read | o_write: access |= GENERIC_READ | GENERIC_WRITE; break;
|
||||
case o_read | o_write | o_append: access |= GENERIC_READ | FILE_APPEND_DATA; break;
|
||||
case fom::read: access |= GENERIC_READ; break;
|
||||
case fom::read | fom::append: access |= GENERIC_READ; break;
|
||||
case fom::write: access |= GENERIC_WRITE; break;
|
||||
case fom::write | fom::append: access |= FILE_APPEND_DATA; break;
|
||||
case fom::read | fom::write: access |= GENERIC_READ | GENERIC_WRITE; break;
|
||||
case fom::read | fom::write | fom::append: access |= GENERIC_READ | FILE_APPEND_DATA; break;
|
||||
default:
|
||||
{
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode);
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither fom::read nor fom::write specified (0x%x)", filename, mode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DWORD disp = 0;
|
||||
switch (mode & (o_create | o_trunc | o_excl))
|
||||
switch (mode & (fom::create | fom::trunc | fom::excl))
|
||||
{
|
||||
case 0: disp = OPEN_EXISTING; break;
|
||||
case o_create: disp = OPEN_ALWAYS; break;
|
||||
case o_trunc: disp = TRUNCATE_EXISTING; break;
|
||||
case o_create | o_trunc: disp = CREATE_ALWAYS; break;
|
||||
case o_create | o_excl: disp = CREATE_NEW; break;
|
||||
case o_create | o_excl | o_trunc: disp = CREATE_NEW; break;
|
||||
case fom::create: disp = OPEN_ALWAYS; break;
|
||||
case fom::trunc: disp = TRUNCATE_EXISTING; break;
|
||||
case fom::create | fom::trunc: disp = CREATE_ALWAYS; break;
|
||||
case fom::create | fom::excl: disp = CREATE_NEW; break;
|
||||
case fom::create | fom::excl | fom::trunc: disp = CREATE_NEW; break;
|
||||
}
|
||||
|
||||
if (!disp || (mode & ~(o_read | o_write | o_append | o_create | o_trunc | o_excl)))
|
||||
if (!disp || (mode & ~(fom::read | fom::write | fom::append | fom::create | fom::trunc | fom::excl)))
|
||||
{
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: unknown mode specified (0x%x)", filename, mode);
|
||||
return false;
|
||||
}
|
||||
|
||||
m_fd = (intptr_t)CreateFileW(to_wchar(filename).get(), access, FILE_SHARE_READ, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
m_fd = (intptr_t)CreateFileW(to_wchar(filename).get(), access, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, disp, FILE_ATTRIBUTE_NORMAL, NULL);
|
||||
#else
|
||||
int flags = 0;
|
||||
|
||||
switch (mode & (o_read | o_write))
|
||||
switch (mode & (fom::read | fom::write))
|
||||
{
|
||||
case o_read: flags |= O_RDONLY; break;
|
||||
case o_write: flags |= O_WRONLY; break;
|
||||
case o_read | o_write: flags |= O_RDWR; break;
|
||||
case fom::read: flags |= O_RDONLY; break;
|
||||
case fom::write: flags |= O_WRONLY; break;
|
||||
case fom::read | fom::write: flags |= O_RDWR; break;
|
||||
default:
|
||||
{
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither o_read nor o_write specified (0x%x)", filename, mode);
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: neither fom::read nor fom::write specified (0x%x)", filename, mode);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (mode & o_append) flags |= O_APPEND;
|
||||
if (mode & o_create) flags |= O_CREAT;
|
||||
if (mode & o_trunc) flags |= O_TRUNC;
|
||||
if (mode & o_excl) flags |= O_EXCL;
|
||||
if (mode & fom::append) flags |= O_APPEND;
|
||||
if (mode & fom::create) flags |= O_CREAT;
|
||||
if (mode & fom::trunc) flags |= O_TRUNC;
|
||||
if (mode & fom::excl) flags |= O_EXCL;
|
||||
|
||||
if (((mode & o_excl) && !(mode & o_create)) || (mode & ~(o_read | o_write | o_append | o_create | o_trunc | o_excl)))
|
||||
if (((mode & fom::excl) && !(mode & fom::create)) || (mode & ~(fom::read | fom::write | fom::append | fom::create | fom::trunc | fom::excl)))
|
||||
{
|
||||
LOG_ERROR(GENERAL, "fs::file::open('%s') failed: unknown mode specified (0x%x)", filename, mode);
|
||||
return false;
|
||||
@ -458,6 +484,8 @@ bool fs::file::open(const std::string& filename, u32 mode)
|
||||
|
||||
bool fs::file::trunc(u64 size) const
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER old, pos;
|
||||
|
||||
@ -479,6 +507,8 @@ bool fs::file::trunc(u64 size) const
|
||||
|
||||
bool fs::file::stat(stat_t& info) const
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
FILE_BASIC_INFO basic_info;
|
||||
|
||||
@ -513,6 +543,8 @@ bool fs::file::stat(stat_t& info) const
|
||||
|
||||
bool fs::file::close()
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
if (m_fd == null)
|
||||
{
|
||||
return false;
|
||||
@ -530,6 +562,8 @@ bool fs::file::close()
|
||||
|
||||
u64 fs::file::read(void* buffer, u64 count) const
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
const int size = count <= INT_MAX ? static_cast<int>(count) : throw EXCEPTION("Invalid count (0x%llx)", count);
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -547,6 +581,8 @@ u64 fs::file::read(void* buffer, u64 count) const
|
||||
|
||||
u64 fs::file::write(const void* buffer, u64 count) const
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
const int size = count <= INT_MAX ? static_cast<int>(count) : throw EXCEPTION("Invalid count (0x%llx)", count);
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -562,14 +598,20 @@ u64 fs::file::write(const void* buffer, u64 count) const
|
||||
#endif
|
||||
}
|
||||
|
||||
u64 fs::file::seek(u64 offset, u32 mode) const
|
||||
u64 fs::file::seek(s64 offset, fsm seek_mode) const
|
||||
{
|
||||
assert(mode < 3);
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER pos;
|
||||
pos.QuadPart = offset;
|
||||
|
||||
const DWORD mode =
|
||||
seek_mode == fsm::begin ? FILE_BEGIN :
|
||||
seek_mode == fsm::cur ? FILE_CURRENT :
|
||||
seek_mode == fsm::end ? FILE_END :
|
||||
throw EXCEPTION("Unknown seek_mode (0x%x)", seek_mode);
|
||||
|
||||
if (!SetFilePointerEx((HANDLE)m_fd, pos, &pos, mode))
|
||||
{
|
||||
return -1;
|
||||
@ -577,12 +619,20 @@ u64 fs::file::seek(u64 offset, u32 mode) const
|
||||
|
||||
return pos.QuadPart;
|
||||
#else
|
||||
return ::lseek(m_fd, offset, mode);
|
||||
const int whence =
|
||||
seek_mode == fsm::begin ? SEEK_SET :
|
||||
seek_mode == fsm::cur ? SEEK_CUR :
|
||||
seek_mode == fsm::end ? SEEK_END :
|
||||
throw EXCEPTION("Unknown seek_mode (0x%x)", seek_mode);
|
||||
|
||||
return ::lseek(m_fd, offset, whence);
|
||||
#endif
|
||||
}
|
||||
|
||||
u64 fs::file::size() const
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
#ifdef _WIN32
|
||||
LARGE_INTEGER size;
|
||||
if (!GetFileSizeEx((HANDLE)m_fd, &size))
|
||||
@ -625,6 +675,8 @@ void fs::dir::import(handle_type dd, const std::string& path)
|
||||
#endif
|
||||
}
|
||||
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
m_dd = dd;
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -646,6 +698,8 @@ bool fs::dir::open(const std::string& dirname)
|
||||
#endif
|
||||
}
|
||||
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
m_dd = null;
|
||||
|
||||
m_path.reset();
|
||||
@ -667,6 +721,8 @@ bool fs::dir::open(const std::string& dirname)
|
||||
|
||||
bool fs::dir::close()
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
if (m_dd == null)
|
||||
{
|
||||
if (m_path)
|
||||
@ -703,6 +759,8 @@ bool fs::dir::get_first(std::string& name, stat_t& info)
|
||||
#endif
|
||||
}
|
||||
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
m_dd = null;
|
||||
|
||||
if (!m_path)
|
||||
@ -739,6 +797,8 @@ bool fs::dir::get_first(std::string& name, stat_t& info)
|
||||
|
||||
bool fs::dir::get_next(std::string& name, stat_t& info)
|
||||
{
|
||||
g_tls_error = fse::ok;
|
||||
|
||||
if (m_dd == null)
|
||||
{
|
||||
return false;
|
||||
|
@ -1,32 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
enum file_seek_mode : u32
|
||||
enum class fsm : u32 // file seek mode
|
||||
{
|
||||
from_begin,
|
||||
from_cur,
|
||||
from_end,
|
||||
begin,
|
||||
cur,
|
||||
end,
|
||||
};
|
||||
|
||||
enum file_open_mode : u32
|
||||
namespace fom // file open mode
|
||||
{
|
||||
o_read = 1 << 0,
|
||||
o_write = 1 << 1,
|
||||
o_append = 1 << 2,
|
||||
o_create = 1 << 3,
|
||||
o_trunc = 1 << 4,
|
||||
o_excl = 1 << 5,
|
||||
enum : u32
|
||||
{
|
||||
read = 1 << 0,
|
||||
write = 1 << 1,
|
||||
append = 1 << 2,
|
||||
create = 1 << 3,
|
||||
trunc = 1 << 4,
|
||||
excl = 1 << 5,
|
||||
};
|
||||
};
|
||||
|
||||
enum class fse : u32 // filesystem (file or dir) error
|
||||
{
|
||||
ok, // no error
|
||||
invalid_arguments,
|
||||
};
|
||||
|
||||
enum : u32 // obsolete flags
|
||||
{
|
||||
o_read = fom::read,
|
||||
o_write = fom::write,
|
||||
o_append = fom::append,
|
||||
o_create = fom::create,
|
||||
o_trunc = fom::trunc,
|
||||
o_excl = fom::excl,
|
||||
};
|
||||
|
||||
namespace fs
|
||||
{
|
||||
thread_local extern fse g_tls_error;
|
||||
|
||||
struct stat_t
|
||||
{
|
||||
bool is_directory;
|
||||
bool is_writable;
|
||||
u64 size;
|
||||
time_t atime;
|
||||
time_t mtime;
|
||||
time_t ctime;
|
||||
s64 atime;
|
||||
s64 mtime;
|
||||
s64 ctime;
|
||||
};
|
||||
|
||||
bool stat(const std::string& path, stat_t& info);
|
||||
@ -53,7 +74,7 @@ namespace fs
|
||||
public:
|
||||
file() = default;
|
||||
~file();
|
||||
explicit file(const std::string& filename, u32 mode = o_read) { open(filename, mode); }
|
||||
explicit file(const std::string& filename, u32 mode = fom::read) { open(filename, mode); }
|
||||
|
||||
file(const file&) = delete;
|
||||
file(file&&) = delete; // possibly TODO
|
||||
@ -65,7 +86,7 @@ namespace fs
|
||||
|
||||
void import(handle_type fd) { this->~file(); m_fd = fd; }
|
||||
|
||||
bool open(const std::string& filename, u32 mode = o_read);
|
||||
bool open(const std::string& filename, u32 mode = fom::read);
|
||||
bool is_opened() const { return m_fd != null; }
|
||||
bool trunc(u64 size) const; // change file size (possibly appending zero bytes)
|
||||
bool stat(stat_t& info) const; // get file info
|
||||
@ -73,7 +94,7 @@ namespace fs
|
||||
|
||||
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 seek(s64 offset, fsm seek_mode = fsm::begin) const;
|
||||
u64 size() const;
|
||||
};
|
||||
|
||||
|
@ -94,7 +94,7 @@ struct FileListener : LogListener
|
||||
bool mPrependChannelName;
|
||||
|
||||
FileListener(const std::string& name = _PRGNAME_, bool prependChannel = true)
|
||||
: mFile(rPlatform::getConfigDir() + name + ".log", o_write | o_create | o_trunc)
|
||||
: mFile(rPlatform::getConfigDir() + name + ".log", fom::write | fom::create | fom::trunc)
|
||||
, mPrependChannelName(prependChannel)
|
||||
{
|
||||
if (!mFile)
|
||||
|
@ -815,7 +815,7 @@ int DecryptEDAT(const std::string& input_file_name, const std::string& output_fi
|
||||
{
|
||||
// Prepare the files.
|
||||
fs::file input(input_file_name);
|
||||
fs::file output(output_file_name, o_write | o_create | o_trunc);
|
||||
fs::file output(output_file_name, fom::write | fom::create | fom::trunc);
|
||||
fs::file rap(rap_file_name);
|
||||
|
||||
// Set keys (RIF and DEVKLIC).
|
||||
|
@ -69,7 +69,7 @@ static bool CheckHeader(const fs::file& pkg_f, PKGHeader& header)
|
||||
bool Unpack(const fs::file& pkg_f, std::string dir)
|
||||
{
|
||||
// Save current file offset (probably zero)
|
||||
const u64 start_offset = pkg_f.seek(0, from_cur);
|
||||
const u64 start_offset = pkg_f.seek(0, fsm::cur);
|
||||
|
||||
// Get basic PKG information
|
||||
PKGHeader header;
|
||||
@ -186,7 +186,7 @@ bool Unpack(const fs::file& pkg_f, std::string dir)
|
||||
LOG_WARNING(LOADER, "PKG Loader: '%s' is overwritten", path);
|
||||
}
|
||||
|
||||
if (fs::file out{ path, o_write | o_create | o_trunc })
|
||||
if (fs::file out{ path, fom::write | fom::create | fom::trunc })
|
||||
{
|
||||
for (u64 pos = 0; pos < entry.file_size; pos += BUF_SIZE)
|
||||
{
|
||||
|
@ -1076,7 +1076,7 @@ bool SELFDecrypter::DecryptData()
|
||||
bool SELFDecrypter::MakeElf(const std::string& elf, bool isElf32)
|
||||
{
|
||||
// Create a new ELF file.
|
||||
fs::file e(elf, o_write | o_create | o_trunc);
|
||||
fs::file e(elf, fom::write | fom::create | fom::trunc);
|
||||
if(!e)
|
||||
{
|
||||
LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str());
|
||||
@ -1283,7 +1283,7 @@ bool CheckDebugSelf(const std::string& self, const std::string& elf)
|
||||
s.seek(elf_offset);
|
||||
|
||||
// Write the real ELF file back.
|
||||
fs::file e(elf, o_write | o_create | o_trunc);
|
||||
fs::file e(elf, fom::write | fom::create | fom::trunc);
|
||||
if(!e)
|
||||
{
|
||||
LOG_ERROR(LOADER, "Could not create ELF file! (%s)", elf.c_str());
|
||||
|
@ -12,7 +12,7 @@ AudioDumper::~AudioDumper()
|
||||
|
||||
bool AudioDumper::Init(u8 ch)
|
||||
{
|
||||
if ((m_init = m_output.open("audio.wav", o_write | o_create | o_trunc)))
|
||||
if ((m_init = m_output.open("audio.wav", fom::write | fom::create | fom::trunc)))
|
||||
{
|
||||
m_header = WAVHeader(ch);
|
||||
WriteHeader();
|
||||
|
@ -160,7 +160,7 @@ void SPURecompilerCore::Compile(u16 pos)
|
||||
// entry[start].count, excess, stamp1 - stamp0, time0, get_system_time() - stamp1);
|
||||
//}
|
||||
|
||||
//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());
|
||||
//fs::file(fmt::Format("SPUjit_%d.log", this->CPU.GetId()), fom::write | fom::create | (first ? fom::trunc : fom::append)).write(log.c_str(), log.size());
|
||||
|
||||
m_enc->compiler = nullptr;
|
||||
first = false;
|
||||
|
@ -48,7 +48,7 @@ u64 vfsFile::Read(void* dst, u64 size)
|
||||
return m_stream->Read(dst, size);
|
||||
}
|
||||
|
||||
u64 vfsFile::Seek(s64 offset, u32 mode)
|
||||
u64 vfsFile::Seek(s64 offset, fsm mode)
|
||||
{
|
||||
return m_stream->Seek(offset, mode);
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "vfsFileBase.h"
|
||||
|
||||
class vfsFile : public vfsFileBase
|
||||
@ -8,9 +9,9 @@ private:
|
||||
|
||||
public:
|
||||
vfsFile();
|
||||
vfsFile(const std::string& path, u32 mode = vfsRead);
|
||||
vfsFile(const std::string& path, u32 mode = fom::read);
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode = vfsRead) override;
|
||||
virtual bool Open(const std::string& path, u32 mode = fom::read) override;
|
||||
virtual bool Close() override;
|
||||
|
||||
virtual u64 GetSize() const override;
|
||||
@ -18,7 +19,7 @@ public:
|
||||
virtual u64 Write(const void* src, u64 size) override;
|
||||
virtual u64 Read(void* dst, u64 size) override;
|
||||
|
||||
virtual u64 Seek(s64 offset, u32 mode = from_begin) override;
|
||||
virtual u64 Seek(s64 offset, fsm seek_mode = fsm::begin) override;
|
||||
virtual u64 Tell() const override;
|
||||
|
||||
virtual bool IsOpened() const override;
|
||||
|
@ -1,13 +1,6 @@
|
||||
#pragma once
|
||||
#include "vfsStream.h"
|
||||
|
||||
enum vfsOpenMode : u32
|
||||
{
|
||||
vfsRead = o_read,
|
||||
vfsReadWrite = o_read | o_write,
|
||||
vfsWriteNew = o_write | o_create | o_trunc,
|
||||
vfsWriteExcl = o_write | o_create | o_excl,
|
||||
};
|
||||
#include "vfsStream.h"
|
||||
|
||||
class vfsDevice;
|
||||
|
||||
|
@ -33,14 +33,14 @@ u64 vfsLocalFile::Read(void* dst, u64 size)
|
||||
return m_file.read(dst, size);
|
||||
}
|
||||
|
||||
u64 vfsLocalFile::Seek(s64 offset, u32 mode)
|
||||
u64 vfsLocalFile::Seek(s64 offset, fsm mode)
|
||||
{
|
||||
return m_file.seek(offset, mode);
|
||||
}
|
||||
|
||||
u64 vfsLocalFile::Tell() const
|
||||
{
|
||||
return m_file.seek(0, from_cur);
|
||||
return m_file.seek(0, fsm::cur);
|
||||
}
|
||||
|
||||
bool vfsLocalFile::IsOpened() const
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "vfsFileBase.h"
|
||||
|
||||
class vfsLocalFile : public vfsFileBase
|
||||
@ -9,7 +10,7 @@ private:
|
||||
public:
|
||||
vfsLocalFile(vfsDevice* device);
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode = vfsRead) override;
|
||||
virtual bool Open(const std::string& path, u32 mode = fom::read) override;
|
||||
virtual bool Close() override;
|
||||
|
||||
virtual u64 GetSize() const override;
|
||||
@ -17,7 +18,7 @@ public:
|
||||
virtual u64 Write(const void* src, u64 size) override;
|
||||
virtual u64 Read(void* dst, u64 size) override;
|
||||
|
||||
virtual u64 Seek(s64 offset, u32 mode = from_begin) override;
|
||||
virtual u64 Seek(s64 offset, fsm seek_mode = fsm::begin) override;
|
||||
virtual u64 Tell() const override;
|
||||
|
||||
virtual bool IsOpened() const override;
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
|
||||
#include "Utilities/File.h"
|
||||
|
||||
struct vfsStream
|
||||
@ -31,7 +32,7 @@ struct vfsStream
|
||||
return Read(&data, count) == count;
|
||||
}
|
||||
|
||||
virtual u64 Seek(s64 offset, u32 mode = from_begin) = 0;
|
||||
virtual u64 Seek(s64 offset, fsm seek_mode = fsm::begin) = 0;
|
||||
|
||||
virtual u64 Tell() const = 0;
|
||||
|
||||
|
@ -31,18 +31,16 @@ public:
|
||||
|
||||
virtual u64 Read(void* dst, u64 count) override;
|
||||
|
||||
virtual u64 Seek(s64 offset, u32 mode = from_begin) override
|
||||
virtual u64 Seek(s64 offset, fsm seek_mode = fsm::begin) override
|
||||
{
|
||||
assert(mode < 3);
|
||||
|
||||
switch (mode)
|
||||
switch (seek_mode)
|
||||
{
|
||||
case from_begin: return m_pos = offset;
|
||||
case from_cur: return m_pos += offset;
|
||||
case from_end: return m_pos = m_size + offset;
|
||||
case fsm::begin: return m_pos = offset;
|
||||
case fsm::cur: return m_pos += offset;
|
||||
case fsm::end: return m_pos = m_size + offset;
|
||||
}
|
||||
|
||||
return m_pos;
|
||||
throw EXCEPTION("Unknown seek_mode (0x%x)", seek_mode);
|
||||
}
|
||||
|
||||
virtual u64 Tell() const override
|
||||
|
@ -15,13 +15,13 @@ void vfsHDDManager::CreateEntry(vfsHDD_Entry& entry)
|
||||
entry.atime = ctime;
|
||||
entry.ctime = ctime;
|
||||
entry.mtime = ctime;
|
||||
entry.access = vfsReadWrite;
|
||||
entry.access = 0666;
|
||||
CreateBlock(entry);
|
||||
}
|
||||
|
||||
void vfsHDDManager::CreateHDD(const std::string& path, u64 size, u64 block_size)
|
||||
{
|
||||
fs::file f(path, o_write | o_create | o_trunc);
|
||||
fs::file f(path, fom::write | fom::create | fom::trunc);
|
||||
|
||||
static const u64 cur_dir_block = 1;
|
||||
|
||||
@ -353,7 +353,7 @@ vfsHDD::vfsHDD(vfsDevice* device, const std::string& hdd_path)
|
||||
, m_hdd_path(hdd_path)
|
||||
, vfsFileBase(device)
|
||||
{
|
||||
m_hdd_file.Open(hdd_path, vfsReadWrite);
|
||||
m_hdd_file.Open(hdd_path, fom::read | fom::write);
|
||||
m_hdd_file.Read(&m_hdd_info, sizeof(vfsHDD_Hdr));
|
||||
m_cur_dir_block = m_hdd_info.next_block;
|
||||
if (!m_hdd_info.block_size)
|
||||
@ -747,16 +747,16 @@ u64 vfsHDD::Read(void* dst, u64 size)
|
||||
return m_file.Read(dst, size); // ???
|
||||
}
|
||||
|
||||
u64 vfsHDD::Seek(s64 offset, u32 mode)
|
||||
u64 vfsHDD::Seek(s64 offset, fsm seek_mode)
|
||||
{
|
||||
switch (mode)
|
||||
switch (seek_mode)
|
||||
{
|
||||
case from_begin: return m_file.Seek(offset);
|
||||
case from_cur: return m_file.Seek(Tell() + offset);
|
||||
case from_end: return m_file.Seek(m_file.GetSize() + offset);
|
||||
case fsm::begin: return m_file.Seek(offset);
|
||||
case fsm::cur: return m_file.Seek(Tell() + offset);
|
||||
case fsm::end: return m_file.Seek(m_file.GetSize() + offset);
|
||||
}
|
||||
|
||||
return m_file.Tell(); // ???
|
||||
throw EXCEPTION("Unknown seek_mode(0x%x)", seek_mode);
|
||||
}
|
||||
|
||||
u64 vfsHDD::Tell() const
|
||||
|
@ -182,7 +182,7 @@ public:
|
||||
|
||||
bool GetNextEntry(u64& block, vfsHDD_Entry& entry, std::string& name);
|
||||
|
||||
virtual bool Open(const std::string& path, u32 mode = vfsRead) override;
|
||||
virtual bool Open(const std::string& path, u32 mode = fom::read) override;
|
||||
|
||||
bool HasEntry(const std::string& name);
|
||||
|
||||
@ -196,7 +196,7 @@ public:
|
||||
|
||||
virtual u64 Read(void* dst, u64 count) override;
|
||||
|
||||
virtual u64 Seek(s64 offset, u32 mode = from_begin) override;
|
||||
virtual u64 Seek(s64 offset, fsm seek_mode = fsm::begin) override;
|
||||
|
||||
virtual u64 Tell() const override;
|
||||
|
||||
|
@ -2,7 +2,7 @@
|
||||
|
||||
#define ID_MANAGER_INCLUDED
|
||||
|
||||
// default specialization for all types
|
||||
// default traits for any arbitrary type
|
||||
template<typename T> struct id_traits
|
||||
{
|
||||
// get next mapped id (may return 0 if out of IDs)
|
||||
|
@ -580,7 +580,7 @@ void GLTexture::Save(RSXTexture& tex, const std::string& name)
|
||||
return;
|
||||
}
|
||||
|
||||
fs::file(name + ".raw", o_write | o_create | o_trunc).write(alldata, texPixelCount * 4);
|
||||
fs::file(name + ".raw", fom::write | fom::create | fom::trunc).write(alldata, texPixelCount * 4);
|
||||
|
||||
u8* data = new u8[texPixelCount * 3];
|
||||
u8* alpha = new u8[texPixelCount];
|
||||
|
@ -19,7 +19,7 @@ struct GLTraits
|
||||
//checkForGlError("m_fragment_prog.Compile");
|
||||
|
||||
// TODO: This shouldn't use current dir
|
||||
fs::file("./FragmentProgram.txt", o_write | o_create | o_trunc).write(fragmentProgramData.shader.c_str(), fragmentProgramData.shader.size());
|
||||
fs::file("./FragmentProgram.txt", fom::write | fom::create | fom::trunc).write(fragmentProgramData.shader.c_str(), fragmentProgramData.shader.size());
|
||||
}
|
||||
|
||||
static
|
||||
@ -30,7 +30,7 @@ struct GLTraits
|
||||
//checkForGlError("m_vertex_prog.Compile");
|
||||
|
||||
// TODO: This shouldn't use current dir
|
||||
fs::file("./VertexProgram.txt", o_write | o_create | o_trunc).write(vertexProgramData.shader.c_str(), vertexProgramData.shader.size());
|
||||
fs::file("./VertexProgram.txt", fom::write | fom::create | fom::trunc).write(vertexProgramData.shader.c_str(), vertexProgramData.shader.size());
|
||||
}
|
||||
|
||||
static
|
||||
|
@ -752,8 +752,8 @@ bool sdata_check(u32 version, u32 flags, u64 filesizeInput, u64 filesizeTmp)
|
||||
|
||||
s32 sdata_unpack(const std::string& packed_file, const std::string& unpacked_file)
|
||||
{
|
||||
std::shared_ptr<vfsFileBase> packed_stream(Emu.GetVFS().OpenFile(packed_file, vfsRead));
|
||||
std::shared_ptr<vfsFileBase> unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, vfsWriteNew));
|
||||
std::shared_ptr<vfsFileBase> packed_stream(Emu.GetVFS().OpenFile(packed_file, fom::read));
|
||||
std::shared_ptr<vfsFileBase> unpacked_stream(Emu.GetVFS().OpenFile(unpacked_file, fom::write | fom::create | fom::trunc));
|
||||
|
||||
if (!packed_stream || !packed_stream->IsOpened())
|
||||
{
|
||||
|
@ -64,7 +64,7 @@ s32 cellGifDecOpen(PMainHandle mainHandle, PPSubHandle subHandle, PSrc src, POpe
|
||||
case CELL_GIFDEC_FILE:
|
||||
{
|
||||
// Get file descriptor and size
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead));
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), fom::read));
|
||||
if (!file_s) return CELL_GIFDEC_ERROR_OPEN_FILE;
|
||||
|
||||
current_subHandle.fd = idm::make<lv2_file_t>(file_s, 0, 0);
|
||||
|
@ -53,7 +53,7 @@ s32 cellJpgDecOpen(u32 mainHandle, vm::ptr<u32> subHandle, vm::ptr<CellJpgDecSrc
|
||||
case CELL_JPGDEC_FILE:
|
||||
{
|
||||
// Get file descriptor and size
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead));
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), fom::read));
|
||||
if (!file_s) return CELL_JPGDEC_ERROR_OPEN_FILE;
|
||||
|
||||
current_subHandle.fd = idm::make<lv2_file_t>(file_s, 0, 0);
|
||||
|
@ -98,7 +98,7 @@ s32 pngDecOpen(PMainHandle dec, PPSubHandle subHandle, PSrc src, POpenInfo openI
|
||||
case CELL_PNGDEC_FILE:
|
||||
{
|
||||
// Get file descriptor and size
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), vfsRead));
|
||||
std::shared_ptr<vfsStream> file_s(Emu.GetVFS().OpenFile(src->fileName.get_ptr(), fom::read));
|
||||
if (!file_s) return CELL_PNGDEC_ERROR_OPEN_FILE;
|
||||
|
||||
stream->fd = idm::make<lv2_file_t>(file_s, 0, 0);
|
||||
|
@ -561,7 +561,7 @@ never_inline s32 savedata_op(PPUThread& ppu, u32 operation, u32 version, vm::cpt
|
||||
{
|
||||
case CELL_SAVEDATA_FILEOP_READ:
|
||||
{
|
||||
fs::file file(local_path, o_read);
|
||||
fs::file file(local_path, fom::read);
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.read(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
break;
|
||||
@ -569,10 +569,10 @@ never_inline s32 savedata_op(PPUThread& ppu, u32 operation, u32 version, vm::cpt
|
||||
|
||||
case CELL_SAVEDATA_FILEOP_WRITE:
|
||||
{
|
||||
fs::file file(local_path, o_write | o_create);
|
||||
fs::file file(local_path, fom::write | fom::create);
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
file.trunc(file.seek(0, from_cur)); // truncate
|
||||
file.trunc(file.seek(0, fsm::cur)); // truncate
|
||||
break;
|
||||
}
|
||||
|
||||
@ -585,7 +585,7 @@ never_inline s32 savedata_op(PPUThread& ppu, u32 operation, u32 version, vm::cpt
|
||||
|
||||
case CELL_SAVEDATA_FILEOP_WRITE_NOTRUNC:
|
||||
{
|
||||
fs::file file(local_path, o_write | o_create);
|
||||
fs::file file(local_path, fom::write | fom::create);
|
||||
file.seek(fileSet->fileOffset);
|
||||
fileGet->excSize = static_cast<u32>(file.write(fileSet->fileBuf.get_ptr(), std::min<u32>(fileSet->fileSize, fileSet->fileBufSize)));
|
||||
break;
|
||||
@ -602,7 +602,7 @@ never_inline s32 savedata_op(PPUThread& ppu, u32 operation, u32 version, vm::cpt
|
||||
// Write PARAM.SFO
|
||||
if (psf)
|
||||
{
|
||||
vfsFile f(sfo_path, vfsWriteNew);
|
||||
vfsFile f(sfo_path, fom::write | fom::create | fom::trunc);
|
||||
psf.Save(f);
|
||||
}
|
||||
|
||||
|
@ -22,7 +22,7 @@ s32 cellUserInfoGetStat(u32 id, vm::ptr<CellUserInfoUserStat> stat)
|
||||
return CELL_USERINFO_ERROR_NOUSER;
|
||||
|
||||
sprintf(path, "/dev_hdd0/home/%08d/localusername", id);
|
||||
vfsStream* stream = Emu.GetVFS().OpenFile(path, vfsRead);
|
||||
vfsStream* stream = Emu.GetVFS().OpenFile(path, fom::read);
|
||||
if (!stream || !(stream->IsOpened()))
|
||||
return CELL_USERINFO_ERROR_INTERNAL;
|
||||
|
||||
|
@ -103,7 +103,7 @@ s32 sceNpTrophyCreateContext(vm::ptr<u32> context, vm::cptr<SceNpCommunicationId
|
||||
std::string name = fmt::format("%s_%02d", commId->data, commId->num);
|
||||
|
||||
// open trophy pack file
|
||||
std::unique_ptr<vfsStream> stream(Emu.GetVFS().OpenFile("/app_home/../TROPDIR/" + name + "/TROPHY.TRP", vfsRead));
|
||||
std::unique_ptr<vfsStream> stream(Emu.GetVFS().OpenFile("/app_home/../TROPDIR/" + name + "/TROPHY.TRP", fom::read));
|
||||
|
||||
// check if exists and opened
|
||||
if (!stream || !stream->IsOpened())
|
||||
|
@ -53,31 +53,31 @@ s32 sys_fs_open(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, s32 mode, vm::c
|
||||
|
||||
switch (flags & CELL_FS_O_ACCMODE)
|
||||
{
|
||||
case CELL_FS_O_RDONLY: open_mode |= o_read; break;
|
||||
case CELL_FS_O_WRONLY: open_mode |= o_write; break;
|
||||
case CELL_FS_O_RDWR: open_mode |= o_read | o_write; break;
|
||||
case CELL_FS_O_RDONLY: open_mode |= fom::read; break;
|
||||
case CELL_FS_O_WRONLY: open_mode |= fom::write; break;
|
||||
case CELL_FS_O_RDWR: open_mode |= fom::read | fom::write; break;
|
||||
}
|
||||
|
||||
if (flags & CELL_FS_O_CREAT)
|
||||
{
|
||||
open_mode |= o_create;
|
||||
open_mode |= fom::create;
|
||||
}
|
||||
|
||||
if (flags & CELL_FS_O_TRUNC)
|
||||
{
|
||||
open_mode |= o_trunc;
|
||||
open_mode |= fom::trunc;
|
||||
}
|
||||
|
||||
if (flags & CELL_FS_O_APPEND)
|
||||
{
|
||||
open_mode |= o_append;
|
||||
open_mode |= fom::append;
|
||||
}
|
||||
|
||||
if (flags & CELL_FS_O_EXCL)
|
||||
{
|
||||
if (flags & CELL_FS_O_CREAT)
|
||||
{
|
||||
open_mode |= o_excl;
|
||||
open_mode |= fom::excl;
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -106,7 +106,7 @@ s32 sys_fs_open(vm::cptr<char> path, s32 flags, vm::ptr<u32> fd, s32 mode, vm::c
|
||||
{
|
||||
sys_fs.Error("sys_fs_open('%s'): failed to open file (flags=%#o, mode=%#o)", path.get_ptr(), flags, mode);
|
||||
|
||||
if (open_mode & o_excl)
|
||||
if (open_mode & fom::excl)
|
||||
{
|
||||
return CELL_FS_EEXIST; // approximation
|
||||
}
|
||||
@ -430,7 +430,7 @@ s32 sys_fs_lseek(u32 fd, s64 offset, s32 whence, vm::ptr<u64> pos)
|
||||
|
||||
std::lock_guard<std::mutex> lock(file->mutex);
|
||||
|
||||
*pos = file->file->Seek(offset, whence);
|
||||
*pos = file->file->Seek(offset, (fsm)whence);
|
||||
|
||||
return CELL_OK;
|
||||
}
|
||||
|
@ -96,7 +96,7 @@ void AutoPauseManagerDialog::LoadEntries(void)
|
||||
//This would always use a 0xFFFFFFFF as end of the pause.bin
|
||||
void AutoPauseManagerDialog::SaveEntries(void)
|
||||
{
|
||||
fs::file list("pause.bin", o_write | o_create | o_trunc);
|
||||
fs::file list("pause.bin", fom::write | fom::create | fom::trunc);
|
||||
//System calls ID and Function calls ID are all u32 iirc.
|
||||
u32 num = 0;
|
||||
list.seek(0);
|
||||
|
@ -245,7 +245,7 @@ void MainFrame::InstallPkg(wxCommandEvent& WXUNUSED(event))
|
||||
Emu.Stop();
|
||||
|
||||
// Open and install PKG file
|
||||
fs::file pkg_f(ctrl.GetPath().ToStdString(), o_read);
|
||||
fs::file pkg_f(ctrl.GetPath().ToStdString(), fom::read);
|
||||
|
||||
if (pkg_f)
|
||||
{
|
||||
|
@ -122,7 +122,7 @@ void VHDDExplorer::Import(const std::string& path, const std::string& to)
|
||||
return;
|
||||
}
|
||||
|
||||
if(!m_hdd->Open(to, o_write))
|
||||
if(!m_hdd->Open(to, fom::write))
|
||||
{
|
||||
wxMessageBox("IMPORT ERROR: file open error.");
|
||||
return;
|
||||
|
@ -29,7 +29,7 @@ bool TROPUSRLoader::Load(const std::string& filepath, const std::string& configp
|
||||
Generate(filepath, configpath);
|
||||
}
|
||||
|
||||
m_file = Emu.GetVFS().OpenFile(filepath, vfsRead);
|
||||
m_file = Emu.GetVFS().OpenFile(filepath, fom::read);
|
||||
LoadHeader();
|
||||
LoadTableHeaders();
|
||||
LoadTables();
|
||||
@ -124,7 +124,7 @@ bool TROPUSRLoader::Save(const std::string& filepath)
|
||||
Close();
|
||||
}
|
||||
|
||||
m_file = Emu.GetVFS().OpenFile(filepath, vfsWriteNew);
|
||||
m_file = Emu.GetVFS().OpenFile(filepath, fom::write | fom::create | fom::trunc);
|
||||
m_file->Write(&m_header, sizeof(TROPUSRHeader));
|
||||
|
||||
for (const TROPUSRTableHeader& tableHeader : m_tableHeaders)
|
||||
|
@ -36,7 +36,7 @@ bool TRPLoader::Install(std::string dest, bool show)
|
||||
char* buffer = new char [(u32)entry.size];
|
||||
trp_f.Seek(entry.offset);
|
||||
trp_f.Read(buffer, entry.size);
|
||||
vfsFile(dest + entry.name, vfsWriteNew).Write(buffer, entry.size);
|
||||
vfsFile(dest + entry.name, fom::write | fom::create | fom::trunc).Write(buffer, entry.size);
|
||||
delete[] buffer;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user