18 #include "precompiled.h"
28 m_VFS(vfs), m_FileExtension(fileExtension)
39 loadPath = archiveCachePath;
59 if (
m_VFS->GetFileInfo(looseCachePath, NULL) >= 0)
61 loadPath = looseCachePath;
67 loadPath = looseCachePath;
76 size_t archiveCachePriority = 0;
77 size_t sourcePriority = 0;
79 bool archiveCacheExists = (
m_VFS->GetFilePriority(archiveCachePath, &archiveCachePriority) >= 0);
82 if (!archiveCacheExists)
85 bool sourceExists = (
m_VFS->GetFilePriority(sourcePath, &sourcePriority) >= 0);
93 if (archiveCachePriority < sourcePriority)
99 if (
m_VFS->GetFileInfo(sourcePath, &sourceInfo) >= 0 &&
100 m_VFS->GetFileInfo(archiveCachePath, &archiveCacheInfo) >= 0)
102 const double howMuchNewer = difftime(sourceInfo.
MTime(), archiveCacheInfo.
MTime());
103 const double threshold = 2.0;
104 if (howMuchNewer > threshold)
120 if (
m_VFS->GetFileInfo(sourcePath, &fileInfo) < 0)
131 MD5 hash = initialHash;
132 hash.
Update((
const u8*)&mtime,
sizeof(mtime));
133 hash.
Update((
const u8*)&size,
sizeof(size));
134 hash.
Update((
const u8*)&version,
sizeof(version));
141 std::wstringstream digestPrefix;
142 digestPrefix << std::hex;
143 for (
size_t i = 0; i < 8; ++i)
144 digestPrefix << std::setfill(L
'0') << std::setw(2) << (int)digest[i];
148 m_VFS->GetRealPath(sourcePath, path);
Path VfsPath
VFS path of the form "(dir/)*file?".
std::wstring m_FileExtension
static const size_t DIGESTSIZE
VfsPath LooseCachePath(const VfsPath &sourcePath, const MD5 &initialHash, u32 version)
Return the path of the loose cache for the given source file.
Path BeforeCommon(Path other) const
Return the path before the common part of both paths.
void Update(const u8 *data, size_t len)
VfsPath ArchiveCachePath(const VfsPath &sourcePath)
Return the path of the archive cache for the given source file.
const String & string() const
i64 Status
Error handling system.
CCacheLoader(PIVFS vfs, const std::wstring &fileExtension)
Path ChangeExtension(Path extension) const
const wchar_t * path_name_only(const wchar_t *path)
Get the path component of a path.
#define debug_warn(expr)
display the error dialog with the given text.
bool CanUseArchiveCache(const VfsPath &sourcePath, const VfsPath &archiveCachePath)
Determines whether we can safely use the archived cache file, or need to re-convert the source file...
Status TryLoadingCached(const VfsPath &sourcePath, const MD5 &initialHash, u32 version, VfsPath &loadPath)
Attempts to find a valid cached which can be loaded.