Changeset - r19849:42900960d059
[Not reviewed]
master
0 8 0
frosch - 11 years ago 2012-12-09 16:52:43
frosch@openttd.org
(svn r24804) -Add: Separate subdirectory for screenshots.
8 files changed with 36 insertions and 10 deletions:
0 comments (0 inline, 0 general)
readme.txt
Show inline comments
 
@@ -296,13 +296,13 @@ your operating system:
 
		It includes the OpenTTD files (grf+lng) and it will work as long as they
 
		are not touched
 

	
 
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)
 
	32bpp Sets:          newgrf                  (or a subdirectory thereof)
 
	Music Sets:          baseset                 (or a subdirectory thereof)
 
	AIs:                 ai                      (or a subdirectory thereof)
src/crashlog.cpp
Show inline comments
 
@@ -385,13 +385,13 @@ bool CrashLog::WriteSavegame(char *filen
 
 */
 
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;
 
}
 

	
 
/**
 
 * Makes the crash log, writes it to a file and then subsequently tries
src/fileio.cpp
Show inline comments
 
@@ -280,12 +280,13 @@ static const char * const _subdirs[] = {
 
	"newgrf" PATHSEP,
 
	"lang" PATHSEP,
 
	"ai" PATHSEP,
 
	"ai" PATHSEP "library" PATHSEP,
 
	"game" PATHSEP,
 
	"game" PATHSEP "library" PATHSEP,
 
	"screenshot" PATHSEP,
 
};
 
assert_compile(lengthof(_subdirs) == NUM_SUBDIRS);
 

	
 
const char *_searchpaths[NUM_SEARCHPATHS];
 
TarList _tar_list[NUM_SUBDIRS];
 
TarFileList _tar_filelist[NUM_SUBDIRS];
 
@@ -1199,13 +1200,13 @@ void DeterminePaths(const char *exe)
 
	/* Make the necessary folders */
 
#if !defined(__MORPHOS__) && !defined(__AMIGA__) && defined(WITH_PERSONAL_DIR)
 
	FioCreateDirectory(_personal_dir);
 
#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++) {
 
		char *dir = str_fmt("%s%s", _personal_dir, _subdirs[default_subdirs[i]]);
 
		FioCreateDirectory(dir);
 
		free(dir);
src/fileio_func.h
Show inline comments
 
@@ -53,12 +53,14 @@ FILE *FioFOpenFile(const char *filename,
 
bool FioCheckFileExists(const char *filename, Subdirectory subdir);
 
char *FioGetFullPath(char *buf, size_t buflen, Searchpath sp, Subdirectory subdir, const char *filename);
 
char *FioFindFullPath(char *buf, size_t buflen, Subdirectory subdir, const char *filename);
 
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);
 
void *ReadFileToMem(const char *filename, size_t *lenp, size_t maxsize);
 
bool FileExists(const char *filename);
 
const char *FioTarFirstDir(const char *tarname, Subdirectory subdir);
src/fileio_type.h
Show inline comments
 
@@ -29,12 +29,13 @@ enum Subdirectory {
 
	NEWGRF_DIR,    ///< Subdirectory for all NewGRFs
 
	LANG_DIR,      ///< Subdirectory for all translation files
 
	AI_DIR,        ///< Subdirectory for all %AI files
 
	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
 
};
 

	
 
/**
 
 * Types of searchpaths OpenTTD might use
src/fios.cpp
Show inline comments
 
@@ -552,12 +552,28 @@ void FiosGetHeightmapList(SaveLoadDialog
 
	char base_path[MAX_PATH];
 
	FioGetDirectory(base_path, sizeof(base_path), HEIGHTMAP_DIR);
 

	
 
	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"
 

	
 
/** Basic data to distinguish a scenario. Used in the server list window */
 
struct ScenarioIdentifier {
src/screenshot.cpp
Show inline comments
 
@@ -695,15 +695,16 @@ static void LargeWorldCallback(void *use
 
}
 

	
 
/**
 
 * 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);
 

	
 
	if (generate) {
 
		if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_company == COMPANY_SPECTATOR) {
 
			strecpy(_screenshot_name, default_fn, lastof(_screenshot_name));
 
@@ -713,14 +714,16 @@ static const char *MakeScreenshotName(co
 
	}
 

	
 
	/* Add extension to screenshot file */
 
	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;
 
		}
 
		if (!generate) break; // allow overwriting of non-automatic filenames
 
		if (!FileExists(_full_screenshot_name)) break;
 
@@ -729,16 +732,16 @@ static const char *MakeScreenshotName(co
 
	}
 

	
 
	return _full_screenshot_name;
 
}
 

	
 
/** 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);
 
}
 

	
 
/** Make a zoomed-in screenshot of the currently visible area. */
 
static bool MakeZoomedInScreenshot(ZoomLevel zl)
 
{
 
@@ -848,14 +851,17 @@ bool MakeScreenshot(ScreenshotType t, co
 
	_screenshot_name[0] = '\0';
 
	if (name != NULL) strecpy(_screenshot_name, name, lastof(_screenshot_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:
 
			ret = MakeZoomedInScreenshot(_settings_client.gui.zoom_min);
 
			break;
 

	
src/screenshot.h
Show inline comments
 
@@ -19,13 +19,13 @@ bool GetScreenshotFormatSupports_32bpp(i
 
void SetScreenshotFormat(uint i);
 
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.
 
	SC_HEIGHTMAP,   ///< Heightmap of the world.
 
};
 

	
0 comments (0 inline, 0 general)