2013-06-30 10:46:29 +02:00
|
|
|
#pragma once
|
2014-11-30 12:18:17 +01:00
|
|
|
#include <map>
|
2014-03-27 05:34:55 +01:00
|
|
|
|
2014-08-25 20:09:48 +02:00
|
|
|
class vfsDevice;
|
|
|
|
|
struct vfsFileBase;
|
|
|
|
|
class vfsDirBase;
|
2013-06-30 10:46:29 +02:00
|
|
|
|
2013-08-03 11:40:03 +02:00
|
|
|
enum vfsDeviceType
|
|
|
|
|
{
|
|
|
|
|
vfsDevice_LocalFile,
|
|
|
|
|
vfsDevice_HDD,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
static const char* vfsDeviceTypeNames[] =
|
|
|
|
|
{
|
|
|
|
|
"Local",
|
|
|
|
|
"HDD",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct VFSManagerEntry
|
|
|
|
|
{
|
|
|
|
|
vfsDeviceType device;
|
2014-04-01 02:33:55 +02:00
|
|
|
std::string device_path;
|
|
|
|
|
std::string path;
|
|
|
|
|
std::string mount;
|
2013-08-03 11:40:03 +02:00
|
|
|
|
2014-01-07 21:11:02 +01:00
|
|
|
VFSManagerEntry()
|
|
|
|
|
: device(vfsDevice_LocalFile)
|
|
|
|
|
, device_path("")
|
|
|
|
|
, path("")
|
|
|
|
|
, mount("")
|
2013-08-03 11:40:03 +02:00
|
|
|
{
|
|
|
|
|
}
|
2014-03-27 05:34:55 +01:00
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
VFSManagerEntry(const vfsDeviceType& device, const std::string& path, const std::string& mount)
|
2014-03-27 05:34:55 +01:00
|
|
|
: device(device)
|
|
|
|
|
, device_path("")
|
|
|
|
|
, path(path)
|
|
|
|
|
, mount(mount)
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-08-03 11:40:03 +02:00
|
|
|
};
|
|
|
|
|
|
2014-11-29 14:16:53 +01:00
|
|
|
std::vector<std::string> simplify_path_blocks(const std::string& path);
|
2015-01-08 23:17:26 +01:00
|
|
|
std::string simplify_path(const std::string& path, bool is_dir, bool is_ps3);
|
2014-11-29 14:16:53 +01:00
|
|
|
|
2013-06-30 10:46:29 +02:00
|
|
|
struct VFS
|
|
|
|
|
{
|
2014-04-15 16:12:15 +02:00
|
|
|
~VFS();
|
|
|
|
|
|
2014-11-29 14:16:53 +01:00
|
|
|
std::string cwd;
|
|
|
|
|
|
2014-04-14 10:55:43 +02:00
|
|
|
//TODO: find out where these are supposed to be deleted or just make it shared_ptr
|
|
|
|
|
//and also make GetDevice and GetDeviceLocal return shared_ptr then.
|
2014-04-15 16:12:15 +02:00
|
|
|
// A vfsDevice will be deleted when they're unmounted or the VFS struct is destroyed.
|
|
|
|
|
// This will cause problems if other code stores the pointer returned by GetDevice/GetDeviceLocal
|
|
|
|
|
// and tries to use it after the device is unmounted.
|
2014-04-10 00:54:32 +02:00
|
|
|
std::vector<vfsDevice *> m_devices;
|
2014-11-30 12:18:17 +01:00
|
|
|
|
|
|
|
|
struct links_sorter
|
|
|
|
|
{
|
2015-02-11 05:17:39 +01:00
|
|
|
bool operator()(const std::vector<std::string>& a, const std::vector<std::string>& b) const
|
2014-11-30 12:18:17 +01:00
|
|
|
{
|
|
|
|
|
return b.size() < a.size();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
std::map<std::vector<std::string>, std::vector<std::string>, links_sorter> links;
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Mount(const std::string& ps3_path, const std::string& local_path, vfsDevice* device);
|
2014-11-30 12:18:17 +01:00
|
|
|
void Link(const std::string& mount_point, const std::string& ps3_path);
|
2014-04-01 02:33:55 +02:00
|
|
|
void UnMount(const std::string& ps3_path);
|
2013-08-03 11:40:03 +02:00
|
|
|
void UnMountAll();
|
2013-06-30 10:46:29 +02:00
|
|
|
|
2015-01-08 23:17:26 +01:00
|
|
|
std::string GetLinked(const std::string& ps3_path) const;
|
2014-11-30 12:18:17 +01:00
|
|
|
|
2015-04-19 15:19:24 +02:00
|
|
|
vfsFileBase* OpenFile(const std::string& ps3_path, u32 mode) const;
|
2014-04-01 02:33:55 +02:00
|
|
|
vfsDirBase* OpenDir(const std::string& ps3_path) const;
|
|
|
|
|
bool CreateDir(const std::string& ps3_path) const;
|
2015-04-20 17:53:31 +02:00
|
|
|
bool CreatePath(const std::string& ps3_path) const;
|
2014-04-01 02:33:55 +02:00
|
|
|
bool RemoveFile(const std::string& ps3_path) const;
|
|
|
|
|
bool RemoveDir(const std::string& ps3_path) const;
|
|
|
|
|
bool ExistsFile(const std::string& ps3_path) const;
|
|
|
|
|
bool ExistsDir(const std::string& ps3_path) const;
|
|
|
|
|
bool RenameFile(const std::string& ps3_path_from, const std::string& ps3_path_to) const;
|
|
|
|
|
bool RenameDir(const std::string& ps3_path_from, const std::string& ps3_path_to) const;
|
2015-04-13 16:46:10 +02:00
|
|
|
bool CopyFile(const std::string& ps3_path_from, const std::string& ps3_path_to, bool overwrite = true) const;
|
2015-04-18 15:38:42 +02:00
|
|
|
bool TruncateFile(const std::string& ps3_path, u64 length) const;
|
2014-02-16 16:19:06 +01:00
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
vfsDevice* GetDevice(const std::string& ps3_path, std::string& path) const;
|
|
|
|
|
vfsDevice* GetDeviceLocal(const std::string& local_path, std::string& path) const;
|
2013-08-03 11:40:03 +02:00
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
void Init(const std::string& path);
|
2014-03-27 05:34:55 +01:00
|
|
|
void SaveLoadDevices(std::vector<VFSManagerEntry>& res, bool is_load);
|
2014-04-10 00:54:32 +02:00
|
|
|
};
|