Skip to content

Commit f45ba78

Browse files
authoredApr 6, 2020
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.
1 parent 661b4a1 commit f45ba78

File tree

3 files changed

+16
-4
lines changed

3 files changed

+16
-4
lines changed
 

Diff for: ‎builtin/settingtypes.txt

+3-2
Original file line numberDiff line numberDiff line change
@@ -903,8 +903,9 @@ fallback_font_shadow_alpha (Fallback font shadow alpha) int 128 0 255
903903
# This font will be used for certain languages or if the default font is unavailable.
904904
fallback_font_path (Fallback font path) filepath fonts/DroidSansFallbackFull.ttf
905905

906-
# Path to save screenshots at.
907-
screenshot_path (Screenshot folder) path
906+
# Path to save screenshots at. Can be an absolute or relative path.
907+
# The folder will be created if it doesn't already exist.
908+
screenshot_path (Screenshot folder) path screenshots
908909

909910
# Format of screenshots.
910911
screenshot_format (Screenshot format) enum png png,jpg,bmp,pcx,ppm,tga

Diff for: ‎src/client/client.cpp

+12-1
Original file line numberDiff line numberDiff line change
@@ -1780,13 +1780,24 @@ void Client::makeScreenshot()
17801780
char timetstamp_c[64];
17811781
strftime(timetstamp_c, sizeof(timetstamp_c), "%Y%m%d_%H%M%S", tm);
17821782

1783-
std::string filename_base = g_settings->get("screenshot_path")
1783+
std::string screenshot_dir;
1784+
1785+
if (fs::IsPathAbsolute(g_settings->get("screenshot_path")))
1786+
screenshot_dir = g_settings->get("screenshot_path");
1787+
else
1788+
screenshot_dir = porting::path_user + DIR_DELIM + g_settings->get("screenshot_path");
1789+
1790+
std::string filename_base = screenshot_dir
17841791
+ DIR_DELIM
17851792
+ std::string("screenshot_")
17861793
+ std::string(timetstamp_c);
17871794
std::string filename_ext = "." + g_settings->get("screenshot_format");
17881795
std::string filename;
17891796

1797+
// Create the directory if it doesn't already exist.
1798+
// Otherwise, saving the screenshot would fail.
1799+
fs::CreateDir(screenshot_dir);
1800+
17901801
u32 quality = (u32)g_settings->getS32("screenshot_quality");
17911802
quality = MYMIN(MYMAX(quality, 0), 100) / 100.0 * 255;
17921803

Diff for: ‎src/defaultsettings.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ void set_default_settings(Settings *settings)
4848
settings->setDefault("pitch_move", "false");
4949
settings->setDefault("fast_move", "false");
5050
settings->setDefault("noclip", "false");
51-
settings->setDefault("screenshot_path", ".");
51+
settings->setDefault("screenshot_path", "screenshots");
5252
settings->setDefault("screenshot_format", "png");
5353
settings->setDefault("screenshot_quality", "0");
5454
settings->setDefault("client_unload_unused_data_timeout", "600");

0 commit comments

Comments
 (0)
Please sign in to comment.