rpcs3/Utilities/rFile.h

95 lines
2.1 KiB
C
Raw Normal View History

#pragma once
2015-04-15 16:27:37 +02:00
struct FileInfo
{
bool exists;
bool isDirectory;
bool isWritable;
uint64_t size;
2015-04-15 16:27:37 +02:00
time_t atime;
time_t mtime;
time_t ctime;
};
2015-04-15 16:27:37 +02:00
bool get_file_info(const std::string& path, FileInfo& fileInfo);
2015-04-20 17:53:31 +02:00
bool rExists(const std::string& path);
bool rIsFile(const std::string& file);
2015-04-15 16:27:37 +02:00
bool rIsDir(const std::string& dir);
2015-04-20 17:53:31 +02:00
bool rRmDir(const std::string& dir);
bool rMkDir(const std::string& dir);
bool rMkPath(const std::string& path);
2015-04-13 16:46:10 +02:00
bool rRename(const std::string& from, const std::string& to);
bool rCopy(const std::string& from, const std::string& to, bool overwrite);
2015-04-18 15:38:42 +02:00
bool rRemoveFile(const std::string& file);
bool rTruncate(const std::string& file, uint64_t length);
2015-04-19 15:19:24 +02:00
enum rfile_seek_mode : u32
{
2015-04-19 15:19:24 +02:00
from_begin,
from_cur,
from_end,
};
2015-04-19 15:19:24 +02:00
enum rfile_open_mode : u32
{
2015-04-19 15:19:24 +02:00
o_read = 1 << 0,
o_write = 1 << 1,
2015-04-24 16:06:30 +02:00
o_append = 1 << 2,
o_create = 1 << 3,
o_trunc = 1 << 4,
o_excl = 1 << 5,
2015-04-19 15:19:24 +02:00
};
struct rfile_t final
{
#ifdef _WIN32
using handle_type = void*;
#else
2015-04-23 18:58:37 +02:00
using handle_type = intptr_t;
2015-04-19 15:19:24 +02:00
#endif
private:
handle_type fd;
public:
2015-04-19 15:19:24 +02:00
rfile_t();
~rfile_t();
explicit rfile_t(const std::string& filename, u32 mode = o_read);
2015-04-19 15:19:24 +02:00
rfile_t(const rfile_t&) = delete;
2015-04-20 00:26:28 +02:00
rfile_t(rfile_t&&) = delete; // possibly TODO
2015-04-19 15:19:24 +02:00
rfile_t& operator =(const rfile_t&) = delete;
2015-04-20 00:26:28 +02:00
rfile_t& operator =(rfile_t&&) = delete; // possibly TODO
operator bool() const; // check is_opened()
2015-04-19 15:19:24 +02:00
2015-04-20 00:26:28 +02:00
void import(handle_type fd); // replace file handle
2015-04-19 15:19:24 +02:00
bool open(const std::string& filename, u32 mode = o_read);
2015-04-20 00:26:28 +02:00
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
2015-04-19 15:19:24 +02:00
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);
2014-08-06 00:34:26 +02:00
bool IsOpened() const;
static bool Exists(const std::string &path);
bool GetFirst(std::string *filename) const;
bool GetNext(std::string *filename) const;
void *handle;
};