2006-08-05 00:16:24 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2007-02-23 01:48:53 +00:00
|
|
|
/** @file fios.cpp
|
2006-08-05 00:16:24 +00:00
|
|
|
* This file contains functions for building file lists for the save/load dialogs.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "stdafx.h"
|
|
|
|
#include "openttd.h"
|
|
|
|
#include "variables.h"
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
#include "heightmap.h"
|
2006-08-05 00:47:32 +00:00
|
|
|
#include "fios.h"
|
2007-06-17 15:48:57 +00:00
|
|
|
#include "fileio.h"
|
2007-12-25 09:48:53 +00:00
|
|
|
#include "core/alloc_func.hpp"
|
2007-12-25 11:26:07 +00:00
|
|
|
#include "functions.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2006-08-05 00:16:24 +00:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
#ifdef WIN32
|
2007-03-07 18:58:28 +00:00
|
|
|
# include <tchar.h>
|
2008-05-07 21:51:13 +00:00
|
|
|
# ifndef UNICODE
|
|
|
|
# include <io.h>
|
|
|
|
# endif
|
2008-01-22 15:47:40 +00:00
|
|
|
# define access _taccess
|
|
|
|
# define unlink _tunlink
|
2006-08-05 00:16:24 +00:00
|
|
|
#else
|
|
|
|
# include <unistd.h>
|
|
|
|
#endif /* WIN32 */
|
|
|
|
|
2008-01-13 01:21:35 +00:00
|
|
|
#include "table/strings.h"
|
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
/* Variables to display file lists */
|
|
|
|
int _fios_num;
|
|
|
|
|
|
|
|
static char *_fios_path;
|
|
|
|
static FiosItem *_fios_items;
|
2007-12-28 03:14:55 +00:00
|
|
|
SmallFiosItem _file_to_saveload;
|
2006-08-05 00:59:45 +00:00
|
|
|
static int _fios_count, _fios_alloc;
|
2006-08-05 00:16:24 +00:00
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
/* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
|
|
|
|
extern bool FiosIsRoot(const char *path);
|
|
|
|
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
|
2007-03-06 22:37:04 +00:00
|
|
|
extern bool FiosIsHiddenFile(const struct dirent *ent);
|
2007-03-07 11:47:46 +00:00
|
|
|
extern void FiosGetDrives();
|
2006-08-05 00:53:09 +00:00
|
|
|
extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* get the name of an oldstyle savegame */
|
|
|
|
extern void GetOldSaveGameName(char *title, const char *path, const char *file);
|
|
|
|
|
2006-08-05 00:16:24 +00:00
|
|
|
/**
|
|
|
|
* Allocate a new FiosItem.
|
|
|
|
* @return A pointer to the newly allocated FiosItem.
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
FiosItem *FiosAlloc()
|
2006-08-05 00:16:24 +00:00
|
|
|
{
|
|
|
|
if (_fios_count == _fios_alloc) {
|
|
|
|
_fios_alloc += 256;
|
2007-01-11 17:29:39 +00:00
|
|
|
_fios_items = ReallocT(_fios_items, _fios_alloc);
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
return &_fios_items[_fios_count++];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Compare two FiosItem's. Used with qsort when sorting the file list.
|
|
|
|
* @param a A pointer to the first FiosItem to compare.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param b A pointer to the second FiosItem to compare.
|
2006-08-05 00:16:24 +00:00
|
|
|
* @return -1, 0 or 1, depending on how the two items should be sorted.
|
|
|
|
*/
|
|
|
|
int CDECL compare_FiosItems(const void *a, const void *b)
|
|
|
|
{
|
|
|
|
const FiosItem *da = (const FiosItem *)a;
|
|
|
|
const FiosItem *db = (const FiosItem *)b;
|
|
|
|
int r;
|
|
|
|
|
|
|
|
if (_savegame_sort_order & SORT_BY_NAME) {
|
|
|
|
r = strcasecmp(da->title, db->title);
|
|
|
|
} else {
|
|
|
|
r = da->mtime < db->mtime ? -1 : 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_savegame_sort_order & SORT_DESCENDING) r = -r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Free the list of savegames
|
|
|
|
*/
|
2007-03-07 11:47:46 +00:00
|
|
|
void FiosFreeSavegameList()
|
2006-08-05 00:16:24 +00:00
|
|
|
{
|
|
|
|
free(_fios_items);
|
|
|
|
_fios_items = NULL;
|
|
|
|
_fios_alloc = _fios_count = 0;
|
|
|
|
}
|
|
|
|
|
2006-08-05 00:53:09 +00:00
|
|
|
/**
|
|
|
|
* Get descriptive texts. Returns the path and free space
|
|
|
|
* left on the device
|
|
|
|
* @param path string describing the path
|
|
|
|
* @param total_free total free space in megabytes, optional (can be NULL)
|
|
|
|
* @return StringID describing the path (free space or failure)
|
|
|
|
*/
|
|
|
|
StringID FiosGetDescText(const char **path, uint32 *total_free)
|
|
|
|
{
|
|
|
|
*path = _fios_path;
|
|
|
|
return FiosGetDiskFreeSpace(*path, total_free) ? STR_4005_BYTES_FREE : STR_4006_UNABLE_TO_READ_DRIVE;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Browse to a new path based on the passed FiosItem struct
|
|
|
|
* @param *item FiosItem object telling us what to do
|
|
|
|
* @return a string if we have given a file as a target, otherwise NULL */
|
|
|
|
char *FiosBrowseTo(const FiosItem *item)
|
|
|
|
{
|
|
|
|
char *path = _fios_path;
|
|
|
|
|
|
|
|
switch (item->type) {
|
2008-04-23 13:36:52 +00:00
|
|
|
case FIOS_TYPE_DRIVE:
|
2007-08-04 12:53:41 +00:00
|
|
|
#if defined(WINCE)
|
2008-04-23 13:36:52 +00:00
|
|
|
sprintf(path, PATHSEP "");
|
2007-08-04 12:53:41 +00:00
|
|
|
#elif defined(WIN32) || defined(__OS2__)
|
2008-04-23 13:36:52 +00:00
|
|
|
sprintf(path, "%c:" PATHSEP, item->title[0]);
|
2006-08-05 00:53:09 +00:00
|
|
|
#endif
|
2008-04-23 13:36:52 +00:00
|
|
|
/* Fallthrough */
|
|
|
|
case FIOS_TYPE_INVALID:
|
|
|
|
break;
|
2006-08-05 00:53:09 +00:00
|
|
|
|
2008-04-23 11:57:58 +00:00
|
|
|
case FIOS_TYPE_PARENT: {
|
|
|
|
/* Check for possible NULL ptr (not required for UNIXes, but AmigaOS-alikes) */
|
|
|
|
char *s = strrchr(path, PATHSEPCHAR);
|
|
|
|
if (s != NULL && s != path) {
|
|
|
|
s[0] = '\0'; // Remove last path separator character, so we can go up one level.
|
|
|
|
}
|
|
|
|
s = strrchr(path, PATHSEPCHAR);
|
|
|
|
if (s != NULL) s[1] = '\0'; // go up a directory
|
2006-08-05 00:53:09 +00:00
|
|
|
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
2008-04-23 11:57:58 +00:00
|
|
|
/* On MorphOS or AmigaOS paths look like: "Volume:directory/subdirectory" */
|
|
|
|
else if ((s = strrchr(path, ':')) != NULL) s[1] = '\0';
|
2006-08-05 00:53:09 +00:00
|
|
|
#endif
|
2008-04-23 11:57:58 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case FIOS_TYPE_DIR:
|
|
|
|
strcat(path, item->name);
|
|
|
|
strcat(path, PATHSEP);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOS_TYPE_DIRECT:
|
|
|
|
sprintf(path, "%s", item->name);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOS_TYPE_FILE:
|
|
|
|
case FIOS_TYPE_OLDFILE:
|
|
|
|
case FIOS_TYPE_SCENARIO:
|
|
|
|
case FIOS_TYPE_OLD_SCENARIO:
|
|
|
|
case FIOS_TYPE_PNG:
|
|
|
|
case FIOS_TYPE_BMP:
|
|
|
|
{
|
|
|
|
static char str_buffr[512];
|
|
|
|
snprintf(str_buffr, lengthof(str_buffr), "%s%s", path, item->name);
|
|
|
|
return str_buffr;
|
|
|
|
}
|
2006-08-05 00:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2006-08-05 00:16:24 +00:00
|
|
|
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
|
|
|
|
{
|
|
|
|
const char *extension, *period;
|
|
|
|
|
|
|
|
extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
|
|
|
|
|
|
|
|
/* Don't append the extension if it is already there */
|
|
|
|
period = strrchr(name, '.');
|
|
|
|
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
|
2007-11-18 18:28:32 +00:00
|
|
|
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
|
|
|
if (_fios_path != NULL) {
|
|
|
|
unsigned char sepchar = _fios_path[(strlen(_fios_path) - 1)];
|
|
|
|
|
|
|
|
if (sepchar != ':' && sepchar != '/') {
|
|
|
|
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
|
|
|
|
} else {
|
|
|
|
snprintf(buf, size, "%s%s%s", _fios_path, name, extension);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
snprintf(buf, size, "%s%s", name, extension);
|
|
|
|
}
|
|
|
|
#else
|
2006-08-05 00:16:24 +00:00
|
|
|
snprintf(buf, size, "%s" PATHSEP "%s%s", _fios_path, name, extension);
|
2007-11-18 18:28:32 +00:00
|
|
|
#endif
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
|
2007-03-07 18:58:28 +00:00
|
|
|
#if defined(WIN32)
|
|
|
|
# define unlink _tunlink
|
2006-11-28 14:42:31 +00:00
|
|
|
#endif
|
|
|
|
|
2006-08-05 00:16:24 +00:00
|
|
|
bool FiosDelete(const char *name)
|
|
|
|
{
|
|
|
|
char filename[512];
|
|
|
|
|
|
|
|
FiosMakeSavegameName(filename, name, lengthof(filename));
|
2006-11-28 14:42:31 +00:00
|
|
|
return unlink(OTTD2FS(filename)) == 0;
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool FileExists(const char *filename)
|
|
|
|
{
|
2007-01-21 14:21:31 +00:00
|
|
|
#if defined(WINCE)
|
|
|
|
/* There is always one platform that doesn't support basic commands... */
|
2007-02-23 12:56:10 +00:00
|
|
|
HANDLE hand = CreateFile(OTTD2FS(filename), 0, 0, NULL, OPEN_EXISTING, 0, NULL);
|
2007-01-21 14:21:31 +00:00
|
|
|
if (hand == INVALID_HANDLE_VALUE) return 1;
|
|
|
|
CloseHandle(hand);
|
|
|
|
return 0;
|
|
|
|
#else
|
2008-01-22 15:47:40 +00:00
|
|
|
return access(OTTD2FS(filename), 0) == 0;
|
2007-01-21 14:21:31 +00:00
|
|
|
#endif
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/** Create a list of the files in a directory, according to some arbitrary rule.
|
|
|
|
* @param mode The mode we are in. Some modes don't allow 'parent'.
|
2007-04-17 20:23:13 +00:00
|
|
|
* @param callback_proc The function that is called where you need to do the filtering.
|
2006-08-05 00:47:32 +00:00
|
|
|
* @return Return the list of files. */
|
2008-04-23 12:03:47 +00:00
|
|
|
static FiosItem *FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc)
|
2006-08-05 00:47:32 +00:00
|
|
|
{
|
|
|
|
struct stat sb;
|
|
|
|
struct dirent *dirent;
|
|
|
|
DIR *dir;
|
|
|
|
FiosItem *fios;
|
|
|
|
int sort_start;
|
2007-02-17 16:41:56 +00:00
|
|
|
char d_name[sizeof(fios->name)];
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* A parent directory link exists if we are not in the root directory */
|
|
|
|
if (!FiosIsRoot(_fios_path) && mode != SLD_NEW_GAME) {
|
|
|
|
fios = FiosAlloc();
|
|
|
|
fios->type = FIOS_TYPE_PARENT;
|
|
|
|
fios->mtime = 0;
|
|
|
|
ttd_strlcpy(fios->name, "..", lengthof(fios->name));
|
|
|
|
ttd_strlcpy(fios->title, ".. (Parent directory)", lengthof(fios->title));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Show subdirectories */
|
2007-02-20 00:09:23 +00:00
|
|
|
if (mode != SLD_NEW_GAME && (dir = ttd_opendir(_fios_path)) != NULL) {
|
2006-08-05 00:47:32 +00:00
|
|
|
while ((dirent = readdir(dir)) != NULL) {
|
2007-02-17 16:41:56 +00:00
|
|
|
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
|
2006-11-28 14:42:31 +00:00
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
/* found file must be directory, but not '.' or '..' */
|
|
|
|
if (FiosIsValidFile(_fios_path, dirent, &sb) && (sb.st_mode & S_IFDIR) &&
|
2007-03-06 22:37:04 +00:00
|
|
|
(!FiosIsHiddenFile(dirent) || strncasecmp(d_name, PERSONAL_DIR, strlen(d_name)) == 0) &&
|
|
|
|
strcmp(d_name, ".") != 0 && strcmp(d_name, "..") != 0) {
|
2006-08-05 00:47:32 +00:00
|
|
|
fios = FiosAlloc();
|
|
|
|
fios->type = FIOS_TYPE_DIR;
|
|
|
|
fios->mtime = 0;
|
2006-11-28 14:42:31 +00:00
|
|
|
ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
|
|
|
|
snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name);
|
2006-08-05 00:47:32 +00:00
|
|
|
str_validate(fios->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the subdirs always by name, ascending, remember user-sorting order */
|
|
|
|
{
|
|
|
|
byte order = _savegame_sort_order;
|
|
|
|
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
|
|
|
|
qsort(_fios_items, _fios_count, sizeof(FiosItem), compare_FiosItems);
|
|
|
|
_savegame_sort_order = order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is where to start sorting for the filenames */
|
|
|
|
sort_start = _fios_count;
|
|
|
|
|
|
|
|
/* Show files */
|
2007-02-20 00:09:23 +00:00
|
|
|
dir = ttd_opendir(_fios_path);
|
2006-08-05 00:47:32 +00:00
|
|
|
if (dir != NULL) {
|
|
|
|
while ((dirent = readdir(dir)) != NULL) {
|
|
|
|
char fios_title[64];
|
|
|
|
char *t;
|
2007-02-17 16:41:56 +00:00
|
|
|
ttd_strlcpy(d_name, FS2OTTD(dirent->d_name), sizeof(d_name));
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2007-03-06 22:37:04 +00:00
|
|
|
if (!FiosIsValidFile(_fios_path, dirent, &sb) || !(sb.st_mode & S_IFREG) || FiosIsHiddenFile(dirent)) continue;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* File has no extension, skip it */
|
2006-11-28 14:42:31 +00:00
|
|
|
if ((t = strrchr(d_name, '.')) == NULL) continue;
|
2006-08-05 00:47:32 +00:00
|
|
|
fios_title[0] = '\0'; // reset the title;
|
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosType type = callback_proc(mode, d_name, t, fios_title);
|
2006-08-05 00:47:32 +00:00
|
|
|
if (type != FIOS_TYPE_INVALID) {
|
|
|
|
fios = FiosAlloc();
|
|
|
|
fios->mtime = sb.st_mtime;
|
|
|
|
fios->type = type;
|
2006-11-28 14:42:31 +00:00
|
|
|
ttd_strlcpy(fios->name, d_name, lengthof(fios->name));
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* Some callbacks want to lookup the title of the file. Allow that.
|
|
|
|
* If we just copy the title from the filename, strip the extension */
|
2006-11-28 14:42:31 +00:00
|
|
|
t = (fios_title[0] == '\0') ? *t = '\0', d_name : fios_title;
|
|
|
|
ttd_strlcpy(fios->title, t, lengthof(fios->title));
|
2006-08-05 00:47:32 +00:00
|
|
|
str_validate(fios->title);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
qsort(_fios_items + sort_start, _fios_count - sort_start, sizeof(FiosItem), compare_FiosItems);
|
|
|
|
|
|
|
|
/* Show drives */
|
|
|
|
if (mode != SLD_NEW_GAME) FiosGetDrives();
|
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
_fios_num = _fios_count;
|
2006-08-05 00:47:32 +00:00
|
|
|
return _fios_items;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for FiosGetFileList. It tells if a file is a savegame or not.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @param file Name of the file to check.
|
|
|
|
* @param ext A pointer to the extension identifier inside file
|
|
|
|
* @param title Buffer if a callback wants to lookup the title of the file
|
|
|
|
* @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
|
|
|
|
* @see FiosGetFileList
|
|
|
|
* @see FiosGetSavegameList
|
|
|
|
*/
|
2008-04-23 12:03:47 +00:00
|
|
|
static FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
2006-08-05 00:47:32 +00:00
|
|
|
{
|
|
|
|
/* Show savegame files
|
|
|
|
* .SAV OpenTTD saved game
|
|
|
|
* .SS1 Transport Tycoon Deluxe preset game
|
|
|
|
* .SV1 Transport Tycoon Deluxe (Patch) saved game
|
|
|
|
* .SV2 Transport Tycoon Deluxe (Patch) saved 2-player game */
|
|
|
|
if (strcasecmp(ext, ".sav") == 0) return FIOS_TYPE_FILE;
|
|
|
|
|
|
|
|
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
|
|
|
if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
|
|
|
|
strcasecmp(ext, ".sv2") == 0) {
|
|
|
|
GetOldSaveGameName(title, _fios_path, file);
|
|
|
|
return FIOS_TYPE_OLDFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of savegames.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
|
|
|
* @see FiosGetFileList
|
|
|
|
*/
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosItem *FiosGetSavegameList(SaveLoadDialogMode mode)
|
2006-08-05 00:47:32 +00:00
|
|
|
{
|
2008-04-23 12:03:47 +00:00
|
|
|
static char *fios_save_path = NULL;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
if (fios_save_path == NULL) {
|
|
|
|
fios_save_path = MallocT<char>(MAX_PATH);
|
|
|
|
FioGetDirectory(fios_save_path, MAX_PATH, SAVE_DIR);
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
_fios_path = fios_save_path;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
return FiosGetFileList(mode, &FiosGetSavegameListCallback);
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Callback for FiosGetFileList. It tells if a file is a scenario or not.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @param file Name of the file to check.
|
|
|
|
* @param ext A pointer to the extension identifier inside file
|
|
|
|
* @param title Buffer if a callback wants to lookup the title of the file
|
|
|
|
* @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario
|
|
|
|
* @see FiosGetFileList
|
|
|
|
* @see FiosGetScenarioList
|
|
|
|
*/
|
2008-04-23 12:03:47 +00:00
|
|
|
static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
2006-08-05 00:47:32 +00:00
|
|
|
{
|
|
|
|
/* Show scenario files
|
|
|
|
* .SCN OpenTTD style scenario file
|
|
|
|
* .SV0 Transport Tycoon Deluxe (Patch) scenario
|
|
|
|
* .SS0 Transport Tycoon Deluxe preset scenario */
|
|
|
|
if (strcasecmp(ext, ".scn") == 0) return FIOS_TYPE_SCENARIO;
|
|
|
|
|
|
|
|
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) {
|
|
|
|
if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
|
|
|
|
GetOldSaveGameName(title, _fios_path, file);
|
|
|
|
return FIOS_TYPE_OLD_SCENARIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of scenarios.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @return A pointer to an array of FiosItem representing all the files to be shown in the save/load dialog.
|
|
|
|
* @see FiosGetFileList
|
|
|
|
*/
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosItem *FiosGetScenarioList(SaveLoadDialogMode mode)
|
2006-08-05 00:47:32 +00:00
|
|
|
{
|
2008-04-23 12:03:47 +00:00
|
|
|
static char *fios_scn_path = NULL;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2007-06-17 15:48:57 +00:00
|
|
|
/* Copy the default path on first run or on 'New Game' */
|
2008-04-23 12:03:47 +00:00
|
|
|
if (fios_scn_path == NULL) {
|
|
|
|
fios_scn_path = MallocT<char>(MAX_PATH);
|
|
|
|
FioGetDirectory(fios_scn_path, MAX_PATH, SCENARIO_DIR);
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
_fios_path = fios_scn_path;
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2006-08-05 00:59:45 +00:00
|
|
|
return FiosGetFileList(mode, &FiosGetScenarioListCallback);
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title)
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
{
|
|
|
|
/* Show heightmap files
|
|
|
|
* .PNG PNG Based heightmap files
|
|
|
|
* .BMP BMP Based heightmap files
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef WITH_PNG
|
|
|
|
if (strcasecmp(ext, ".png") == 0) return FIOS_TYPE_PNG;
|
|
|
|
#endif /* WITH_PNG */
|
|
|
|
|
|
|
|
if (strcasecmp(ext, ".bmp") == 0) return FIOS_TYPE_BMP;
|
|
|
|
|
|
|
|
return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
2007-03-01 01:24:44 +00:00
|
|
|
/* Get a list of Heightmaps */
|
2008-04-23 12:03:47 +00:00
|
|
|
FiosItem *FiosGetHeightmapList(SaveLoadDialogMode mode)
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
{
|
2008-04-23 12:03:47 +00:00
|
|
|
static char *fios_hmap_path = NULL;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
if (fios_hmap_path == NULL) {
|
|
|
|
fios_hmap_path = MallocT<char>(MAX_PATH);
|
|
|
|
FioGetDirectory(fios_hmap_path, MAX_PATH, HEIGHTMAP_DIR);
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
}
|
|
|
|
|
2008-04-23 12:03:47 +00:00
|
|
|
_fios_path = fios_hmap_path;
|
(svn r5946) -Add: merged the TGP branch to mainline. TGP adds:
- New optional landscape generator (TerraGenesis Perlin)
- Load heightmaps (either BMP or PNG)
- Progress dialog while generating worlds (no longer a 'hanging' screen)
- New dialogs for NewGame, Create Scenario and Play Heightmap
- Easier to configure your landscape
- More things to configure (tree-placer, ..)
- Speedup of world generation
- New console command 'restart': restart the map EXACTLY as it was when you
first started it (needs a game made after or with this commit)
- New console command 'getseed': get the seed of your map and share it with
others (of course only works with generated maps)
- Many new, world generation related, things
- Many internal cleanups and rewrites
Many tnx to those people who helped making this:
Belugas, DaleStan, glx, KUDr, RichK67, Rubidium, and TrueLight (alfabetic)
Many tnx to those who helped testing:
Arnau, Bjarni, and tokai (alfabetic)
And to all other people who helped testing and sending comments / bugs
Stats: 673 lines changed, 3534 new lines, 79 new strings
2006-08-19 10:00:30 +00:00
|
|
|
|
|
|
|
return FiosGetFileList(mode, &FiosGetHeightmapListCallback);
|
|
|
|
}
|