src/fios.cpp
author rubidium
Fri, 25 Apr 2008 15:22:32 +0000
changeset 9055 4dc6a0c0ef47
parent 9032 0412a7e3c1d9
child 9131 d7da7ac0f845
permissions -rw-r--r--
(svn r12897) -Codechange: some coding style in station_cmd.cpp.
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     1
/* $Id$ */
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     2
6117
6507b2a7e71d (svn r8853) -Cleanup: doxygen changes. Correct forgotten c files to cpp files with the @file tag as well as a few general comments style
belugas
parents: 6088
diff changeset
     3
/** @file fios.cpp
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     4
 * This file contains functions for building file lists for the save/load dialogs.
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     5
 */
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     6
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     7
#include "stdafx.h"
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     8
#include "openttd.h"
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
     9
#include "variables.h"
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
    10
#include "heightmap.h"
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    11
#include "fios.h"
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6763
diff changeset
    12
#include "fileio.h"
8130
d2eb7d04f6e1 (svn r11691) -Codechange: move+rename helpers.hpp and only include it when it is really needed.
rubidium
parents: 7911
diff changeset
    13
#include "core/alloc_func.hpp"
8131
160939e24ed3 (svn r11692) -Codechange: move some functions from 'functions.h' to a more logical place and remove about 50% of the includes of 'functions.h'
rubidium
parents: 8130
diff changeset
    14
#include "functions.h"
8214
971f861d5543 (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8151
diff changeset
    15
#include "string_func.h"
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    16
#include <sys/types.h>
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    17
#include <sys/stat.h>
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    18
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    19
#ifdef WIN32
6251
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6247
diff changeset
    20
# include <tchar.h>
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    21
# include <io.h>
8378
5a5206510c1a (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8264
diff changeset
    22
# define access _taccess
5a5206510c1a (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8264
diff changeset
    23
# define unlink _tunlink
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    24
#else
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    25
# include <unistd.h>
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    26
#endif /* WIN32 */
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    27
8264
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    28
#include "table/strings.h"
b1e85998c7d3 (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8214
diff changeset
    29
4223
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    30
/* Variables to display file lists */
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    31
int _fios_num;
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    32
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    33
static char *_fios_path;
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    34
static FiosItem *_fios_items;
8151
4cefeef74c28 (svn r11713) -Codechange: Move some declarations and definitions in a more logical disposition
belugas
parents: 8131
diff changeset
    35
SmallFiosItem _file_to_saveload;
4223
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
    36
static int _fios_count, _fios_alloc;
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    37
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    38
/* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    39
extern bool FiosIsRoot(const char *path);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    40
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
6240
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6179
diff changeset
    41
extern bool FiosIsHiddenFile(const struct dirent *ent);
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
    42
extern void FiosGetDrives();
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    43
extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    44
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    45
/* get the name of an oldstyle savegame */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    46
extern void GetOldSaveGameName(char *title, const char *path, const char *file);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
    47
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    48
/**
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    49
 * Allocate a new FiosItem.
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    50
 * @return A pointer to the newly allocated FiosItem.
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    51
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
    52
FiosItem *FiosAlloc()
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    53
{
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    54
	if (_fios_count == _fios_alloc) {
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    55
		_fios_alloc += 256;
5609
dc6a58930ba4 (svn r8066) - Codechange: MallocT(), CallocT(), ReallocT() now return the pointer to allocated memory instead of modifying the pointer given as parameter
KUDr
parents: 5587
diff changeset
    56
		_fios_items = ReallocT(_fios_items, _fios_alloc);
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    57
	}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    58
	return &_fios_items[_fios_count++];
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    59
}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    60
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    61
/**
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    62
 * Compare two FiosItem's. Used with qsort when sorting the file list.
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    63
 * @param a A pointer to the first FiosItem to compare.
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6251
diff changeset
    64
 * @param b A pointer to the second FiosItem to compare.
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    65
 * @return -1, 0 or 1, depending on how the two items should be sorted.
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    66
 */
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    67
int CDECL compare_FiosItems(const void *a, const void *b)
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    68
{
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    69
	const FiosItem *da = (const FiosItem *)a;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    70
	const FiosItem *db = (const FiosItem *)b;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    71
	int r;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    72
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    73
	if (_savegame_sort_order & SORT_BY_NAME) {
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    74
		r = strcasecmp(da->title, db->title);
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    75
	} else {
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    76
		r = da->mtime < db->mtime ? -1 : 1;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    77
	}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    78
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    79
	if (_savegame_sort_order & SORT_DESCENDING) r = -r;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    80
	return r;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    81
}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    82
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    83
/**
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    84
 * Free the list of savegames
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    85
 */
6247
7d81e3a5d803 (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6240
diff changeset
    86
void FiosFreeSavegameList()
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    87
{
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    88
	free(_fios_items);
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    89
	_fios_items = NULL;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    90
	_fios_alloc = _fios_count = 0;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    91
}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
    92
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    93
/**
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    94
 * Get descriptive texts. Returns the path and free space
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    95
 * left on the device
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    96
 * @param path string describing the path
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    97
 * @param total_free total free space in megabytes, optional (can be NULL)
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    98
 * @return StringID describing the path (free space or failure)
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    99
 */
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   100
StringID FiosGetDescText(const char **path, uint32 *total_free)
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   101
{
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   102
	*path = _fios_path;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   103
	return FiosGetDiskFreeSpace(*path, total_free) ? STR_4005_BYTES_FREE : STR_4006_UNABLE_TO_READ_DRIVE;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   104
}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   105
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   106
/* Browse to a new path based on the passed FiosItem struct
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   107
 * @param *item FiosItem object telling us what to do
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   108
 * @return a string if we have given a file as a target, otherwise NULL */
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   109
char *FiosBrowseTo(const FiosItem *item)
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   110
{
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   111
	char *path = _fios_path;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   112
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   113
	switch (item->type) {
9032
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   114
		case FIOS_TYPE_DRIVE:
7408
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7138
diff changeset
   115
#if defined(WINCE)
9032
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   116
			sprintf(path, PATHSEP "");
7408
605b333582d5 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7138
diff changeset
   117
#elif defined(WIN32) || defined(__OS2__)
9032
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   118
			sprintf(path, "%c:" PATHSEP, item->title[0]);
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   119
#endif
9032
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   120
		/* Fallthrough */
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   121
		case FIOS_TYPE_INVALID:
0412a7e3c1d9 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 9031
diff changeset
   122
			break;
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   123
9030
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   124
		case FIOS_TYPE_PARENT: {
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   125
			/* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   126
			char *s = strrchr(path, PATHSEPCHAR);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   127
			if (s != NULL && s != path) {
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   128
				s[0] = '\0'; // Remove last path separator character, so we can go up one level.
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   129
			}
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   130
			s = strrchr(path, PATHSEPCHAR);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   131
			if (s != NULL) s[1] = '\0'; // go up a directory
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   132
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   133
			/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   134
			else if ((s = strrchr(path, ':')) != NULL) s[1] = '\0';
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   135
#endif
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   136
			break;
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   137
		}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   138
9030
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   139
		case FIOS_TYPE_DIR:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   140
			strcat(path, item->name);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   141
			strcat(path, PATHSEP);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   142
			break;
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   143
9030
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   144
		case FIOS_TYPE_DIRECT:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   145
			sprintf(path, "%s", item->name);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   146
			break;
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   147
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   148
		case FIOS_TYPE_FILE:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   149
		case FIOS_TYPE_OLDFILE:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   150
		case FIOS_TYPE_SCENARIO:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   151
		case FIOS_TYPE_OLD_SCENARIO:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   152
		case FIOS_TYPE_PNG:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   153
		case FIOS_TYPE_BMP:
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   154
		{
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   155
			static char str_buffr[512];
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   156
			snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   157
			return str_buffr;
096c2ae42927 (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8378
diff changeset
   158
		}
4222
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   159
	}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   160
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   161
	return NULL;
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   162
}
36e9bd216011 (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   163
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   164
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   165
{
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   166
	const char *extension, *period;
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   167
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   168
	extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   169
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   170
	/* Don't append the extension if it is already there */
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   171
	period = strrchr(name, '.');
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   172
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
7911
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   173
#if  defined(__MORPHOS__) || defined(__AMIGAOS__)
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   174
	if (_fios_path != NULL) {
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   175
		unsigned char sepchar = _fios_path[(strlen(_fios_path) - 1)];
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   176
7911
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   177
		if (sepchar != ':' && sepchar != '/') {
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   178
			snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   179
		} else {
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   180
			snprintf(buf, size, "%s%s%s", _fios_path, name, extension);
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   181
		}
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   182
	} else {
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   183
		snprintf(buf, size, "%s%s", name, extension);
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   184
	}
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   185
#else
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   186
	snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
7911
48610042ac18 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7408
diff changeset
   187
#endif
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   188
}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   189
6251
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6247
diff changeset
   190
#if defined(WIN32)
2ad87f850eb9 (svn r9055) -Codechange: Change windows unicode handling and allow a pure non-unicode build to function. Win9x binaries will be possible with mingw/nightly system.
Darkvater
parents: 6247
diff changeset
   191
# define unlink _tunlink
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   192
#endif
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   193
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   194
bool FiosDelete(const char *name)
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   195
{
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   196
	char filename[512];
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   197
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   198
	FiosMakeSavegameName(filename, name, lengthof(filename));
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   199
	return unlink(OTTD2FS(filename)) == 0;
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   200
}
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   201
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   202
bool FileExists(const char *filename)
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   203
{
5757
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   204
#if defined(WINCE)
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   205
	/* There is always one platform that doesn't support basic commands... */
6124
9f822ae6c086 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 6117
diff changeset
   206
	HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
5757
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   207
	if (hand == INVALID_HANDLE_VALUE) return 1;
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   208
	CloseHandle(hand);
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   209
	return 0;
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   210
#else
8378
5a5206510c1a (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8264
diff changeset
   211
	return access(OTTD2FS(filename), 0) == 0;
5757
04e5be1f7d71 (svn r8308) [WinCE] -Revert r5764: in case of WinCE, use the code for FileExists as it was in pre-r5764 for Win32 (tnx Darkvater)
truelight
parents: 5609
diff changeset
   212
#endif
4220
e3bee34c9076 (svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
Darkvater
parents:
diff changeset
   213
}
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   214
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   215
typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   216
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   217
/** Create a list of the files in a directory, according to some arbitrary rule.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   218
 *  @param mode The mode we are in. Some modes don't allow 'parent'.
6481
85ad87daf4b0 (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6251
diff changeset
   219
 *  @param callback_proc The function that is called where you need to do the filtering.
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   220
 *  @return Return the list of files. */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   221
static FiosItem *FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   222
{
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   223
	struct stat sb;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   224
	struct dirent *dirent;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   225
	DIR *dir;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   226
	FiosItem *fios;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   227
	int sort_start;
6054
e42d8064c845 (svn r8784) -Regression (r7274 most likely): Unable to load TTDP (on *NIX) games because the static buffer used for name conversion is overwritten in the callback function.
Darkvater
parents: 5757
diff changeset
   228
	char d_name[sizeof(fios->name)];
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   229
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   230
	/* A parent directory link exists if we are not in the root directory */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   231
	if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   232
		fios = FiosAlloc();
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   233
		fios->type = FIOS_TYPE_PARENT;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   234
		fios->mtime = 0;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   235
		ttd_strlcpy(fios->name, "..", lengthof(fios->name));
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   236
		ttd_strlcpy(fios->title, ".. (Parent directory)", lengthof(fios->title));
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   237
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   238
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   239
	/* Show subdirectories */
6086
37ea367a54e6 (svn r8821) -Regression: Unable to browse directories on *nix if the filesystem is not in UTF-8 charset and special characters are used. The string passed to opendir() which is UTF-8 was not parsed back to the filesystem format. Use a wrapper called ttd_opendir() instead of redefining opendir itself.
Darkvater
parents: 6054
diff changeset
   240
	if (mode != SLD_NEW_GAME && (dir = ttd_opendir(_fios_path)) != NULL) {
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   241
		while ((dirent = readdir(dir)) != NULL) {
6054
e42d8064c845 (svn r8784) -Regression (r7274 most likely): Unable to load TTDP (on *NIX) games because the static buffer used for name conversion is overwritten in the callback function.
Darkvater
parents: 5757
diff changeset
   242
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   243
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   244
			/* found file must be directory, but not '.' or '..' */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   245
			if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
6240
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6179
diff changeset
   246
					(!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6179
diff changeset
   247
					strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   248
				fios = FiosAlloc();
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   249
				fios->type = FIOS_TYPE_DIR;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   250
				fios->mtime = 0;
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   251
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   252
				snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   253
				str_validate(fios->title);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   254
			}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   255
		}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   256
		closedir(dir);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   257
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   258
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   259
	/* Sort the subdirs always by name, ascending, remember user-sorting order */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   260
	{
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   261
		byte order = _savegame_sort_order;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   262
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   263
		qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   264
		_savegame_sort_order = order;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   265
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   266
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   267
	/* This is where to start sorting for the filenames */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   268
	sort_start = _fios_count;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   269
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   270
	/* Show files */
6086
37ea367a54e6 (svn r8821) -Regression: Unable to browse directories on *nix if the filesystem is not in UTF-8 charset and special characters are used. The string passed to opendir() which is UTF-8 was not parsed back to the filesystem format. Use a wrapper called ttd_opendir() instead of redefining opendir itself.
Darkvater
parents: 6054
diff changeset
   271
	dir = ttd_opendir(_fios_path);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   272
	if (dir != NULL) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   273
		while ((dirent = readdir(dir)) != NULL) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   274
			char fios_title[64];
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   275
			char *t;
6054
e42d8064c845 (svn r8784) -Regression (r7274 most likely): Unable to load TTDP (on *NIX) games because the static buffer used for name conversion is overwritten in the callback function.
Darkvater
parents: 5757
diff changeset
   276
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   277
6240
9d9874ef9f0b (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6179
diff changeset
   278
			if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   279
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   280
			/* File has no extension, skip it */
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   281
			if ((t = strrchr(d_name, '.')) == NULL) continue;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   282
			fios_title[0] = '\0'; // reset the title;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   283
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   284
			FiosType type = callback_proc(mode, d_name, t, fios_title);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   285
			if (type != FIOS_TYPE_INVALID) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   286
				fios = FiosAlloc();
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   287
				fios->mtime = sb.st_mtime;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   288
				fios->type = type;
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   289
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   290
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   291
				/* Some callbacks want to lookup the title of the file. Allow that.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   292
				 * If we just copy the title from the filename, strip the extension */
5167
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   293
				t = (fios_title[0] == '\0') ? *t = '\0', d_name : fios_title;
12c46fb7eccf (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   294
				ttd_strlcpy(fios->title, t, lengthof(fios->title));
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   295
				str_validate(fios->title);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   296
			}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   297
		}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   298
		closedir(dir);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   299
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   300
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   301
	qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   302
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   303
	/* Show drives */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   304
	if (mode != SLD_NEW_GAME) FiosGetDrives();
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   305
4223
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
   306
	_fios_num = _fios_count;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   307
	return _fios_items;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   308
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   309
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   310
/**
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   311
 * Callback for FiosGetFileList. It tells if a file is a savegame or not.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   312
 * @param mode Save/load mode.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   313
 * @param file Name of the file to check.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   314
 * @param ext A pointer to the extension identifier inside file
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   315
 * @param title Buffer if a callback wants to lookup the title of the file
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   316
 * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   317
 * @see FiosGetFileList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   318
 * @see FiosGetSavegameList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   319
 */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   320
static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   321
{
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   322
	/* Show savegame files
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   323
	 * .SAV OpenTTD saved game
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   324
	 * .SS1 Transport Tycoon Deluxe preset game
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   325
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   326
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   327
	if (strcasecmp(ext, ".sav") == 0) return FIOS_TYPE_FILE;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   328
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   329
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   330
		if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   331
				strcasecmp(ext, ".sv2") == 0) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   332
			GetOldSaveGameName(title, _fios_path, file);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   333
			return FIOS_TYPE_OLDFILE;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   334
		}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   335
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   336
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   337
	return FIOS_TYPE_INVALID;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   338
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   339
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   340
/**
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   341
 * Get a list of savegames.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   342
 * @param mode Save/load mode.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   343
 * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   344
 * @see FiosGetFileList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   345
 */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   346
FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode)
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   347
{
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   348
	static char *fios_save_path = NULL;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   349
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   350
	if (fios_save_path == NULL) {
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   351
		fios_save_path = MallocT<char>(MAX_PATH);
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   352
		FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   353
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   354
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   355
	_fios_path = fios_save_path;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   356
4223
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
   357
	return FiosGetFileList(mode, &FiosGetSavegameListCallback);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   358
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   359
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   360
/**
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   361
 * Callback for FiosGetFileList. It tells if a file is a scenario or not.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   362
 * @param mode Save/load mode.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   363
 * @param file Name of the file to check.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   364
 * @param ext A pointer to the extension identifier inside file
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   365
 * @param title Buffer if a callback wants to lookup the title of the file
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   366
 * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   367
 * @see FiosGetFileList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   368
 * @see FiosGetScenarioList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   369
 */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   370
static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   371
{
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   372
	/* Show scenario files
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   373
	 * .SCN OpenTTD style scenario file
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   374
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   375
	 * .SS0 Transport Tycoon Deluxe preset scenario */
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   376
	if (strcasecmp(ext, ".scn") == 0) return FIOS_TYPE_SCENARIO;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   377
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   378
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   379
		if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   380
			GetOldSaveGameName(title, _fios_path, file);
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   381
			return FIOS_TYPE_OLD_SCENARIO;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   382
		}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   383
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   384
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   385
	return FIOS_TYPE_INVALID;
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   386
}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   387
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   388
/**
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   389
 * Get a list of scenarios.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   390
 * @param mode Save/load mode.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   391
 * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   392
 * @see FiosGetFileList
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   393
 */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   394
FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode)
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   395
{
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   396
	static char *fios_scn_path = NULL;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   397
6929
56470c1b8a66 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 6763
diff changeset
   398
	/* Copy the default path on first run or on 'New Game' */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   399
	if (fios_scn_path == NULL) {
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   400
		fios_scn_path = MallocT<char>(MAX_PATH);
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   401
		FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   402
	}
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   403
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   404
	_fios_path = fios_scn_path;
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   405
4223
d4c9ef555f43 (svn r5767) - Cleanup: Improve upon the header file mess regarding fios. Move all relevant types from hal.h into fios.h, eliminate the unneccessary passing of a global variable, and extern variables in header files (declare in fios.c and misc_gui.c
Darkvater
parents: 4222
diff changeset
   406
	return FiosGetFileList(mode, &FiosGetScenarioListCallback);
4221
ff4a040f30c6 (svn r5765) - Codechange: Fully unify the OS-specific FiosGet...List functions into fios.c, as well as FiosGetSavegameList and FiosGetScenarioList functions with the help of some callbacks.
Darkvater
parents: 4220
diff changeset
   407
}
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   408
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   409
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   410
{
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   411
	/* Show heightmap files
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   412
	 * .PNG PNG Based heightmap files
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   413
	 * .BMP BMP Based heightmap files
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   414
	 */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   415
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   416
#ifdef WITH_PNG
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   417
	if (strcasecmp(ext, ".png") == 0) return FIOS_TYPE_PNG;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   418
#endif /* WITH_PNG */
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   419
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   420
	if (strcasecmp(ext, ".bmp") == 0) return FIOS_TYPE_BMP;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   421
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   422
	return FIOS_TYPE_INVALID;
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   423
}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   424
6179
d19b0137d8e4 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6124
diff changeset
   425
/* Get a list of Heightmaps */
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   426
FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode)
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   427
{
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   428
	static char *fios_hmap_path = NULL;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   429
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   430
	if (fios_hmap_path == NULL) {
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   431
		fios_hmap_path = MallocT<char>(MAX_PATH);
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   432
		FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   433
	}
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   434
9031
445046ca06af (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 9030
diff changeset
   435
	_fios_path = fios_hmap_path;
4300
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   436
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   437
	return FiosGetFileList(mode, &FiosGetHeightmapListCallback);
c7e43c47a2b9 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   438
}