@@ -385,12 +385,29 @@ void DeterminePaths(const char *exe)
_config_file = str_fmt("%sopenttd.cfg", _paths.personal_dir);
}
_highscore_file = str_fmt("%shs.dat", _paths.personal_dir);
_log_file = str_fmt("%sopenttd.log", _paths.personal_dir);
/* 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;
@@ -11,16 +11,17 @@ uint32 FioGetPos();
byte FioReadByte();
uint16 FioReadWord();
uint32 FioReadDword();
void FioCloseAll();
void FioOpenFile(int slot, const char *filename);
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 */
@@ -26,24 +26,25 @@
#include "town.h"
#include "sound.h"
#include "network/network.h"
#include "string.h"
#include "variables.h"
#include "vehicle.h"
#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;
static bool _fios_path_changed;
static bool _savegame_sort_dirty;
enum {
LAND_INFO_LINES = 7,
@@ -1387,24 +1388,25 @@ static void MakeSortedSaveGameList()
static void GenerateFileName()
/* Check if we are not a specatator who wants to generate a name..
Let's use the name of player #0 for now. */
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)
static FiosItem o_dir;
switch (e->event) {
case WE_CREATE: { // Set up OPENTTD button
o_dir.type = FIOS_TYPE_DIRECT;
switch (_saveload_mode) {
@@ -5,24 +5,25 @@
#include "debug.h"
#include "functions.h"
#include "strings.h"
#include "table/strings.h"
#include "gfx.h"
#include "hal.h"
#include "viewport.h"
#include "player.h"
#include "screenshot.h"
#include "helpers.hpp"
char _screenshot_format_name[8];
uint _num_screenshot_formats;
uint _cur_screenshot_format;
ScreenshotType current_screenshot_type;
/* called by the ScreenShot proc to generate screenshot lines. */
typedef void ScreenshotCallback(void *userdata, Pixel *buf, uint y, uint pitch, uint n);
typedef bool ScreenshotHandlerProc(const char *name, ScreenshotCallback *callb, void *userdata, uint w, uint h, int pixelformat, const Colour *palette);
struct ScreenshotFormat {
const char *name;
@@ -496,24 +497,25 @@ static char *MakeScreenshotName(const ch
int serial;
if (_game_mode == GM_EDITOR || _game_mode == GM_MENU || _local_player == PLAYER_SPECTATOR) {
sprintf(_screenshot_name, "screenshot");
} else {
const Player* p = GetPlayer(_local_player);
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);
if (!FileExists(filename))
sprintf(base, " #%d.%s", ++serial, ext);
return filename;
Status change: