diff options
author | Hugo Locurcio <hugo.locurcio@hugo.pro> | 2020-04-06 16:54:12 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-04-06 16:54:12 +0200 |
commit | f45ba78a72d86fd481a2d2064ac63858d69ad7ee (patch) | |
tree | 319698f6edccc3d4b82fb9ca5bd99ea65b4589de /src/client | |
parent | 661b4a1837067082a76114c08a7aebec83bc2b58 (diff) | |
download | minetest-f45ba78a72d86fd481a2d2064ac63858d69ad7ee.tar.gz minetest-f45ba78a72d86fd481a2d2064ac63858d69ad7ee.tar.bz2 minetest-f45ba78a72d86fd481a2d2064ac63858d69ad7ee.zip |
Allow relative directories for `screenshot_path`, tweak default path (#9122)
This will likely be more intuitive for users and should play better
with sandboxed distributions such as Flatpak.
In addition, the screenshot directory will now be created if it doesn't
exist already.
Diffstat (limited to 'src/client')
-rw-r--r-- | src/client/client.cpp | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/client/client.cpp b/src/client/client.cpp index c6d28ce80..e15391dde 100644 --- a/src/client/client.cpp +++ b/src/client/client.cpp @@ -1780,13 +1780,24 @@ void Client::makeScreenshot() char timetstamp_c[64]; strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", tm); - std::string filename_base = g_settings->get("screenshot_path") + std::string screenshot_dir; + + if (fs::IsPathAbsolute(g_settings->get("screenshot_path"))) + screenshot_dir = g_settings->get("screenshot_path"); + else + screenshot_dir = porting::path_user + DIR_DELIM + g_settings->get("screenshot_path"); + + std::string filename_base = screenshot_dir + DIR_DELIM + std::string("screenshot_") + std::string(timetstamp_c); std::string filename_ext = "." + g_settings->get("screenshot_format"); std::string filename; + // Create the directory if it doesn't already exist. + // Otherwise, saving the screenshot would fail. + fs::CreateDir(screenshot_dir); + u32 quality = (u32)g_settings->getS32("screenshot_quality"); quality = MYMIN(MYMAX(quality, 0), 100) / 100.0 * 255; |