Changeset - r6875:4b8e730c2c52
[Not reviewed]
master
0 4 0
rubidium - 17 years ago 2007-06-12 15:46:34
rubidium@openttd.org
(svn r10116) -Fix [FS#850]: remove invalid characters (for the file system) from savegame names. Based on a patch by TheJosh.
4 files changed with 22 insertions and 0 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -391,6 +391,23 @@ void DeterminePaths(const char *exe)
 
	/* Make (auto)save and scenario folder */
 
	FioCreateDirectory(_paths.save_dir);
 
	FioCreateDirectory(_paths.autosave_dir);
 
	FioCreateDirectory(_paths.scenario_dir);
 
	FioCreateDirectory(_paths.heightmap_dir);
 
}
 

	
 
/**
 
 * Sanitizes a filename, i.e. removes all illegal characters from it.
 
 * @param filename the "\0" terminated filename
 
 */
 
void SanitizeFilename(char *filename)
 
{
 
	for (; *filename != '\0'; filename++) {
 
		switch (*filename) {
 
			/* The following characters are not allowed in filenames
 
			 * on at least one of the supported operating systems: */
 
			case ':': case '\\': case '*': case '?': case '/':
 
				*filename = '_';
 
				break;
 
		}
 
	}
 
}
src/fileio.h
Show inline comments
 
@@ -17,10 +17,11 @@ void FioReadBlock(void *ptr, uint size);
 
void FioSkipBytes(int n);
 

	
 
FILE *FioFOpenFile(const char *filename);
 
bool FioCheckFileExists(const char *filename);
 
void FioCreateDirectory(const char *filename);
 

	
 
void SanitizeFilename(char *filename);
 
void AppendPathSeparator(char *buf, size_t buflen);
 
void DeterminePaths(const char *exe);
 

	
 
#endif /* FILEIO_H */
src/misc_gui.cpp
Show inline comments
 
@@ -32,12 +32,13 @@
 
#include "train.h"
 
#include "tgp.h"
 
#include "settings.h"
 
#include "date.h"
 
#include "cargotype.h"
 
#include "player_face.h"
 
#include "fileio.h"
 

	
 
#include "fios.h"
 
/* Variables to display file lists */
 
FiosItem *_fios_list;
 
int _saveload_mode;
 

	
 
@@ -1393,12 +1394,13 @@ static void GenerateFileName()
 
	const Player *p = GetPlayer(IsValidPlayer(_local_player) ? _local_player : PLAYER_FIRST);
 

	
 
	SetDParam(0, p->name_1);
 
	SetDParam(1, p->name_2);
 
	SetDParam(2, _date);
 
	GetString(_edit_str_buf, STR_4004, lastof(_edit_str_buf));
 
	SanitizeFilename(_edit_str_buf);
 
}
 

	
 
extern void StartupEngines();
 

	
 
static void SaveLoadDlgWndProc(Window *w, WindowEvent *e)
 
{
src/screenshot.cpp
Show inline comments
 
@@ -11,12 +11,13 @@
 
#include "viewport.h"
 
#include "player.h"
 
#include "screenshot.h"
 
#include "variables.h"
 
#include "date.h"
 
#include "helpers.hpp"
 
#include "fileio.h"
 

	
 
char _screenshot_format_name[8];
 
uint _num_screenshot_formats;
 
uint _cur_screenshot_format;
 
ScreenshotType current_screenshot_type;
 

	
 
@@ -502,12 +503,13 @@ static char *MakeScreenshotName(const ch
 
		SetDParam(0, p->name_1);
 
		SetDParam(1, p->name_2);
 
		SetDParam(2, _date);
 
		GetString(_screenshot_name, STR_4004, lastof(_screenshot_name));
 
	}
 

	
 
	SanitizeFilename(_screenshot_name);
 
	base = strchr(_screenshot_name, 0);
 
	base[0] = '.'; strcpy(base + 1, ext);
 

	
 
	serial = 0;
 
	for (;;) {
 
		snprintf(filename, sizeof(filename), "%s%s", _paths.personal_dir, _screenshot_name);
0 comments (0 inline, 0 general)