Exemplo n.º 1
0
    fs::path path_difference(fs::path const& outdir, fs::path const& path)
    {
        fs::path outtmp, temp;
        fs::path::iterator out = outdir.begin(), file = path.begin();
        for(; out != outdir.end() && file != path.end(); ++out, ++file)
        {
            if(!fs::equivalent(outtmp /= *out, temp /= *file))
                break;
        }
        out = (out == outdir.begin()) ? outdir.end() : out;

        fs::path result = fs::path();
        for(; out != outdir.end(); ++out)
            if(*out != ".") result /= "..";
        std::divides<fs::path> concat;
        return std::accumulate(file, path.end(), result, concat);
    }
Exemplo n.º 2
0
fs::path relative_path(const fs::path& inFromDir, const fs::path& inFile)
{
//	assert(false);

	fs::path::iterator d = inFromDir.begin();
	fs::path::iterator f = inFile.begin();
	
	while (d != inFromDir.end() and f != inFile.end() and *d == *f)
	{
		++d;
		++f;
	}
	
	fs::path result;
	
	if (d == inFromDir.end() and f == inFile.end())
		result = ".";
	else
	{
		while (d != inFromDir.end())
		{
			result /= "..";
			++d;
		}
		
		while (f != inFile.end())
		{
			result /= *f;
			++f;
		}
	}

	return result;
}
Exemplo n.º 3
0
fs::path Path::MakeRelative(fs::path const& path, fs::path const& base) const {
	if (path.empty() || base.empty()) return path;

	const auto str = path.string();
	if (boost::starts_with(str, "?dummy") || boost::starts_with(str, "dummy-audio:"))
		return path;

	// Paths on different volumes can't be made relative to each other
	if (path.has_root_name() && path.root_name() != base.root_name())
		return path.string();

	auto path_it = path.begin();
	auto ref_it = base.begin();
	for (; path_it != path.end() && ref_it != base.end() && *path_it == *ref_it; ++path_it, ++ref_it) ;

	agi::fs::path result;
	for (; ref_it != base.end(); ++ref_it)
		result /= "..";
	for (; path_it != path.end(); ++path_it)
		result /= *path_it;

	return result;
}
Exemplo n.º 4
0
bool can::is_in_home(const fs::path& file)
{
	fs::path home{user::current().get_HOME()};

	for (auto it = home.begin(), file_it = file.begin();
		 it != home.end() && file_it != file.end();
		 it++, file_it++)
	{
		if (*it != *file_it)
		{
			return false;
		}
	}
	return true;
}
Exemplo n.º 5
0
void MResourceFileImp::AddEntry(
	fs::path		inPath,
	const char*		inData,
	uint32			inSize)
{
	uint32 node = 0;	// start at root
	
	for (fs::path::iterator p = inPath.begin(); p != inPath.end(); ++p)
	{
		// no such child? Add it and continue
		if (mIndex[node].mChild == 0)
		{
			MResourceImp child = {};
			
			child.mName = mName.size();
			copy(p->begin(), p->end(), back_inserter(mName));
			mName.push_back(0);
			
			mIndex[node].mChild = mIndex.size();
			mIndex.push_back(child);
			
			node = mIndex[node].mChild;
			continue;
		}
		
		// lookup the path element in the current directory
		uint32 next = mIndex[node].mChild;
		for (;;)
		{
			const char* name = &mName[0] + mIndex[next].mName;
			
			// if this is the one we're looking for, break out of the loop
			if (*p == name)
			{
				node = next;
				break;
			}
			
			// if there is a next element, loop
			if (mIndex[next].mNext != 0)
			{
				next = mIndex[next].mNext;
				continue;
			}
			
			// not found, create it
			MResourceImp n = {};
			
			n.mName = mName.size();
			copy(p->begin(), p->end(), back_inserter(mName));
			mName.push_back(0);
			
			node = mIndex.size();
			mIndex[next].mNext = node;
			mIndex.push_back(n);

			break;
		}
	}
	
	assert(node != 0);
	assert(node < mIndex.size());
	
	mIndex[node].mSize = inSize;
	mIndex[node].mData = mData.size();
	
	copy(inData, inData + inSize, back_inserter(mData));
	while ((mData.size() % 8) != 0)
		mData.push_back('\0');
}