src/fios.cpp
author rubidium
Fri, 18 Jul 2008 12:20:31 +0000
changeset 11171 04fc8e49df1b
parent 10808 d42b140d24f2
permissions -rw-r--r--
(svn r13729) -Fix: assumption that non-north tiles of a house do not have the 1x1 building bit set was flawed with some NewGRFs. This caused the amount of houses to differ, which causes the town radii to differ, which causes desyncs when towns are expanded.
4220
86ca889037b3 (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$ */
86ca889037b3 (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
6443
b8f06d8eb7be (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: 6414
diff changeset
     3
/** @file fios.cpp
4220
86ca889037b3 (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.
86ca889037b3 (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
 */
86ca889037b3 (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
86ca889037b3 (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"
86ca889037b3 (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"
86ca889037b3 (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
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
    10
#include "heightmap.h"
4221
bb06fe8dcce2 (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"
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7259
diff changeset
    12
#include "fileio.h"
8627
448ebf3a8291 (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: 8626
diff changeset
    13
#include "functions.h"
8710
52015340050c (svn r11777) -Codechange: split the string header and make do not include it when it's not necessary.
rubidium
parents: 8647
diff changeset
    14
#include "string_func.h"
4220
86ca889037b3 (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
    15
#include <sys/types.h>
86ca889037b3 (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/stat.h>
86ca889037b3 (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
86ca889037b3 (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
#ifdef WIN32
6577
ee768d653dd0 (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: 6573
diff changeset
    19
# include <tchar.h>
10458
c0a45f0594cf (svn r13000) -Fix (r12991): broken win9x compilation
glx
parents: 10449
diff changeset
    20
# ifndef UNICODE
c0a45f0594cf (svn r13000) -Fix (r12991): broken win9x compilation
glx
parents: 10449
diff changeset
    21
#  include <io.h>
c0a45f0594cf (svn r13000) -Fix (r12991): broken win9x compilation
glx
parents: 10449
diff changeset
    22
# endif
8874
c165c8f53102 (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8760
diff changeset
    23
# define access _taccess
c165c8f53102 (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8760
diff changeset
    24
# define unlink _tunlink
4220
86ca889037b3 (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
#else
86ca889037b3 (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
# include <unistd.h>
86ca889037b3 (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
#endif /* WIN32 */
86ca889037b3 (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
    28
8760
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8710
diff changeset
    29
#include "table/strings.h"
ce0891c412ce (svn r11828) -Codechange: include table/* as the last includes and remove an unneeded include from openttd.h.
rubidium
parents: 8710
diff changeset
    30
4223
0f9535dda7ed (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
/* Variables to display file lists */
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
    32
SmallVector<FiosItem, 32> _fios_items;
4223
0f9535dda7ed (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;
8647
0709611186e0 (svn r11713) -Codechange: Move some declarations and definitions in a more logical disposition
belugas
parents: 8627
diff changeset
    34
SmallFiosItem _file_to_saveload;
4220
86ca889037b3 (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
    35
4221
bb06fe8dcce2 (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
    36
/* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
bb06fe8dcce2 (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
    37
extern bool FiosIsRoot(const char *path);
bb06fe8dcce2 (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
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
6566
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6505
diff changeset
    39
extern bool FiosIsHiddenFile(const struct dirent *ent);
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6566
diff changeset
    40
extern void FiosGetDrives();
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    41
extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot);
4221
bb06fe8dcce2 (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
    42
bb06fe8dcce2 (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
    43
/* get the name of an oldstyle savegame */
bb06fe8dcce2 (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
extern void GetOldSaveGameName(char *title, const char *path, const char *file);
bb06fe8dcce2 (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
4220
86ca889037b3 (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
    46
/**
86ca889037b3 (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
    47
 * Compare two FiosItem's. Used with qsort when sorting the file list.
86ca889037b3 (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
 * @param a A pointer to the first FiosItem to compare.
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6577
diff changeset
    49
 * @param b A pointer to the second FiosItem to compare.
4220
86ca889037b3 (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 -1, 0 or 1, depending on how the two items should be sorted.
86ca889037b3 (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
 */
86ca889037b3 (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
    52
int CDECL compare_FiosItems(const void *a, const void *b)
86ca889037b3 (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
{
86ca889037b3 (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
	const FiosItem *da = (const FiosItem *)a;
86ca889037b3 (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
	const FiosItem *db = (const FiosItem *)b;
86ca889037b3 (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
    56
	int r;
86ca889037b3 (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
86ca889037b3 (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
	if (_savegame_sort_order & SORT_BY_NAME) {
86ca889037b3 (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
		r = strcasecmp(da->title, db->title);
86ca889037b3 (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
	} else {
86ca889037b3 (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
		r = da->mtime < db->mtime ? -1 : 1;
86ca889037b3 (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
	}
86ca889037b3 (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
86ca889037b3 (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
    64
	if (_savegame_sort_order & SORT_DESCENDING) r = -r;
86ca889037b3 (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 r;
86ca889037b3 (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
}
86ca889037b3 (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
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
    68
/** Clear the list */
6573
7624f942237f (svn r9050) -Codechange: Foo(void) -> Foo()
rubidium
parents: 6566
diff changeset
    69
void FiosFreeSavegameList()
4220
86ca889037b3 (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
{
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
    71
	_fios_items.Clear();
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
    72
	_fios_items.Compact();
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
    73
};
4220
86ca889037b3 (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
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    75
/**
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    76
 * Get descriptive texts. Returns the path and free space
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    77
 * left on the device
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    78
 * @param path string describing the path
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    79
 * @param total_free total free space in megabytes, optional (can be NULL)
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    80
 * @return StringID describing the path (free space or failure)
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    81
 */
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    82
StringID FiosGetDescText(const char **path, uint32 *total_free)
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    83
{
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    84
	*path = _fios_path;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    85
	return FiosGetDiskFreeSpace(*path, total_free) ? STR_4005_BYTES_FREE : STR_4006_UNABLE_TO_READ_DRIVE;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    86
}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    87
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    88
/* Browse to a new path based on the passed FiosItem struct
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    89
 * @param *item FiosItem object telling us what to do
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    90
 * @return a string if we have given a file as a target, otherwise NULL */
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    91
char *FiosBrowseTo(const FiosItem *item)
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    92
{
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    93
	char *path = _fios_path;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    94
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
    95
	switch (item->type) {
10309
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
    96
		case FIOS_TYPE_DRIVE:
7904
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7634
diff changeset
    97
#if defined(WINCE)
10309
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
    98
			sprintf(path, PATHSEP "");
7904
238db1373ca3 (svn r10781) -Fix: ported more pieces to WinCE, so it compiles a bit more
truelight
parents: 7634
diff changeset
    99
#elif defined(WIN32) || defined(__OS2__)
10309
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
   100
			sprintf(path, "%c:" PATHSEP, item->title[0]);
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   101
#endif
10309
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
   102
		/* Fallthrough */
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
   103
		case FIOS_TYPE_INVALID:
717d0e92ffe6 (svn r12850) -Fix (r12848): compilation was broken for some platforms
glx
parents: 10307
diff changeset
   104
			break;
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   105
10306
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   106
		case FIOS_TYPE_PARENT: {
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   107
			/* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   108
			char *s = strrchr(path, PATHSEPCHAR);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   109
			if (s != NULL && s != path) {
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   110
				s[0] = '\0'; // Remove last path separator character, so we can go up one level.
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   111
			}
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   112
			s = strrchr(path, PATHSEPCHAR);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   113
			if (s != NULL) s[1] = '\0'; // go up a directory
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   114
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   115
			/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   116
			else if ((s = strrchr(path, ':')) != NULL) s[1] = '\0';
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   117
#endif
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   118
			break;
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   119
		}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   120
10306
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   121
		case FIOS_TYPE_DIR:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   122
			strcat(path, item->name);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   123
			strcat(path, PATHSEP);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   124
			break;
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   125
10306
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   126
		case FIOS_TYPE_DIRECT:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   127
			sprintf(path, "%s", item->name);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   128
			break;
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   129
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   130
		case FIOS_TYPE_FILE:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   131
		case FIOS_TYPE_OLDFILE:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   132
		case FIOS_TYPE_SCENARIO:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   133
		case FIOS_TYPE_OLD_SCENARIO:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   134
		case FIOS_TYPE_PNG:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   135
		case FIOS_TYPE_BMP:
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   136
		{
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   137
			static char str_buffr[512];
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   138
			snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   139
			return str_buffr;
772197a76d4b (svn r12847) -Cleanup: Identing and variable scope
peter1138
parents: 8874
diff changeset
   140
		}
4222
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   141
	}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   142
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   143
	return NULL;
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   144
}
951fbf19b1ad (svn r5766) - Cleanup: Unify FiosBrowseTo and FiosGetDescText
Darkvater
parents: 4221
diff changeset
   145
4220
86ca889037b3 (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
   146
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
86ca889037b3 (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
   147
{
86ca889037b3 (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
   148
	const char *extension, *period;
86ca889037b3 (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
   149
86ca889037b3 (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
   150
	extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
86ca889037b3 (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
   151
86ca889037b3 (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
   152
	/* Don't append the extension if it is already there */
86ca889037b3 (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
   153
	period = strrchr(name, '.');
86ca889037b3 (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
   154
	if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
8407
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   155
#if  defined(__MORPHOS__) || defined(__AMIGAOS__)
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   156
	if (_fios_path != NULL) {
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   157
		unsigned char sepchar = _fios_path[(strlen(_fios_path) - 1)];
4220
86ca889037b3 (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
   158
8407
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   159
		if (sepchar != ':' && sepchar != '/') {
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   160
			snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   161
		} else {
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   162
			snprintf(buf, size, "%s%s%s", _fios_path, name, extension);
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   163
		}
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   164
	} else {
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   165
		snprintf(buf, size, "%s%s", name, extension);
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   166
	}
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   167
#else
4220
86ca889037b3 (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
	snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
8407
f2f6dae6b6d3 (svn r11464) -Fix: some issue that made OpenTTD on MorphOS seriously unplayable.
rubidium
parents: 7904
diff changeset
   169
#endif
4220
86ca889037b3 (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
}
86ca889037b3 (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
6577
ee768d653dd0 (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: 6573
diff changeset
   172
#if defined(WIN32)
ee768d653dd0 (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: 6573
diff changeset
   173
# define unlink _tunlink
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   174
#endif
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   175
4220
86ca889037b3 (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
bool FiosDelete(const char *name)
86ca889037b3 (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
   177
{
86ca889037b3 (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
   178
	char filename[512];
86ca889037b3 (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
   179
86ca889037b3 (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
   180
	FiosMakeSavegameName(filename, name, lengthof(filename));
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   181
	return unlink(OTTD2FS(filename)) == 0;
4220
86ca889037b3 (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
   182
}
86ca889037b3 (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
   183
86ca889037b3 (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
   184
bool FileExists(const char *filename)
86ca889037b3 (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
   185
{
6008
1ed2f76ac388 (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: 5860
diff changeset
   186
#if defined(WINCE)
1ed2f76ac388 (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: 5860
diff changeset
   187
	/* There is always one platform that doesn't support basic commands... */
6450
1c2016673250 (svn r8860) -Cleanup: some style changes, proper #endif comments, variable initialisation, WINCE ifdef and a vsprintf to vsnprintf change.
Darkvater
parents: 6443
diff changeset
   188
	HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
6008
1ed2f76ac388 (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: 5860
diff changeset
   189
	if (hand == INVALID_HANDLE_VALUE) return 1;
1ed2f76ac388 (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: 5860
diff changeset
   190
	CloseHandle(hand);
1ed2f76ac388 (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: 5860
diff changeset
   191
	return 0;
1ed2f76ac388 (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: 5860
diff changeset
   192
#else
8874
c165c8f53102 (svn r11945) -Fix: FileExists() failed for non latin paths (win32)
glx
parents: 8760
diff changeset
   193
	return access(OTTD2FS(filename), 0) == 0;
6008
1ed2f76ac388 (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: 5860
diff changeset
   194
#endif
4220
86ca889037b3 (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
}
4221
bb06fe8dcce2 (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
   196
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   197
typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title);
4221
bb06fe8dcce2 (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
   198
bb06fe8dcce2 (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
   199
/** Create a list of the files in a directory, according to some arbitrary rule.
bb06fe8dcce2 (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
   200
 *  @param mode The mode we are in. Some modes don't allow 'parent'.
6977
67b989528f3d (svn r9662) -Documentation: Doxygen corrections and @file omissions
belugas
parents: 6577
diff changeset
   201
 *  @param callback_proc The function that is called where you need to do the filtering.
4221
bb06fe8dcce2 (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
   202
 *  @return Return the list of files. */
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   203
static FiosItem *FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
4221
bb06fe8dcce2 (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
   204
{
bb06fe8dcce2 (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
   205
	struct stat sb;
bb06fe8dcce2 (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
   206
	struct dirent *dirent;
bb06fe8dcce2 (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
   207
	DIR *dir;
bb06fe8dcce2 (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
   208
	FiosItem *fios;
bb06fe8dcce2 (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
   209
	int sort_start;
6380
f5c826d923ee (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: 6008
diff changeset
   210
	char d_name[sizeof(fios->name)];
4221
bb06fe8dcce2 (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
   211
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   212
	_fios_items.Clear();
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   213
4221
bb06fe8dcce2 (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
	/* A parent directory link exists if we are not in the root directory */
bb06fe8dcce2 (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
   215
	if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   216
		fios = _fios_items.Append();
4221
bb06fe8dcce2 (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
		fios->type = FIOS_TYPE_PARENT;
bb06fe8dcce2 (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
		fios->mtime = 0;
bb06fe8dcce2 (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
   219
		ttd_strlcpy(fios->name, "..", lengthof(fios->name));
bb06fe8dcce2 (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
		ttd_strlcpy(fios->title, ".. (Parent directory)", lengthof(fios->title));
bb06fe8dcce2 (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
   221
	}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	/* Show subdirectories */
6412
a77de25206bc (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: 6380
diff changeset
   224
	if (mode != SLD_NEW_GAME && (dir = ttd_opendir(_fios_path)) != NULL) {
4221
bb06fe8dcce2 (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
		while ((dirent = readdir(dir)) != NULL) {
6380
f5c826d923ee (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: 6008
diff changeset
   226
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   227
4221
bb06fe8dcce2 (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
   228
			/* found file must be directory, but not '.' or '..' */
bb06fe8dcce2 (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
			if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
6566
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6505
diff changeset
   230
					(!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6505
diff changeset
   231
					strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   232
				fios = _fios_items.Append();
4221
bb06fe8dcce2 (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_DIR;
bb06fe8dcce2 (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;
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   235
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   236
				snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name);
4221
bb06fe8dcce2 (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
				str_validate(fios->title);
bb06fe8dcce2 (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
			}
bb06fe8dcce2 (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
		}
bb06fe8dcce2 (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
   240
		closedir(dir);
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
   242
bb06fe8dcce2 (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
   243
	/* Sort the subdirs always by name, ascending, remember user-sorting order */
bb06fe8dcce2 (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
	{
bb06fe8dcce2 (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
		byte order = _savegame_sort_order;
bb06fe8dcce2 (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
   246
		_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   247
		qsort(_fios_items.Begin(), _fios_items.Length(), sizeof(FiosItem), compare_FiosItems);
4221
bb06fe8dcce2 (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
		_savegame_sort_order = order;
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
   251
	/* This is where to start sorting for the filenames */
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   252
	sort_start = _fios_items.Length();
4221
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	/* Show files */
6412
a77de25206bc (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: 6380
diff changeset
   255
	dir = ttd_opendir(_fios_path);
4221
bb06fe8dcce2 (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
	if (dir != NULL) {
bb06fe8dcce2 (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
		while ((dirent = readdir(dir)) != NULL) {
bb06fe8dcce2 (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
			char fios_title[64];
bb06fe8dcce2 (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
			char *t;
6380
f5c826d923ee (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: 6008
diff changeset
   260
			ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
4221
bb06fe8dcce2 (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
6566
a780a47d6af3 (svn r9043) -Fix [FS#652]: the personal (.openttd) directories were hidden in the load/save directory listings (stepancheg).
rubidium
parents: 6505
diff changeset
   262
			if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue;
4221
bb06fe8dcce2 (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
bb06fe8dcce2 (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
			/* File has no extension, skip it */
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   265
			if ((t = strrchr(d_name, '.')) == NULL) continue;
4221
bb06fe8dcce2 (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
			fios_title[0] = '\0'; // reset the title;
bb06fe8dcce2 (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
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   268
			FiosType type = callback_proc(mode, d_name, t, fios_title);
4221
bb06fe8dcce2 (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
			if (type != FIOS_TYPE_INVALID) {
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   270
				fios = _fios_items.Append();
4221
bb06fe8dcce2 (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
   271
				fios->mtime = sb.st_mtime;
bb06fe8dcce2 (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
				fios->type = type;
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   273
				ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
4221
bb06fe8dcce2 (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
bb06fe8dcce2 (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
				/* Some callbacks want to lookup the title of the file. Allow that.
bb06fe8dcce2 (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
   276
				 * If we just copy the title from the filename, strip the extension */
5167
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   277
				t = (fios_title[0] == '\0') ? *t = '\0', d_name : fios_title;
2b9d61386688 (svn r7274) -Codechange [utf8]: Add input/output unicode support. This actually only changes win32
Darkvater
parents: 4300
diff changeset
   278
				ttd_strlcpy(fios->title, t, lengthof(fios->title));
4221
bb06fe8dcce2 (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
				str_validate(fios->title);
bb06fe8dcce2 (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
			}
bb06fe8dcce2 (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
   281
		}
bb06fe8dcce2 (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
		closedir(dir);
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
   284
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   285
	qsort(_fios_items.Get(sort_start), _fios_items.Length() - sort_start, sizeof(FiosItem), compare_FiosItems);
4221
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	/* Show drives */
bb06fe8dcce2 (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
	if (mode != SLD_NEW_GAME) FiosGetDrives();
bb06fe8dcce2 (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
   289
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   290
	_fios_items.Compact();
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   291
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   292
	return _fios_items.Begin();
4221
bb06fe8dcce2 (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
   293
}
bb06fe8dcce2 (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
   294
bb06fe8dcce2 (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
/**
bb06fe8dcce2 (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
 * Callback for FiosGetFileList. It tells if a file is a savegame or not.
bb06fe8dcce2 (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
 * @param mode Save/load mode.
bb06fe8dcce2 (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
 * @param file Name of the file to check.
bb06fe8dcce2 (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
 * @param ext A pointer to the extension identifier inside file
bb06fe8dcce2 (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
 * @param title Buffer if a callback wants to lookup the title of the file
bb06fe8dcce2 (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
 * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
bb06fe8dcce2 (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
 * @see FiosGetFileList
bb06fe8dcce2 (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
 * @see FiosGetSavegameList
bb06fe8dcce2 (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
 */
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   305
static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4221
bb06fe8dcce2 (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
   306
{
bb06fe8dcce2 (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
	/* Show savegame files
bb06fe8dcce2 (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
	 * .SAV OpenTTD saved game
bb06fe8dcce2 (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
	 * .SS1 Transport Tycoon Deluxe preset game
bb06fe8dcce2 (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
	 * .SV1 Transport Tycoon Deluxe (Patch) saved game
bb06fe8dcce2 (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
	 * .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
bb06fe8dcce2 (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
	if (strcasecmp(ext, ".sav") == 0) return FIOS_TYPE_FILE;
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
bb06fe8dcce2 (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
		if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
bb06fe8dcce2 (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
				strcasecmp(ext, ".sv2") == 0) {
bb06fe8dcce2 (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
			GetOldSaveGameName(title, _fios_path, file);
bb06fe8dcce2 (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
			return FIOS_TYPE_OLDFILE;
bb06fe8dcce2 (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
		}
bb06fe8dcce2 (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
   320
	}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	return FIOS_TYPE_INVALID;
bb06fe8dcce2 (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
}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
/**
bb06fe8dcce2 (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
 * Get a list of savegames.
bb06fe8dcce2 (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
 * @param mode Save/load mode.
bb06fe8dcce2 (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
 * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
bb06fe8dcce2 (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
 * @see FiosGetFileList
bb06fe8dcce2 (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
 */
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   331
void FiosGetSavegameList(SaveLoadDialogMode mode)
4221
bb06fe8dcce2 (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
{
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   333
	static char *fios_save_path = NULL;
4221
bb06fe8dcce2 (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
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   335
	if (fios_save_path == NULL) {
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   336
		fios_save_path = MallocT<char>(MAX_PATH);
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   337
		FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR);
4221
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   340
	_fios_path = fios_save_path;
4221
bb06fe8dcce2 (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
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   342
	FiosGetFileList(mode, &FiosGetSavegameListCallback);
4221
bb06fe8dcce2 (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
}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
/**
bb06fe8dcce2 (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
   346
 * Callback for FiosGetFileList. It tells if a file is a scenario or not.
bb06fe8dcce2 (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
 * @param mode Save/load mode.
bb06fe8dcce2 (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
   348
 * @param file Name of the file to check.
bb06fe8dcce2 (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
 * @param ext A pointer to the extension identifier inside file
bb06fe8dcce2 (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
   350
 * @param title Buffer if a callback wants to lookup the title of the file
bb06fe8dcce2 (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
   351
 * @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario
bb06fe8dcce2 (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
   352
 * @see FiosGetFileList
bb06fe8dcce2 (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
 * @see FiosGetScenarioList
bb06fe8dcce2 (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
 */
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   355
static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4221
bb06fe8dcce2 (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
{
bb06fe8dcce2 (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
   357
	/* Show scenario files
bb06fe8dcce2 (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
	 * .SCN OpenTTD style scenario file
bb06fe8dcce2 (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
	 * .SV0 Transport Tycoon Deluxe (Patch) scenario
bb06fe8dcce2 (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
	 * .SS0 Transport Tycoon Deluxe preset scenario */
bb06fe8dcce2 (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
	if (strcasecmp(ext, ".scn") == 0) return FIOS_TYPE_SCENARIO;
bb06fe8dcce2 (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
bb06fe8dcce2 (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
	if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) {
bb06fe8dcce2 (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
		if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
bb06fe8dcce2 (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
			GetOldSaveGameName(title, _fios_path, file);
bb06fe8dcce2 (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 FIOS_TYPE_OLD_SCENARIO;
bb06fe8dcce2 (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
		}
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
   370
	return FIOS_TYPE_INVALID;
bb06fe8dcce2 (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
}
bb06fe8dcce2 (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
bb06fe8dcce2 (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
/**
bb06fe8dcce2 (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
 * Get a list of scenarios.
bb06fe8dcce2 (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
 * @param mode Save/load mode.
bb06fe8dcce2 (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
 * @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
bb06fe8dcce2 (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
 * @see FiosGetFileList
bb06fe8dcce2 (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
 */
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   379
void FiosGetScenarioList(SaveLoadDialogMode mode)
4221
bb06fe8dcce2 (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
{
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   381
	static char *fios_scn_path = NULL;
4221
bb06fe8dcce2 (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
7425
350b9265b7a2 (svn r10182) -Codechange: rewrite most part of the file loading/searching to be more flexible.
rubidium
parents: 7259
diff changeset
   383
	/* Copy the default path on first run or on 'New Game' */
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   384
	if (fios_scn_path == NULL) {
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   385
		fios_scn_path = MallocT<char>(MAX_PATH);
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   386
		FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR);
4221
bb06fe8dcce2 (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
	}
bb06fe8dcce2 (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
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   389
	_fios_path = fios_scn_path;
4221
bb06fe8dcce2 (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
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   391
	FiosGetFileList(mode, &FiosGetScenarioListCallback);
4221
bb06fe8dcce2 (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
}
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   393
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   394
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   395
{
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   396
	/* Show heightmap files
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   397
	 * .PNG PNG Based heightmap files
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   398
	 * .BMP BMP Based heightmap files
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   399
	 */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   400
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   401
#ifdef WITH_PNG
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   402
	if (strcasecmp(ext, ".png") == 0) return FIOS_TYPE_PNG;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   403
#endif /* WITH_PNG */
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   404
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   405
	if (strcasecmp(ext, ".bmp") == 0) return FIOS_TYPE_BMP;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   406
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   407
	return FIOS_TYPE_INVALID;
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   408
}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   409
6505
abcb0580d976 (svn r8950) -Cleanup: doxygen changes. Mostly @files missing tags and a few comments style.
belugas
parents: 6450
diff changeset
   410
/* Get a list of Heightmaps */
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   411
void FiosGetHeightmapList(SaveLoadDialogMode mode)
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   412
{
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   413
	static char *fios_hmap_path = NULL;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   414
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   415
	if (fios_hmap_path == NULL) {
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   416
		fios_hmap_path = MallocT<char>(MAX_PATH);
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   417
		FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   418
	}
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   419
10307
624bb10b4ca8 (svn r12848) -Cleanup/Codechange: Use correct variable types, don't prefix with _ for non-globals, and use implicit enum numbering.
peter1138
parents: 10306
diff changeset
   420
	_fios_path = fios_hmap_path;
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   421
10808
d42b140d24f2 (svn r13359) -Codechange: convert _fios_items to a SmallVector
skidd13
parents: 10458
diff changeset
   422
	FiosGetFileList(mode, &FiosGetHeightmapListCallback);
4300
687a17c9c557 (svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
truelight
parents: 4235
diff changeset
   423
}