Feature/filesystem cleanup (#1587)

* Adapting to the changes in Ghoul
* First step of moving filesystem functions to std
* Remove persistence flag from cachemanager
This commit is contained in:
Alexander Bock
2021-05-16 20:26:49 +02:00
committed by GitHub
parent 2ca7101b6c
commit ccdc5a5dc3
87 changed files with 648 additions and 711 deletions
@@ -47,6 +47,7 @@
#include <ghoul/glm.h>
#include <glm/gtx/string_cast.hpp>
#include <array>
#include <filesystem>
#include <fstream>
#include <cstdint>
#include <locale>
@@ -1035,12 +1036,11 @@ bool RenderableBillboardsCloud::loadSpeckData() {
}
bool success = true;
const std::string& cachedFile = FileSys.cacheManager()->cachedFilename(
ghoul::filesystem::File(_speckFile),
"RenderableDUMeshes|" + identifier(),
ghoul::filesystem::CacheManager::Persistent::Yes
_speckFile,
"RenderableDUMeshes|" + identifier()
);
const bool hasCachedFile = FileSys.fileExists(cachedFile);
const bool hasCachedFile = std::filesystem::is_regular_file(cachedFile);
if (hasCachedFile) {
LINFO(fmt::format(
"Cached file '{}' used for Speck file '{}'",
@@ -1076,15 +1076,8 @@ bool RenderableBillboardsCloud::loadLabelData() {
return true;
}
bool success = true;
// I disabled the cache as it didn't work on Mac --- abock
const std::string& cachedFile = FileSys.cacheManager()->cachedFilename(
ghoul::filesystem::File(_labelFile),
ghoul::filesystem::CacheManager::Persistent::Yes
);
if (!_hasSpeckFile && !_hasColorMapFile) {
success = true;
}
const bool hasCachedFile = FileSys.fileExists(cachedFile);
const std::string& cachedFile = FileSys.cacheManager()->cachedFilename(_labelFile);
const bool hasCachedFile = std::filesystem::is_regular_file(cachedFile);
if (hasCachedFile) {
LINFO(fmt::format(
"Cached file '{}' used for Label file '{}'",
@@ -1357,7 +1350,9 @@ bool RenderableBillboardsCloud::loadCachedFile(const std::string& file) {
if (version != CurrentCacheVersion) {
LINFO("The format of the cached file has changed: deleting old cache");
fileStream.close();
FileSys.deleteFile(file);
if (std::filesystem::is_regular_file(file)) {
std::filesystem::remove(file);
}
return false;
}
@@ -44,6 +44,7 @@
#include <ghoul/opengl/textureunit.h>
#include <array>
#include <cstdint>
#include <filesystem>
#include <fstream>
#include <optional>
@@ -785,7 +786,9 @@ bool RenderableDUMeshes::loadCachedFile(const std::string& file) {
if (version != CurrentCacheVersion) {
LINFO("The format of the cached file has changed: deleting old cache");
fileStream.close();
FileSys.deleteFile(file);
if (std::filesystem::is_regular_file(file)) {
std::filesystem::remove(file);
}
return false;
}
@@ -41,6 +41,7 @@
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <array>
#include <filesystem>
#include <fstream>
#include <optional>
#include <string>
@@ -842,13 +843,13 @@ bool RenderablePlanesCloud::readSpeckFile() {
std::string fullPath = absPath(_texturesPath + '/' + fileName);
std::string pngPath =
ghoul::filesystem::File(fullPath).fullBaseName() + ".png";
std::filesystem::path(fullPath).replace_extension(".png").string();
if (FileSys.fileExists(fullPath)) {
if (std::filesystem::is_regular_file(fullPath)) {
_textureFileMap.insert({ textureIndex, fullPath });
}
else if (FileSys.fileExists(pngPath)) {
else if (std::filesystem::is_regular_file(pngPath)) {
_textureFileMap.insert({ textureIndex, pngPath });
}
else {
@@ -1015,7 +1016,9 @@ bool RenderablePlanesCloud::loadCachedFile(const std::string& file) {
if (version != CurrentCacheVersion) {
LINFO("The format of the cached file has changed: deleting old cache");
fileStream.close();
FileSys.deleteFile(file);
if (std::filesystem::is_regular_file(file)) {
std::filesystem::remove(file);
}
return false;
}
@@ -40,6 +40,7 @@
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <array>
#include <filesystem>
#include <fstream>
#include <locale>
#include <cstdint>
@@ -176,13 +177,11 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary)
if (p.texture.has_value()) {
_spriteTexturePath = absPath(*p.texture);
_spriteTextureFile = std::make_unique<ghoul::filesystem::File>(
_spriteTexturePath
_spriteTexturePath.value()
);
_spriteTexturePath.onChange([&] { _spriteTextureIsDirty = true; });
_spriteTextureFile->setCallback(
[&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; }
);
_spriteTexturePath.onChange([this]() { _spriteTextureIsDirty = true; });
_spriteTextureFile->setCallback([this]() { _spriteTextureIsDirty = true; });
addProperty(_spriteTexturePath);
_hasSpriteTexture = true;
@@ -374,23 +373,17 @@ void RenderablePoints::update(const UpdateData&) {
);
_spriteTextureFile = std::make_unique<ghoul::filesystem::File>(
_spriteTexturePath
);
_spriteTextureFile->setCallback(
[&](const ghoul::filesystem::File&) { _spriteTextureIsDirty = true; }
_spriteTexturePath.value()
);
_spriteTextureFile->setCallback([this]() { _spriteTextureIsDirty = true; });
}
_spriteTextureIsDirty = false;
}
}
bool RenderablePoints::loadData() {
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
_speckFile,
ghoul::filesystem::CacheManager::Persistent::Yes
);
bool hasCachedFile = FileSys.fileExists(cachedFile);
std::string cachedFile = FileSys.cacheManager()->cachedFilename(_speckFile);
bool hasCachedFile = std::filesystem::is_regular_file(cachedFile);
if (hasCachedFile) {
LINFO(fmt::format(
"Cached file '{}' used for Speck file '{}'",
@@ -553,7 +546,9 @@ bool RenderablePoints::loadCachedFile(const std::string& file) {
if (version != CurrentCacheVersion) {
LINFO("The format of the cached file has changed: deleting old cache");
fileStream.close();
FileSys.deleteFile(file);
if (std::filesystem::is_regular_file(file)) {
std::filesystem::remove(file);
}
return false;
}