From ccdc5a5dc3e2daf0085bb06d64e70d5bc82e6bcc Mon Sep 17 00:00:00 2001 From: Alexander Bock Date: Sun, 16 May 2021 20:26:49 +0200 Subject: [PATCH] Feature/filesystem cleanup (#1587) * Adapting to the changes in Ghoul * First step of moving filesystem functions to std * Remove persistence flag from cachemanager --- apps/OpenSpace/main.cpp | 25 ++-- apps/TaskRunner/main.cpp | 14 +- ext/ghoul | 2 +- include/openspace/engine/configuration.h | 5 +- include/openspace/engine/downloadmanager.h | 3 +- .../openspace/rendering/texturecomponent.h | 3 +- include/openspace/scene/assetloader.h | 3 +- .../rendering/atmospheredeferredcaster.cpp | 2 +- modules/base/rendering/renderabledisc.cpp | 4 +- .../rendering/renderableplaneimagelocal.cpp | 12 +- .../base/rendering/screenspaceimagelocal.cpp | 7 +- modules/base/rotation/luarotation.cpp | 6 +- modules/base/scale/luascale.cpp | 6 +- modules/base/translation/luatranslation.cpp | 4 +- .../rendering/renderablebillboardscloud.cpp | 23 ++- .../rendering/renderabledumeshes.cpp | 5 +- .../rendering/renderableplanescloud.cpp | 11 +- .../rendering/renderablepoints.cpp | 27 ++-- modules/exoplanets/exoplanetsmodule_lua.inl | 2 +- .../rendering/renderableorbitdisc.cpp | 4 +- .../renderablefieldlinessequence.cpp | 29 ++-- .../gaia/rendering/renderablegaiastars.cpp | 32 ++--- modules/gaia/tasks/constructoctreetask.cpp | 20 ++- modules/gaia/tasks/readfitstask.cpp | 19 ++- modules/galaxy/rendering/renderablegalaxy.cpp | 5 +- .../src/globelabelscomponent.cpp | 11 +- .../globebrowsing/src/rawtiledatareader.cpp | 3 +- modules/globebrowsing/src/ringscomponent.cpp | 78 +++++----- modules/globebrowsing/src/tileprovider.cpp | 14 +- modules/imgui/src/gui.cpp | 7 +- modules/imgui/src/guiassetcomponent.cpp | 6 +- modules/iswa/util/dataprocessorkameleon.cpp | 5 +- modules/iswa/util/iswamanager.cpp | 19 ++- modules/kameleon/src/kameleonwrapper.cpp | 3 +- .../kameleonvolume/kameleonvolumereader.cpp | 3 +- .../rendering/renderablekameleonvolume.cpp | 22 +-- .../rendering/renderablemultiresvolume.cpp | 47 +++--- modules/multiresvolume/rendering/tsp.cpp | 13 +- modules/space/rendering/renderablerings.cpp | 10 +- .../space/rendering/renderablesatellites.cpp | 3 +- .../space/rendering/renderablesmallbody.cpp | 3 +- modules/space/rendering/renderablestars.cpp | 50 +++---- .../space/translation/horizonstranslation.cpp | 17 ++- .../space/translation/spicetranslation.cpp | 3 +- modules/space/translation/tletranslation.cpp | 3 +- .../rendering/renderablemodelprojection.cpp | 2 +- .../rendering/renderableplaneprojection.cpp | 4 +- .../util/hongkangparser.cpp | 4 +- .../util/instrumenttimesparser.cpp | 16 +-- .../util/labelparser.cpp | 34 ++--- modules/sync/syncs/httpsynchronization.cpp | 28 ++-- modules/sync/syncs/urlsynchronization.cpp | 22 ++- .../rendering/renderabletimevaryingvolume.cpp | 29 ++-- .../volume/tasks/generaterawvolumetask.cpp | 9 +- modules/webbrowser/src/browserinstance.cpp | 3 +- modules/webbrowser/webbrowsermodule.cpp | 3 +- src/documentation/verifier.cpp | 28 ++-- src/engine/configuration.cpp | 33 ++--- src/engine/downloadmanager.cpp | 27 ++-- src/engine/openspaceengine.cpp | 40 +++--- src/engine/openspaceengine_lua.inl | 11 +- src/interaction/navigationhandler.cpp | 3 +- src/interaction/sessionrecording.cpp | 43 +++--- .../tasks/convertrecfileversiontask.cpp | 11 +- .../tasks/convertrecformattask.cpp | 29 ++-- src/mission/mission.cpp | 3 +- src/mission/missionmanager.cpp | 6 +- src/properties/list/intlistproperty.cpp | 2 +- src/rendering/helper.cpp | 9 +- src/rendering/luaconsole.cpp | 16 +-- src/rendering/renderengine.cpp | 11 +- src/rendering/texturecomponent.cpp | 10 +- src/rendering/transferfunction.cpp | 30 +--- src/scene/asset.cpp | 3 +- src/scene/assetloader.cpp | 36 ++--- src/scene/profile_lua.inl | 12 +- src/scripting/scriptengine.cpp | 3 +- src/scripting/scriptengine_lua.inl | 135 ++++++++---------- src/util/httprequest.cpp | 19 ++- src/util/openspacemodule.cpp | 22 ++- src/util/spicemanager.cpp | 39 ++--- src/util/spicemanager_lua.inl | 3 +- src/util/taskloader.cpp | 3 +- .../set_openspace_compile_settings.cmake | 2 - tests/main.cpp | 12 +- tests/test_assetloader.cpp | 8 +- tests/test_lua_createsinglecolorimage.cpp | 3 +- 87 files changed, 648 insertions(+), 711 deletions(-) diff --git a/apps/OpenSpace/main.cpp b/apps/OpenSpace/main.cpp index 9adc728a07..5735eca1a8 100644 --- a/apps/OpenSpace/main.cpp +++ b/apps/OpenSpace/main.cpp @@ -61,6 +61,7 @@ #include #include #include +#include #include #ifdef WIN32 @@ -1039,7 +1040,7 @@ int main(int argc, char* argv[]) { // to make it possible to find other files in the same directory. FileSys.registerPathToken( "${BIN}", - ghoul::filesystem::File(absPath(argv[0])).directoryName(), + std::filesystem::path(argv[0]).parent_path(), ghoul::filesystem::FileSystem::Override::Yes ); @@ -1092,23 +1093,27 @@ int main(int argc, char* argv[]) { std::string windowConfiguration; try { // Find configuration - std::string configurationFilePath = commandlineArguments.configurationName; - if (commandlineArguments.configurationName.empty()) { + std::filesystem::path configurationFilePath; + if (!commandlineArguments.configurationName.empty()) { + configurationFilePath = absPath(commandlineArguments.configurationName); + } + else { LDEBUG("Finding configuration"); configurationFilePath = configuration::findConfiguration(); } - configurationFilePath = absPath(configurationFilePath); - if (!FileSys.fileExists(configurationFilePath)) { - LFATALC("main", "Could not find configuration: " + configurationFilePath); + if (!std::filesystem::is_regular_file(configurationFilePath)) { + LFATALC( + "main", + fmt::format("Could not find configuration {}", configurationFilePath) + ); exit(EXIT_FAILURE); } - LINFO(fmt::format("Configuration Path: '{}'", configurationFilePath)); + LINFO(fmt::format("Configuration Path: {}", configurationFilePath)); // Register the base path as the directory where the configuration file lives - std::string base = ghoul::filesystem::File(configurationFilePath).directoryName(); - constexpr const char* BasePathToken = "${BASE}"; - FileSys.registerPathToken(BasePathToken, base); + std::filesystem::path base = configurationFilePath.parent_path(); + FileSys.registerPathToken("${BASE}", base); // Loading configuration from disk LDEBUG("Loading configuration from disk"); diff --git a/apps/TaskRunner/main.cpp b/apps/TaskRunner/main.cpp index 7e038fe34d..1bd16c6394 100644 --- a/apps/TaskRunner/main.cpp +++ b/apps/TaskRunner/main.cpp @@ -32,7 +32,6 @@ #include #include #include -#include #include #include #include @@ -117,18 +116,21 @@ int main(int argc, char** argv) { // to make it possible to find other files in the same directory. FileSys.registerPathToken( "${BIN}", - ghoul::filesystem::File(absPath(argv[0])).directoryName(), + std::filesystem::path(argv[0]).parent_path(), ghoul::filesystem::FileSystem::Override::Yes ); - std::string configFile = configuration::findConfiguration(); + std::filesystem::path configFile = configuration::findConfiguration(); // Register the base path as the directory where the configuration file lives - std::string base = ghoul::filesystem::File(configFile).directoryName(); + std::filesystem::path base = configFile.parent_path(); constexpr const char* BasePathToken = "${BASE}"; FileSys.registerPathToken(BasePathToken, base); - *global::configuration = configuration::loadConfigurationFromFile(configFile, ""); + *global::configuration = configuration::loadConfigurationFromFile( + configFile.string(), + "" + ); openspace::global::openSpaceEngine->registerPathTokens(); global::openSpaceEngine->initialize(); @@ -160,7 +162,7 @@ int main(int argc, char** argv) { // If no task file was specified in as argument, run in CLI mode. LINFO(fmt::format("Task root: {}", absPath("${TASKS}"))); - FileSys.setCurrentDirectory(ghoul::filesystem::Directory(absPath("${TASKS}"))); + std::filesystem::current_path(absPath("${TASKS}")); std::cout << "TASK > "; while (std::cin >> tasksPath) { diff --git a/ext/ghoul b/ext/ghoul index 324db538a6..9239222dd4 160000 --- a/ext/ghoul +++ b/ext/ghoul @@ -1 +1 @@ -Subproject commit 324db538a63653fa9bf6d78cf04135ece0fa3c3f +Subproject commit 9239222dd465c3c4893d1110820848f564602934 diff --git a/include/openspace/engine/configuration.h b/include/openspace/engine/configuration.h index 47d00ac21f..83970d9fdf 100644 --- a/include/openspace/engine/configuration.h +++ b/include/openspace/engine/configuration.h @@ -27,6 +27,7 @@ #include #include +#include #include #include #include @@ -129,9 +130,9 @@ struct Configuration { ghoul::lua::LuaState state; }; -std::string findConfiguration(const std::string& filename = "openspace.cfg"); +std::filesystem::path findConfiguration(const std::string& filename = "openspace.cfg"); -Configuration loadConfigurationFromFile(const std::string& filename, +Configuration loadConfigurationFromFile(const std::filesystem::path& filename, const std::string& overrideScript); } // namespace openspace::configuration diff --git a/include/openspace/engine/downloadmanager.h b/include/openspace/engine/downloadmanager.h index 26b0fa21f6..1bfb97a229 100644 --- a/include/openspace/engine/downloadmanager.h +++ b/include/openspace/engine/downloadmanager.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___DOWNLOADMANAGER___H__ #include +#include #include #include #include @@ -99,7 +100,7 @@ public: // finishedCallback - callback when download finished (happens on different thread) // progressCallback - callback for status during (happens on different thread) std::shared_ptr downloadFile(const std::string& url, - const ghoul::filesystem::File& file, + const std::filesystem::path& file, OverrideFile overrideFile = OverrideFile::Yes, FailOnError failOnError = FailOnError::No, unsigned int timeout_secs = 0, DownloadFinishedCallback finishedCallback = DownloadFinishedCallback(), diff --git a/include/openspace/rendering/texturecomponent.h b/include/openspace/rendering/texturecomponent.h index 5c4d905a7c..1940e05fac 100644 --- a/include/openspace/rendering/texturecomponent.h +++ b/include/openspace/rendering/texturecomponent.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___TEXTURECOMPONENT___H__ #include +#include namespace ghoul::filesystem { class File; } namespace ghoul::opengl {class Texture; } @@ -48,7 +49,7 @@ public: void uploadToGpu(); // Loads a texture from a file on disk - void loadFromFile(const std::string& path); + void loadFromFile(const std::filesystem::path& path); // Function to call in a renderable's update function to make sure // the texture is kept up to date diff --git a/include/openspace/scene/assetloader.h b/include/openspace/scene/assetloader.h index 779e98e892..141dc5aa2c 100644 --- a/include/openspace/scene/assetloader.h +++ b/include/openspace/scene/assetloader.h @@ -26,6 +26,7 @@ #define __OPENSPACE_CORE___ASSETLOADER___H__ #include +#include #include #include #include @@ -169,7 +170,7 @@ private: void tearDownAssetLuaTable(Asset* asset); std::shared_ptr getAsset(const std::string& name); - ghoul::filesystem::Directory currentDirectory() const; + std::filesystem::path currentDirectory() const; void setCurrentAsset(Asset* asset); void addLuaDependencyTable(Asset* dependant, Asset* dependency); diff --git a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp index 049279ca5b..59a664be99 100644 --- a/modules/atmosphere/rendering/atmospheredeferredcaster.cpp +++ b/modules/atmosphere/rendering/atmospheredeferredcaster.cpp @@ -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); } diff --git a/modules/base/rendering/renderabledisc.cpp b/modules/base/rendering/renderabledisc.cpp index ca17160453..f00b2134dc 100644 --- a/modules/base/rendering/renderabledisc.cpp +++ b/modules/base/rendering/renderabledisc.cpp @@ -96,7 +96,7 @@ RenderableDisc::RenderableDisc(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(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(); diff --git a/modules/base/rendering/renderableplaneimagelocal.cpp b/modules/base/rendering/renderableplaneimagelocal.cpp index b19206d0c5..008f47159e 100644 --- a/modules/base/rendering/renderableplaneimagelocal.cpp +++ b/modules/base/rendering/renderableplaneimagelocal.cpp @@ -102,13 +102,11 @@ RenderablePlaneImageLocal::RenderablePlaneImageLocal(const ghoul::Dictionary& di addProperty(_blendMode); _texturePath = absPath(p.texture); - _textureFile = std::make_unique(_texturePath); + _textureFile = std::make_unique(_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(_texturePath); - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } - ); + _textureFile = std::make_unique(_texturePath.value()); + _textureFile->setCallback([this]() { _textureIsDirty = true; }); } } diff --git a/modules/base/rendering/screenspaceimagelocal.cpp b/modules/base/rendering/screenspaceimagelocal.cpp index 3c74143c2f..b03ab47a07 100644 --- a/modules/base/rendering/screenspaceimagelocal.cpp +++ b/modules/base/rendering/screenspaceimagelocal.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include 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( diff --git a/modules/base/rotation/luarotation.cpp b/modules/base/rotation/luarotation.cpp index f6f0f822a5..98f9e90afa 100644 --- a/modules/base/rotation/luarotation.cpp +++ b/modules/base/rotation/luarotation.cpp @@ -69,10 +69,8 @@ LuaRotation::LuaRotation() _luaScriptFile.onChange([&]() { requireUpdate(); - _fileHandle = std::make_unique(_luaScriptFile); - _fileHandle->setCallback([&](const ghoul::filesystem::File&) { - requireUpdate(); - }); + _fileHandle = std::make_unique(_luaScriptFile.value()); + _fileHandle->setCallback([this]() { requireUpdate(); }); }); } diff --git a/modules/base/scale/luascale.cpp b/modules/base/scale/luascale.cpp index 8ea195e15c..14099d39cd 100644 --- a/modules/base/scale/luascale.cpp +++ b/modules/base/scale/luascale.cpp @@ -68,10 +68,8 @@ LuaScale::LuaScale() _luaScriptFile.onChange([&]() { requireUpdate(); - _fileHandle = std::make_unique(_luaScriptFile); - _fileHandle->setCallback([&](const ghoul::filesystem::File&) { - requireUpdate(); - }); + _fileHandle = std::make_unique(_luaScriptFile.value()); + _fileHandle->setCallback([this]() { requireUpdate(); }); }); } diff --git a/modules/base/translation/luatranslation.cpp b/modules/base/translation/luatranslation.cpp index 8f850d1f28..f9d89649a4 100644 --- a/modules/base/translation/luatranslation.cpp +++ b/modules/base/translation/luatranslation.cpp @@ -69,8 +69,8 @@ LuaTranslation::LuaTranslation() _luaScriptFile.onChange([&]() { requireUpdate(); - _fileHandle = std::make_unique(_luaScriptFile); - _fileHandle->setCallback([&](const ghoul::filesystem::File&) { + _fileHandle = std::make_unique(_luaScriptFile.value()); + _fileHandle->setCallback([this]() { requireUpdate(); notifyObservers(); }); diff --git a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp index 3da6f82553..a60e70ff89 100644 --- a/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp +++ b/modules/digitaluniverse/rendering/renderablebillboardscloud.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/modules/digitaluniverse/rendering/renderabledumeshes.cpp b/modules/digitaluniverse/rendering/renderabledumeshes.cpp index d73465cc19..177536f8fc 100644 --- a/modules/digitaluniverse/rendering/renderabledumeshes.cpp +++ b/modules/digitaluniverse/rendering/renderabledumeshes.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include @@ -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; } diff --git a/modules/digitaluniverse/rendering/renderableplanescloud.cpp b/modules/digitaluniverse/rendering/renderableplanescloud.cpp index 7d754f9308..050dc24743 100644 --- a/modules/digitaluniverse/rendering/renderableplanescloud.cpp +++ b/modules/digitaluniverse/rendering/renderableplanescloud.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -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; } diff --git a/modules/digitaluniverse/rendering/renderablepoints.cpp b/modules/digitaluniverse/rendering/renderablepoints.cpp index 96c5420b91..94cde199ff 100644 --- a/modules/digitaluniverse/rendering/renderablepoints.cpp +++ b/modules/digitaluniverse/rendering/renderablepoints.cpp @@ -40,6 +40,7 @@ #include #include #include +#include #include #include #include @@ -176,13 +177,11 @@ RenderablePoints::RenderablePoints(const ghoul::Dictionary& dictionary) if (p.texture.has_value()) { _spriteTexturePath = absPath(*p.texture); _spriteTextureFile = std::make_unique( - _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( - _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; } diff --git a/modules/exoplanets/exoplanetsmodule_lua.inl b/modules/exoplanets/exoplanetsmodule_lua.inl index 5843cec267..5b0369dad7 100644 --- a/modules/exoplanets/exoplanetsmodule_lua.inl +++ b/modules/exoplanets/exoplanetsmodule_lua.inl @@ -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); diff --git a/modules/exoplanets/rendering/renderableorbitdisc.cpp b/modules/exoplanets/rendering/renderableorbitdisc.cpp index 7581788fac..bc1d0299b2 100644 --- a/modules/exoplanets/rendering/renderableorbitdisc.cpp +++ b/modules/exoplanets/rendering/renderableorbitdisc.cpp @@ -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(); diff --git a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp index b500fe33c6..83ed4b58c1 100644 --- a/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp +++ b/modules/fieldlinessequence/rendering/renderablefieldlinessequence.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include @@ -417,13 +418,16 @@ bool RenderableFieldlinesSequence::extractMandatoryInfoFromDictionary( // Ensure that the source folder exists and then extract // the files with the same extension as - 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 as extension _sourceFiles.erase( @@ -471,8 +475,7 @@ void RenderableFieldlinesSequence::extractOptionalInfoFromDictionary( // ------------------- EXTRACT OPTIONAL VALUES FROM DICTIONARY ------------------- // if (_dictionary->hasValue(KeyOutputFolder)) { outputFolderPath = _dictionary->value(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(KeyCdfSeedPointFile)) { seedFilePath = _dictionary->value(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& 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; diff --git a/modules/gaia/rendering/renderablegaiastars.cpp b/modules/gaia/rendering/renderablegaiastars.cpp index e89dc71d06..4394236a15 100644 --- a/modules/gaia/rendering/renderablegaiastars.cpp +++ b/modules/gaia/rendering/renderablegaiastars.cpp @@ -463,10 +463,10 @@ RenderableGaiaStars::RenderableGaiaStars(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(dictionary); _filePath = absPath(p.file); - _dataFile = std::make_unique(_filePath); - _dataFile->setCallback([&](const File&) { _dataIsDirty = true; }); + _dataFile = std::make_unique(_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( + _pointSpreadFunctionTexturePath.value() ); - _pointSpreadFunctionFile = std::make_unique(_pointSpreadFunctionTexturePath); _pointSpreadFunctionFile->setCallback( - [&](const File&) { _pointSpreadFunctionTextureIsDirty = true; } + [this]() { _pointSpreadFunctionTextureIsDirty = true; } ); _colorTexturePath = absPath(p.colorMap); - _colorTextureFile = std::make_unique(_colorTexturePath); - _colorTexturePath.onChange([&]() { _colorTextureIsDirty = true; }); - _colorTextureFile->setCallback([&](const File&) { _colorTextureIsDirty = true; }); + _colorTextureFile = std::make_unique(_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( - _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( - _colorTexturePath - ); - _colorTextureFile->setCallback( - [&](const ghoul::filesystem::File&) { _colorTextureIsDirty = true; } + _colorTexturePath.value() ); + _colorTextureFile->setCallback([this]() { _colorTextureIsDirty = true; }); } _colorTextureIsDirty = false; } diff --git a/modules/gaia/tasks/constructoctreetask.cpp b/modules/gaia/tasks/constructoctreetask.cpp index 7fefa17517..f39e7db3ed 100644 --- a/modules/gaia/tasks/constructoctreetask.cpp +++ b/modules/gaia/tasks/constructoctreetask.cpp @@ -28,9 +28,9 @@ #include #include #include -#include #include #include +#include #include #include @@ -452,8 +452,16 @@ void ConstructOctreeTask::constructOctreeFromFolder( //int starsOutside2000 = 0; //int starsOutside5000 = 0; - ghoul::filesystem::Directory currentDir(_inFileOrFolderPath); - std::vector allInputFiles = currentDir.readFiles(); + std::vector 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 filterValues; auto writeThreads = std::vector(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 )); } diff --git a/modules/gaia/tasks/readfitstask.cpp b/modules/gaia/tasks/readfitstask.cpp index 865433da6a..86e7b0ee34 100644 --- a/modules/gaia/tasks/readfitstask.cpp +++ b/modules/gaia/tasks/readfitstask.cpp @@ -30,10 +30,9 @@ #include #include -#include #include #include - +#include #include #include #include @@ -185,8 +184,16 @@ void ReadFitsTask::readAllFitsFilesFromFolder(const Task::ProgressCallback&) { ConcurrentJobManager>> jobManager(threadPool); // Get all files in specified folder. - ghoul::filesystem::Directory currentDir(_inFileOrFolderPath); - std::vector allInputFiles = currentDir.readFiles(); + std::vector 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( - fileToRead, + fileToRead.string(), _allColumnNames, _firstRow, _lastRow, diff --git a/modules/galaxy/rendering/renderablegalaxy.cpp b/modules/galaxy/rendering/renderablegalaxy.cpp index 50cff4ca7a..563c560e54 100644 --- a/modules/galaxy/rendering/renderablegalaxy.cpp +++ b/modules/galaxy/rendering/renderablegalaxy.cpp @@ -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 diff --git a/modules/globebrowsing/src/globelabelscomponent.cpp b/modules/globebrowsing/src/globelabelscomponent.cpp index 185dc0ce6b..1b665f255b 100644 --- a/modules/globebrowsing/src/globelabelscomponent.cpp +++ b/modules/globebrowsing/src/globelabelscomponent.cpp @@ -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; } diff --git a/modules/globebrowsing/src/rawtiledatareader.cpp b/modules/globebrowsing/src/rawtiledatareader.cpp index 81254ff64d..ebe9a2ec92 100644 --- a/modules/globebrowsing/src/rawtiledatareader.cpp +++ b/modules/globebrowsing/src/rawtiledatareader.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #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); diff --git a/modules/globebrowsing/src/ringscomponent.cpp b/modules/globebrowsing/src/ringscomponent.cpp index e59917235b..174c49c47f 100644 --- a/modules/globebrowsing/src/ringscomponent.cpp +++ b/modules/globebrowsing/src/ringscomponent.cpp @@ -258,50 +258,52 @@ void RingsComponent::initialize() { if (p.texture.has_value()) { _texturePath = absPath(p.texture->string()); - _textureFile = std::make_unique(_texturePath); - _texturePath.onChange([&]() { loadTexture(); }); + _textureFile = std::make_unique(_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(_textureFwrdPath); - _textureFwrdPath.onChange([&]() { loadTexture(); }); + _textureFileForwards = std::make_unique(_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(_textureBckwrdPath); - _textureBckwrdPath.onChange([&]() { loadTexture(); }); + _textureFileBackwards = std::make_unique(_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(_textureUnlitPath); - _textureUnlitPath.onChange([&]() { loadTexture(); }); + _textureFileUnlit = std::make_unique(_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(_textureColorPath); - _textureColorPath.onChange([&]() { loadTexture(); }); + _textureFileColor = std::make_unique(_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(_textureTransparencyPath); - _textureTransparencyPath.onChange([&]() { loadTexture(); }); + _textureFileTransparency = std::make_unique( + _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(_texturePath); - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + _textureFile = std::make_unique( + _texturePath.value() ); + _textureFile->setCallback([this]() { _textureIsDirty = true; }); } } @@ -655,11 +657,9 @@ void RingsComponent::loadTexture() { ghoul::opengl::Texture::FilterMode::AnisotropicMipMap); _textureFileForwards = std::make_unique( - _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( - _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(_textureUnlitPath); - _textureFileUnlit->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + _textureFileUnlit = std::make_unique( + _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(_textureColorPath); - _textureFileColor->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + _textureFileColor = std::make_unique( + _textureColorPath.value() ); + _textureFileColor->setCallback([this]() { _textureIsDirty = true; }); } } @@ -762,11 +760,9 @@ void RingsComponent::loadTexture() { ); _textureFileTransparency = std::make_unique( - _textureTransparencyPath - ); - _textureFileTransparency->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + _textureTransparencyPath.value() ); + _textureFileTransparency->setCallback([this]() { _textureIsDirty = true; }); } } diff --git a/modules/globebrowsing/src/tileprovider.cpp b/modules/globebrowsing/src/tileprovider.cpp index 10fa05b65f..53d75717f3 100644 --- a/modules/globebrowsing/src/tileprovider.cpp +++ b/modules/globebrowsing/src/tileprovider.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include #include "cpl_minixml.h" @@ -359,12 +360,11 @@ std::unique_ptr 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(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); diff --git a/modules/imgui/src/gui.cpp b/modules/imgui/src/gui.cpp index b86622ba16..ec0d76b0a5 100644 --- a/modules/imgui/src/gui.cpp +++ b/modules/imgui/src/gui.cpp @@ -38,7 +38,7 @@ #include #include #include - +#include namespace { constexpr const char* _loggerCat = "GUI"; @@ -53,7 +53,7 @@ namespace { constexpr const std::array 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)); diff --git a/modules/imgui/src/guiassetcomponent.cpp b/modules/imgui/src/guiassetcomponent.cpp index 92b6eedaa5..d0eedb873f 100644 --- a/modules/imgui/src/guiassetcomponent.cpp +++ b/modules/imgui/src/guiassetcomponent.cpp @@ -30,9 +30,9 @@ #include #include #include - #include #include +#include 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()); diff --git a/modules/iswa/util/dataprocessorkameleon.cpp b/modules/iswa/util/dataprocessorkameleon.cpp index 7c0a1b4e1c..f7074a27ec 100644 --- a/modules/iswa/util/dataprocessorkameleon.cpp +++ b/modules/iswa/util/dataprocessorkameleon.cpp @@ -31,6 +31,7 @@ #include #include #include +#include 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(); } diff --git a/modules/iswa/util/iswamanager.cpp b/modules/iswa/util/iswamanager.cpp index ff0655fdbc..f08199b32f 100644 --- a/modules/iswa/util/iswamanager.cpp +++ b/modules/iswa/util/iswamanager.cpp @@ -42,6 +42,7 @@ #include #include #include +#include #include #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); diff --git a/modules/kameleon/src/kameleonwrapper.cpp b/modules/kameleon/src/kameleonwrapper.cpp index 5528881746..05927d31d8 100644 --- a/modules/kameleon/src/kameleonwrapper.cpp +++ b/modules/kameleon/src/kameleonwrapper.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #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; } diff --git a/modules/kameleonvolume/kameleonvolumereader.cpp b/modules/kameleonvolume/kameleonvolumereader.cpp index 63301ba596..9d4cef1d7c 100644 --- a/modules/kameleonvolume/kameleonvolumereader.cpp +++ b/modules/kameleonvolume/kameleonvolumereader.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #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); } diff --git a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp index b12c28ac9f..9ee8420615 100644 --- a/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp +++ b/modules/kameleonvolume/rendering/renderablekameleonvolume.cpp @@ -45,6 +45,7 @@ #include #include #include +#include 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(tolower(v)); } - ); - if (extension == "cdf") { + std::filesystem::path extension = std::filesystem::path(path).extension(); + if (extension == ".cdf" || extension == ".CDF") { loadCdf(path); } else { diff --git a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp index 6e75384f79..547160fba5 100644 --- a/modules/multiresvolume/rendering/renderablemultiresvolume.cpp +++ b/modules/multiresvolume/rendering/renderablemultiresvolume.cpp @@ -54,6 +54,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/modules/multiresvolume/rendering/tsp.cpp b/modules/multiresvolume/rendering/tsp.cpp index e056dbaeb4..124d1cea24 100644 --- a/modules/multiresvolume/rendering/tsp.cpp +++ b/modules/multiresvolume/rendering/tsp.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include @@ -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); diff --git a/modules/space/rendering/renderablerings.cpp b/modules/space/rendering/renderablerings.cpp index 6e45f719b6..416acd498d 100644 --- a/modules/space/rendering/renderablerings.cpp +++ b/modules/space/rendering/renderablerings.cpp @@ -126,7 +126,7 @@ RenderableRings::RenderableRings(const ghoul::Dictionary& dictionary) addProperty(_size); _texturePath = absPath(p.texture); - _textureFile = std::make_unique(_texturePath); + _textureFile = std::make_unique(_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(_texturePath); - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } + _textureFile = std::make_unique( + _texturePath.value() ); + _textureFile->setCallback([this]() { _textureIsDirty = true; }); } } } diff --git a/modules/space/rendering/renderablesatellites.cpp b/modules/space/rendering/renderablesatellites.cpp index f808be2147..15fb459236 100644 --- a/modules/space/rendering/renderablesatellites.cpp +++ b/modules/space/rendering/renderablesatellites.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include @@ -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 )); diff --git a/modules/space/rendering/renderablesmallbody.cpp b/modules/space/rendering/renderablesmallbody.cpp index 72414c3453..cd37e99256 100644 --- a/modules/space/rendering/renderablesmallbody.cpp +++ b/modules/space/rendering/renderablesmallbody.cpp @@ -41,6 +41,7 @@ #include #include #include +#include #include #include #include @@ -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 )); diff --git a/modules/space/rendering/renderablestars.cpp b/modules/space/rendering/renderablestars.cpp index eefa4ba887..6e1035759f 100644 --- a/modules/space/rendering/renderablestars.cpp +++ b/modules/space/rendering/renderablestars.cpp @@ -440,12 +440,12 @@ RenderableStars::RenderableStars(const ghoul::Dictionary& dictionary) addProperty(_speckFile); _colorTexturePath = p.colorMap.string(); - _colorTextureFile = std::make_unique(_colorTexturePath); + _colorTextureFile = std::make_unique(_colorTexturePath.value()); - /*_shapeTexturePath = absPath(dictionary.value( - ShapeTextureInfo.identifier - )); - _shapeTextureFile = std::make_unique(_shapeTexturePath);*/ + //_shapeTexturePath = absPath(dictionary.value( + // ShapeTextureInfo.identifier + // )); + //_shapeTextureFile = std::make_unique(_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(_pointSpreadFunctionTexturePath); - _pointSpreadFunctionTexturePath.onChange([&]() { + _pointSpreadFunctionFile = std::make_unique( + _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( - _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( - _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; } diff --git a/modules/space/translation/horizonstranslation.cpp b/modules/space/translation/horizonstranslation.cpp index 6f294d3055..ef58b66467 100644 --- a/modules/space/translation/horizonstranslation.cpp +++ b/modules/space/translation/horizonstranslation.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include namespace { @@ -69,8 +70,10 @@ HorizonsTranslation::HorizonsTranslation() _horizonsTextFile.onChange([&](){ requireUpdate(); - _fileHandle = std::make_unique(_horizonsTextFile); - _fileHandle->setCallback([&](const ghoul::filesystem::File&) { + _fileHandle = std::make_unique( + _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 diff --git a/modules/space/translation/spicetranslation.cpp b/modules/space/translation/spicetranslation.cpp index 519539d9d6..5b1d298f8b 100644 --- a/modules/space/translation/spicetranslation.cpp +++ b/modules/space/translation/spicetranslation.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include namespace { @@ -97,7 +98,7 @@ SpiceTranslation::SpiceTranslation(const ghoul::Dictionary& dictionary) const Parameters p = codegen::bake(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 )); diff --git a/modules/space/translation/tletranslation.cpp b/modules/space/translation/tletranslation.cpp index 83f5794355..36082a69c8 100644 --- a/modules/space/translation/tletranslation.cpp +++ b/modules/space/translation/tletranslation.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include #include #include @@ -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); diff --git a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp index 376e7c509d..e0017d42ac 100644 --- a/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderablemodelprojection.cpp @@ -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. } diff --git a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp index be21ff31a0..c23bbebe4a 100644 --- a/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp +++ b/modules/spacecraftinstruments/rendering/renderableplaneprojection.cpp @@ -196,9 +196,7 @@ void RenderablePlaneProjection::loadTexture() { _texture = std::move(texture); _textureFile = std::make_unique(_texturePath); - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _textureIsDirty = true; } - ); + _textureFile->setCallback([this]() { _textureIsDirty = true; }); } } } diff --git a/modules/spacecraftinstruments/util/hongkangparser.cpp b/modules/spacecraftinstruments/util/hongkangparser.cpp index 4c413a72df..6832dc8b1a 100644 --- a/modules/spacecraftinstruments/util/hongkangparser.cpp +++ b/modules/spacecraftinstruments/util/hongkangparser.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include 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; } diff --git a/modules/spacecraftinstruments/util/instrumenttimesparser.cpp b/modules/spacecraftinstruments/util/instrumenttimesparser.cpp index 350a5b73fb..0f7b319bd6 100644 --- a/modules/spacecraftinstruments/util/instrumenttimesparser.cpp +++ b/modules/spacecraftinstruments/util/instrumenttimesparser.cpp @@ -29,8 +29,8 @@ #include #include #include -#include #include +#include #include 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& 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; } diff --git a/modules/spacecraftinstruments/util/labelparser.cpp b/modules/spacecraftinstruments/util/labelparser.cpp index f8c2360224..40c06ba146 100644 --- a/modules/spacecraftinstruments/util/labelparser.cpp +++ b/modules/spacecraftinstruments/util/labelparser.cpp @@ -26,12 +26,12 @@ #include #include -#include #include #include #include #include #include +#include #include 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 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 spiceInstrument; spiceInstrument.push_back(_instrumentID); diff --git a/modules/sync/syncs/httpsynchronization.cpp b/modules/sync/syncs/httpsynchronization.cpp index 80acc90ddb..57b20df45c 100644 --- a/modules/sync/syncs/httpsynchronization.cpp +++ b/modules/sync/syncs/httpsynchronization.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -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( diff --git a/modules/sync/syncs/urlsynchronization.cpp b/modules/sync/syncs/urlsynchronization.cpp index b1c75a80a6..9633f63280 100644 --- a/modules/sync/syncs/urlsynchronization.cpp +++ b/modules/sync/syncs/urlsynchronization.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include #include @@ -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 download = std::make_unique( @@ -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); } diff --git a/modules/volume/rendering/renderabletimevaryingvolume.cpp b/modules/volume/rendering/renderabletimevaryingvolume.cpp index 71494ca0ab..f182dd268c 100644 --- a/modules/volume/rendering/renderabletimevaryingvolume.cpp +++ b/modules/volume/rendering/renderabletimevaryingvolume.cpp @@ -44,6 +44,7 @@ #include #include #include +#include #include 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 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& 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 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; diff --git a/modules/volume/tasks/generaterawvolumetask.cpp b/modules/volume/tasks/generaterawvolumetask.cpp index 53372f91f8..4236267d8d 100644 --- a/modules/volume/tasks/generaterawvolumetask.cpp +++ b/modules/volume/tasks/generaterawvolumetask.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include 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 writer(_rawVolumeOutputPath); diff --git a/modules/webbrowser/src/browserinstance.cpp b/modules/webbrowser/src/browserinstance.cpp index 2a4b6d6492..9e84c5922b 100644 --- a/modules/webbrowser/src/browserinstance.cpp +++ b/modules/webbrowser/src/browserinstance.cpp @@ -35,6 +35,7 @@ #include #include #include +#include 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; } diff --git a/modules/webbrowser/webbrowsermodule.cpp b/modules/webbrowser/webbrowsermodule.cpp index 5f20bffa7a..63cbd14390 100644 --- a/modules/webbrowser/webbrowsermodule.cpp +++ b/modules/webbrowser/webbrowsermodule.cpp @@ -37,6 +37,7 @@ #include #include #include +#include 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 )); diff --git a/src/documentation/verifier.cpp b/src/documentation/verifier.cpp index a4a9c20d9b..22ffdec0a6 100644 --- a/src/documentation/verifier.cpp +++ b/src/documentation/verifier.cpp @@ -733,18 +733,18 @@ TestResult AndVerifier::operator()(const ghoul::Dictionary& dictionary, ); if (success) { - TestResult res; - res.success = true; - return res; + TestResult r; + r.success = true; + return r; } else { - TestResult res; - res.success = false; + TestResult r; + r.success = false; TestResult::Offense o; o.offender = key; o.reason = TestResult::Offense::Reason::Verification; - res.offenses.push_back(o); - return res; + r.offenses.push_back(o); + return r; } } @@ -810,18 +810,18 @@ TestResult OrVerifier::operator()(const ghoul::Dictionary& dictionary, ); if (success) { - TestResult res; - res.success = true; - return res; + TestResult r; + r.success = true; + return r; } else { - TestResult res; - res.success = false; + TestResult r; + r.success = false; TestResult::Offense o; o.offender = key; o.reason = TestResult::Offense::Reason::Verification; - res.offenses.push_back(o); - return res; + r.offenses.push_back(o); + return r; } } diff --git a/src/engine/configuration.cpp b/src/engine/configuration.cpp index cf586ec77a..c3d19c0498 100644 --- a/src/engine/configuration.cpp +++ b/src/engine/configuration.cpp @@ -605,31 +605,23 @@ void parseLuaState(Configuration& configuration) { documentation::Documentation Configuration::Documentation = codegen::doc(); -std::string findConfiguration(const std::string& filename) { - using ghoul::filesystem::Directory; - - Directory directory = FileSys.absolutePath("${BIN}"); +std::filesystem::path findConfiguration(const std::string& filename) { + std::filesystem::path directory = absPath("${BIN}"); while (true) { - std::string fullPath = FileSys.pathByAppendingComponent( - directory, - filename - ); - - if (FileSys.fileExists(fullPath)) { + std::filesystem::path p = directory / filename; + if (std::filesystem::exists(p) && std::filesystem::is_regular_file(p)) { // We have found the configuration file and can bail out - return fullPath; + return p; } // Otherwise, we traverse the directory tree up - Directory nextDirectory = directory.parentDirectory( - ghoul::filesystem::Directory::AbsolutePath::Yes - ); + std::filesystem::path nextDirectory = directory.parent_path(); - if (directory.path() == nextDirectory.path()) { + if (directory == nextDirectory) { // We have reached the root of the file system and did not find the file throw ghoul::RuntimeError( - "Could not find configuration file '" + filename + "'", + fmt::format("Could not find configuration file '{}'", filename), "ConfigurationManager" ); } @@ -637,21 +629,20 @@ std::string findConfiguration(const std::string& filename) { } } -Configuration loadConfigurationFromFile(const std::string& filename, +Configuration loadConfigurationFromFile(const std::filesystem::path& filename, const std::string& overrideScript) { - ghoul_assert(!filename.empty(), "Filename must not be empty"); - ghoul_assert(FileSys.fileExists(filename), "File must exist"); + ghoul_assert(std::filesystem::is_regular_file(filename), "File must exist"); Configuration result; // If there is an initial config helper file, load it into the state - if (FileSys.fileExists(absPath(InitialConfigHelper))) { + if (std::filesystem::is_regular_file(absPath(InitialConfigHelper))) { ghoul::lua::runScriptFile(result.state, absPath(InitialConfigHelper)); } // Load the configuration file into the state - ghoul::lua::runScriptFile(result.state, filename); + ghoul::lua::runScriptFile(result.state, filename.string()); if (!overrideScript.empty()) { LDEBUGC("Configuration", "Executing Lua script passed through the commandline:"); diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index 4efe92c9e6..cc8429fa84 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #ifdef OPENSPACE_CURL_ENABLED @@ -133,36 +134,36 @@ DownloadManager::DownloadManager(UseMultipleThreads useMultipleThreads) std::shared_ptr DownloadManager::downloadFile( const std::string& url, - const ghoul::filesystem::File& file, + const std::filesystem::path& file, OverrideFile overrideFile, FailOnError failOnError, unsigned int timeout_secs, DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback) { - if (!overrideFile && FileSys.fileExists(file)) { + if (!overrideFile && std::filesystem::is_regular_file(file)) { return nullptr; } - std::shared_ptr future = std::make_shared(file.filename()); + std::shared_ptr future = std::make_shared( + file.filename().string() + ); errno = 0; #ifdef WIN32 FILE* fp; - errno_t error = fopen_s(&fp, file.path().c_str(), "wb"); + errno_t error = fopen_s(&fp, file.string().c_str(), "wb"); if (error != 0) { - LERROR( - "Could not open/create file:" + file.path() + - ". Errno: " + std::to_string(errno) - ); + LERROR(fmt::format( + "Could not open/create file: {}. Errno: {}", file, errno + )); } #else - FILE* fp = fopen(file.path().c_str(), "wb"); // write binary + FILE* fp = fopen(file.string().c_str(), "wb"); // write binary #endif // WIN32 if (!fp) { - LERROR( - "Could not open/create file:" + file.path() + - ". Errno: " + std::to_string(errno) - ); + LERROR(fmt::format( + "Could not open/create file: {}. Errno: {}", file, errno + )); } auto downloadFunction = [url, failOnError, timeout_secs, diff --git a/src/engine/openspaceengine.cpp b/src/engine/openspaceengine.cpp index dcc7785866..2db6e17405 100644 --- a/src/engine/openspaceengine.cpp +++ b/src/engine/openspaceengine.cpp @@ -95,8 +95,6 @@ namespace { constexpr const char* _loggerCat = "OpenSpaceEngine"; - constexpr const int CacheVersion = 1; - } // namespace namespace openspace { @@ -155,9 +153,7 @@ void OpenSpaceEngine::registerPathTokens() { // overwrite the default path of the cfg directory using T = std::string; for (const std::pair& path : global::configuration->pathTokens) { - std::string fullKey = ghoul::filesystem::FileSystem::TokenOpeningBraces + - path.first + - ghoul::filesystem::FileSystem::TokenClosingBraces; + std::string fullKey = "${" + path.first + "}"; LDEBUG(fmt::format("Registering path {}: {}", fullKey, path.second)); const bool overrideBase = (fullKey == "${BASE}"); @@ -210,14 +206,13 @@ void OpenSpaceEngine::initialize() { // Create directories that doesn't exist for (const std::string& token : FileSys.tokens()) { - if (!FileSys.directoryExists(token)) { - std::string p = absPath(token); - FileSys.createDirectory(p, ghoul::filesystem::FileSystem::Recursive::Yes); + if (!std::filesystem::is_directory(token)) { + std::filesystem::create_directories(absPath(token)); } } try { - FileSys.createCacheManager(cacheFolder, CacheVersion); + FileSys.createCacheManager(cacheFolder); } catch (const ghoul::RuntimeError& e) { LFATAL("Could not create Cache Manager"); @@ -307,11 +302,11 @@ void OpenSpaceEngine::initialize() { std::string outputAsset = outputScenePath + "/" + global::configuration->profile + ".asset"; - if (FileSys.fileExists(inputUserProfile)) { + if (std::filesystem::is_regular_file(inputUserProfile)) { inputProfile = inputUserProfile; } - if (!FileSys.fileExists(inputProfile)) { + if (!std::filesystem::is_regular_file(inputProfile)) { LERROR(fmt::format( "Could not load profile '{}': File does not exist", inputProfile) ); @@ -352,7 +347,7 @@ void OpenSpaceEngine::initialize() { // Set up asset loader global::openSpaceEngine->_assetManager = std::make_unique( global::scriptEngine->luaState(), - FileSys.absPath("${ASSETS}") + absPath("${ASSETS}") ); global::scriptEngine->addLibrary( @@ -962,16 +957,13 @@ void OpenSpaceEngine::createUserDirectoriesIfNecessary() { LTRACE(absPath("${USER}")); if (!std::filesystem::exists(absPath("${USER_ASSETS}"))) { - FileSys.createDirectory(absPath("${USER_ASSETS}"), - ghoul::filesystem::FileSystem::Recursive::Yes); + std::filesystem::create_directories(absPath("${USER_ASSETS}")); } if (!std::filesystem::exists(absPath("${USER_PROFILES}"))) { - FileSys.createDirectory(absPath("${USER_PROFILES}"), - ghoul::filesystem::FileSystem::Recursive::Yes); + std::filesystem::create_directories(absPath("${USER_PROFILES}")); } if (!std::filesystem::exists(absPath("${USER_CONFIG}"))) { - FileSys.createDirectory(absPath("${USER_CONFIG}"), - ghoul::filesystem::FileSystem::Recursive::Yes); + std::filesystem::create_directories(absPath("${USER_CONFIG}")); } } @@ -984,7 +976,7 @@ void OpenSpaceEngine::runGlobalCustomizationScripts() { for (const std::string& script : global::configuration->globalCustomizationScripts) { std::string s = absPath(script); - if (FileSys.fileExists(s)) { + if (std::filesystem::is_regular_file(s)) { try { LINFO(fmt::format("Running global customization script: {}", s)); ghoul::lua::runScriptFile(state, s); @@ -1004,19 +996,19 @@ void OpenSpaceEngine::loadFonts() { using T = std::string; for (const std::pair& font : global::configuration->fonts) { std::string key = font.first; - std::string fontName = absPath(font.second); + std::filesystem::path fontName = absPath(font.second); - if (!FileSys.fileExists(fontName)) { - LERROR(fmt::format("Could not find font '{}' for key '{}'", fontName, key)); + if (!std::filesystem::is_regular_file(fontName)) { + LERROR(fmt::format("Could not find font {} for key '{}'", fontName, key)); continue; } - LDEBUG(fmt::format("Registering font '{}' with key '{}'", fontName, key)); + LDEBUG(fmt::format("Registering font {} with key '{}'", fontName, key)); bool success = global::fontManager->registerFontPath(key, fontName); if (!success) { LERROR(fmt::format( - "Error registering font '{}' with key '{}'", fontName, key + "Error registering font {} with key '{}'", fontName, key )); } } diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index aa16a79db2..929da98766 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -193,7 +193,7 @@ int setScreenshotFolder(lua_State* L) { std::string arg = ghoul::lua::value(L); lua_pop(L, 0); - std::string folder = FileSys.absolutePath(arg); + std::string folder = absPath(arg); if (!std::filesystem::exists(folder)) { std::filesystem::create_directory(folder); } @@ -332,13 +332,8 @@ int createSingleColorImage(lua_State* L) { const glm::dvec3 color = colorDict.value(key); - const std::string& fileName = FileSys.cacheManager()->cachedFilename( - fmt::format("{}.ppm", name), - "", - ghoul::filesystem::CacheManager::Persistent::Yes - ); - - const bool hasCachedFile = FileSys.fileExists(fileName); + std::string fileName = FileSys.cacheManager()->cachedFilename(name + ".ppm", ""); + const bool hasCachedFile = std::filesystem::is_regular_file(fileName); if (hasCachedFile) { LDEBUGC("OpenSpaceEngine", fmt::format("Cached file '{}' used", fileName)); ghoul::lua::push(L, fileName); diff --git a/src/interaction/navigationhandler.cpp b/src/interaction/navigationhandler.cpp index 203a674f1e..6726e232ef 100644 --- a/src/interaction/navigationhandler.cpp +++ b/src/interaction/navigationhandler.cpp @@ -39,6 +39,7 @@ #include #include #include +#include #include namespace { @@ -470,7 +471,7 @@ void NavigationHandler::loadNavigationState(const std::string& filepath) { const std::string absolutePath = absPath(filepath); LINFO(fmt::format("Reading camera state from file: {}", absolutePath)); - if (!FileSys.fileExists(absolutePath)) { + if (!std::filesystem::is_regular_file(absolutePath)) { throw ghoul::FileNotFoundError(absolutePath, "NavigationState"); } diff --git a/src/interaction/sessionrecording.cpp b/src/interaction/sessionrecording.cpp index d89b9c8c11..906731a9b7 100644 --- a/src/interaction/sessionrecording.cpp +++ b/src/interaction/sessionrecording.cpp @@ -47,6 +47,7 @@ #include #include #include +#include #include #ifdef WIN32 @@ -165,7 +166,7 @@ bool SessionRecording::handleRecordingFile(std::string filenameIn) { std::string absFilename = absPath("${RECORDINGS}/" + filenameIn); - if (FileSys.fileExists(absFilename)) { + if (std::filesystem::is_regular_file(absFilename)) { LERROR(fmt::format( "Unable to start recording; file {} already exists.", absFilename.c_str() )); @@ -196,11 +197,8 @@ bool SessionRecording::startRecording(const std::string& filename) { LERROR("Unable to start recording while in session playback mode"); return false; } - if (!FileSys.directoryExists(absPath("${RECORDINGS}"))) { - FileSys.createDirectory( - absPath("${RECORDINGS}"), - ghoul::filesystem::FileSystem::Recursive::Yes - ); + if (!std::filesystem::is_directory(absPath("${RECORDINGS}"))) { + std::filesystem::create_directories(absPath("${RECORDINGS}")); } bool recordingFileOK = handleRecordingFile(filename); @@ -256,7 +254,7 @@ bool SessionRecording::startPlayback(std::string& filename, //Run through conversion in case file is older. Does nothing if the file format // is up-to-date filename = convertFile(filename); - if (FileSys.fileExists(filename)) { + if (std::filesystem::is_regular_file(filename)) { absFilename = filename; } else { @@ -272,7 +270,7 @@ bool SessionRecording::startPlayback(std::string& filename, return false; } - if (!FileSys.fileExists(absFilename)) { + if (!std::filesystem::is_regular_file(absFilename)) { LERROR("Cannot find the specified playback file."); cleanUpPlayback(); return false; @@ -1713,20 +1711,25 @@ std::vector SessionRecording::playbackList() const { const std::string path = absPath("${RECORDINGS}"); std::vector fileList; - ghoul::filesystem::Directory currentDir(path); - std::vector allInputFiles = currentDir.readFiles(); - for (const std::string& f : allInputFiles) { - // Remove path and keep only the filename - const std::string filename = f.substr(path.length() + 1, f.length() - path.length() - 1); - bool isHidden = false; + if (std::filesystem::is_directory(path)) { + namespace fs = std::filesystem; + for (const fs::directory_entry& e : fs::directory_iterator(path)) { + if (!e.is_regular_file()) { + continue; + } + + // Remove path and keep only the filename + const std::string filename = e.path().filename().string(); #ifdef WIN32 - DWORD attributes = GetFileAttributes(f.c_str()); - isHidden = attributes & FILE_ATTRIBUTE_HIDDEN; + DWORD attributes = GetFileAttributes(e.path().string().c_str()); + bool isHidden = attributes & FILE_ATTRIBUTE_HIDDEN; #else - isHidden = filename.rfind(".", 0) != 0; + bool isHidden = filename.rfind(".", 0) != 0; #endif // WIN32 - if (!isHidden) { //Don't add hidden files - fileList.push_back(filename); + if (!isHidden) { + // Don't add hidden files + fileList.push_back(filename); + } } } return fileList; @@ -1794,7 +1797,7 @@ void SessionRecording::readFileIntoStringStream(std::string filename, throw ConversionError("Playback filename must not contain path (/) elements"); } std::string conversionInFilename = absPath("${RECORDINGS}/" + filename); - if (!FileSys.fileExists(conversionInFilename)) { + if (!std::filesystem::is_regular_file(conversionInFilename)) { throw ConversionError(fmt::format( "Cannot find the specified playback file '{}' to convert.", conversionInFilename diff --git a/src/interaction/tasks/convertrecfileversiontask.cpp b/src/interaction/tasks/convertrecfileversiontask.cpp index 83eea9640c..1a12609377 100644 --- a/src/interaction/tasks/convertrecfileversiontask.cpp +++ b/src/interaction/tasks/convertrecfileversiontask.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -56,8 +57,8 @@ ConvertRecFileVersionTask::ConvertRecFileVersionTask(const ghoul::Dictionary& di _inFilename = _inFilename.substr(idx + 1); } - ghoul_assert(FileSys.fileExists(_inFilePath), "The filename must exist"); - if (!FileSys.fileExists(_inFilePath)) { + ghoul_assert(std::filesystem::is_regular_file(_inFilePath), "The file must exist"); + if (!std::filesystem::is_regular_file(_inFilePath)) { LERROR(fmt::format("Failed to load session recording file: {}", _inFilePath)); } else { @@ -72,8 +73,10 @@ ConvertRecFileVersionTask::~ConvertRecFileVersionTask() { } std::string ConvertRecFileVersionTask::description() { - std::string description = "Convert file format of session recording file '" - + _inFilePath + "' to current version."; + std::string description = fmt::format( + "Convert file format of session recording file '{}' to current version", + _inFilePath + ); return description; } diff --git a/src/interaction/tasks/convertrecformattask.cpp b/src/interaction/tasks/convertrecformattask.cpp index 3651d49868..dd4a2a4ed7 100644 --- a/src/interaction/tasks/convertrecformattask.cpp +++ b/src/interaction/tasks/convertrecformattask.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include @@ -51,8 +52,8 @@ ConvertRecFormatTask::ConvertRecFormatTask(const ghoul::Dictionary& dictionary) _inFilePath = absPath(dictionary.value(KeyInFilePath)); _outFilePath = absPath(dictionary.value(KeyOutFilePath)); - ghoul_assert(FileSys.fileExists(_inFilePath), "The filename must exist"); - if (!FileSys.fileExists(_inFilePath)) { + ghoul_assert(std::filesystem::is_regular_file(_inFilePath), "The file must exist"); + if (!std::filesystem::is_regular_file(_inFilePath)) { LERROR(fmt::format("Failed to load session recording file: {}", _inFilePath)); } else { @@ -71,7 +72,8 @@ ConvertRecFormatTask::~ConvertRecFormatTask() { } std::string ConvertRecFormatTask::description() { - std::string description = "Convert session recording file '" + _inFilePath + "' "; + std::string description = + fmt::format("Convert session recording file {}", _inFilePath); if (_fileFormatType == SessionRecording::DataMode::Ascii) { description += "(ascii format) "; } @@ -81,7 +83,7 @@ std::string ConvertRecFormatTask::description() { else { description += "(UNKNOWN format) "; } - description += "conversion to file '" + _outFilePath + "'."; + description += fmt::format("conversion to file {}.", _outFilePath); return description; } @@ -103,21 +105,20 @@ void ConvertRecFormatTask::convert() { expectedFileExtension_out = SessionRecording::FileExtensionBinary; } - if (!SessionRecording::hasFileExtension(_inFilePath, expectedFileExtension_in)) { + if (std::filesystem::path(_inFilePath).extension() != expectedFileExtension_in) { LWARNING(fmt::format( - "Input filename doesn't have expected {} format file extension", - currentFormat) - ); + "Input filename doesn't have expected {} format file extension", currentFormat + )); } - if (SessionRecording::hasFileExtension(_outFilePath, expectedFileExtension_in)) { + if (std::filesystem::path(_outFilePath).extension() == expectedFileExtension_in) { LERROR(fmt::format( "Output filename has {} file extension, but is conversion from {}", - currentFormat, - currentFormat) - ); + currentFormat, currentFormat + )); return; } - else if (!SessionRecording::hasFileExtension(_outFilePath, expectedFileExtension_out)) + else if (std::filesystem::path(_outFilePath).extension() != + expectedFileExtension_out) { _outFilePath += expectedFileExtension_out; } @@ -142,7 +143,7 @@ void ConvertRecFormatTask::convert() { convertToAscii(); } else { - //Add error output for file type not recognized + // Add error output for file type not recognized LERROR("Session recording file unrecognized format type."); } } diff --git a/src/mission/mission.cpp b/src/mission/mission.cpp index feadaac081..bfdaaafc38 100644 --- a/src/mission/mission.cpp +++ b/src/mission/mission.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include namespace { @@ -165,7 +166,7 @@ void MissionPhase::phaseTrace(double time, Trace& trace, int maxDepth) const { Mission missionFromFile(const std::string& filename) { ghoul_assert(!filename.empty(), "filename must not be empty"); ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens"); - ghoul_assert(FileSys.fileExists(filename), "filename must exist"); + ghoul_assert(std::filesystem::is_regular_file(filename), "filename must exist"); ghoul::Dictionary missionDict; ghoul::lua::loadDictionaryFromFile(filename, missionDict); diff --git a/src/mission/missionmanager.cpp b/src/mission/missionmanager.cpp index c84cbd8399..1ec94598b4 100644 --- a/src/mission/missionmanager.cpp +++ b/src/mission/missionmanager.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include "missionmanager_lua.inl" @@ -58,7 +59,10 @@ bool MissionManager::hasCurrentMission() const { std::string MissionManager::loadMission(const std::string& filename) { ghoul_assert(!filename.empty(), "filename must not be empty"); ghoul_assert(!FileSys.containsToken(filename), "filename must not contain tokens"); - ghoul_assert(FileSys.fileExists(filename), "filename " + filename + " must exist"); + ghoul_assert( + std::filesystem::is_regular_file(filename), + "filename " + filename + " must exist" + ); // Changing the values might invalidate the _currentMission iterator std::string currentMission = hasCurrentMission() ? _currentMission->first : ""; diff --git a/src/properties/list/intlistproperty.cpp b/src/properties/list/intlistproperty.cpp index 8423f18ec4..243f4f4eb6 100644 --- a/src/properties/list/intlistproperty.cpp +++ b/src/properties/list/intlistproperty.cpp @@ -57,7 +57,7 @@ std::vector IntListProperty::fromLuaConversion(lua_State* state, lua_pushnil(state); while (lua_next(state, -2) != 0) { if (lua_isnumber(state, -1)) { - result.emplace_back(lua_tonumber(state, -1)); + result.emplace_back(static_cast(lua_tonumber(state, -1))); } else { success = false; diff --git a/src/rendering/helper.cpp b/src/rendering/helper.cpp index 43fa4fae94..aaf4daa902 100644 --- a/src/rendering/helper.cpp +++ b/src/rendering/helper.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -295,18 +296,18 @@ void deinitialize() { ghoul_assert(isInitialized, "Rendering Helper not initialized"); if (!xyuvrgbaVertexFile.empty()) { - FileSys.deleteFile(xyuvrgbaVertexFile); + std::filesystem::remove(xyuvrgbaVertexFile); } if (!xyuvrgbaFragmentFile.empty()) { - FileSys.deleteFile(xyuvrgbaFragmentFile); + std::filesystem::remove(xyuvrgbaFragmentFile); } shaders.xyuvrgba.program = nullptr; if (!screenFillingVertexFile.empty()) { - FileSys.deleteFile(screenFillingVertexFile); + std::filesystem::remove(screenFillingVertexFile); } if (!screenFillingFragmentFile.empty()) { - FileSys.deleteFile(screenFillingVertexFile); + std::filesystem::remove(screenFillingVertexFile); } shaders.screenfilling.program = nullptr; diff --git a/src/rendering/luaconsole.cpp b/src/rendering/luaconsole.cpp index dfbfc483d5..2d953ac33b 100644 --- a/src/rendering/luaconsole.cpp +++ b/src/rendering/luaconsole.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include namespace { @@ -169,13 +170,8 @@ LuaConsole::~LuaConsole() {} // NOLINT void LuaConsole::initialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename( - HistoryFile, - "", - ghoul::filesystem::CacheManager::Persistent::Yes - ); - - if (FileSys.fileExists(filename)) { + const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); + if (std::filesystem::is_regular_file(filename)) { std::ifstream file(filename, std::ios::binary | std::ios::in); if (file.good()) { @@ -234,11 +230,7 @@ void LuaConsole::initialize() { void LuaConsole::deinitialize() { ZoneScoped - const std::string filename = FileSys.cacheManager()->cachedFilename( - HistoryFile, - "", - ghoul::filesystem::CacheManager::Persistent::Yes - ); + const std::string filename = FileSys.cacheManager()->cachedFilename(HistoryFile, ""); // We want to limit the command history to a realistic value, so that it doesn't // grow without bounds diff --git a/src/rendering/renderengine.cpp b/src/rendering/renderengine.cpp index ff37ec8c07..9971de3eb3 100644 --- a/src/rendering/renderengine.cpp +++ b/src/rendering/renderengine.cpp @@ -372,8 +372,8 @@ RenderEngine::RenderEngine() strftime(date, sizeof(date), "%Y-%m-%d-%H-%M", nowTime); std::string newFolder = absPath("${STARTUP_SCREENSHOT}/" + std::string(date)); - if (!FileSys.directoryExists(newFolder)) { - FileSys.createDirectory(newFolder); + if (!std::filesystem::is_directory(newFolder)) { + std::filesystem::create_directory(newFolder); } FileSys.registerPathToken( "${SCREENSHOTS}", @@ -1101,11 +1101,8 @@ void RenderEngine::takeScreenshot() { // screenshot folder everytime we start OpenSpace even when we are not taking any // screenshots. So the first time we actually take one, we create the folder: - if (!FileSys.directoryExists(absPath("${SCREENSHOTS}"))) { - FileSys.createDirectory( - absPath("${SCREENSHOTS}"), - ghoul::filesystem::FileSystem::Recursive::Yes - ); + if (!std::filesystem::is_directory(absPath("${SCREENSHOTS}"))) { + std::filesystem::create_directories(absPath("${SCREENSHOTS}")); } _latestScreenshotNumber = global::windowDelegate->takeScreenshot(_applyWarping); diff --git a/src/rendering/texturecomponent.cpp b/src/rendering/texturecomponent.cpp index ce771887f8..fb41eb6fee 100644 --- a/src/rendering/texturecomponent.cpp +++ b/src/rendering/texturecomponent.cpp @@ -77,23 +77,21 @@ void TextureComponent::uploadToGpu() { } } -void TextureComponent::loadFromFile(const std::string& path) { +void TextureComponent::loadFromFile(const std::filesystem::path& path) { if (!path.empty()) { using namespace ghoul::io; using namespace ghoul::opengl; std::unique_ptr texture = TextureReader::ref().loadTexture( - absPath(path) + absPath(path.string()) ); if (texture) { - LDEBUG(fmt::format("Loaded texture from '{}'", absPath(path))); + LDEBUG(fmt::format("Loaded texture from '{}'", absPath(path.string()))); _texture = std::move(texture); _textureFile = std::make_unique(path); if (_shouldWatchFile) { - _textureFile->setCallback( - [&](const ghoul::filesystem::File&) { _fileIsDirty = true; } - ); + _textureFile->setCallback([this]() { _fileIsDirty = true; }); } _fileIsDirty = false; diff --git a/src/rendering/transferfunction.cpp b/src/rendering/transferfunction.cpp index db342727d0..d0f8f81c30 100644 --- a/src/rendering/transferfunction.cpp +++ b/src/rendering/transferfunction.cpp @@ -32,27 +32,14 @@ #include #include #include +#include #include #include namespace { constexpr const char* _loggerCat = "TransferFunction"; - - // @TODO Replace with Filesystem::File extension - bool hasExtension(const std::string& filepath, const std::string& extension) { - std::string ending = "." + extension; - if (filepath.length() > ending.length()) { - return (0 == filepath.compare( - filepath.length() - ending.length(), - ending.length(), ending)); - } - else { - return false; - } - } } // namespace - namespace openspace { TransferFunction::TransferFunction(const std::string& filepath, @@ -70,20 +57,15 @@ void TransferFunction::setPath(const std::string& filepath) { _file = nullptr; } std::string f = absPath(filepath); - if (!FileSys.fileExists(f)) { + if (!std::filesystem::is_regular_file(f)) { LERROR("Could not find transfer function file."); _file = nullptr; return; } _filepath = f; - _file = std::make_unique( - _filepath, - ghoul::filesystem::File::RawPath::Yes - ); + _file = std::make_unique(_filepath); _needsUpdate = true; - _file->setCallback([this](const ghoul::filesystem::File&) { - _needsUpdate = true; - }); + _file->setCallback([this]() { _needsUpdate = true; }); } ghoul::opengl::Texture& TransferFunction::texture() { @@ -94,7 +76,7 @@ ghoul::opengl::Texture& TransferFunction::texture() { void TransferFunction::update() { if (_needsUpdate) { - if (hasExtension(_filepath, "txt")) { + if (std::filesystem::path(_filepath).extension() == ".txt") { setTextureFromTxt(); } else { @@ -114,7 +96,7 @@ void TransferFunction::setCallback(TfChangedCallback callback) { void TransferFunction::setTextureFromTxt() { std::ifstream in; - in.open(_filepath.c_str()); + in.open(_filepath); if (!in.is_open()) { throw ghoul::FileNotFoundError(_filepath); diff --git a/src/scene/asset.cpp b/src/scene/asset.cpp index b264fc1e2a..dc03a46118 100644 --- a/src/scene/asset.cpp +++ b/src/scene/asset.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include namespace openspace { @@ -673,7 +674,7 @@ bool Asset::hasAssetFile() const { } std::string Asset::assetDirectory() const { - return ghoul::filesystem::File(_assetPath).directoryName(); + return std::filesystem::path(_assetPath).parent_path().string(); } const std::string& Asset::assetName() const { diff --git a/src/scene/assetloader.cpp b/src/scene/assetloader.cpp index 3e5c76be55..c29f14a7b6 100644 --- a/src/scene/assetloader.cpp +++ b/src/scene/assetloader.cpp @@ -265,7 +265,7 @@ bool AssetLoader::loadAsset(Asset* asset) { setCurrentAsset(parentAsset); }; - if (!FileSys.fileExists(asset->assetFilePath())) { + if (!std::filesystem::is_regular_file(asset->assetFilePath())) { LERROR(fmt::format( "Could not load asset '{}': File does not exist", asset->assetFilePath()) ); @@ -387,10 +387,10 @@ std::string AssetLoader::generateAssetPath(const std::string& baseDirectory, PathType pathType = classifyPath(assetPath); std::string prefix; if (pathType == PathType::RelativeToAsset) { - prefix = baseDirectory + ghoul::filesystem::FileSystem::PathSeparator; + prefix = baseDirectory + '/'; } else if (pathType == PathType::RelativeToAssetRoot) { - prefix = _assetRootDirectory + ghoul::filesystem::FileSystem::PathSeparator; + prefix = _assetRootDirectory + '/'; } // Construct the full path including the .asset extension @@ -405,7 +405,7 @@ std::string AssetLoader::generateAssetPath(const std::string& baseDirectory, if (!hasAssetSuffix) { fullAssetPath += assetSuffix; } - bool fullAssetPathExists = FileSys.fileExists(FileSys.absPath(fullAssetPath)); + bool fullAssetPathExists = std::filesystem::is_regular_file(absPath(fullAssetPath)); // Construct the full path including the .scene extension const std::string sceneSuffix = std::string(".") + SceneFileSuffix; @@ -416,7 +416,8 @@ std::string AssetLoader::generateAssetPath(const std::string& baseDirectory, hasSceneSuffix ? prefix + assetPath : prefix + assetPath + sceneSuffix; - const bool fullScenePathExists = FileSys.fileExists(FileSys.absPath(fullScenePath)); + const bool fullScenePathExists = + std::filesystem::is_regular_file(absPath(fullScenePath)); if (fullAssetPathExists && fullScenePathExists) { LWARNING(fmt::format( @@ -425,21 +426,21 @@ std::string AssetLoader::generateAssetPath(const std::string& baseDirectory, fullAssetPath, fullScenePath, prefix + assetPath, fullAssetPath )); - return FileSys.absPath(fullAssetPath); + return absPath(fullAssetPath); } if (fullScenePathExists) { - return FileSys.absPath(fullScenePath); + return absPath(fullScenePath); } // We don't check whether the file exists here as the error will be more // comprehensively logged by Lua either way - return FileSys.absPath(fullAssetPath); + return absPath(fullAssetPath); } std::shared_ptr AssetLoader::getAsset(const std::string& name) { - ghoul::filesystem::Directory directory = currentDirectory(); - const std::string path = generateAssetPath(directory, name); + std::filesystem::path directory = currentDirectory(); + const std::string path = generateAssetPath(directory.string(), name); // Check if asset is already loaded. const auto it = _trackedAssets.find(path); @@ -507,7 +508,7 @@ void AssetLoader::unrequest(const std::string& identifier) { assetUnrequested(parent, asset); } -ghoul::filesystem::Directory AssetLoader::currentDirectory() const { +std::filesystem::path AssetLoader::currentDirectory() const { if (_currentAsset->hasAssetFile()) { return _currentAsset->assetDirectory(); } @@ -535,8 +536,8 @@ void AssetLoader::remove(const std::string& identifier) { } std::shared_ptr AssetLoader::has(const std::string& identifier) const { - ghoul::filesystem::Directory directory = currentDirectory(); - std::string path = generateAssetPath(directory, identifier); + std::filesystem::path directory = currentDirectory(); + std::string path = generateAssetPath(directory.string(), identifier); const auto it = _trackedAssets.find(path); if (it == _trackedAssets.end()) { @@ -641,8 +642,7 @@ int AssetLoader::localResourceLua(Asset* asset) { ghoul::lua::PopValue::Yes ); - const std::string resolvedName = - asset->assetDirectory() + ghoul::filesystem::FileSystem::PathSeparator + name; + const std::string resolvedName = fmt::format("{}/{}", asset->assetDirectory(), name); lua_pushstring(*_luaState, resolvedName.c_str()); @@ -742,11 +742,11 @@ int AssetLoader::existsLua(Asset*) { const std::string assetName = luaL_checkstring(*_luaState, 1); - const ghoul::filesystem::Directory directory = currentDirectory(); - const std::string path = generateAssetPath(directory, assetName); + const std::filesystem::path directory = currentDirectory(); + const std::string path = generateAssetPath(directory.string(), assetName); lua_settop(*_luaState, 0); - lua_pushboolean(*_luaState, FileSys.fileExists(path)); + lua_pushboolean(*_luaState, std::filesystem::is_regular_file(path)); ghoul_assert(lua_gettop(*_luaState) == 1, "Incorrect number of items left on stack"); return 1; } diff --git a/src/scene/profile_lua.inl b/src/scene/profile_lua.inl index 385b26b0f8..db1f350984 100644 --- a/src/scene/profile_lua.inl +++ b/src/scene/profile_lua.inl @@ -51,8 +51,6 @@ int saveSettingsToProfile(lua_State* L) { std::string saveFilePath; if (n == 0) { - const ghoul::filesystem::File f = global::configuration->profile; - std::time_t t = std::time(nullptr); std::tm* utcTime = std::gmtime(&t); ghoul_assert(utcTime, "Conversion to UTC failed"); @@ -66,12 +64,14 @@ int saveSettingsToProfile(lua_State* L) { utcTime->tm_min, utcTime->tm_sec ); - std::string newFile = fmt::format("{}_{}", f.fullBaseName(), time); + std::filesystem::path path = global::configuration->profile; + path.replace_extension(); + std::string newFile = fmt::format("{}_{}", path.string(), time); std::string sourcePath = fmt::format("{}/{}.profile", absPath("${USER_PROFILES}"), global::configuration->profile); std::string destPath = fmt::format("{}/{}.profile", absPath("${PROFILES}"), global::configuration->profile); - if (!FileSys.fileExists(sourcePath)) { + if (!std::filesystem::is_regular_file(sourcePath)) { sourcePath = absPath("${USER_PROFILES}") + '/' + global::configuration->profile + ".profile"; } @@ -105,12 +105,12 @@ int saveSettingsToProfile(lua_State* L) { std::string absFilename = fmt::format("{}/{}.profile", absPath("${PROFILES}"), saveFilePath); - if (!FileSys.fileExists(absFilename)) { + if (!std::filesystem::is_regular_file(absFilename)) { absFilename = absPath("${USER_PROFILES}/" + saveFilePath + ".profile"); } const bool overwrite = (n == 2) ? ghoul::lua::value(L, 2) : true; - if (FileSys.fileExists(absFilename) && !overwrite) { + if (std::filesystem::is_regular_file(absFilename) && !overwrite) { return luaL_error( L, fmt::format( diff --git a/src/scripting/scriptengine.cpp b/src/scripting/scriptengine.cpp index 0693847c5c..97df3646a5 100644 --- a/src/scripting/scriptengine.cpp +++ b/src/scripting/scriptengine.cpp @@ -34,6 +34,7 @@ #include #include #include +#include #include #include "scriptengine_lua.inl" @@ -211,7 +212,7 @@ bool ScriptEngine::runScriptFile(const std::string& filename) { LWARNING("Filename was empty"); return false; } - if (!FileSys.fileExists(filename)) { + if (!std::filesystem::is_regular_file(filename)) { LERROR(fmt::format("Script with name '{}' did not exist", filename)); return false; } diff --git a/src/scripting/scriptengine_lua.inl b/src/scripting/scriptengine_lua.inl index d221232ca6..46b742f3be 100644 --- a/src/scripting/scriptengine_lua.inl +++ b/src/scripting/scriptengine_lua.inl @@ -22,69 +22,13 @@ * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************************/ -#include #include +#include #include namespace openspace::luascriptfunctions { -namespace { - -// Defining a common walk function that works off a pointer-to-member function -template -int walkCommon(lua_State* L, Func func) { - int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 1, 3 }, "lua::walkCommon"); - - std::string path = ghoul::lua::value(L, 1); - - std::vector result; - if (nArguments == 1) { - // Only the path was passed - result = std::invoke( - func, - ghoul::filesystem::Directory(path), - ghoul::filesystem::Directory::Recursive::No, - ghoul::filesystem::Directory::Sort::No - ); - } - else if (nArguments == 2) { - // The path and the recursive value were passed - const bool recursive = ghoul::lua::value(L, 2); - result = std::invoke( - func, - ghoul::filesystem::Directory(path), - ghoul::filesystem::Directory::Recursive(recursive), - ghoul::filesystem::Directory::Sort::No - ); - } - else if (nArguments == 3) { - // All three arguments were passed - const bool recursive = ghoul::lua::value(L, 2); - const bool sorted = ghoul::lua::value(L, 3); - result = std::invoke( - func, - ghoul::filesystem::Directory(path), - ghoul::filesystem::Directory::Recursive(recursive), - ghoul::filesystem::Directory::Sort(sorted) - ); - } - - lua_settop(L, 0); - - // Copy values into the lua_State - lua_newtable(L); - - for (int i = 0; i < static_cast(result.size()); ++i) { - lua_pushstring(L, result[i].c_str()); - lua_rawseti(L, -2, i + 1); - } - - ghoul_assert(lua_gettop(L) == 1, "Incorrect number of items left on stack"); - return 1; -} -} // namespace - int printInternal(ghoul::logging::LogLevel level, lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::printInternal"); @@ -245,7 +189,7 @@ int fileExists(lua_State* L) { 1, ghoul::lua::PopValue::Yes ); - const bool e = FileSys.fileExists(absPath(file)); + const bool e = std::filesystem::is_regular_file(absPath(file)); ghoul::lua::push(L, e); @@ -266,7 +210,7 @@ int directoryExists(lua_State* L) { 1, ghoul::lua::PopValue::Yes ); - const bool e = FileSys.directoryExists(absPath(file)); + const bool e = std::filesystem::is_directory(absPath(file)); ghoul::lua::push(L, e); @@ -274,6 +218,45 @@ int directoryExists(lua_State* L) { return 1; } +int walkCommon(lua_State* L, std::function filter) { + int nArguments = ghoul::lua::checkArgumentsAndThrow(L, { 1, 3 }, "lua::walkCommon"); + + const std::string path = ghoul::lua::value(L, 1); + const bool recursive = nArguments >= 2 ? ghoul::lua::value(L, 2) : false; + const bool sorted = nArguments == 3 ? ghoul::lua::value(L, 3) : false; + + namespace fs = std::filesystem; + std::vector result; + if (fs::is_directory(path)) { + if (recursive) { + for (fs::directory_entry e : fs::recursive_directory_iterator(path)) { + if (filter(e)) { + result.push_back(e); + } + } + } + else { + for (fs::directory_entry e : fs::directory_iterator(path)) { + if (filter(e)) { + result.push_back(e); + } + } + } + + if (sorted) { + std::sort(result.begin(), result.end()); + } + } + + lua_newtable(L); + + for (int i = 0; i < static_cast(result.size()); ++i) { + lua_pushstring(L, result[i].path().string().c_str()); + lua_rawseti(L, -2, i + 1); + } + return 1; +} + /** * \ingroup LuaScripts * walkDirectory(string, bool, bool): @@ -284,7 +267,11 @@ int directoryExists(lua_State* L) { * table that is returned is sorted. The default value for this parameter is "false". */ int walkDirectory(lua_State* L) { - return walkCommon(L, &ghoul::filesystem::Directory::read); + namespace fs = std::filesystem; + return walkCommon( + L, + [](const fs::path& p) { return fs::is_directory(p) || fs::is_regular_file(p); } + ); } /** @@ -297,8 +284,8 @@ int walkDirectory(lua_State* L) { * table that is returned is sorted. The default value for this parameter is "false". */ int walkDirectoryFiles(lua_State* L) { - return walkCommon(L, &ghoul::filesystem::Directory::readFiles); - + namespace fs = std::filesystem; + return walkCommon(L, [](const fs::path& p) { return fs::is_regular_file(p); }); } /** @@ -311,10 +298,10 @@ int walkDirectoryFiles(lua_State* L) { * table that is returned is sorted. The default value for this parameter is "false". */ int walkDirectoryFolder(lua_State* L) { - return walkCommon(L, &ghoul::filesystem::Directory::readDirectories); + namespace fs = std::filesystem; + return walkCommon(L, [](const fs::path& p) { return fs::is_directory(p); }); } - /** * \ingroup LuaScripts * directoryForPath(string): @@ -325,12 +312,8 @@ int walkDirectoryFolder(lua_State* L) { int directoryForPath(lua_State* L) { ghoul::lua::checkArgumentsAndThrow(L, 1, "lua::directoryForPath"); - std::string file = ghoul::lua::value( - L, - 1, - ghoul::lua::PopValue::Yes - ); - std::string path = ghoul::filesystem::File(std::move(file)).directoryName(); + std::string file = ghoul::lua::value(L, 1, ghoul::lua::PopValue::Yes); + std::string path = std::filesystem::path(std::move(file)).parent_path().string(); ghoul::lua::push(L, path); @@ -369,8 +352,8 @@ int unzipFile(lua_State* L) { int arg = 2; zip_extract(source.c_str(), dest.c_str(), onExtractEntry, &arg); - if (deleteSource) { - FileSys.deleteFile(source); + if (deleteSource && std::filesystem::is_regular_file(source)) { + std::filesystem::remove(source); } lua_settop(L, 0); @@ -436,7 +419,9 @@ int saveLastChangeToProfile(lua_State* L) { filein.close(); fileout.close(); if (found) { - FileSys.deleteFile(assetPath); + if (std::filesystem::is_regular_file(assetPath)) { + std::filesystem::remove(assetPath); + } int success = rename(tempAssetPath.c_str(), assetPath.c_str()); if (success != 0) { std::string error = fmt::format("Error renaming file {} to {}", @@ -445,7 +430,9 @@ int saveLastChangeToProfile(lua_State* L) { printInternal(ghoul::logging::LogLevel::Error, L); return -1; } - FileSys.deleteFile(tempAssetPath); + if (std::filesystem::is_regular_file(tempAssetPath)) { + std::filesystem::remove(tempAssetPath); + } return 0; } else { diff --git a/src/util/httprequest.cpp b/src/util/httprequest.cpp index 4692e19525..7e1ba8d541 100644 --- a/src/util/httprequest.cpp +++ b/src/util/httprequest.cpp @@ -25,10 +25,10 @@ #include #include -#include #include #include #include +#include #ifdef OPENSPACE_CURL_ENABLED #ifdef WIN32 @@ -254,7 +254,7 @@ void AsyncHttpDownload::start(HttpRequest::RequestOptions opt) { try { download(opt); } - catch (const ghoul::filesystem::FileSystem::FileSystemException& e) { + catch (const ghoul::RuntimeError& e) { LERRORC(e.component, e.message); } }); @@ -349,18 +349,17 @@ HttpFileDownload::HttpFileDownload(std::string destination, {} bool HttpFileDownload::initDownload() { - if (!_overwrite && FileSys.fileExists(_destination)) { + if (!_overwrite && std::filesystem::is_regular_file(_destination)) { LWARNING(fmt::format("File {} already exists", _destination)); return false; } - ghoul::filesystem::File destinationFile = _destination; - ghoul::filesystem::Directory d = destinationFile.directoryName(); + std::filesystem::path d = std::filesystem::path(_destination).parent_path(); { - std::lock_guard g(_directoryCreationMutex); - if (!FileSys.directoryExists(d)) { - FileSys.createDirectory(d, ghoul::filesystem::FileSystem::Recursive::Yes); + std::lock_guard g(_directoryCreationMutex); + if (!std::filesystem::is_directory(d)) { + std::filesystem::create_directories(d); } } @@ -392,13 +391,13 @@ bool HttpFileDownload::initDownload() { std::string message(Buffer, size); LERROR(fmt::format( - "Cannot open file {}: {}", std::string(destinationFile), message) + "Cannot open file {}: {}", _destination, message) ); return false; } else { - LERROR(fmt::format("Cannot open file {}", std::string(destinationFile))); + LERROR(fmt::format("Cannot open file {}", _destination)); return false; } #else diff --git a/src/util/openspacemodule.cpp b/src/util/openspacemodule.cpp index 0bc39e71cd..f6df4a3f06 100644 --- a/src/util/openspacemodule.cpp +++ b/src/util/openspacemodule.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include @@ -59,13 +60,9 @@ void OpenSpaceModule::initialize(const ghoul::Dictionary& configuration) { [](char v) { return static_cast(toupper(v)); } ); - std::string moduleToken = - ghoul::filesystem::FileSystem::TokenOpeningBraces + - std::string(ModuleBaseToken) + - upperIdentifier + - ghoul::filesystem::FileSystem::TokenClosingBraces; + std::string moduleToken = "${" + std::string(ModuleBaseToken) + upperIdentifier + "}"; - std::string path = modulePath(); + std::filesystem::path path = modulePath(); LDEBUG(fmt::format("Registering module path {}: {}", moduleToken, path)); FileSys.registerPathToken(moduleToken, std::move(path)); @@ -123,21 +120,22 @@ std::string OpenSpaceModule::modulePath() const { ); // First try the internal module directory - if (FileSys.directoryExists(absPath("${MODULES}/" + moduleIdentifier))) { - return absPath("${MODULES}/" + moduleIdentifier); + std::string path = absPath("${MODULES}/" + moduleIdentifier); + if (std::filesystem::is_directory(path)) { + return path; } else { // Otherwise, it might be one of the external directories for (const char* dir : ModulePaths) { - const std::string& path = std::string(dir) + '/' + moduleIdentifier; - if (FileSys.directoryExists(absPath(path))) { - return absPath(path); + const std::string& p = std::string(dir) + '/' + moduleIdentifier; + if (std::filesystem::is_directory(absPath(p))) { + return absPath(p); } } } // If we got this far, neither the internal module nor any of the external modules fit throw ghoul::RuntimeError( - "Could not resolve path for module '" + identifier() + "'", + fmt::format("Could not resolve path for module {}", identifier()), "OpenSpaceModule" ); } diff --git a/src/util/spicemanager.cpp b/src/util/spicemanager.cpp index 1b22158f2c..884721932d 100644 --- a/src/util/spicemanager.cpp +++ b/src/util/spicemanager.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include "SpiceUsr.h" #include "SpiceZpr.h" @@ -202,14 +203,14 @@ void throwSpiceError(const std::string& errorMessage) { SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { ghoul_assert(!filePath.empty(), "Empty file path"); ghoul_assert( - FileSys.fileExists(filePath), + std::filesystem::is_regular_file(filePath), fmt::format("File '{}' ('{}') does not exist", filePath, absPath(filePath)) ); ghoul_assert( - FileSys.directoryExists(ghoul::filesystem::File(filePath).directoryName()), + std::filesystem::is_directory(std::filesystem::path(filePath).parent_path()), fmt::format( "File '{}' exists, but directory '{}' doesn't", - absPath(filePath), ghoul::filesystem::File(filePath).directoryName() + absPath(filePath), std::filesystem::path(filePath).parent_path().string() ) ); @@ -228,33 +229,27 @@ SpiceManager::KernelHandle SpiceManager::loadKernel(std::string filePath) { // We need to set the current directory as meta-kernels are usually defined relative // to the directory they reside in. The directory change is not necessary for regular // kernels - ghoul::filesystem::Directory currentDirectory = FileSys.currentDirectory(); - using RawPath = ghoul::filesystem::File::RawPath; - std::string fileDirectory = ghoul::filesystem::File( - path, - RawPath::Yes - ).directoryName(); - FileSys.setCurrentDirectory(fileDirectory); + std::filesystem::path currentDirectory = std::filesystem::current_path(); + + std::filesystem::path p = std::filesystem::path(path).parent_path(); + std::filesystem::current_path(p); LINFO(fmt::format("Loading SPICE kernel '{}'", path)); // Load the kernel furnsh_c(path.c_str()); // Reset the current directory to the previous one - FileSys.setCurrentDirectory(currentDirectory); + std::filesystem::current_path(currentDirectory); if (failed_c()) { throwSpiceError("Kernel loading"); } - std::string fileExtension = ghoul::filesystem::File( - path, - RawPath::Yes - ).fileExtension(); - if (fileExtension == "bc" || fileExtension == "BC") { + std::filesystem::path fileExtension = std::filesystem::path(path).extension(); + if (fileExtension == ".bc" || fileExtension == ".BC") { findCkCoverage(path); // binary ck kernel } - else if (fileExtension == "bsp" || fileExtension == "BSP") { + else if (fileExtension == ".bsp" || fileExtension == ".BSP") { findSpkCoverage(path); // binary spk kernel } @@ -1006,7 +1001,10 @@ SpiceManager::TerminatorEllipseResult SpiceManager::terminatorEllipse( void SpiceManager::findCkCoverage(const std::string& path) { ghoul_assert(!path.empty(), "Empty file path"); - ghoul_assert(FileSys.fileExists(path), fmt::format("File '{}' does not exist", path)); + ghoul_assert( + std::filesystem::is_regular_file(path), + fmt::format("File '{}' does not exist", path) + ); constexpr unsigned int MaxObj = 256; constexpr unsigned int WinSiz = 10000; @@ -1062,7 +1060,10 @@ void SpiceManager::findCkCoverage(const std::string& path) { void SpiceManager::findSpkCoverage(const std::string& path) { ghoul_assert(!path.empty(), "Empty file path"); - ghoul_assert(FileSys.fileExists(path), fmt::format("File '{}' does not exist", path)); + ghoul_assert( + std::filesystem::is_regular_file(path), + fmt::format("File '{}' does not exist", path) + ); constexpr unsigned int MaxObj = 256; constexpr unsigned int WinSiz = 10000; diff --git a/src/util/spicemanager_lua.inl b/src/util/spicemanager_lua.inl index 0633be6b09..c5e68d796b 100644 --- a/src/util/spicemanager_lua.inl +++ b/src/util/spicemanager_lua.inl @@ -25,6 +25,7 @@ #include #include #include +#include namespace openspace::luascriptfunctions { @@ -51,7 +52,7 @@ int loadKernel(lua_State* L) { 1, ghoul::lua::PopValue::Yes ); - if (!FileSys.fileExists(argument)) { + if (!std::filesystem::is_regular_file(argument)) { return ghoul::lua::luaError( L, fmt::format("Kernel file '{}' did not exist", argument) diff --git a/src/util/taskloader.cpp b/src/util/taskloader.cpp index 821dc8d108..f4771ef60c 100644 --- a/src/util/taskloader.cpp +++ b/src/util/taskloader.cpp @@ -33,6 +33,7 @@ #include #include #include +#include namespace { constexpr const char* _loggerCat = "TaskRunner"; @@ -69,7 +70,7 @@ std::vector> TaskLoader::tasksFromDictionary( std::vector> TaskLoader::tasksFromFile(const std::string& path) { std::string absTasksFile = absPath(path); - if (!FileSys.fileExists(ghoul::filesystem::File(absTasksFile))) { + if (!std::filesystem::is_regular_file(absTasksFile)) { LERROR(fmt::format( "Could not load tasks file '{}'. File not found", absTasksFile )); diff --git a/support/cmake/set_openspace_compile_settings.cmake b/support/cmake/set_openspace_compile_settings.cmake index a0c96ab0a9..2dc978d17f 100644 --- a/support/cmake/set_openspace_compile_settings.cmake +++ b/support/cmake/set_openspace_compile_settings.cmake @@ -55,12 +55,10 @@ function (set_openspace_compile_settings target) # This is disabled until GLM is updated to version 0.9.9 that removes occurrance of this warning # "/w44574" # 'identifier' is defined to be '0': did you mean to use '#if identifier'? "/w44608" # 'symbol1' has already been initialized by another union member in the initializer list, 'symbol2' - "/w44619" # #pragma warning: there is no warning number 'number' "/w44628" # digraphs not supported with -Ze. Character sequence 'digraph' not interpreted as alternate token for 'char' "/w44640" # 'instance': construction of local static object is not thread-safe "/w44905" # wide string literal cast to 'LPSTR' "/w44906" # string literal cast to 'LPWSTR' - "/w44946" # reinterpret_cast used between related classes: 'class1' and 'class2' "/w44986" # 'symbol': exception specification does not match previous declaration "/w44988" # 'symbol': variable declared outside class/function scope "/std:c++latest" diff --git a/tests/main.cpp b/tests/main.cpp index 578dc62cb1..05358752c3 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -38,6 +38,7 @@ #include #include #include +#include #include int main(int argc, char** argv) { @@ -54,17 +55,20 @@ int main(int argc, char** argv) { // to make it possible to find other files in the same directory. FileSys.registerPathToken( "${BIN}", - ghoul::filesystem::File(absPath(argv[0])).directoryName(), + std::filesystem::path(argv[0]).parent_path(), ghoul::filesystem::FileSystem::Override::Yes ); - std::string configFile = configuration::findConfiguration(); + std::filesystem::path configFile = configuration::findConfiguration(); // Register the base path as the directory where 'filename' lives - std::string base = ghoul::filesystem::File(configFile).directoryName(); + std::filesystem::path base = configFile.parent_path(); constexpr const char* BasePathToken = "${BASE}"; FileSys.registerPathToken(BasePathToken, base); - *global::configuration = configuration::loadConfigurationFromFile(configFile, ""); + *global::configuration = configuration::loadConfigurationFromFile( + configFile.string(), + "" + ); global::openSpaceEngine->registerPathTokens(); global::openSpaceEngine->initialize(); diff --git a/tests/test_assetloader.cpp b/tests/test_assetloader.cpp index 084e52dd44..d379038541 100644 --- a/tests/test_assetloader.cpp +++ b/tests/test_assetloader.cpp @@ -57,7 +57,7 @@ TEST_CASE("AssetLoader: Assertion", "[assetloader]") { openspace::AssetLoader assetLoader( state, &syncWatcher, - FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + absPath("${TESTDIR}/AssetLoaderTest/") ); REQUIRE_NOTHROW(assetLoader.add("passassertion")); @@ -71,7 +71,7 @@ TEST_CASE("AssetLoader: Basic Export Import", "[assetloader]") { openspace::AssetLoader assetLoader( state, &syncWatcher, - FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + absPath("${TESTDIR}/AssetLoaderTest/") ); REQUIRE_NOTHROW(assetLoader.add("require")); @@ -84,7 +84,7 @@ TEST_CASE("AssetLoader: Asset Functions", "[assetloader]") { openspace::AssetLoader assetLoader( state, &syncWatcher, - FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + absPath("${TESTDIR}/AssetLoaderTest/") ); REQUIRE_NOTHROW(assetLoader.add("assetfunctionsexist")); @@ -97,7 +97,7 @@ TEST_CASE("AssetLoader: Asset Initialization", "[assetloader]") { openspace::AssetLoader assetLoader( state, &syncWatcher, - FileSys.absolutePath("${TESTDIR}/AssetLoaderTest/") + absPath("${TESTDIR}/AssetLoaderTest/") ); bool passed; diff --git a/tests/test_lua_createsinglecolorimage.cpp b/tests/test_lua_createsinglecolorimage.cpp index 88b98d68ab..8c6f8120e6 100644 --- a/tests/test_lua_createsinglecolorimage.cpp +++ b/tests/test_lua_createsinglecolorimage.cpp @@ -30,6 +30,7 @@ #include #include #include +#include TEST_CASE("CreateSingleColorImage: Create image and check return value", "[createsinglecolorimage]") @@ -126,7 +127,7 @@ TEST_CASE("CreateSingleColorImage: Check if file was created", CHECK(res == 1); std::string path = ghoul::lua::value(L, 1); - CHECK(FileSys.fileExists(path)); + CHECK(std::filesystem::is_regular_file(path)); } TEST_CASE("CreateSingleColorImage: Load created image", "[createsinglecolorimage]") {