Changeset - r11261:09d86b53f1da
[Not reviewed]
master
0 2 0
rubidium - 15 years ago 2009-03-04 23:12:15
rubidium@openttd.org
(svn r15615) -Feature: show scenarios/heightmaps from both your home directory and installation directory.
-Change [FS#2692]: make it more likely that scenarios are saved to the directory where openttd.cfg is and not the installation directory (gives problems with e.g. Vista). The working directory still overrides the openttd.cfg directory though, but only if it has a scenario directory.
2 files changed with 53 insertions and 11 deletions:
0 comments (0 inline, 0 general)
src/fileio.cpp
Show inline comments
 
@@ -941,7 +941,7 @@ void DeterminePaths(const char *exe)
 
#endif
 

	
 
	static const Subdirectory default_subdirs[] = {
 
		SAVE_DIR, AUTOSAVE_DIR
 
		SAVE_DIR, AUTOSAVE_DIR, SCENARIO_DIR, HEIGHTMAP_DIR
 
	};
 

	
 
	for (uint i = 0; i < lengthof(default_subdirs); i++) {
src/fios.cpp
Show inline comments
 
@@ -256,8 +256,9 @@ bool FiosFileScanner::AddFile(const char
 
/** Fill the list of the files in a directory, according to some arbitrary rule.
 
 *  @param mode The mode we are in. Some modes don't allow 'parent'.
 
 *  @param callback_proc The function that is called where you need to do the filtering.
 
 *  @param subdir The directory from where to start (global) searching.
 
 */
 
static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
 
static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc, Subdirectory subdir)
 
{
 
	struct stat sb;
 
	struct dirent *dirent;
 
@@ -310,7 +311,11 @@ static void FiosGetFileList(SaveLoadDial
 

	
 
	/* Show files */
 
	FiosFileScanner scanner(mode, callback_proc);
 
	scanner.Scan(NULL, _fios_path, false);
 
	if (subdir == NO_DIRECTORY) {
 
		scanner.Scan(NULL, _fios_path, false);
 
	} else {
 
		scanner.Scan(NULL, subdir, true, true);
 
	}
 

	
 
	qsort(_fios_items.Get(sort_start), _fios_items.Length() - sort_start, sizeof(FiosItem), compare_FiosItems);
 

	
 
@@ -321,6 +326,27 @@ static void FiosGetFileList(SaveLoadDial
 
}
 

	
 
/**
 
 * Get the title of a file, which (if exists) is stored in a file named
 
 * the same as the data file but with '.title' added to it.
 
 * @param file filename to get the title for
 
 * @param title the title buffer to fill
 
 * @param last the last element in the title buffer
 
 */
 
static void GetFileTitle(const char *file, char *title, const char *last)
 
{
 
	char buf[MAX_PATH];
 
	strecpy(buf, file, lastof(buf));
 
	strecat(buf, ".title", lastof(buf));
 

	
 
	FILE *f = FioFOpenFile(buf, "r");
 
	if (f == NULL) return;
 

	
 
	size_t read = fread(title, 1, last - title, f);
 
	assert(title + read <= last);
 
	title[read] = '\0';
 
}
 

	
 
/**
 
 * Callback for FiosGetFileList. It tells if a file is a savegame or not.
 
 * @param mode Save/load mode.
 
 * @param file Name of the file to check.
 
@@ -338,7 +364,10 @@ FiosType FiosGetSavegameListCallback(Sav
 
	 * .SS1 Transport Tycoon Deluxe preset game
 
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
 
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
 
	if (strcasecmp(ext, ".sav") == 0) return FIOS_TYPE_FILE;
 
	if (strcasecmp(ext, ".sav") == 0) {
 
		GetFileTitle(file, title, last);
 
		return FIOS_TYPE_FILE;
 
	}
 

	
 
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
 
		if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
 
@@ -368,7 +397,7 @@ void FiosGetSavegameList(SaveLoadDialogM
 

	
 
	_fios_path = fios_save_path;
 

	
 
	FiosGetFileList(mode, &FiosGetSavegameListCallback);
 
	FiosGetFileList(mode, &FiosGetSavegameListCallback, NO_DIRECTORY);
 
}
 

	
 
/**
 
@@ -388,7 +417,10 @@ static FiosType FiosGetScenarioListCallb
 
	 * .SCN OpenTTD style scenario file
 
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
 
	 * .SS0 Transport Tycoon Deluxe preset scenario */
 
	if (strcasecmp(ext, ".scn") == 0) return FIOS_TYPE_SCENARIO;
 
	if (strcasecmp(ext, ".scn") == 0) {
 
		GetFileTitle(file, title, last);
 
		return FIOS_TYPE_SCENARIO;
 
	}
 

	
 
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) {
 
		if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
 
@@ -418,7 +450,10 @@ void FiosGetScenarioList(SaveLoadDialogM
 

	
 
	_fios_path = fios_scn_path;
 

	
 
	FiosGetFileList(mode, &FiosGetScenarioListCallback);
 
	char base_path[MAX_PATH];
 
	FioGetDirectory(base_path, sizeof(base_path), SCENARIO_DIR);
 

	
 
	FiosGetFileList(mode, &FiosGetScenarioListCallback, (mode == SLD_LOAD_SCENARIO && strcmp(base_path, _fios_path) == 0) ? SCENARIO_DIR : NO_DIRECTORY);
 
}
 

	
 
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
 
@@ -428,13 +463,17 @@ static FiosType FiosGetHeightmapListCall
 
	 * .BMP BMP Based heightmap files
 
	 */
 

	
 
	FiosType type = FIOS_TYPE_INVALID;
 

	
 
#ifdef WITH_PNG
 
	if (strcasecmp(ext, ".png") == 0) return FIOS_TYPE_PNG;
 
	if (strcasecmp(ext, ".png") == 0) type = FIOS_TYPE_PNG;
 
#endif /* WITH_PNG */
 

	
 
	if (strcasecmp(ext, ".bmp") == 0) return FIOS_TYPE_BMP;
 
	if (strcasecmp(ext, ".bmp") == 0) type = FIOS_TYPE_BMP;
 

	
 
	return FIOS_TYPE_INVALID;
 
	if (type != FIOS_TYPE_INVALID) GetFileTitle(file, title, last);
 

	
 
	return type;
 
}
 

	
 
/* Get a list of Heightmaps */
 
@@ -449,5 +488,8 @@ void FiosGetHeightmapList(SaveLoadDialog
 

	
 
	_fios_path = fios_hmap_path;
 

	
 
	FiosGetFileList(mode, &FiosGetHeightmapListCallback);
 
	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);
 
}
0 comments (0 inline, 0 general)