From 2b54e6216b4b8773d3b7481684540849ac5a5e82 Mon Sep 17 00:00:00 2001 From: p4r4digm Date: Sun, 19 Apr 2020 16:34:00 -0700 Subject: [PATCH 1/2] Added setting to change the directory screenshots are stored in --- apps/openmw/engine.cpp | 4 ++-- components/files/configurationmanager.cpp | 13 +++++++++++++ components/files/configurationmanager.hpp | 1 + files/settings-default.cfg | 3 +++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index ec8c1e3059..5b0bd491f5 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -657,7 +657,6 @@ private: }; // Initialise and enter main loop. - void OMW::Engine::go() { assert (!mContentFiles.empty()); @@ -686,7 +685,8 @@ void OMW::Engine::go() mViewer->setUseConfigureAffinity(false); #endif - mScreenCaptureOperation = new WriteScreenshotToFileOperation(mCfgMgr.getUserDataPath().string(), + mScreenCaptureOperation = new WriteScreenshotToFileOperation( + mCfgMgr.getScreenshotPath(Settings::Manager::getString("screenshot path", "General")).string(), Settings::Manager::getString("screenshot format", "General")); mScreenCaptureHandler = new osgViewer::ScreenCaptureHandler(mScreenCaptureOperation); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 3bc6e17729..231401c08b 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -196,4 +196,17 @@ const boost::filesystem::path& ConfigurationManager::getLogPath() const return mLogPath; } +const boost::filesystem::path ConfigurationManager::getScreenshotPath(std::string const& screenshotSettings) const +{ + boost::filesystem::path ssPath = screenshotSettings; + if (ssPath.is_relative()) { + ssPath = mFixedPath.getUserDataPath() / ssPath; + } + boost::system::error_code dirErr; + if (!boost::filesystem::create_directories(ssPath, dirErr) && !boost::filesystem::is_directory(ssPath)) { + ssPath = mFixedPath.getUserDataPath(); + } + return ssPath; +} + } /* namespace Cfg */ diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index df131e6714..1c6123b846 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -41,6 +41,7 @@ struct ConfigurationManager const boost::filesystem::path& getCachePath() const; const boost::filesystem::path& getLogPath() const; + const boost::filesystem::path getScreenshotPath(std::string const& screenshotSetting) const; private: typedef Files::FixedPath<> FixedPathType; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 06950e50df..08a520ca01 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -284,6 +284,9 @@ anisotropy = 4 # File format for screenshots. (jpg, png, tga, and possibly more). screenshot format = png +# Directory to store screenshots in. Supports relative and absolute paths. Relative paths will be to the user data folder. +screenshot path =./ + # Texture magnification filter type. (nearest or linear). texture mag filter = linear From 0741fe5b800278b11e2a34bb878116a38c21eee1 Mon Sep 17 00:00:00 2001 From: p4r4digm Date: Mon, 20 Apr 2020 09:22:50 -0700 Subject: [PATCH 2/2] removed path configuration and made screenshots just save in a folder --- apps/openmw/engine.cpp | 2 +- components/files/configurationmanager.cpp | 20 ++++++++++---------- components/files/configurationmanager.hpp | 3 ++- files/settings-default.cfg | 3 --- 4 files changed, 13 insertions(+), 15 deletions(-) diff --git a/apps/openmw/engine.cpp b/apps/openmw/engine.cpp index 5b0bd491f5..3d609259f0 100644 --- a/apps/openmw/engine.cpp +++ b/apps/openmw/engine.cpp @@ -686,7 +686,7 @@ void OMW::Engine::go() #endif mScreenCaptureOperation = new WriteScreenshotToFileOperation( - mCfgMgr.getScreenshotPath(Settings::Manager::getString("screenshot path", "General")).string(), + mCfgMgr.getScreenshotPath().string(), Settings::Manager::getString("screenshot format", "General")); mScreenCaptureHandler = new osgViewer::ScreenCaptureHandler(mScreenCaptureOperation); diff --git a/components/files/configurationmanager.cpp b/components/files/configurationmanager.cpp index 231401c08b..0ba2d15193 100644 --- a/components/files/configurationmanager.cpp +++ b/components/files/configurationmanager.cpp @@ -32,6 +32,14 @@ ConfigurationManager::ConfigurationManager(bool silent) boost::filesystem::create_directories(mFixedPath.getUserDataPath()); mLogPath = mFixedPath.getUserConfigPath(); + + mScreenshotPath = mFixedPath.getUserDataPath() / "screenshots"; + + // probably not necessary but validate the creation of the screenshots directory and fallback to the original behavior if it fails + boost::system::error_code dirErr; + if (!boost::filesystem::create_directories(mScreenshotPath, dirErr) && !boost::filesystem::is_directory(mScreenshotPath)) { + mScreenshotPath = mFixedPath.getUserDataPath(); + } } ConfigurationManager::~ConfigurationManager() @@ -196,17 +204,9 @@ const boost::filesystem::path& ConfigurationManager::getLogPath() const return mLogPath; } -const boost::filesystem::path ConfigurationManager::getScreenshotPath(std::string const& screenshotSettings) const +const boost::filesystem::path& ConfigurationManager::getScreenshotPath() const { - boost::filesystem::path ssPath = screenshotSettings; - if (ssPath.is_relative()) { - ssPath = mFixedPath.getUserDataPath() / ssPath; - } - boost::system::error_code dirErr; - if (!boost::filesystem::create_directories(ssPath, dirErr) && !boost::filesystem::is_directory(ssPath)) { - ssPath = mFixedPath.getUserDataPath(); - } - return ssPath; + return mScreenshotPath; } } /* namespace Cfg */ diff --git a/components/files/configurationmanager.hpp b/components/files/configurationmanager.hpp index 1c6123b846..446abd4dc5 100644 --- a/components/files/configurationmanager.hpp +++ b/components/files/configurationmanager.hpp @@ -41,7 +41,7 @@ struct ConfigurationManager const boost::filesystem::path& getCachePath() const; const boost::filesystem::path& getLogPath() const; - const boost::filesystem::path getScreenshotPath(std::string const& screenshotSetting) const; + const boost::filesystem::path& getScreenshotPath() const; private: typedef Files::FixedPath<> FixedPathType; @@ -58,6 +58,7 @@ struct ConfigurationManager FixedPathType mFixedPath; boost::filesystem::path mLogPath; + boost::filesystem::path mScreenshotPath; TokensMappingContainer mTokensMapping; diff --git a/files/settings-default.cfg b/files/settings-default.cfg index 08a520ca01..06950e50df 100644 --- a/files/settings-default.cfg +++ b/files/settings-default.cfg @@ -284,9 +284,6 @@ anisotropy = 4 # File format for screenshots. (jpg, png, tga, and possibly more). screenshot format = png -# Directory to store screenshots in. Supports relative and absolute paths. Relative paths will be to the user data folder. -screenshot path =./ - # Texture magnification filter type. (nearest or linear). texture mag filter = linear