summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfrosch <frosch@openttd.org>2012-12-09 16:52:43 +0000
committerfrosch <frosch@openttd.org>2012-12-09 16:52:43 +0000
commitedd9c0553a7ff735000cc52c9b02fa33db767521 (patch)
tree76e8bfb70df3f1b2ff3789f2e2ebf022ba0f8290
parent1c71fbe0f0a909b0fa865fcb1a83532c6ab871fd (diff)
downloadopenttd-edd9c0553a7ff735000cc52c9b02fa33db767521.tar.xz
(svn r24804) -Add: Separate subdirectory for screenshots.
-rw-r--r--readme.txt2
-rw-r--r--src/crashlog.cpp2
-rw-r--r--src/fileio.cpp3
-rw-r--r--src/fileio_func.h2
-rw-r--r--src/fileio_type.h1
-rw-r--r--src/fios.cpp16
-rw-r--r--src/screenshot.cpp18
-rw-r--r--src/screenshot.h2
8 files changed, 36 insertions, 10 deletions
diff --git a/readme.txt b/readme.txt
index 40da17dac..b62ebb2d4 100644
--- a/readme.txt
+++ b/readme.txt
@@ -299,7 +299,7 @@ your operating system:
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)
diff --git a/src/crashlog.cpp b/src/crashlog.cpp
index 8948fec1d..6881ff31f 100644
--- a/src/crashlog.cpp
+++ b/src/crashlog.cpp
@@ -388,7 +388,7 @@ bool CrashLog::WriteScreenshot(char *filename, const char *filename_last) const
/* 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;
}
diff --git a/src/fileio.cpp b/src/fileio.cpp
index 7e4d21f01..924141a85 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -283,6 +283,7 @@ static const char * const _subdirs[] = {
"ai" PATHSEP "library" PATHSEP,
"game" PATHSEP,
"game" PATHSEP "library" PATHSEP,
+ "screenshot" PATHSEP,
};
assert_compile(lengthof(_subdirs) == NUM_SUBDIRS);
@@ -1202,7 +1203,7 @@ void DeterminePaths(const char *exe)
#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++) {
diff --git a/src/fileio_func.h b/src/fileio_func.h
index 25d961bc0..d85c8630c 100644
--- a/src/fileio_func.h
+++ b/src/fileio_func.h
@@ -56,6 +56,8 @@ char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char
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);
diff --git a/src/fileio_type.h b/src/fileio_type.h
index 516bf0e35..3f21be6dd 100644
--- a/src/fileio_type.h
+++ b/src/fileio_type.h
@@ -32,6 +32,7 @@ enum Subdirectory {
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
};
diff --git a/src/fios.cpp b/src/fios.cpp
index e948b5680..b2ed1ec50 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -555,6 +555,22 @@ void FiosGetHeightmapList(SaveLoadDialogMode mode)
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"
diff --git a/src/screenshot.cpp b/src/screenshot.cpp
index e3c277b47..39e579cd5 100644
--- a/src/screenshot.cpp
+++ b/src/screenshot.cpp
@@ -698,9 +698,10 @@ static void LargeWorldCallback(void *userdata, void *buf, uint y, uint pitch, ui
* 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 @@ static const char *MakeScreenshotName(const char *default_fn, const char *ext)
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 @@ static const char *MakeScreenshotName(const char *default_fn, const char *ext)
}
/** 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 MakeScreenshot(ScreenshotType t, const char *name)
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:
diff --git a/src/screenshot.h b/src/screenshot.h
index 844085423..a9b4c0f6e 100644
--- a/src/screenshot.h
+++ b/src/screenshot.h
@@ -22,7 +22,7 @@ const char *GetCurrentScreenshotExtension();
/** 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.