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

View File

@@ -338,12 +338,11 @@ void GlobeLabelsComponent::initializeFonts() {
bool GlobeLabelsComponent::loadLabelsData(const std::string& file) {
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
ghoul::filesystem::File(file),
"GlobeLabelsComponent|" + identifier(),
ghoul::filesystem::CacheManager::Persistent::Yes
file,
"GlobeLabelsComponent|" + identifier()
);
bool hasCachedFile = FileSys.fileExists(cachedFile);
bool hasCachedFile = std::filesystem::is_regular_file(cachedFile);
if (hasCachedFile) {
LINFO(fmt::format("Cached file '{}' used for labels file: {}", cachedFile, file));
@@ -476,7 +475,9 @@ bool GlobeLabelsComponent::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;
}

View File

@@ -34,6 +34,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/exception.h>
#include <ghoul/misc/profiling.h>
#include <filesystem>
#ifdef _MSC_VER
#pragma warning (push)
@@ -450,7 +451,7 @@ void RawTileDataReader::initialize() {
if (module.isWMSCachingEnabled()) {
ZoneScopedN("WMS Caching")
std::string c;
if (FileSys.fileExists(_datasetFilePath)) {
if (std::filesystem::is_regular_file(_datasetFilePath)) {
// Only replace the 'content' if the dataset is an XML file and we want to do
// caching
std::ifstream t(_datasetFilePath);

View File

@@ -258,50 +258,52 @@ void RingsComponent::initialize() {
if (p.texture.has_value()) {
_texturePath = absPath(p.texture->string());
_textureFile = std::make_unique<File>(_texturePath);
_texturePath.onChange([&]() { loadTexture(); });
_textureFile = std::make_unique<File>(_texturePath.value());
_texturePath.onChange([this]() { loadTexture(); });
addProperty(_texturePath);
_textureFile->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFile->setCallback([this]() { _textureIsDirty = true; });
}
if (p.textureFwrd.has_value()) {
_textureFwrdPath = absPath(p.textureFwrd->string());
_textureFileForwards = std::make_unique<File>(_textureFwrdPath);
_textureFwrdPath.onChange([&]() { loadTexture(); });
_textureFileForwards = std::make_unique<File>(_textureFwrdPath.value());
_textureFwrdPath.onChange([this]() { loadTexture(); });
addProperty(_textureFwrdPath);
_textureFileForwards->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFileForwards->setCallback([this]() { _textureIsDirty = true; });
}
if (p.textureBckwrd.has_value()) {
_textureBckwrdPath = absPath(p.textureBckwrd->string());
_textureFileBackwards = std::make_unique<File>(_textureBckwrdPath);
_textureBckwrdPath.onChange([&]() { loadTexture(); });
_textureFileBackwards = std::make_unique<File>(_textureBckwrdPath.value());
_textureBckwrdPath.onChange([this]() { loadTexture(); });
addProperty(_textureBckwrdPath);
_textureFileBackwards->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFileBackwards->setCallback([this]() { _textureIsDirty = true; });
}
if (p.textureUnlit.has_value()) {
_textureUnlitPath = absPath(p.textureUnlit->string());
_textureFileUnlit = std::make_unique<File>(_textureUnlitPath);
_textureUnlitPath.onChange([&]() { loadTexture(); });
_textureFileUnlit = std::make_unique<File>(_textureUnlitPath.value());
_textureUnlitPath.onChange([this]() { loadTexture(); });
addProperty(_textureUnlitPath);
_textureFileUnlit->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFileUnlit->setCallback([this]() { _textureIsDirty = true; });
}
if (p.textureColor.has_value()) {
_textureColorPath = absPath(p.textureColor->string());
_textureFileColor = std::make_unique<File>(_textureColorPath);
_textureColorPath.onChange([&]() { loadTexture(); });
_textureFileColor = std::make_unique<File>(_textureColorPath.value());
_textureColorPath.onChange([this]() { loadTexture(); });
addProperty(_textureColorPath);
_textureFileColor->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFileColor->setCallback([this]() { _textureIsDirty = true; });
}
if (p.textureTransparency.has_value()) {
_textureTransparencyPath = absPath(p.textureTransparency->string());
_textureFileTransparency = std::make_unique<File>(_textureTransparencyPath);
_textureTransparencyPath.onChange([&]() { loadTexture(); });
_textureFileTransparency = std::make_unique<File>(
_textureTransparencyPath.value()
);
_textureTransparencyPath.onChange([this]() { loadTexture(); });
addProperty(_textureTransparencyPath);
_textureFileTransparency->setCallback([&](const File&) { _textureIsDirty = true; });
_textureFileTransparency->setCallback([this]() { _textureIsDirty = true; });
}
_offset = p.offset.value_or(_offset);
@@ -628,10 +630,10 @@ void RingsComponent::loadTexture() {
_texture->uploadTexture();
_texture->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureFile = std::make_unique<ghoul::filesystem::File>(
_texturePath.value()
);
_textureFile->setCallback([this]() { _textureIsDirty = true; });
}
}
@@ -655,11 +657,9 @@ void RingsComponent::loadTexture() {
ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureFileForwards = std::make_unique<ghoul::filesystem::File>(
_textureFwrdPath
);
_textureFileForwards->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureFwrdPath.value()
);
_textureFileForwards->setCallback([this]() { _textureIsDirty = true; });
}
}
@@ -683,11 +683,9 @@ void RingsComponent::loadTexture() {
ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureFileBackwards = std::make_unique<ghoul::filesystem::File>(
_textureBckwrdPath
);
_textureFileBackwards->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureBckwrdPath.value()
);
_textureFileBackwards->setCallback([this]() { _textureIsDirty = true; });
}
}
@@ -707,12 +705,12 @@ void RingsComponent::loadTexture() {
_textureUnlit = std::move(textureUnlit);
_textureUnlit->uploadTexture();
_textureUnlit->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureUnlit->setFilter(Texture::FilterMode::AnisotropicMipMap);
_textureFileUnlit = std::make_unique<ghoul::filesystem::File>(_textureUnlitPath);
_textureFileUnlit->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureFileUnlit = std::make_unique<ghoul::filesystem::File>(
_textureUnlitPath.value()
);
_textureFileUnlit->setCallback([this]() { _textureIsDirty = true; });
}
}
@@ -732,12 +730,12 @@ void RingsComponent::loadTexture() {
_textureColor = std::move(textureColor);
_textureColor->uploadTexture();
_textureColor->setFilter(ghoul::opengl::Texture::FilterMode::AnisotropicMipMap);
_textureColor->setFilter(Texture::FilterMode::AnisotropicMipMap);
_textureFileColor = std::make_unique<ghoul::filesystem::File>(_textureColorPath);
_textureFileColor->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureFileColor = std::make_unique<ghoul::filesystem::File>(
_textureColorPath.value()
);
_textureFileColor->setCallback([this]() { _textureIsDirty = true; });
}
}
@@ -762,11 +760,9 @@ void RingsComponent::loadTexture() {
);
_textureFileTransparency = std::make_unique<ghoul::filesystem::File>(
_textureTransparencyPath
);
_textureFileTransparency->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
_textureTransparencyPath.value()
);
_textureFileTransparency->setCallback([this]() { _textureIsDirty = true; });
}
}

View File

@@ -44,6 +44,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
#include <ghoul/opengl/openglstatecache.h>
#include <filesystem>
#include <fstream>
#include "cpl_minixml.h"
@@ -359,12 +360,11 @@ std::unique_ptr<TileProvider> initTileProvider(TemporalTileProvider& t,
const size_t numChars = strlen(temporal::UrlTimePlaceholder);
// @FRAGILE: This will only find the first instance. Dangerous if that instance is
// commented out ---abock
const std::string timeSpecifiedXml = xmlTemplate.replace(pos, numChars, timekey);
std::string gdalDatasetXml = timeSpecifiedXml;
std::string xml = xmlTemplate.replace(pos, numChars, timekey);
FileSys.expandPathTokens(gdalDatasetXml, IgnoredTokens);
xml = FileSys.expandPathTokens(std::move(xml), IgnoredTokens).string();
t.initDict.setValue(KeyFilePath, gdalDatasetXml);
t.initDict.setValue(KeyFilePath, xml);
return std::make_unique<DefaultTileProvider>(t.initDict);
}
@@ -513,9 +513,9 @@ bool readFilePath(TemporalTileProvider& t) {
}
// File path was not a path to a file but a GDAL config or empty
ghoul::filesystem::File f(t.filePath);
if (FileSys.fileExists(f)) {
t.initDict.setValue(temporal::KeyBasePath, f.directoryName());
std::filesystem::path f(t.filePath.value());
if (std::filesystem::is_regular_file(f)) {
t.initDict.setValue(temporal::KeyBasePath, f.parent_path().string());
}
t.gdalXmlTemplate = consumeTemporalMetaData(t, xml);