mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-05-23 04:48:53 -05:00
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:
@@ -126,7 +126,7 @@ RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_size);
|
||||
|
||||
_texturePath = absPath(p.texture);
|
||||
_textureFile = std::make_unique<File>(_texturePath);
|
||||
_textureFile = std::make_unique<File>(_texturePath.value());
|
||||
|
||||
_offset = p.offset.value_or(_offset);
|
||||
addProperty(_offset);
|
||||
@@ -134,7 +134,7 @@ RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary)
|
||||
_texturePath.onChange([&]() { loadTexture(); });
|
||||
addProperty(_texturePath);
|
||||
|
||||
_textureFile->setCallback([&](const File&) { _textureIsDirty = true; });
|
||||
_textureFile->setCallback([this]() { _textureIsDirty = true; });
|
||||
|
||||
_nightFactor = p.nightFactor.value_or(_nightFactor);
|
||||
addProperty(_nightFactor);
|
||||
@@ -249,10 +249,10 @@ void RenderableRings::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; });
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <chrono>
|
||||
#include <math.h>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
|
||||
@@ -105,7 +106,7 @@ RenderableSatellites::RenderableSatellites(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void RenderableSatellites::readDataFile(const std::string& filename) {
|
||||
if (!FileSys.fileExists(filename)) {
|
||||
if (!std::filesystem::is_regular_file(filename)) {
|
||||
throw ghoul::RuntimeError(fmt::format(
|
||||
"Satellite TLE file {} does not exist", filename
|
||||
));
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include <ghoul/opengl/programobject.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <math.h>
|
||||
#include <vector>
|
||||
@@ -172,7 +173,7 @@ RenderableSmallBody::RenderableSmallBody(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
void RenderableSmallBody::readDataFile(const std::string& filename) {
|
||||
if (!FileSys.fileExists(filename)) {
|
||||
if (!std::filesystem::is_regular_file(filename)) {
|
||||
throw ghoul::RuntimeError(fmt::format(
|
||||
"JPL SBDB file {} does not exist.", filename
|
||||
));
|
||||
|
||||
@@ -440,12 +440,12 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_speckFile);
|
||||
|
||||
_colorTexturePath = p.colorMap.string();
|
||||
_colorTextureFile = std::make_unique<File>(_colorTexturePath);
|
||||
_colorTextureFile = std::make_unique<File>(_colorTexturePath.value());
|
||||
|
||||
/*_shapeTexturePath = absPath(dictionary.value<std::string>(
|
||||
ShapeTextureInfo.identifier
|
||||
));
|
||||
_shapeTextureFile = std::make_unique<File>(_shapeTexturePath);*/
|
||||
//_shapeTexturePath = absPath(dictionary.value<std::string>(
|
||||
// ShapeTextureInfo.identifier
|
||||
// ));
|
||||
//_shapeTextureFile = std::make_unique<File>(_shapeTexturePath);
|
||||
|
||||
if (p.otherDataColorMap.has_value()) {
|
||||
_otherDataColorMapPath = absPath(*p.otherDataColorMap);
|
||||
@@ -484,9 +484,7 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
addProperty(_colorOption);
|
||||
|
||||
_colorTexturePath.onChange([&] { _colorTextureIsDirty = true; });
|
||||
_colorTextureFile->setCallback([&](const File&) {
|
||||
_colorTextureIsDirty = true;
|
||||
});
|
||||
_colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; });
|
||||
addProperty(_colorTexturePath);
|
||||
|
||||
/*_shapeTexturePath.onChange([&] { _shapeTextureIsDirty = true; });
|
||||
@@ -527,11 +525,13 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary)
|
||||
}
|
||||
|
||||
_pointSpreadFunctionTexturePath = absPath(p.texture.string());
|
||||
_pointSpreadFunctionFile = std::make_unique<File>(_pointSpreadFunctionTexturePath);
|
||||
_pointSpreadFunctionTexturePath.onChange([&]() {
|
||||
_pointSpreadFunctionFile = std::make_unique<File>(
|
||||
_pointSpreadFunctionTexturePath.value()
|
||||
);
|
||||
_pointSpreadFunctionTexturePath.onChange([this]() {
|
||||
_pointSpreadFunctionTextureIsDirty = true;
|
||||
});
|
||||
_pointSpreadFunctionFile->setCallback([&](const File&) {
|
||||
_pointSpreadFunctionFile->setCallback([this]() {
|
||||
_pointSpreadFunctionTextureIsDirty = true;
|
||||
});
|
||||
_userProvidedTextureOwner.addProperty(_pointSpreadFunctionTexturePath);
|
||||
@@ -757,12 +757,10 @@ void RenderableStars::loadPSFTexture() {
|
||||
);
|
||||
|
||||
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(
|
||||
_pointSpreadFunctionTexturePath
|
||||
);
|
||||
_pointSpreadFunctionTexturePath.value()
|
||||
);
|
||||
_pointSpreadFunctionFile->setCallback(
|
||||
[&](const ghoul::filesystem::File&) {
|
||||
_pointSpreadFunctionTextureIsDirty = true;
|
||||
}
|
||||
[this]() { _pointSpreadFunctionTextureIsDirty = true; }
|
||||
);
|
||||
}
|
||||
_pointSpreadFunctionTextureIsDirty = false;
|
||||
@@ -1172,11 +1170,9 @@ void RenderableStars::update(const UpdateData&) {
|
||||
}
|
||||
|
||||
_colorTextureFile = std::make_unique<ghoul::filesystem::File>(
|
||||
_colorTexturePath
|
||||
);
|
||||
_colorTextureFile->setCallback(
|
||||
[&](const ghoul::filesystem::File&) { _colorTextureIsDirty = true; }
|
||||
_colorTexturePath.value()
|
||||
);
|
||||
_colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; });
|
||||
}
|
||||
_colorTextureIsDirty = false;
|
||||
}
|
||||
@@ -1239,21 +1235,17 @@ void RenderableStars::loadShapeTexture() {
|
||||
|
||||
void RenderableStars::loadData() {
|
||||
std::string file = absPath(_speckFile);
|
||||
if (!FileSys.fileExists(file)) {
|
||||
if (!std::filesystem::is_regular_file(file)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
|
||||
file,
|
||||
ghoul::filesystem::CacheManager::Persistent::Yes
|
||||
);
|
||||
|
||||
_nValuesPerStar = 0;
|
||||
_slicedData.clear();
|
||||
_fullData.clear();
|
||||
_dataNames.clear();
|
||||
|
||||
bool hasCachedFile = FileSys.fileExists(cachedFile);
|
||||
std::string cachedFile = FileSys.cacheManager()->cachedFilename(file);
|
||||
bool hasCachedFile = std::filesystem::is_regular_file(cachedFile);
|
||||
if (hasCachedFile) {
|
||||
LINFO(fmt::format("Cached file '{}' used for Speck file '{}'",
|
||||
cachedFile, file
|
||||
@@ -1399,7 +1391,9 @@ bool RenderableStars::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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user