rpcsx/rpcs3/Emu/FS/vfsDir.cpp

113 lines
2 KiB
C++
Raw Normal View History

#include "stdafx.h"
#include "Emu/System.h"
2014-11-29 14:16:53 +01:00
#include "vfsDevice.h"
2014-08-26 01:55:37 +02:00
#include "VFS.h"
#include "vfsDir.h"
vfsDir::vfsDir()
: vfsDirBase(nullptr)
, m_stream(nullptr)
{
// TODO: proper implementation
// m_stream is nullptr here. So open root until a proper dir is given
2014-11-29 14:16:53 +01:00
//Open("/");
}
vfsDir::vfsDir(const std::string& path)
: vfsDirBase(nullptr)
, m_stream(nullptr)
{
Open(path);
}
bool vfsDir::Open(const std::string& path)
{
Close();
2014-02-16 16:37:32 +01:00
m_stream.reset(Emu.GetVFS().OpenDir(path));
2014-11-29 14:16:53 +01:00
DirEntryInfo info;
2015-01-08 23:17:26 +01:00
m_cwd = simplify_path(Emu.GetVFS().GetLinked(0 && m_stream && m_stream->IsOpened() ? m_stream->GetPath() : path), true, true);
2014-11-29 14:16:53 +01:00
auto blocks = simplify_path_blocks(GetPath());
for (auto dev : Emu.GetVFS().m_devices)
{
auto dev_blocks = simplify_path_blocks(dev->GetPs3Path());
if (dev_blocks.size() < (blocks.size() + 1))
{
continue;
}
bool is_ok = true;
for (size_t i = 0; i < blocks.size(); ++i)
{
2014-11-29 23:03:29 +01:00
if (strcmp(dev_blocks[i].c_str(), blocks[i].c_str()))
2014-11-29 14:16:53 +01:00
{
is_ok = false;
break;
}
}
if (is_ok)
{
info.name = dev_blocks[blocks.size()];
m_entries.push_back(info);
}
}
if (m_stream && m_stream->IsOpened())
{
m_entries.insert(m_entries.begin(), m_stream->GetEntries().begin(), m_stream->GetEntries().end());
}
return !m_entries.empty();
}
bool vfsDir::Create(const std::string& path)
{
2014-11-29 14:16:53 +01:00
return Emu.GetVFS().CreateDir(path);
}
bool vfsDir::IsExists(const std::string& path) const
{
2014-11-29 14:16:53 +01:00
auto path_blocks = simplify_path_blocks(path);
2014-11-29 14:16:53 +01:00
if (path_blocks.empty())
return false;
std::string dir_name = path_blocks[path_blocks.size() - 1];
for (const auto entry : vfsDir(path + "/.."))
{
2014-11-29 16:15:26 +01:00
if (!strcmp(entry->name.c_str(), dir_name.c_str()))
2014-11-29 14:16:53 +01:00
return true;
}
return false;
}
bool vfsDir::Rename(const std::string& from, const std::string& to)
{
2014-11-29 14:16:53 +01:00
return Emu.GetVFS().RenameDir(from, to);
}
bool vfsDir::Remove(const std::string& path)
{
2014-11-29 14:16:53 +01:00
return Emu.GetVFS().RemoveDir(path);
}
void vfsDir::Close()
{
m_stream.reset();
}
bool vfsDir::IsOpened() const
{
2014-11-29 14:16:53 +01:00
return !m_entries.empty();
}