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
@@ -213,7 +213,7 @@ void AtmosphereDeferredcaster::preRaycast(const RenderData& renderData,
renderData.camera.sgctInternal.projectionMatrix()
) * renderData.camera.combinedViewMatrix();
const float totalAtmosphere = (scaledRadius + ATM_EPS);
const double totalAtmosphere = (scaledRadius + ATM_EPS);
if (!isAtmosphereInFrustum(MV, tPlanetPosWorld, totalAtmosphere)) {
program.setUniform(_uniformCache.cullAtmosphere, 1);
}
+2 -2
View File
@@ -96,7 +96,7 @@ RenderableDisc::RenderableDisc(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
_texturePath = p.texture.string();
_texturePath.onChange([&]() { _texture->loadFromFile(_texturePath); });
_texturePath.onChange([&]() { _texture->loadFromFile(_texturePath.value()); });
addProperty(_texturePath);
_size.setViewOption(properties::Property::ViewOptions::Logarithmic);
@@ -129,7 +129,7 @@ void RenderableDisc::initialize() {
void RenderableDisc::initializeGL() {
initializeShader();
_texture->loadFromFile(_texturePath);
_texture->loadFromFile(_texturePath.value());
_texture->uploadToGpu();
_plane->initialize();
@@ -102,13 +102,11 @@ RenderablePlaneImageLocal::RenderablePlaneImageLocal(const ghoul::Dictionary& di
addProperty(_blendMode);
_texturePath = absPath(p.texture);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath.value());
addProperty(_texturePath);
_texturePath.onChange([this]() { loadTexture(); });
_textureFile->setCallback(
[this](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
_textureFile->setCallback([this]() { _textureIsDirty = true; });
if (p.renderType.has_value()) {
switch (*p.renderType) {
@@ -209,10 +207,8 @@ void RenderablePlaneImageLocal::loadTexture() {
BaseModule::TextureManager.release(t);
_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; });
}
}
@@ -32,6 +32,7 @@
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureconversion.h>
#include <filesystem>
#include <optional>
namespace {
@@ -81,7 +82,7 @@ ScreenSpaceImageLocal::ScreenSpaceImageLocal(const ghoul::Dictionary& dictionary
setIdentifier(identifier);
_texturePath.onChange([this]() {
if (!FileSys.fileExists(FileSys.absolutePath(_texturePath))) {
if (!std::filesystem::is_regular_file(absPath(_texturePath))) {
LWARNINGC(
"ScreenSpaceImageLocal",
fmt::format("Image {} did not exist for {}", _texturePath, _identifier)
@@ -94,8 +95,8 @@ ScreenSpaceImageLocal::ScreenSpaceImageLocal(const ghoul::Dictionary& dictionary
addProperty(_texturePath);
if (p.texturePath.has_value()) {
if (FileSys.fileExists(FileSys.absolutePath(*p.texturePath))) {
_texturePath = FileSys.absolutePath(*p.texturePath);
if (std::filesystem::is_regular_file(absPath(*p.texturePath))) {
_texturePath = absPath(*p.texturePath);
}
else {
LWARNINGC(
+2 -4
View File
@@ -69,10 +69,8 @@ LuaRotation::LuaRotation()
_luaScriptFile.onChange([&]() {
requireUpdate();
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
requireUpdate();
});
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile.value());
_fileHandle->setCallback([this]() { requireUpdate(); });
});
}
+2 -4
View File
@@ -68,10 +68,8 @@ LuaScale::LuaScale()
_luaScriptFile.onChange([&]() {
requireUpdate();
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
requireUpdate();
});
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile.value());
_fileHandle->setCallback([this]() { requireUpdate(); });
});
}
+2 -2
View File
@@ -69,8 +69,8 @@ LuaTranslation::LuaTranslation()
_luaScriptFile.onChange([&]() {
requireUpdate();
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile);
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
_fileHandle = std::make_unique<ghoul::filesystem::File>(_luaScriptFile.value());
_fileHandle->setCallback([this]() {
requireUpdate();
notifyObservers();
});
@@ -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;
}
+1 -1
View File
@@ -512,7 +512,7 @@ void createExoplanetSystem(const std::string& starName) {
// the luminosity of a star is proportional to: (radius^2)*(temperature^4)
// Maybe a better option would be to compute the size based on the aboslute
// magnitude or star luminosity, but for now this looks good enough.
float size = 59.f * radiusInMeter;
double size = 59.0 * radiusInMeter;
if (hasTeff) {
constexpr const float sunTeff = 5780.f;
size *= std::pow(system.starData.teff / sunTeff, 2.0);
@@ -118,7 +118,7 @@ RenderableOrbitDisc::RenderableOrbitDisc(const ghoul::Dictionary& dictionary)
setBoundingSphere(_size + _offset.value().y * _size);
_texturePath = p.texture.string();
_texturePath.onChange([&]() { _texture->loadFromFile(_texturePath); });
_texturePath.onChange([&]() { _texture->loadFromFile(_texturePath.value()); });
addProperty(_texturePath);
_eccentricity = p.eccentricity;
@@ -148,7 +148,7 @@ void RenderableOrbitDisc::initializeGL() {
ghoul::opengl::updateUniformLocations(*_shader, _uniformCache, UniformNames);
_texture->loadFromFile(_texturePath);
_texture->loadFromFile(_texturePath.value());
_texture->uploadToGpu();
_plane->initialize();
@@ -38,6 +38,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/textureunit.h>
#include <filesystem>
#include <fstream>
#include <thread>
@@ -417,13 +418,16 @@ bool RenderableFieldlinesSequence::extractMandatoryInfoFromDictionary(
// Ensure that the source folder exists and then extract
// the files with the same extension as <inputFileTypeString>
ghoul::filesystem::Directory sourceFolder(sourceFolderPath);
if (FileSys.directoryExists(sourceFolder)) {
if (std::filesystem::is_directory(sourceFolderPath)) {
// Extract all file paths from the provided folder
_sourceFiles = sourceFolder.readFiles(
ghoul::filesystem::Directory::Recursive::No,
ghoul::filesystem::Directory::Sort::Yes
);
_sourceFiles.clear();
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::directory_iterator(sourceFolderPath)) {
if (e.is_regular_file()) {
_sourceFiles.push_back(e.path().string());
}
}
std::sort(_sourceFiles.begin(), _sourceFiles.end());
// Remove all files that don't have <inputFileTypeString> as extension
_sourceFiles.erase(
@@ -471,8 +475,7 @@ void RenderableFieldlinesSequence::extractOptionalInfoFromDictionary(
// ------------------- EXTRACT OPTIONAL VALUES FROM DICTIONARY ------------------- //
if (_dictionary->hasValue<std::string>(KeyOutputFolder)) {
outputFolderPath = _dictionary->value<std::string>(KeyOutputFolder);
ghoul::filesystem::Directory outputFolder(outputFolderPath);
if (FileSys.directoryExists(outputFolder)) {
if (std::filesystem::is_directory(outputFolderPath)) {
outputFolderPath = absPath(outputFolderPath);
}
else {
@@ -605,8 +608,9 @@ void RenderableFieldlinesSequence::loadOsflsStatesIntoRAM(const std::string& out
if (newState.loadStateFromOsfls(filePath)) {
addStateToSequence(newState);
if (!outputFolder.empty()) {
ghoul::filesystem::File tmpFile(filePath);
newState.saveStateToJson(outputFolder + tmpFile.baseName());
newState.saveStateToJson(
outputFolder + std::filesystem::path(filePath).stem().string()
);
}
}
else {
@@ -916,8 +920,7 @@ bool RenderableFieldlinesSequence::extractCdfInfoFromDictionary(std::string& see
{
if (_dictionary->hasValue<std::string>(KeyCdfSeedPointFile)) {
seedFilePath = _dictionary->value<std::string>(KeyCdfSeedPointFile);
ghoul::filesystem::File seedPointFile(seedFilePath);
if (FileSys.fileExists(seedPointFile)) {
if (std::filesystem::is_regular_file(seedFilePath)) {
seedFilePath = absPath(seedFilePath);
}
else {
@@ -962,7 +965,7 @@ bool RenderableFieldlinesSequence::extractSeedPointsFromFile(const std::string&
std::vector<glm::vec3>& outVec)
{
std::ifstream seedFile(FileSys.relativePath(path));
std::ifstream seedFile(path);
if (!seedFile.good()) {
LERROR(fmt::format("Could not open seed points file '{}'", path));
return false;
+15 -17
View File
@@ -463,10 +463,10 @@ RenderableGaiaStars::RenderableGaiaStars(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
_filePath = absPath(p.file);
_dataFile = std::make_unique<File>(_filePath);
_dataFile->setCallback([&](const File&) { _dataIsDirty = true; });
_dataFile = std::make_unique<File>(_filePath.value());
_dataFile->setCallback([this]() { _dataIsDirty = true; });
_filePath.onChange([&]() { _dataIsDirty = true; });
_filePath.onChange([this]() { _dataIsDirty = true; });
addProperty(_filePath);
_fileReaderOption.addOptions({
@@ -569,17 +569,19 @@ RenderableGaiaStars::RenderableGaiaStars(const ghoul::Dictionary& dictionary)
_pointSpreadFunctionTexturePath = absPath(p.texture);
_pointSpreadFunctionTexturePath.onChange(
[&](){ _pointSpreadFunctionTextureIsDirty = true; }
[this](){ _pointSpreadFunctionTextureIsDirty = true; }
);
_pointSpreadFunctionFile = std::make_unique<File>(
_pointSpreadFunctionTexturePath.value()
);
_pointSpreadFunctionFile = std::make_unique<File>(_pointSpreadFunctionTexturePath);
_pointSpreadFunctionFile->setCallback(
[&](const File&) { _pointSpreadFunctionTextureIsDirty = true; }
[this]() { _pointSpreadFunctionTextureIsDirty = true; }
);
_colorTexturePath = absPath(p.colorMap);
_colorTextureFile = std::make_unique<File>(_colorTexturePath);
_colorTexturePath.onChange([&]() { _colorTextureIsDirty = true; });
_colorTextureFile->setCallback([&](const File&) { _colorTextureIsDirty = true; });
_colorTextureFile = std::make_unique<File>(_colorTexturePath.value());
_colorTexturePath.onChange([this]() { _colorTextureIsDirty = true; });
_colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; });
_luminosityMultiplier = p.luminosityMultiplier.value_or(_luminosityMultiplier);
_magnitudeBoost = p.magnitudeBoost.value_or(_magnitudeBoost);
@@ -2115,12 +2117,10 @@ void RenderableGaiaStars::update(const UpdateData&) {
);
_pointSpreadFunctionFile = std::make_unique<ghoul::filesystem::File>(
_pointSpreadFunctionTexturePath
_pointSpreadFunctionTexturePath.value()
);
_pointSpreadFunctionFile->setCallback(
[&](const ghoul::filesystem::File&) {
_pointSpreadFunctionTextureIsDirty = true;
}
[this]() { _pointSpreadFunctionTextureIsDirty = true; }
);
}
_pointSpreadFunctionTextureIsDirty = false;
@@ -2141,11 +2141,9 @@ void RenderableGaiaStars::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;
}
+14 -6
View File
@@ -28,9 +28,9 @@
#include <openspace/documentation/verifier.h>
#include <ghoul/fmt.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#include <fstream>
#include <thread>
@@ -452,8 +452,16 @@ void ConstructOctreeTask::constructOctreeFromFolder(
//int starsOutside2000 = 0;
//int starsOutside5000 = 0;
ghoul::filesystem::Directory currentDir(_inFileOrFolderPath);
std::vector<std::string> allInputFiles = currentDir.readFiles();
std::vector<std::filesystem::path> allInputFiles;
if (std::filesystem::is_directory(_inFileOrFolderPath)) {
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::directory_iterator(_inFileOrFolderPath)) {
if (!e.is_regular_file()) {
allInputFiles.push_back(e.path());
}
}
}
std::vector<float> filterValues;
auto writeThreads = std::vector<std::thread>(8);
@@ -467,10 +475,10 @@ void ConstructOctreeTask::constructOctreeFromFolder(
));
for (size_t idx = 0; idx < allInputFiles.size(); ++idx) {
std::string inFilePath = allInputFiles[idx];
std::filesystem::path inFilePath = allInputFiles[idx];
int nStarsInfile = 0;
LINFO("Reading data file: " + inFilePath);
LINFO(fmt::format("Reading data file: {}", inFilePath));
std::ifstream inFileStream(inFilePath, std::ifstream::binary);
if (inFileStream.good()) {
@@ -528,7 +536,7 @@ void ConstructOctreeTask::constructOctreeFromFolder(
}
else {
LERROR(fmt::format(
"Error opening file '{}' for loading preprocessed file!", inFilePath
"Error opening file {} for loading preprocessed file!", inFilePath
));
}
+13 -6
View File
@@ -30,10 +30,9 @@
#include <ghoul/misc/dictionary.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/fmt.h>
#include <filesystem>
#include <fstream>
#include <set>
#include <optional>
@@ -185,8 +184,16 @@ void ReadFitsTask::readAllFitsFilesFromFolder(const Task::ProgressCallback&) {
ConcurrentJobManager<std::vector<std::vector<float>>> jobManager(threadPool);
// Get all files in specified folder.
ghoul::filesystem::Directory currentDir(_inFileOrFolderPath);
std::vector<std::string> allInputFiles = currentDir.readFiles();
std::vector<std::filesystem::path> allInputFiles;
if (std::filesystem::is_directory(_inFileOrFolderPath)) {
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::directory_iterator(_inFileOrFolderPath)) {
if (e.is_regular_file()) {
allInputFiles.push_back(e.path());
}
}
}
size_t nInputFiles = allInputFiles.size();
LINFO("Files to read: " + std::to_string(nInputFiles));
@@ -238,12 +245,12 @@ void ReadFitsTask::readAllFitsFilesFromFolder(const Task::ProgressCallback&) {
// Divide all files into ReadFilejobs and then delegate them onto several threads!
while (!allInputFiles.empty()) {
std::string fileToRead = allInputFiles.back();
std::filesystem::path fileToRead = allInputFiles.back();
allInputFiles.erase(allInputFiles.end() - 1);
// Add reading of file to jobmanager, which will distribute it to our threadpool.
auto readFileJob = std::make_shared<gaia::ReadFileJob>(
fileToRead,
fileToRead.string(),
_allColumnNames,
_firstRow,
_lastRow,
@@ -322,10 +322,9 @@ void RenderableGalaxy::initialize() {
_volume = reader.read();
std::string cachedPointsFile = FileSys.cacheManager()->cachedFilename(
_pointsFilename,
ghoul::filesystem::CacheManager::Persistent::Yes
_pointsFilename
);
const bool hasCachedFile = FileSys.fileExists(cachedPointsFile);
const bool hasCachedFile = std::filesystem::is_regular_file(cachedPointsFile);
if (hasCachedFile) {
LINFO(fmt::format("Cached file '{}' used for galaxy point file '{}'",
cachedPointsFile, _pointsFilename
@@ -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;
}
@@ -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);
+37 -41
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; });
}
}
+7 -7
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);
+3 -4
View File
@@ -38,7 +38,7 @@
#include <ghoul/opengl/programobject.h>
#include <ghoul/opengl/texture.h>
#include <ghoul/opengl/textureunit.h>
#include <filesystem>
namespace {
constexpr const char* _loggerCat = "GUI";
@@ -53,7 +53,7 @@ namespace {
constexpr const std::array<const char*, 2> UniformNames = { "tex", "ortho" };
void addScreenSpaceRenderableLocal(std::string identifier, std::string texturePath) {
if (!FileSys.fileExists(absPath(texturePath))) {
if (!std::filesystem::is_regular_file(absPath(texturePath))) {
LWARNING(fmt::format("Could not find image '{}'", texturePath));
return;
}
@@ -206,8 +206,7 @@ void GUI::deinitialize() {
void GUI::initializeGL() {
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
configurationFile,
"",
ghoul::filesystem::CacheManager::Persistent::Yes
""
);
LDEBUG(fmt::format("Using {} as ImGUI cache location", cachedFile));
+3 -3
View File
@@ -30,9 +30,9 @@
#include <openspace/engine/openspaceengine.h>
#include <openspace/scene/assetmanager.h>
#include <openspace/scene/asset.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/file.h>
#include <filesystem>
namespace {
std::string assetStateToString(openspace::Asset::State state) {
@@ -90,10 +90,10 @@ void GuiAssetComponent::renderTree(const Asset& asset, const std::string& relati
using namespace ghoul::filesystem;
std::string assetPath = asset.assetFilePath();
const std::string& assetDirectory = File(assetPath).directoryName();
std::string assetDirectory = std::filesystem::path(assetPath).parent_path().string();
if (!relativeToPath.empty()) {
assetPath = FileSys.relativePath(assetPath, relativeToPath);
assetPath = std::filesystem::relative(assetPath, relativeToPath).string();
}
std::string assetText = assetPath + " " + assetStateToString(asset.state());
+3 -2
View File
@@ -31,6 +31,7 @@
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <algorithm>
#include <filesystem>
namespace openspace {
@@ -158,8 +159,8 @@ void DataProcessorKameleon::setDimensions(glm::size3_t dimensions) {
}
void DataProcessorKameleon::initializeKameleonWrapper(std::string path) {
const std::string& extension = ghoul::filesystem::File(absPath(path)).fileExtension();
if (FileSys.fileExists(absPath(path)) && extension == "cdf") {
std::filesystem::path extension = std::filesystem::path(absPath(path)).extension();
if (std::filesystem::is_regular_file(absPath(path)) && extension == ".cdf") {
if (_kw) {
_kw->close();
}
+8 -11
View File
@@ -42,6 +42,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/constexpr.h>
#include <filesystem>
#include <fstream>
#include "iswamanager_lua.inl"
@@ -410,9 +411,8 @@ std::string IswaManager::parseKWToLuaTable(const CdfInfo& info, const std::strin
return "";
}
const std::string& extension =
ghoul::filesystem::File(absPath(info.path)).fileExtension();
if (extension == "cdf") {
std::filesystem::path ext = std::filesystem::path(absPath(info.path)).extension();
if (ext == ".cdf") {
KameleonWrapper kw = KameleonWrapper(absPath(info.path));
std::string parent = kw.parent();
@@ -587,10 +587,8 @@ void IswaManager::createSphere(MetadataFuture& data) {
}
void IswaManager::createKameleonPlane(CdfInfo info, std::string cut) {
const std::string& extension = ghoul::filesystem::File(
absPath(info.path)
).fileExtension();
if (FileSys.fileExists(absPath(info.path)) && extension == "cdf") {
std::filesystem::path ext = std::filesystem::path(absPath(info.path)).extension();
if (std::filesystem::is_regular_file(absPath(info.path)) && ext == ".cdf") {
if (!info.group.empty()) {
std::string type = typeid(KameleonPlane).name();
registerGroup(info.group, type);
@@ -628,9 +626,8 @@ void IswaManager::createKameleonPlane(CdfInfo info, std::string cut) {
void IswaManager::createFieldline(std::string name, std::string cdfPath,
std::string seedPath)
{
const std::string& ext = ghoul::filesystem::File(absPath(cdfPath)).fileExtension();
if (FileSys.fileExists(absPath(cdfPath)) && ext == "cdf") {
std::filesystem::path ext = std::filesystem::path(absPath(cdfPath)).extension();
if (std::filesystem::is_regular_file(absPath(cdfPath)) && ext == ".cdf") {
std::string luaTable = "{"
"Name = '" + name + "',"
"Parent = 'Earth',"
@@ -701,7 +698,7 @@ ghoul::Event<>& IswaManager::iswaEvent() {
void IswaManager::addCdfFiles(std::string cdfpath) {
cdfpath = absPath(cdfpath);
if (FileSys.fileExists(cdfpath)) {
if (std::filesystem::is_regular_file(cdfpath)) {
//std::string basePath = path.substr(0, path.find_last_of("/\\"));
std::ifstream jsonFile(cdfpath);
+2 -1
View File
@@ -31,6 +31,7 @@
#include <ghoul/glm.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/misc.h>
#include <filesystem>
#ifdef WIN32
#pragma warning (push)
@@ -113,7 +114,7 @@ KameleonWrapper::~KameleonWrapper() {
bool KameleonWrapper::open(const std::string& filename) {
close();
if (!FileSys.fileExists(filename)) {
if (!std::filesystem::is_regular_file(filename)) {
return false;
}
@@ -31,6 +31,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#ifdef WIN32
#pragma warning (push)
@@ -75,7 +76,7 @@ namespace {
namespace openspace::kameleonvolume {
KameleonVolumeReader::KameleonVolumeReader(std::string path) : _path(std::move(path)) {
if (!FileSys.fileExists(_path)) {
if (!std::filesystem::is_regular_file(_path)) {
throw ghoul::FileNotFoundError(_path);
}
@@ -45,6 +45,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/texture.h>
#include <filesystem>
namespace {
constexpr const char* _loggerCat = "RenderableKameleonVolume";
@@ -323,7 +324,7 @@ bool RenderableKameleonVolume::isCachingEnabled() const {
}
void RenderableKameleonVolume::load() {
if (!FileSys.fileExists(ghoul::filesystem::File(_sourcePath))) {
if (!std::filesystem::is_regular_file(_sourcePath.value())) {
LERROR(fmt::format("File '{}' does not exist", _sourcePath.value()));
return;
}
@@ -331,13 +332,11 @@ void RenderableKameleonVolume::load() {
loadFromPath(_sourcePath);
return;
}
ghoul::filesystem::File sourceFile(_sourcePath);
std::string cachePath = FileSys.cacheManager()->cachedFilename(
sourceFile.baseName(),
cacheSuffix(),
ghoul::filesystem::CacheManager::Persistent::Yes
std::filesystem::path(_sourcePath.value()).stem(),
cacheSuffix()
);
if (FileSys.fileExists(cachePath)) {
if (std::filesystem::is_regular_file(cachePath)) {
loadRaw(cachePath);
}
else {
@@ -352,15 +351,8 @@ std::string RenderableKameleonVolume::cacheSuffix() const {
}
void RenderableKameleonVolume::loadFromPath(const std::string& path) {
ghoul::filesystem::File file(path);
std::string extension = file.fileExtension();
std::transform(
extension.begin(),
extension.end(),
extension.begin(),
[](char v) { return static_cast<char>(tolower(v)); }
);
if (extension == "cdf") {
std::filesystem::path extension = std::filesystem::path(path).extension();
if (extension == ".cdf" || extension == ".CDF") {
loadCdf(path);
}
else {
@@ -54,6 +54,7 @@
#include <ghoul/opengl/texture.h>
#include <algorithm>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <iterator>
@@ -454,14 +455,12 @@ bool RenderableMultiresVolume::initializeSelector() {
switch (_selector) {
case Selector::TF:
if (_errorHistogramManager) {
std::stringstream cacheName;
ghoul::filesystem::File f = _filename;
cacheName << f.baseName() << "_" << nHistograms << "_errorHistograms";
std::string cacheFilename;
cacheFilename = FileSys.cacheManager()->cachedFilename(
cacheName.str(),
"",
ghoul::filesystem::CacheManager::Persistent::Yes
std::string cacheFilename = FileSys.cacheManager()->cachedFilename(
fmt::format(
"{}_{}_errorHistograms",
std::filesystem::path(_filename).stem().string(), nHistograms
),
""
);
std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary);
if (cacheFile.is_open()) {
@@ -472,7 +471,7 @@ bool RenderableMultiresVolume::initializeSelector() {
);
success &= _errorHistogramManager->loadFromFile(cacheFilename);
}
else if (_errorHistogramsPath != "") {
else if (!_errorHistogramsPath.empty()) {
// Read histograms from scene data.
LINFO(fmt::format(
"Loading histograms from scene data: {}", _errorHistogramsPath
@@ -494,14 +493,11 @@ bool RenderableMultiresVolume::initializeSelector() {
case Selector::SIMPLE:
if (_histogramManager) {
std::stringstream cacheName;
ghoul::filesystem::File f = _filename;
cacheName << f.baseName() << "_" << nHistograms << "_histograms";
std::string cacheFilename;
cacheFilename = FileSys.cacheManager()->cachedFilename(
cacheName.str(),
"",
ghoul::filesystem::CacheManager::Persistent::Yes
std::string cacheFilename = FileSys.cacheManager()->cachedFilename(
fmt::format("{}_{}_histogram",
std::filesystem::path(_filename).stem().string(), nHistograms
),
""
);
std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary);
if (cacheFile.is_open()) {
@@ -528,12 +524,12 @@ bool RenderableMultiresVolume::initializeSelector() {
case Selector::LOCAL:
if (_localErrorHistogramManager) {
ghoul::filesystem::File f = _filename;
std::string cacheFilename;
cacheFilename = FileSys.cacheManager()->cachedFilename(
fmt::format("{}_{}_localErrorHistograms", f.baseName(), nHistograms),
"",
ghoul::filesystem::CacheManager::Persistent::Yes
std::string cacheFilename = FileSys.cacheManager()->cachedFilename(
fmt::format(
"{}_{}_localErrorHistograms",
std::filesystem::path(_filename).stem().string(), nHistograms
),
""
);
std::ifstream cacheFile(cacheFilename, std::ios::in | std::ios::binary);
if (cacheFile.is_open()) {
@@ -628,8 +624,9 @@ void RenderableMultiresVolume::update(const UpdateData& data) {
// Make sure that the directory exists
ghoul::filesystem::File file(_statsFileName);
ghoul::filesystem::Directory directory(file.directoryName());
FileSys.createDirectory(directory, ghoul::filesystem::FileSystem::Recursive::Yes);
std::filesystem::path directory =
std::filesystem::path(_statsFileName).parent_path();
std::filesystem::create_directories(directory);
std::ofstream ofs(_statsFileName, std::ofstream::out);
+5 -8
View File
@@ -30,6 +30,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/cachemanager.h>
#include <ghoul/logging/logmanager.h>
#include <filesystem>
#include <numeric>
#include <queue>
@@ -506,11 +507,9 @@ bool TSP::readCache() {
if (!FileSys.cacheManager())
return false;
ghoul::filesystem::File f = _filename;
std::string cacheFilename = FileSys.cacheManager()->cachedFilename(
f.baseName(),
"",
ghoul::filesystem::CacheManager::Persistent::Yes
std::filesystem::path(_filename).stem(),
""
);
std::ifstream file(cacheFilename, std::ios::in | std::ios::binary);
@@ -546,11 +545,9 @@ bool TSP::writeCache() {
return false;
}
ghoul::filesystem::File f = _filename;
std::string cacheFilename = FileSys.cacheManager()->cachedFilename(
f.baseName(),
"",
ghoul::filesystem::CacheManager::Persistent::Yes
std::filesystem::path(_filename).stem(),
""
);
std::ofstream file(cacheFilename, std::ios::out | std::ios::binary);
+5 -5
View File
@@ -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
));
+22 -28
View File
@@ -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;
}
@@ -33,6 +33,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/lua/ghoul_lua.h>
#include <ghoul/lua/lua_helper.h>
#include <filesystem>
#include <fstream>
namespace {
@@ -69,8 +70,10 @@ HorizonsTranslation::HorizonsTranslation()
_horizonsTextFile.onChange([&](){
requireUpdate();
_fileHandle = std::make_unique<ghoul::filesystem::File>(_horizonsTextFile);
_fileHandle->setCallback([&](const ghoul::filesystem::File&) {
_fileHandle = std::make_unique<ghoul::filesystem::File>(
_horizonsTextFile.value()
);
_fileHandle->setCallback([this]() {
requireUpdate();
notifyObservers();
});
@@ -113,16 +116,12 @@ glm::dvec3 HorizonsTranslation::position(const UpdateData& data) const {
void HorizonsTranslation::loadData() {
std::string file = _horizonsTextFile;
if (!FileSys.fileExists(absPath(file))) {
if (!std::filesystem::is_regular_file(absPath(file))) {
return;
}
std::string cachedFile = FileSys.cacheManager()->cachedFilename(
file,
ghoul::filesystem::CacheManager::Persistent::Yes
);
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 Horizon file '{}'", cachedFile, file
@@ -33,6 +33,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/profiling.h>
#include <filesystem>
#include <optional>
namespace {
@@ -97,7 +98,7 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary)
const Parameters p = codegen::bake<Parameters>(dictionary);
auto loadKernel = [](const std::string& kernel) {
if (!FileSys.fileExists(kernel)) {
if (!std::filesystem::is_regular_file(kernel)) {
throw SpiceManager::SpiceException(fmt::format(
"Kernel '{}' does not exist", kernel
));
+2 -1
View File
@@ -28,6 +28,7 @@
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <chrono>
#include <filesystem>
#include <fstream>
#include <optional>
#include <vector>
@@ -238,7 +239,7 @@ TLETranslation::TLETranslation(const ghoul::Dictionary& dictionary) {
}
void TLETranslation::readTLEFile(const std::string& filename, int lineNum) {
ghoul_assert(FileSys.fileExists(filename), "The filename must exist");
ghoul_assert(std::filesystem::is_regular_file(filename), "The filename must exist");
std::ifstream file;
file.exceptions(std::ofstream::failbit | std::ofstream::badbit);
@@ -183,7 +183,7 @@ void RenderableModelProjection::initializeGL() {
_projectionComponent.initializeGL();
float bs = boundingSphere();
double bs = boundingSphere();
_geometry->initialize();
setBoundingSphere(bs); // ignore bounding sphere set by geometry.
}
@@ -196,9 +196,7 @@ void RenderablePlaneProjection::loadTexture() {
_texture = std::move(texture);
_textureFile = std::make_unique<ghoul::filesystem::File>(_texturePath);
_textureFile->setCallback(
[&](const ghoul::filesystem::File&) { _textureIsDirty = true; }
);
_textureFile->setCallback([this]() { _textureIsDirty = true; });
}
}
}
@@ -34,6 +34,7 @@
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/fmt.h>
#include <filesystem>
#include <fstream>
namespace {
@@ -153,8 +154,7 @@ bool HongKangParser::create() {
return true;
}
const std::string& extension = ghoul::filesystem::File(_fileName).fileExtension();
if (extension != "txt") {
if (std::filesystem::path(_fileName).extension() != ".txt") {
return true;
}
@@ -29,8 +29,8 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#include <fstream>
namespace {
@@ -67,10 +67,9 @@ InstrumentTimesParser::InstrumentTimesParser(std::string name, std::string seque
}
bool InstrumentTimesParser::create() {
using RawPath = ghoul::filesystem::Directory::RawPath;
ghoul::filesystem::Directory sequenceDir(_fileName, RawPath::Yes);
if (!FileSys.directoryExists(sequenceDir)) {
LERROR(fmt::format("Could not load Label Directory '{}'", sequenceDir.path()));
std::string sequenceDir = absPath(_fileName);
if (!std::filesystem::is_directory(sequenceDir)) {
LERROR(fmt::format("Could not load Label Directory '{}'", sequenceDir));
return false;
}
@@ -79,12 +78,9 @@ bool InstrumentTimesParser::create() {
for (const std::pair<const K, V>& p : _instrumentFiles) {
const std::string& instrumentID = p.first;
for (std::string filename : p.second) {
std::string filepath = FileSys.pathByAppendingComponent(
sequenceDir.path(),
std::move(filename)
);
std::string filepath = fmt::format("{}/{}", sequenceDir, std::move(filename));
if (!FileSys.fileExists(filepath)) {
if (!std::filesystem::is_regular_file(filepath)) {
LERROR(fmt::format("Unable to read file '{}'. Skipping file", filepath));
continue;
}
@@ -26,12 +26,12 @@
#include <openspace/util/spicemanager.h>
#include <ghoul/fmt.h>
#include <ghoul/filesystem/directory.h>
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/io/texture/texturereader.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#include <fstream>
namespace {
@@ -140,10 +140,9 @@ std::string LabelParser::encode(const std::string& line) const {
}
bool LabelParser::create() {
using RawPath = ghoul::filesystem::Directory::RawPath;
ghoul::filesystem::Directory sequenceDir(_fileName, RawPath::Yes);
if (!FileSys.directoryExists(sequenceDir)) {
LERROR(fmt::format("Could not load Label Directory '{}'", sequenceDir.path()));
std::string sequenceDir = absPath(_fileName);
if (!std::filesystem::is_directory(sequenceDir)) {
LERROR(fmt::format("Could not load Label Directory '{}'", sequenceDir));
return false;
}
@@ -151,26 +150,29 @@ bool LabelParser::create() {
std::string lblName;
using Recursive = ghoul::filesystem::Directory::Recursive;
using Sort = ghoul::filesystem::Directory::Sort;
std::vector<std::string> sequencePaths = sequenceDir.read(Recursive::Yes, Sort::No);
for (const std::string& path : sequencePaths) {
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::recursive_directory_iterator(sequenceDir)) {
if (!e.is_regular_file()) {
continue;
}
std::string path = e.path().string();
size_t position = path.find_last_of('.') + 1;
if (position == 0 || position == std::string::npos) {
continue;
}
ghoul::filesystem::File currentFile(path);
const std::string& extension = currentFile.fileExtension();
std::string extension = std::filesystem::path(path).extension().string();
if (extension != "lbl" && extension != "LBL") {
if (extension != ".lbl" && extension != ".LBL") {
continue;
}
std::ifstream file(currentFile.path());
std::ifstream file(path);
if (!file.good()) {
LERROR(fmt::format("Failed to open label file '{}'", currentFile.path()));
LERROR(fmt::format("Failed to open label file '{}'", path));
return false;
}
@@ -256,7 +258,7 @@ bool LabelParser::create() {
}
else{
LERROR(fmt::format(
"Label file {} deviates from generic standard", currentFile.path()
"Label file {} deviates from generic standard", path
));
LINFO(
"Please make sure input data adheres to format from \
@@ -274,7 +276,7 @@ bool LabelParser::create() {
std::string p = path.substr(0, path.size() - ("lbl"s).size());
for (const std::string& ext : extensions) {
std::string imagePath = p + ext;
if (FileSys.fileExists(imagePath)) {
if (std::filesystem::is_regular_file(imagePath)) {
std::vector<std::string> spiceInstrument;
spiceInstrument.push_back(_instrumentID);
+12 -16
View File
@@ -32,6 +32,7 @@
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <filesystem>
#include <fstream>
#include <numeric>
@@ -85,17 +86,10 @@ HttpSynchronization::~HttpSynchronization() {
}
std::string HttpSynchronization::directory() {
ghoul::filesystem::Directory d(
_synchronizationRoot +
ghoul::filesystem::FileSystem::PathSeparator +
"http" +
ghoul::filesystem::FileSystem::PathSeparator +
_identifier +
ghoul::filesystem::FileSystem::PathSeparator +
std::to_string(_version)
std::string d = fmt::format(
"{}/http/{}/{}", _synchronizationRoot, _identifier, _version
);
return FileSys.absPath(d);
return absPath(d);
}
void HttpSynchronization::start() {
@@ -157,7 +151,7 @@ void HttpSynchronization::createSyncFile() {
const std::string& directoryName = directory();
const std::string& filepath = directoryName + ".ossync";
FileSys.createDirectory(directoryName, ghoul::filesystem::FileSystem::Recursive::Yes);
std::filesystem::create_directories(directoryName);
std::ofstream syncFile(filepath, std::ofstream::out);
syncFile << "Synchronized";
@@ -166,7 +160,7 @@ void HttpSynchronization::createSyncFile() {
bool HttpSynchronization::hasSyncFile() {
const std::string& path = directory() + ".ossync";
return FileSys.fileExists(path);
return std::filesystem::is_regular_file(path);
}
bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
@@ -209,9 +203,9 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
size_t lastSlash = line.find_last_of('/');
std::string filename = line.substr(lastSlash + 1);
std::string fileDestination = directory() +
ghoul::filesystem::FileSystem::PathSeparator +
filename + TempSuffix;
std::string fileDestination = fmt::format(
"{}/{}{}", directory(), filename, TempSuffix
);
if (sizeData.find(line) != sizeData.end()) {
LWARNING(fmt::format("{}: Duplicate entries: {}", _identifier, line));
@@ -278,7 +272,9 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
tempName.size() - strlen(TempSuffix)
);
FileSys.deleteFile(originalName);
if (std::filesystem::is_regular_file(originalName)) {
std::filesystem::remove(originalName);
}
int success = rename(tempName.c_str(), originalName.c_str());
if (success != 0) {
LERROR(fmt::format(
+10 -12
View File
@@ -34,6 +34,7 @@
#include <ghoul/filesystem/file.h>
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/misc/dictionary.h>
#include <filesystem>
#include <fstream>
#include <numeric>
#include <memory>
@@ -171,8 +172,9 @@ void UrlSynchronization::start() {
);
_filename = lastPartOfUrl;
}
std::string fileDestination = directory() +
ghoul::filesystem::FileSystem::PathSeparator + _filename + TempSuffix;
std::string fileDestination = fmt::format(
"{}/{}{}", directory(), _filename, TempSuffix
);
std::unique_ptr<AsyncHttpFileDownload> download =
std::make_unique<AsyncHttpFileDownload>(
@@ -233,7 +235,9 @@ void UrlSynchronization::start() {
tempName.size() - strlen(TempSuffix)
);
FileSys.deleteFile(originalName);
if (std::filesystem::is_regular_file(originalName)) {
std::filesystem::remove(originalName);
}
int success = rename(tempName.c_str(), originalName.c_str());
if (success != 0) {
LERRORC(
@@ -288,7 +292,7 @@ bool UrlSynchronization::nTotalBytesIsKnown() {
void UrlSynchronization::createSyncFile() {
std::string dir = directory();
std::string filepath = dir + ".ossync";
FileSys.createDirectory(dir, ghoul::filesystem::FileSystem::Recursive::Yes);
std::filesystem::create_directories(dir);
std::ofstream syncFile(filepath, std::ofstream::out);
syncFile << "Synchronized";
syncFile.close();
@@ -296,17 +300,11 @@ void UrlSynchronization::createSyncFile() {
bool UrlSynchronization::hasSyncFile() {
const std::string& path = directory() + ".ossync";
return FileSys.fileExists(path);
return std::filesystem::is_regular_file(path);
}
std::string UrlSynchronization::directory() {
ghoul::filesystem::Directory d(
_synchronizationRoot + ghoul::filesystem::FileSystem::PathSeparator +
"url" + ghoul::filesystem::FileSystem::PathSeparator +
_identifier + ghoul::filesystem::FileSystem::PathSeparator +
"files"
);
std::string d = fmt::format("{}/url/{}/files", _synchronizationRoot, _identifier);
return absPath(d);
}
@@ -44,6 +44,7 @@
#include <ghoul/filesystem/filesystem.h>
#include <ghoul/logging/logmanager.h>
#include <ghoul/opengl/texture.h>
#include <filesystem>
#include <optional>
namespace {
@@ -209,32 +210,26 @@ RenderableTimeVaryingVolume::RenderableTimeVaryingVolume(
RenderableTimeVaryingVolume::~RenderableTimeVaryingVolume() {}
void RenderableTimeVaryingVolume::initializeGL() {
using RawPath = ghoul::filesystem::Directory::RawPath;
ghoul::filesystem::Directory sequenceDir(_sourceDirectory, RawPath::Yes);
std::string sequenceDir = absPath(_sourceDirectory);
if (!FileSys.directoryExists(sequenceDir)) {
LERROR(fmt::format("Could not load sequence directory '{}'", sequenceDir.path()));
if (!std::filesystem::is_directory(sequenceDir)) {
LERROR(fmt::format("Could not load sequence directory '{}'", sequenceDir));
return;
}
using Recursive = ghoul::filesystem::Directory::Recursive;
using Sort = ghoul::filesystem::Directory::Sort;
std::vector<std::string> sequencePaths = sequenceDir.read(Recursive::Yes, Sort::No);
for (const std::string& path : sequencePaths) {
ghoul::filesystem::File currentFile(path);
std::string extension = currentFile.fileExtension();
if (extension == "dictionary") {
loadTimestepMetadata(path);
namespace fs = std::filesystem;
for (const fs::directory_entry& e : fs::recursive_directory_iterator(sequenceDir)) {
if (e.is_regular_file() && e.path().extension() == ".dictionary") {
loadTimestepMetadata(e.path().string());
}
}
// TODO: defer loading of data to later (separate thread or at least not when loading)
for (std::pair<const double, Timestep>& p : _volumeTimesteps) {
Timestep& t = p.second;
std::string path = FileSys.pathByAppendingComponent(
_sourceDirectory, t.baseName
) + ".rawvolume";
std::string path = fmt::format(
"{}/{}.rawvolume", _sourceDirectory.value(), t.baseName
);
RawVolumeReader<float> reader(path, t.metadata.dimensions);
t.rawVolume = reader.read();
@@ -334,7 +329,7 @@ void RenderableTimeVaryingVolume::loadTimestepMetadata(const std::string& path)
Timestep t;
t.metadata = metadata;
t.baseName = ghoul::filesystem::File(path).baseName();
t.baseName = std::filesystem::path(path).stem().string();
t.inRam = false;
t.onGpu = false;
@@ -38,6 +38,7 @@
#include <ghoul/lua/lua_helper.h>
#include <ghoul/misc/dictionaryluaformatter.h>
#include <ghoul/misc/defer.h>
#include <filesystem>
#include <fstream>
namespace {
@@ -164,10 +165,10 @@ void GenerateRawVolumeTask::perform(const Task::ProgressCallback& progressCallba
luaL_unref(state, LUA_REGISTRYINDEX, functionReference);
ghoul::filesystem::File file(_rawVolumeOutputPath);
const std::string directory = file.directoryName();
if (!FileSys.directoryExists(directory)) {
FileSys.createDirectory(directory, ghoul::filesystem::FileSystem::Recursive::Yes);
const std::filesystem::path directory =
std::filesystem::path(_rawVolumeOutputPath).parent_path();
if (!std::filesystem::is_directory(directory)) {
std::filesystem::create_directories(directory);
}
volume::RawVolumeWriter<float> writer(_rawVolumeOutputPath);
+2 -1
View File
@@ -35,6 +35,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/assert.h>
#include <ghoul/misc/profiling.h>
#include <filesystem>
namespace {
constexpr const char* _loggerCat = "CEF BrowserInstance";
@@ -96,7 +97,7 @@ void BrowserInstance::loadUrl(std::string url) {
}
bool BrowserInstance::loadLocalPath(std::string path) {
if (!FileSys.fileExists(path)) {
if (!std::filesystem::is_regular_file(path)) {
LDEBUG(fmt::format("Could not find path `{}`, verify that it is correct.", path));
return false;
}
+2 -1
View File
@@ -37,6 +37,7 @@
#include <ghoul/logging/logmanager.h>
#include <ghoul/misc/dictionary.h>
#include <ghoul/misc/profiling.h>
#include <filesystem>
namespace {
constexpr const char* _loggerCat = "WebBrowser";
@@ -117,7 +118,7 @@ void WebBrowserModule::internalDeinitialize() {
std::string WebBrowserModule::findHelperExecutable() {
std::string execLocation = absPath("${BIN}/" + std::string(SubprocessPath));
if (!FileSys.fileExists(execLocation)) {
if (!std::filesystem::is_regular_file(execLocation)) {
LERROR(fmt::format(
"Could not find web helper executable at location: {}" , execLocation
));