2013-06-30 10:46:29 +02:00
|
|
|
#pragma once
|
|
|
|
|
|
2014-08-25 20:09:48 +02:00
|
|
|
class vfsDevice;
|
|
|
|
|
|
2014-02-02 20:42:32 +01:00
|
|
|
enum DirEntryFlags
|
2013-06-30 10:46:29 +02:00
|
|
|
{
|
2014-02-22 03:53:06 +01:00
|
|
|
DirEntry_TypeDir = 0x1,
|
|
|
|
|
DirEntry_TypeFile = 0x2,
|
|
|
|
|
DirEntry_TypeMask = 0x3,
|
2014-02-02 20:42:32 +01:00
|
|
|
DirEntry_PermWritable = 0x20,
|
|
|
|
|
DirEntry_PermReadable = 0x40,
|
|
|
|
|
DirEntry_PermExecutable = 0x80,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
struct DirEntryInfo
|
|
|
|
|
{
|
2014-04-01 02:33:55 +02:00
|
|
|
std::string name;
|
2014-02-02 20:42:32 +01:00
|
|
|
u32 flags;
|
2015-04-15 16:27:37 +02:00
|
|
|
u64 size;
|
2014-02-02 20:42:32 +01:00
|
|
|
time_t create_time;
|
|
|
|
|
time_t access_time;
|
|
|
|
|
time_t modify_time;
|
2013-06-30 10:46:29 +02:00
|
|
|
|
2014-02-02 20:42:32 +01:00
|
|
|
DirEntryInfo()
|
|
|
|
|
: flags(0)
|
2015-04-15 16:27:37 +02:00
|
|
|
, size(0)
|
2014-02-02 20:42:32 +01:00
|
|
|
, create_time(0)
|
|
|
|
|
, access_time(0)
|
|
|
|
|
, modify_time(0)
|
|
|
|
|
{
|
|
|
|
|
}
|
2013-06-30 10:46:29 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class vfsDirBase
|
|
|
|
|
{
|
2014-02-02 20:42:32 +01:00
|
|
|
protected:
|
2014-04-01 02:33:55 +02:00
|
|
|
std::string m_cwd;
|
2014-04-10 00:54:32 +02:00
|
|
|
std::vector<DirEntryInfo> m_entries;
|
2014-02-16 16:19:06 +01:00
|
|
|
uint m_pos;
|
|
|
|
|
vfsDevice* m_device;
|
2014-02-02 20:42:32 +01:00
|
|
|
|
|
|
|
|
public:
|
2014-02-16 16:19:06 +01:00
|
|
|
vfsDirBase(vfsDevice* device);
|
2014-02-02 20:42:32 +01:00
|
|
|
virtual ~vfsDirBase();
|
|
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
virtual bool Open(const std::string& path);
|
2014-02-02 20:42:32 +01:00
|
|
|
virtual bool IsOpened() const;
|
2014-04-01 02:33:55 +02:00
|
|
|
virtual bool IsExists(const std::string& path) const;
|
2014-04-10 00:54:32 +02:00
|
|
|
virtual const std::vector<DirEntryInfo>& GetEntries() const;
|
2014-02-02 20:42:32 +01:00
|
|
|
virtual void Close();
|
2014-04-01 02:33:55 +02:00
|
|
|
virtual std::string GetPath() const;
|
2013-06-30 10:46:29 +02:00
|
|
|
|
2014-04-01 02:33:55 +02:00
|
|
|
virtual bool Create(const std::string& path) = 0;
|
2014-02-02 20:42:32 +01:00
|
|
|
//virtual bool Create(const DirEntryInfo& info)=0;
|
2014-04-01 02:33:55 +02:00
|
|
|
virtual bool Rename(const std::string& from, const std::string& to) = 0;
|
|
|
|
|
virtual bool Remove(const std::string& path) = 0;
|
2014-02-16 16:19:06 +01:00
|
|
|
virtual const DirEntryInfo* Read();
|
2014-11-29 14:16:53 +01:00
|
|
|
virtual const DirEntryInfo* First();
|
|
|
|
|
|
|
|
|
|
class iterator
|
|
|
|
|
{
|
|
|
|
|
vfsDirBase *parent;
|
|
|
|
|
const DirEntryInfo* data;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
iterator(vfsDirBase* parent)
|
2015-01-26 20:01:47 +01:00
|
|
|
: parent(parent)
|
|
|
|
|
, data(parent->First())
|
2014-11-29 14:16:53 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-29 16:48:05 +01:00
|
|
|
iterator(vfsDirBase* parent, const DirEntryInfo* data)
|
|
|
|
|
: parent(parent)
|
|
|
|
|
, data(data)
|
2014-11-29 14:16:53 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterator& operator++()
|
|
|
|
|
{
|
|
|
|
|
data = parent->Read();
|
|
|
|
|
return *this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterator operator++(int)
|
|
|
|
|
{
|
|
|
|
|
const DirEntryInfo* olddata = data;
|
|
|
|
|
data = parent->Read();
|
2015-01-29 16:48:05 +01:00
|
|
|
return iterator(parent, olddata);
|
2014-11-29 14:16:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const DirEntryInfo* operator *()
|
|
|
|
|
{
|
|
|
|
|
return data;
|
|
|
|
|
}
|
|
|
|
|
|
2015-01-29 16:48:05 +01:00
|
|
|
bool operator !=(iterator other) const
|
2014-11-29 14:16:53 +01:00
|
|
|
{
|
|
|
|
|
return data != other.data;
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
iterator begin()
|
|
|
|
|
{
|
|
|
|
|
return iterator(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
iterator end()
|
|
|
|
|
{
|
2015-01-29 16:48:05 +01:00
|
|
|
return iterator(this, nullptr);
|
2014-11-29 14:16:53 +01:00
|
|
|
}
|
2014-04-10 00:54:32 +02:00
|
|
|
};
|