(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
authorDarkvater
Sun, 17 Jul 2005 15:58:47 +0000
changeset 2099 02c5a49863e9
parent 2098 f468eebc49d5
child 2100 217ea6fdfd18
(svn r2609) - Feature: remove extension from savegames/scenarios when browsing the folders.
console_cmds.c
oldloader.c
os2.c
unix.c
variables.h
win32.c
--- a/console_cmds.c	Sun Jul 17 15:55:26 2005 +0000
+++ b/console_cmds.c	Sun Jul 17 15:58:47 2005 +0000
@@ -198,6 +198,7 @@
 
 	for (i = 0; i < _fios_num; i++) {
 		if (strcmp(file, _fios_list[i].name) == 0) break;
+		if (strcmp(file, _fios_list[i].title) == 0) break;
 	}
 
 	if (i == _fios_num) { /* If no name matches, try to parse it as number */
@@ -227,11 +228,13 @@
 	item = GetFiosItem(file);
 	if (item != NULL) {
 		switch (item->type) {
-			case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE:
+			case FIOS_TYPE_FILE: case FIOS_TYPE_OLDFILE: {
 				_switch_mode = SM_LOAD;
 				SetFiosType(item->type);
-				strcpy(_file_to_saveload.name, FiosBrowseTo(item));
-				break;
+
+				ttd_strlcpy(_file_to_saveload.name, FiosBrowseTo(item), sizeof(_file_to_saveload.name));
+				ttd_strlcpy(_file_to_saveload.title, item->title, sizeof(_file_to_saveload.title));
+			} break;
 			default: IConsolePrintF(_icolour_err, "%s: Not a savegame.", file);
 		}
 	} else
@@ -255,7 +258,7 @@
 
 	for (i = 0; i < _fios_num; i++) {
 		const FiosItem *item = &_fios_list[i];
-		IConsolePrintF(_icolour_def, "%d) %s", i, (item->title[0] != '\0') ? item->title : item->name);
+		IConsolePrintF(_icolour_def, "%d) %s", i, item->title);
 	}
 
 	FiosFreeSavegameList();
--- a/oldloader.c	Sun Jul 17 15:55:26 2005 +0000
+++ b/oldloader.c	Sun Jul 17 15:58:47 2005 +0000
@@ -1641,7 +1641,7 @@
 		return;
 
 	if (fread(title, 1, 48, f) != 48)
-		title[0] = '\0';
+		snprintf(title, 48, "Corrupt file");
 
 	fclose(f);
 }
--- a/os2.c	Sun Jul 17 15:55:26 2005 +0000
+++ b/os2.c	Sun Jul 17 15:58:47 2005 +0000
@@ -58,10 +58,7 @@
 	if (_savegame_sort_order < 2) // sort by date
 		r = da->mtime < db->mtime ? -1 : 1;
 	else
-		r = strcasecmp(
-			da->title[0] != '\0' ? da->title : da->name,
-			db->title[0] != '\0' ? db->title : db->name
-		);
+		r = strcasecmp(da->title, db->title);
 
 	if (_savegame_sort_order & 1) r = -r;
 	return r;
@@ -99,10 +96,7 @@
 		strcpy(_fios_save_path, _path.save_dir);
 	}
 
-	if (_game_mode == GM_EDITOR)
-		_fios_path = _fios_scn_path;
-	else
-		_fios_path = _fios_save_path;
+	_fios_path = _fios_scn_path;
 
 	// Parent directory, only if not of the type C:\.
 	if (_fios_path[3] != '\0') {
@@ -125,8 +119,7 @@
 				fios->type = FIOS_TYPE_DIR;
 				fios->mtime = 0;
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
-				snprintf(fios->title, lengthof(fios->title),
-					"%s\\ (Directory)", dirent->d_name);
+				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
 			}
 		}
 		closedir(dir);
@@ -162,8 +155,10 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_FILE;
 				fios->mtime = sb.st_mtime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
+
+				*t = '\0'; // strip extension
+				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
 				if (t != NULL && (
 							strcasecmp(t, ".ss1") == 0 ||
@@ -226,9 +221,8 @@
 	int sort_start;
 	char filename[MAX_PATH];
 
-	if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
-		if (_fios_scn_path == NULL)
-			_fios_scn_path = malloc(MAX_PATH);
+	if (_fios_scn_path == NULL) {
+		_fios_scn_path = malloc(MAX_PATH);
 		strcpy(_fios_scn_path, _path.scenario_dir);
 	}
 
@@ -254,8 +248,7 @@
 				fios->type = FIOS_TYPE_DIR;
 				fios->mtime = 0;
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
-				snprintf(fios->title, lengthof(fios->title),
-					"%s\\ (Directory)", dirent->d_name);
+				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", dirent->d_name);
 			}
 		}
 		closedir(dir);
@@ -282,8 +275,10 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_SCENARIO;
 				fios->mtime = sb.st_mtime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
+
+				*t = '\0'; // strip extension
+				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
 					mode == SLD_NEW_GAME) {
 				if (t != NULL && (
--- a/unix.c	Sun Jul 17 15:55:26 2005 +0000
+++ b/unix.c	Sun Jul 17 15:58:47 2005 +0000
@@ -62,10 +62,7 @@
 	if (_savegame_sort_order < 2) // sort by date
 		r = da->mtime < db->mtime ? -1 : 1;
 	else
-		r = strcasecmp(
-			da->title[0] != '\0' ? da->title : da->name,
-			db->title[0] != '\0' ? db->title : db->name
-		);
+		r = strcasecmp(da->title, db->title);
 
 	if (_savegame_sort_order & 1) r = -r;
 	return r;
@@ -87,10 +84,7 @@
 		strcpy(_fios_save_path, _path.save_dir);
 	}
 
-	if (_game_mode == GM_EDITOR)
-		_fios_path = _fios_scn_path;
-	else
-		_fios_path = _fios_save_path;
+	_fios_path = _fios_save_path;
 
 	// Parent directory, only if not in root already.
 	if (_fios_path[1] != '\0') {
@@ -151,8 +145,10 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_FILE;
 				fios->mtime = sb.st_mtime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
+
+				*t = '\0'; // strip extension
+				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
 				if (t != NULL && (
 							strcasecmp(t, ".ss1") == 0 ||
@@ -212,8 +208,7 @@
 				fios->type = FIOS_TYPE_DIR;
 				fios->mtime = 0;
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
-				snprintf(fios->title, lengthof(fios->title),
-					"%s/ (Directory)", dirent->d_name);
+				snprintf(fios->title, lengthof(fios->title), "%s/ (Directory)", dirent->d_name);
 			}
 		}
 		closedir(dir);
@@ -232,8 +227,7 @@
 		while ((dirent = readdir(dir)) != NULL) {
 			char *t;
 
-			snprintf(filename, lengthof(filename), "%s/%s",
-				_fios_path, dirent->d_name);
+			snprintf(filename, lengthof(filename), "%s/%s", _fios_path, dirent->d_name);
 			if (stat(filename, &sb) || S_ISDIR(sb.st_mode)) continue;
 
 			t = strrchr(dirent->d_name, '.');
@@ -241,8 +235,10 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_SCENARIO;
 				fios->mtime = sb.st_mtime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
+
+				*t  = '\0'; // strip extension
+				ttd_strlcpy(fios->title, dirent->d_name, lengthof(fios->title));
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
 					mode == SLD_NEW_GAME) {
 				if (t != NULL && (
--- a/variables.h	Sun Jul 17 15:55:26 2005 +0000
+++ b/variables.h	Sun Jul 17 15:58:47 2005 +0000
@@ -320,8 +320,9 @@
 
 // Deals with the type of the savegame, independent of extension
 typedef struct {
-	int mode;						// savegame/scenario type (old, new)
-	char name[MAX_PATH];	// name
+	int mode;             // savegame/scenario type (old, new)
+	char name[MAX_PATH];  // name
+	char title[255];      // internal name of the game
 } SmallFiosItem;
 
 // Used when switching from the intro menu.
--- a/win32.c	Sun Jul 17 15:55:26 2005 +0000
+++ b/win32.c	Sun Jul 17 15:58:47 2005 +0000
@@ -1579,10 +1579,7 @@
 	if (_savegame_sort_order < 2) // sort by date
 		r = da->mtime < db->mtime ? -1 : 1;
 	else
-		r = strcasecmp(
-			da->title[0] != '\0' ? da->title : da->name,
-			db->title[0] != '\0' ? db->title : db->name
-		);
+		r = strcasecmp(da->title, db->title);
 
 	if (_savegame_sort_order & 1) r = -r;
 	return r;
@@ -1602,10 +1599,7 @@
 		strcpy(_fios_save_path, _path.save_dir);
 	}
 
-	if (_game_mode == GM_EDITOR)
-		_fios_path = _fios_scn_path;
-	else
-		_fios_path = _fios_save_path;
+	_fios_path = _fios_save_path;
 
 	// Parent directory, only if not of the type C:\.
 	if (_fios_path[3] != '\0') {
@@ -1627,8 +1621,7 @@
 				fios->type = FIOS_TYPE_DIR;
 				fios->mtime = 0;
 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
-				snprintf(fios->title, lengthof(fios->title),
-					"%s\\ (Directory)", fd.cFileName);
+				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
 			}
 		} while (FindNextFile(h, &fd));
 		FindClose(h);
@@ -1655,8 +1648,11 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_FILE;
 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
+
+				*t = '\0'; // strip extension
+				ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
+
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
 				if (t != NULL && (
 							strcasecmp(t, ".ss1") == 0 ||
@@ -1706,9 +1702,8 @@
 	HANDLE h;
 	int sort_start;
 
-	if (mode == SLD_NEW_GAME || _fios_scn_path == NULL) {
-		if (_fios_scn_path == NULL)
-			_fios_scn_path = malloc(MAX_PATH);
+	if (_fios_scn_path == NULL) {
+		_fios_scn_path = malloc(MAX_PATH);
 		strcpy(_fios_scn_path, _path.scenario_dir);
 	}
 
@@ -1733,8 +1728,7 @@
 				fios->type = FIOS_TYPE_DIR;
 				fios->mtime = 0;
 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
-				snprintf(fios->title, lengthof(fios->title),
-					"%s\\ (Directory)", fd.cFileName);
+				snprintf(fios->title, lengthof(fios->title), "%s\\ (Directory)", fd.cFileName);
 			}
 		} while (FindNextFile(h, &fd));
 		FindClose(h);
@@ -1760,8 +1754,11 @@
 				fios = FiosAlloc();
 				fios->type = FIOS_TYPE_SCENARIO;
 				fios->mtime = *(uint64*)&fd.ftLastWriteTime;
-				fios->title[0] = '\0';
 				ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
+
+				*t  = '\0'; // strip extension
+				ttd_strlcpy(fios->title, fd.cFileName, lengthof(fios->title));
+
 			} else if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO ||
 					mode == SLD_NEW_GAME) {
 				if (t != NULL && (
@@ -2269,4 +2266,4 @@
 void CSleep(int milliseconds)
 {
 	Sleep(milliseconds);
-}
\ No newline at end of file
+}