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
 
@@ -290,25 +290,25 @@ your operating system:
 
	4. The binary directory (where the OpenTTD executable is)
 
		Windows: C:\Program Files\OpenTTD
 
		Linux:   /usr/games
 
	5. The installation directory (Linux only)
 
		Linux:   /usr/share/games/openttd
 
	6. The application bundle (Mac OSX only)
 
		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)
 
	AI Libraries:        ai/libraries            (or a subdirectory thereof)
 
	Game Scripts (GS):   game                    (or a subdirectory thereof)
 
	GS Libraries:        game/libraries          (or a subdirectory thereof)
 
	Savegames:           save
 
	Automatic Savegames: save/autosave
 
	Scenarios:           scenario
src/crashlog.cpp
Show inline comments
 
@@ -379,25 +379,25 @@ bool CrashLog::WriteSavegame(char *filen
 
 * Write the (crash) screenshot to a file.
 
 * @note On success the filename will be filled with the full path of the
 
 *       screenshot. Make sure filename is at least \c MAX_PATH big.
 
 * @param filename      Output for the filename of the written file.
 
 * @param filename_last The last position in the filename buffer.
 
 * @return true when the crash screenshot was successfully made.
 
 */
 
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
 
 * to make a crash dump and crash savegame. It uses DEBUG to write
 
 * information like paths to the console.
 
 * @return true when everything is made successfully.
 
 */
 
bool CrashLog::MakeCrashLog() const
 
{
src/fileio.cpp
Show inline comments
 
@@ -274,24 +274,25 @@ static const char * const _subdirs[] = {
 
	"save" PATHSEP "autosave" PATHSEP,
 
	"scenario" PATHSEP,
 
	"scenario" PATHSEP "heightmap" PATHSEP,
 
	"gm" PATHSEP,
 
	"data" PATHSEP,
 
	"baseset" PATHSEP,
 
	"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];
 

	
 
typedef std::map<std::string, std::string> TarLinkList;
 
static TarLinkList _tar_linklist[NUM_SUBDIRS]; ///< List of directory links
 

	
 
/**
 
 * Check whether the given file exists
 
@@ -1193,25 +1194,25 @@ void DeterminePaths(const char *exe)
 
	DEBUG(misc, 3, "%s found as personal directory", _personal_dir);
 

	
 
	_highscore_file = str_fmt("%shs.dat", _personal_dir);
 
	extern char *_hotkeys_file;
 
	_hotkeys_file = str_fmt("%shotkeys.cfg",  _personal_dir);
 

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

	
 
	/* If we have network we make a directory for the autodownloading of content */
 
	_searchpaths[SP_AUTODOWNLOAD_DIR] = str_fmt("%s%s", _personal_dir, "content_download" PATHSEP);
 
#ifdef ENABLE_NETWORK
 
	FioCreateDirectory(_searchpaths[SP_AUTODOWNLOAD_DIR]);
src/fileio_func.h
Show inline comments
 
@@ -47,24 +47,26 @@ static inline bool IsValidSearchPath(Sea
 

	
 
/** Iterator for all the search paths */
 
#define FOR_ALL_SEARCHPATHS(sp) for (sp = SP_FIRST_DIR; sp < NUM_SEARCHPATHS; sp++) if (IsValidSearchPath(sp))
 

	
 
void FioFCloseFile(FILE *f);
 
FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir, size_t *filesize = NULL);
 
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);
 
void FioTarAddLink(const char *src, const char *dest, Subdirectory subdir);
 
bool ExtractTar(const char *tar_filename, Subdirectory subdir);
 

	
 
extern char *_personal_dir; ///< custom directory for personal settings, saves, newgrf, etc.
 

	
 
/** Helper for scanning for files with a given name */
src/fileio_type.h
Show inline comments
 
@@ -23,24 +23,25 @@ enum Subdirectory {
 
	AUTOSAVE_DIR,  ///< Subdirectory of save for autosaves
 
	SCENARIO_DIR,  ///< Base directory for all scenarios
 
	HEIGHTMAP_DIR, ///< Subdirectory of scenario for heightmaps
 
	OLD_GM_DIR,    ///< Old subdirectory for the music
 
	OLD_DATA_DIR,  ///< Old subdirectory for the data.
 
	BASESET_DIR,   ///< Subdirectory for all base data (base sets, intro game)
 
	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
 
 */
 
enum Searchpath {
 
	SP_FIRST_DIR,
 
	SP_WORKING_DIR = SP_FIRST_DIR, ///< Search in the working directory
 
	SP_PERSONAL_DIR,               ///< Search in the personal directory
 
	SP_SHARED_DIR,                 ///< Search in the shared directory, like 'Shared Files' under Windows
src/fios.cpp
Show inline comments
 
@@ -546,24 +546,40 @@ void FiosGetHeightmapList(SaveLoadDialog
 
		fios_hmap_path = MallocT<char>(MAX_PATH);
 
		FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
 
	}
 

	
 
	_fios_path = fios_hmap_path;
 

	
 
	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 {
 
	uint32 scenid;           ///< ID for the scenario (generated by content).
 
	uint8 md5sum[16];        ///< MD5 checksum of file.
 
	char filename[MAX_PATH]; ///< filename of the file.
 

	
 
	bool operator == (const ScenarioIdentifier &other) const
 
	{
src/screenshot.cpp
Show inline comments
 
@@ -689,62 +689,65 @@ static void LargeWorldCallback(void *use
 

	
 
	_cur_dpi = old_dpi;
 

	
 
	/* Switch back to rendering to the screen */
 
	_screen = old_screen;
 
	_screen_disable_anim = old_disable_anim;
 
}
 

	
 
/**
 
 * 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));
 
		} else {
 
			GenerateDefaultSaveName(_screenshot_name, lastof(_screenshot_name));
 
		}
 
	}
 

	
 
	/* 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;
 
		/* If file exists try another one with same name, but just with a higher index */
 
		snprintf(&_screenshot_name[len], lengthof(_screenshot_name) - len, "#%u.%s", serial, ext);
 
	}
 

	
 
	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)
 
{
 
	Window *w = FindWindowById(WC_MAIN_WINDOW, 0);
 
	ViewPort vp;
 

	
 
	vp.zoom = zl;
 
	vp.left = w->viewport->left;
 
	vp.top = w->viewport->top;
 
@@ -842,26 +845,29 @@ bool MakeScreenshot(ScreenshotType t, co
 
		 * of the previous screenshot in the 'successful' message instead of the
 
		 * name of the new screenshot (or an empty name). */
 
		UndrawMouseCursor();
 
		DrawDirtyBlocks();
 
	}
 

	
 
	_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;
 

	
 
		case SC_DEFAULTZOOM:
 
			ret = MakeZoomedInScreenshot(ZOOM_LVL_VIEWPORT);
 
			break;
 

	
 
		case SC_WORLD:
 
			ret = MakeWorldScreenshot();
src/screenshot.h
Show inline comments
 
@@ -13,25 +13,25 @@
 
#define SCREENSHOT_H
 

	
 
void InitializeScreenshotFormats();
 

	
 
const char *GetScreenshotFormatDesc(int i);
 
bool GetScreenshotFormatSupports_32bpp(int 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.
 
};
 

	
 
bool MakeHeightmapScreenshot(const char *filename);
 
bool MakeScreenshot(ScreenshotType t, const char *name);
 

	
 
extern char _screenshot_format_name[8];
 
extern uint _num_screenshot_formats;
 
extern uint _cur_screenshot_format;
0 comments (0 inline, 0 general)