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-10-12 23:44:54 -04:00
|
|
|
FileCache::FileCache(GameData &data)
|
|
|
|
: data(data)
|
|
|
|
{
|
|
|
|
}
|
2023-07-09 10:54:27 -04:00
|
|
|
|
2023-10-13 15:01:23 -04:00
|
|
|
physis_Buffer &FileCache::lookupFile(const QString &path)
|
2023-09-26 00:37:55 -04:00
|
|
|
{
|
2023-09-26 20:20:36 -04:00
|
|
|
QMutexLocker locker(&bufferMutex);
|
|
|
|
|
2023-07-09 10:54:27 -04:00
|
|
|
if (!cachedBuffers.contains(path)) {
|
2023-10-13 15:01:23 -04:00
|
|
|
std::string pathstd = path.toStdString();
|
|
|
|
cachedBuffers[path] = physis_gamedata_extract_file(&data, pathstd.c_str());
|
2023-07-09 10:54:27 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cachedBuffers[path];
|
|
|
|
}
|
|
|
|
|
2023-10-13 15:01:23 -04:00
|
|
|
bool FileCache::fileExists(const QString &path)
|
2023-09-25 22:03:33 -04:00
|
|
|
{
|
2023-09-26 20:20:36 -04:00
|
|
|
QMutexLocker locker(&existMutex);
|
|
|
|
|
2023-09-25 22:03:33 -04:00
|
|
|
if (!cachedExist.contains(path)) {
|
2023-10-13 15:01:23 -04:00
|
|
|
std::string pathstd = path.toStdString();
|
|
|
|
cachedExist[path] = physis_gamedata_exists(&data, pathstd.c_str());
|
2023-09-25 22:03:33 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
return cachedExist[path];
|
|
|
|
}
|