2023-08-06 08:48:11 -04:00
|
|
|
// SPDX-FileCopyrightText: 2023 Joshua Goins <josh@redstrate.com>
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
#include "filecache.h"
|
|
|
|
|
|
|
|
#include <physis.hpp>
|
|
|
|
|
2023-08-06 08:48:11 -04:00
|
|
|
FileCache::FileCache(GameData& data) : data(data) {}
|
2023-07-09 10:54:27 -04:00
|
|
|
|
2023-09-26 00:37:55 -04:00
|
|
|
physis_Buffer &FileCache::lookupFile(const QLatin1String &path)
|
|
|
|
{
|
2023-09-26 20:20:36 -04:00
|
|
|
QMutexLocker locker(&bufferMutex);
|
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
if (!cachedBuffers.contains(path)) {
|
2023-09-26 00:37:55 -04:00
|
|
|
cachedBuffers[path] = physis_gamedata_extract_file(&data, path.data());
|
2023-07-09 10:54:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cachedBuffers[path];
|
|
|
|
}
|
|
|
|
|
2023-09-25 22:03:33 -04:00
|
|
|
bool FileCache::fileExists(const QLatin1String &path)
|
|
|
|
{
|
2023-09-26 20:20:36 -04:00
|
|
|
QMutexLocker locker(&existMutex);
|
|
|
|
|
2023-09-25 22:03:33 -04:00
|
|
|
if (!cachedExist.contains(path)) {
|
|
|
|
cachedExist[path] = physis_gamedata_exists(&data, path.data());
|
|
|
|
}
|
|
|
|
|
|
|
|
return cachedExist[path];
|
|
|
|
}
|