mirror of https://github.com/OpenTTD/OpenTTD
(svn r24804) -Add: Separate subdirectory for screenshots.
parent
1c71fbe0f0
commit
edd9c0553a
|
@ -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)
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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++) {
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
};
|
||||
|
|
16
src/fios.cpp
16
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"
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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.
|
||||
|
|
Loading…
Reference in New Issue