Include mod path in the cache path.

This was SVN commit r13546.
This commit is contained in:
leper
2013-07-10 00:08:01 +00:00
parent fb0c1e6cc6
commit d1af7ea0ef
2 changed files with 29 additions and 5 deletions
+23 -1
View File
@@ -1,4 +1,4 @@
/* Copyright (c) 2010 Wildfire Games
/* Copyright (c) 2013 Wildfire Games
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
@@ -205,6 +205,28 @@ public:
return ret;
}
/**
* Return the path before the common part of both paths
* @param other Indicates the start of the path which should be removed
* @note other should be a VfsPath, while this should be an OsPath
*/
Path BeforeCommon(Path other) const
{
Path ret = *this;
if(ret.empty() || other.empty())
return L"";
// Convert the separator to allow for string comparison
if(other.separator != ret.separator)
replace(other.path.begin(), other.path.end(), other.separator, ret.separator);
const size_t idx = ret.path.rfind(other.path);
if(idx == String::npos)
return L"";
return path.substr(0, idx);
}
static Status Validate(String::value_type c);
private:
+6 -4
View File
@@ -1,4 +1,4 @@
/* Copyright (C) 2012 Wildfire Games.
/* Copyright (C) 2013 Wildfire Games.
* This file is part of 0 A.D.
*
* 0 A.D. is free software: you can redistribute it and/or modify
@@ -143,8 +143,10 @@ VfsPath CCacheLoader::LooseCachePath(const VfsPath& sourcePath, const MD5& initi
for (size_t i = 0; i < 8; ++i)
digestPrefix << std::setfill(L'0') << std::setw(2) << (int)digest[i];
// Construct the final path
return VfsPath("cache") / sourcePath.ChangeExtension(sourcePath.Extension().string() + L"." + digestPrefix.str() + m_FileExtension);
// Get the mod path
OsPath path;
m_VFS->GetRealPath(sourcePath, path);
// TODO: we should probably include the mod name, once that's possible (http://trac.wildfiregames.com/ticket/564)
// Construct the final path
return VfsPath("cache") / path_name_only(path.BeforeCommon(sourcePath).Parent().string().c_str()) / sourcePath.ChangeExtension(sourcePath.Extension().string() + L"." + digestPrefix.str() + m_FileExtension);
}