Exemplo n.º 1
0
Arquivo: VFS.cpp Projeto: ss23/rpcs3
vfsDevice* VFS::GetDevice(const std::string& ps3_path, std::string& path) const
{
	auto try_get_device = [this, &path](const std::string& ps3_path) -> vfsDevice*
	{
		std::vector<std::string> ps3_path_blocks = simplify_path_blocks(ps3_path);
		size_t max_eq = 0;
		int max_i = -1;

		for (u32 i = 0; i < m_devices.size(); ++i)
		{
			std::vector<std::string> dev_ps3_path_blocks = simplify_path_blocks(m_devices[i]->GetPs3Path());

			if (ps3_path_blocks.size() < dev_ps3_path_blocks.size())
				continue;

			size_t eq = 0;
			for (; eq < dev_ps3_path_blocks.size(); ++eq)
			{
				if (strcmp(ps3_path_blocks[eq].c_str(), dev_ps3_path_blocks[eq].c_str()))
				{
					break;
				}
			}

			if (eq > max_eq)
			{
				max_eq = eq;
				max_i = i;
			}
		}

		if (max_i < 0)
			return nullptr;

		path = m_devices[max_i]->GetLocalPath();

		for (size_t i = max_eq; i < ps3_path_blocks.size(); i++)
		{
			path += "/" + ps3_path_blocks[i];
		}

		path = simplify_path(path, false, false);
		
		return m_devices[max_i];
	};

	if (!ps3_path.size() || ps3_path[0] != '/')
	{
		return nullptr;
	}

	return try_get_device(GetLinked(ps3_path));

	// What is it? cwd is real path, ps3_path is ps3 path, but GetLinked accepts ps3 path
	//if (auto res = try_get_device(GetLinked(cwd + ps3_path))) 
	//	return res;
}
Exemplo n.º 2
0
bool vfsDir::Open(const std::string& path)
{
	Close();

	m_stream.reset(Emu.GetVFS().OpenDir(path));

	DirEntryInfo info;

	m_cwd = simplify_path(Emu.GetVFS().GetLinked(0 && m_stream && m_stream->IsOpened() ? m_stream->GetPath() : path), true, true);

	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)
		{
			if (strcmp(dev_blocks[i].c_str(), blocks[i].c_str()))
			{
				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();
}
Exemplo n.º 3
0
Arquivo: VFS.cpp Projeto: ss23/rpcs3
vfsDevice* VFS::GetDeviceLocal(const std::string& local_path, std::string& path) const
{
	int max_eq = -1;
	int max_i = -1;

	std::vector<std::string> local_path_blocks = simplify_path_blocks(local_path);

	for (u32 i = 0; i < m_devices.size(); ++i)
	{
		std::vector<std::string> dev_local_path_blocks = simplify_path_blocks(m_devices[i]->GetLocalPath());

		if (local_path_blocks.size() < dev_local_path_blocks.size())
			continue;

		int dev_blocks = dev_local_path_blocks.size();

		bool prefix_equal = std::equal(
			std::begin(dev_local_path_blocks),
			std::end(dev_local_path_blocks),
			std::begin(local_path_blocks),
			[](const std::string& a, const std::string& b){ return strcmp(a.c_str(), b.c_str()) == 0; }
		);
		
		if (prefix_equal && dev_blocks > max_eq)
		{
			max_eq = dev_blocks;
			max_i = i;
		}
	}

	if (max_i < 0)
		return nullptr;

	path = m_devices[max_i]->GetPs3Path();

	for (size_t i = max_eq; i < local_path_blocks.size(); i++)
	{
		path += "/" + local_path_blocks[i];
	}

	path = simplify_path(path, false, true);

	return m_devices[max_i];
}
Exemplo n.º 4
0
bool vfsDir::IsExists(const std::string& path) const
{
	auto path_blocks = simplify_path_blocks(path);

	if (path_blocks.empty())
		return false;

	std::string dir_name = path_blocks[path_blocks.size() - 1];

	for (const auto entry : vfsDir(path + "/.."))
	{
		if (!strcmp(entry->name.c_str(), dir_name.c_str()))
			return true;
	}

	return false;
}
Exemplo n.º 5
0
Arquivo: VFS.cpp Projeto: ss23/rpcs3
std::string simplify_path(const std::string& path, bool is_dir, bool is_ps3)
{
	std::vector<std::string> path_blocks = simplify_path_blocks(path);

	if (path_blocks.empty())
		return "";

	std::string result = fmt::merge(path_blocks, "/");
	
#ifdef _WIN32
	if (is_ps3)
#endif
	{
		result = "/" + result;
	}

	if (is_dir) result = result + "/";

	return result;
}
Exemplo n.º 6
0
Arquivo: VFS.cpp Projeto: ss23/rpcs3
void VFS::Link(const std::string& mount_point, const std::string& ps3_path)
{
	links[simplify_path_blocks(mount_point)] = simplify_path_blocks(ps3_path);
}