changeset 19871:723a91a42f5c draft

(svn r24804) -Add: Separate subdirectory for screenshots.
author frosch <frosch@openttd.org>
date Sun, 09 Dec 2012 16:52:43 +0000
parents ee19cd20b5a8
children 5d3755fccf0a
files readme.txt src/crashlog.cpp src/fileio.cpp src/fileio_func.h src/fileio_type.h src/fios.cpp src/screenshot.cpp src/screenshot.h
diffstat 8 files changed, 36 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/readme.txt
+++ b/readme.txt
@@ -299,7 +299,7 @@
 Different types of data or extensions go into different subdirectories of the
 chosen main OpenTTD directory:
 	Config File:         (no subdirectory)
-	Screenshots:         (no subdirectory)
+	Screenshots:         screenshot
 	Base Graphics:       baseset                 (or a subdirectory thereof)
 	Sound Sets:          baseset                 (or a subdirectory thereof)
 	NewGRFs:             newgrf                  (or a subdirectory thereof)
--- a/src/crashlog.cpp
+++ b/src/crashlog.cpp
@@ -388,7 +388,7 @@
 	/* Don't draw when we have invalid screen size */
 	if (_screen.width < 1 || _screen.height < 1 || _screen.dst_ptr == NULL) return false;
 
-	bool res = MakeScreenshot(SC_RAW, "crash");
+	bool res = MakeScreenshot(SC_CRASHLOG, "crash");
 	if (res) strecpy(filename, _full_screenshot_name, filename_last);
 	return res;
 }
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -283,6 +283,7 @@
 	"ai" PATHSEP "library" PATHSEP,
 	"game" PATHSEP,
 	"game" PATHSEP "library" PATHSEP,
+	"screenshot" PATHSEP,
 };
 assert_compile(lengthof(_subdirs) == NUM_SUBDIRS);
 
@@ -1202,7 +1203,7 @@
 #endif
 
 	static const Subdirectory default_subdirs[] = {
-		SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR
+		SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR, BASESET_DIR, NEWGRF_DIR, AI_DIR, AI_LIBRARY_DIR, GAME_DIR, GAME_LIBRARY_DIR, SCREENSHOT_DIR
 	};
 
 	for (uint i = 0; i < lengthof(default_subdirs); i++) {
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -56,6 +56,8 @@
 char *FioAppendDirectory(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir);
 char *FioGetDirectory(char *buf, size_t buflen, Subdirectory subdir);
 
+const char *FiosGetScreenshotDir();
+
 void SanitizeFilename(char *filename);
 bool AppendPathSeparator(char *buf, size_t buflen);
 void DeterminePaths(const char *exe);
--- a/src/fileio_type.h
+++ b/src/fileio_type.h
@@ -32,6 +32,7 @@
 	AI_LIBRARY_DIR,///< Subdirectory for all %AI libraries
 	GAME_DIR,      ///< Subdirectory for all game scripts
 	GAME_LIBRARY_DIR, ///< Subdirectory for all GS libraries
+	SCREENSHOT_DIR,   ///< Subdirectory for all screenshots
 	NUM_SUBDIRS,   ///< Number of subdirectories
 	NO_DIRECTORY,  ///< A path without any base directory
 };
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -555,6 +555,22 @@
 	FiosGetFileList(mode, &FiosGetHeightmapListCallback, strcmp(base_path, _fios_path) == 0 ? HEIGHTMAP_DIR : NO_DIRECTORY);
 }
 
+/**
+ * Get the directory for screenshots.
+ * @return path to screenshots
+ */
+const char *FiosGetScreenshotDir()
+{
+	static char *fios_screenshot_path = NULL;
+
+	if (fios_screenshot_path == NULL) {
+		fios_screenshot_path = MallocT<char>(MAX_PATH);
+		FioGetDirectory(fios_screenshot_path, MAX_PATH, SCREENSHOT_DIR);
+	}
+
+	return fios_screenshot_path;
+}
+
 #if defined(ENABLE_NETWORK)
 #include "network/network_content.h"
 #include "3rdparty/md5/md5.h"
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -698,9 +698,10 @@
  * Construct a pathname for a screenshot file.
  * @param default_fn Default filename.
  * @param ext        Extension to use.
+ * @param crashlog   Create path for crash.png
  * @return Pathname for a screenshot file.
  */
-static const char *MakeScreenshotName(const char *default_fn, const char *ext)
+static const char *MakeScreenshotName(const char *default_fn, const char *ext, bool crashlog = false)
 {
 	bool generate = StrEmpty(_screenshot_name);
 
@@ -716,8 +717,10 @@
 	size_t len = strlen(_screenshot_name);
 	snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, ".%s", ext);
 
+	const char *screenshot_dir = crashlog ? _personal_dir : FiosGetScreenshotDir();
+
 	for (uint serial = 1;; serial++) {
-		if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", _personal_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
+		if (snprintf(_full_screenshot_name, lengthof(_full_screenshot_name), "%s%s", screenshot_dir, _screenshot_name) >= (int)lengthof(_full_screenshot_name)) {
 			/* We need more characters than MAX_PATH -> end with error */
 			_full_screenshot_name[0] = '\0';
 			break;
@@ -732,10 +735,10 @@
 }
 
 /** Make a screenshot of the current screen. */
-static bool MakeSmallScreenshot()
+static bool MakeSmallScreenshot(bool crashlog)
 {
 	const ScreenshotFormat *sf = _screenshot_formats + _cur_screenshot_format;
-	return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension), CurrentScreenCallback, NULL, _screen.width, _screen.height,
+	return sf->proc(MakeScreenshotName(SCREENSHOT_NAME, sf->extension, crashlog), CurrentScreenCallback, NULL, _screen.width, _screen.height,
 			BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth(), _cur_palette.palette);
 }
 
@@ -851,8 +854,11 @@
 	bool ret;
 	switch (t) {
 		case SC_VIEWPORT:
-		case SC_RAW:
-			ret = MakeSmallScreenshot();
+			ret = MakeSmallScreenshot(false);
+			break;
+
+		case SC_CRASHLOG:
+			ret = MakeSmallScreenshot(true);
 			break;
 
 		case SC_ZOOMEDIN:
--- a/src/screenshot.h
+++ b/src/screenshot.h
@@ -22,7 +22,7 @@
 /** Type of requested screenshot */
 enum ScreenshotType {
 	SC_VIEWPORT,    ///< Screenshot of viewport.
-	SC_RAW,         ///< Raw screenshot from blitter buffer.
+	SC_CRASHLOG,    ///< Raw screenshot from blitter buffer.
 	SC_ZOOMEDIN,    ///< Fully zoomed in screenshot of the visible area.
 	SC_DEFAULTZOOM, ///< Zoomed to default zoom level screenshot of the visible area.
 	SC_WORLD,       ///< World screenshot.