mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-03-06 14:27:16 +00:00
(svn r2860) Fix some issues in the savegame/scenario list code:
-Fix: Sort the directories when making a scenario list -Fix: Sort the directories when making a savegame list on Windows -Fix: On OS/2 show the trailing \ if the current directory is a root directory -Regression: On OS/2 the savegame list showed the scenario directory or crashed (probably introduced in r2609) The rest is diff reduction between the 3 variants
This commit is contained in:
parent
7e702e2d50
commit
bdff0fa2d2
55
os2.c
55
os2.c
@ -61,14 +61,6 @@ int compare_FiosItems(const void *a, const void *b)
|
||||
}
|
||||
|
||||
|
||||
static DIR *my_opendir(char *path, char *file)
|
||||
{
|
||||
char paths[MAX_PATH];
|
||||
|
||||
append_path(paths, path, file);
|
||||
return opendir(paths);
|
||||
}
|
||||
|
||||
static void append_path(char *out, const char *path, const char *file)
|
||||
{
|
||||
if (path[2] == '\\' && path[3] == '\0')
|
||||
@ -92,7 +84,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
strcpy(_fios_save_path, _path.save_dir);
|
||||
}
|
||||
|
||||
_fios_path = _fios_scn_path;
|
||||
_fios_path = _fios_save_path;
|
||||
|
||||
// Parent directory, only if not of the type C:\.
|
||||
if (_fios_path[3] != '\0') {
|
||||
@ -104,7 +96,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
}
|
||||
|
||||
// Show subdirectories first
|
||||
dir = my_opendir(_fios_path, "*.*");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
append_path(filename, _fios_path, dirent->d_name);
|
||||
@ -138,7 +130,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
* .SV1 Transport Tycoon Deluxe (Patch) saved game
|
||||
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
|
||||
*/
|
||||
dir = my_opendir(_fios_path, "*.*");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t;
|
||||
@ -184,15 +176,13 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
_dos_getdrive(&save);
|
||||
|
||||
/* get available drive letters */
|
||||
for (disk = 1; disk < 27; ++disk)
|
||||
{
|
||||
for (disk = 1; disk < 27; ++disk) {
|
||||
uint disk2;
|
||||
|
||||
_dos_setdrive(disk, &total);
|
||||
_dos_getdrive(&disk2);
|
||||
|
||||
if (disk == disk2)
|
||||
{
|
||||
if (disk == disk2) {
|
||||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_DRIVE;
|
||||
sprintf(fios->name, "%c:", 'A' + disk - 1);
|
||||
@ -233,7 +223,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
}
|
||||
|
||||
// Show subdirectories first
|
||||
dir = my_opendir(_fios_path, "*.*");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
append_path(filename, _fios_path, dirent->d_name);
|
||||
@ -250,6 +240,14 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
{
|
||||
/* XXX ugly global variables ... */
|
||||
byte order = _savegame_sort_order;
|
||||
_savegame_sort_order = 2; // sort ascending by name
|
||||
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
|
||||
_savegame_sort_order = order;
|
||||
}
|
||||
|
||||
// this is where to start sorting
|
||||
sort_start = _fios_count;
|
||||
|
||||
@ -258,7 +256,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
* .SV0 Transport Tycoon Deluxe (Patch) scenario
|
||||
* .SS0 Transport Tycoon Deluxe preset scenario
|
||||
*/
|
||||
dir = my_opendir(_fios_path, "*.*");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t;
|
||||
@ -295,8 +293,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
|
||||
|
||||
// Drives
|
||||
if (mode != SLD_NEW_GAME)
|
||||
{
|
||||
if (mode != SLD_NEW_GAME) {
|
||||
unsigned save, disk, disk2, total;
|
||||
|
||||
/* save original drive */
|
||||
@ -304,13 +301,11 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
|
||||
/* get available drive letters */
|
||||
|
||||
for (disk = 1; disk < 27; ++disk)
|
||||
{
|
||||
for (disk = 1; disk < 27; ++disk) {
|
||||
_dos_setdrive(disk, &total);
|
||||
_dos_getdrive(&disk2);
|
||||
|
||||
if (disk == disk2)
|
||||
{
|
||||
if (disk == disk2) {
|
||||
fios = FiosAlloc();
|
||||
fios->type = FIOS_TYPE_DRIVE;
|
||||
sprintf(fios->name, "%c:", 'A' + disk - 1);
|
||||
@ -347,13 +342,14 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||
|
||||
case FIOS_TYPE_PARENT:
|
||||
s = strrchr(path, '\\');
|
||||
if (s != NULL) *s = '\0';
|
||||
if (s != path + 2)
|
||||
s[0] = '\0';
|
||||
else
|
||||
s[1] = '\0';
|
||||
break;
|
||||
|
||||
case FIOS_TYPE_DIR:
|
||||
s = strchr(item->name, '\\');
|
||||
if (s != NULL) *s = '\0';
|
||||
if (path[3]!= '\0' ) strcat(path, "\\");
|
||||
if (path[3] != '\0') strcat(path, "\\");
|
||||
strcat(path, item->name);
|
||||
break;
|
||||
|
||||
@ -437,9 +433,10 @@ int GetLanguageList(char **languages, int max)
|
||||
|
||||
dir = opendir(_path.lang_dir);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir))) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t = strrchr(dirent->d_name, '.');
|
||||
if (t && !strcmp(t, ".lng")) {
|
||||
|
||||
if (t != NULL && strcmp(t, ".lng") == 0) {
|
||||
languages[num++] = strdup(dirent->d_name);
|
||||
if (num == max) break;
|
||||
}
|
||||
|
28
unix.c
28
unix.c
@ -103,7 +103,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
}
|
||||
|
||||
// Show subdirectories first
|
||||
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
snprintf(filename, lengthof(filename), "%s/%s",
|
||||
@ -138,7 +138,7 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
* .SV1 Transport Tycoon Deluxe (Patch) saved game
|
||||
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game
|
||||
*/
|
||||
dir = opendir(_fios_path[0] != '\0' ? _fios_path : "/");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t;
|
||||
@ -193,6 +193,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
_fios_scn_path = malloc(MAX_PATH);
|
||||
strcpy(_fios_scn_path, _path.scenario_dir);
|
||||
}
|
||||
|
||||
_fios_path = _fios_scn_path;
|
||||
|
||||
// Parent directory, only if not of the type C:\.
|
||||
@ -204,7 +205,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
}
|
||||
|
||||
// Show subdirectories first
|
||||
dir = opendir(_fios_path[0] ? _fios_path : "/");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
snprintf(filename, lengthof(filename), "%s/%s",
|
||||
@ -221,6 +222,14 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
closedir(dir);
|
||||
}
|
||||
|
||||
{
|
||||
/* XXX ugly global variables ... */
|
||||
byte order = _savegame_sort_order;
|
||||
_savegame_sort_order = 2; // sort ascending by name
|
||||
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
|
||||
_savegame_sort_order = order;
|
||||
}
|
||||
|
||||
// this is where to start sorting
|
||||
sort_start = _fios_count;
|
||||
|
||||
@ -229,7 +238,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
* .SV0 Transport Tycoon Deluxe (Patch) scenario
|
||||
* .SS0 Transport Tycoon Deluxe preset scenario
|
||||
*/
|
||||
dir = opendir(_fios_path[0] ? _fios_path : "/");
|
||||
dir = opendir(_fios_path);
|
||||
if (dir != NULL) {
|
||||
while ((dirent = readdir(dir)) != NULL) {
|
||||
char *t;
|
||||
@ -244,7 +253,7 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
fios->mtime = sb.st_mtime;
|
||||
ttd_strlcpy(fios->name, dirent->d_name, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
*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) {
|
||||
@ -286,13 +295,14 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||
switch (item->type) {
|
||||
case FIOS_TYPE_PARENT:
|
||||
s = strrchr(path, '/');
|
||||
if (s != NULL) *s = '\0';
|
||||
if (s != path)
|
||||
s[0] = '\0';
|
||||
else
|
||||
s[1] = '\0';
|
||||
break;
|
||||
|
||||
case FIOS_TYPE_DIR:
|
||||
s = strchr(item->name, '/');
|
||||
if (s != NULL) *s = '\0';
|
||||
strcat(path, "/");
|
||||
if (path[1] != '\0') strcat(path, "/");
|
||||
strcat(path, item->name);
|
||||
break;
|
||||
|
||||
|
30
win32.c
30
win32.c
@ -647,6 +647,14 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
{
|
||||
/* XXX ugly global variables ... */
|
||||
byte order = _savegame_sort_order;
|
||||
_savegame_sort_order = 2; // sort ascending by name
|
||||
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
|
||||
_savegame_sort_order = order;
|
||||
}
|
||||
|
||||
// this is where to start sorting
|
||||
sort_start = _fios_count;
|
||||
|
||||
@ -672,7 +680,6 @@ FiosItem *FiosGetSavegameList(int *num, int mode)
|
||||
|
||||
*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 ||
|
||||
@ -754,6 +761,14 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
FindClose(h);
|
||||
}
|
||||
|
||||
{
|
||||
/* XXX ugly global variables ... */
|
||||
byte order = _savegame_sort_order;
|
||||
_savegame_sort_order = 2; // sort ascending by name
|
||||
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
|
||||
_savegame_sort_order = order;
|
||||
}
|
||||
|
||||
// this is where to start sorting
|
||||
sort_start = _fios_count;
|
||||
|
||||
@ -776,9 +791,8 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
fios->mtime = *(uint64*)&fd.ftLastWriteTime;
|
||||
ttd_strlcpy(fios->name, fd.cFileName, lengthof(fios->name));
|
||||
|
||||
*t = '\0'; // strip extension
|
||||
*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 && (
|
||||
@ -842,14 +856,14 @@ char *FiosBrowseTo(const FiosItem *item)
|
||||
|
||||
case FIOS_TYPE_PARENT:
|
||||
s = strrchr(path, '\\');
|
||||
if (s != NULL) *s = '\0';
|
||||
if (path[2] == '\0' ) strcat(path, "\\");
|
||||
if (s != path + 2)
|
||||
s[0] = '\0';
|
||||
else
|
||||
s[1] = '\0';
|
||||
break;
|
||||
|
||||
case FIOS_TYPE_DIR:
|
||||
s = strchr(item->name, '\\');
|
||||
if (s != NULL) *s = '\0';
|
||||
if (path[3] != '\0' ) strcat(path, "\\");
|
||||
if (path[3] != '\0') strcat(path, "\\");
|
||||
strcat(path, item->name);
|
||||
break;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user