2006-08-05 00:16:24 +00:00
|
|
|
/* $Id$ */
|
|
|
|
|
2009-08-21 20:21:05 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
|
|
|
|
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2010-08-01 19:22:34 +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"
|
2006-08-05 00:47:32 +00:00
|
|
|
#include "fios.h"
|
2008-08-31 10:50:05 +00:00
|
|
|
#include "fileio_func.h"
|
2009-04-10 20:20:37 +00:00
|
|
|
#include "tar_type.h"
|
2011-05-28 13:55:05 +00:00
|
|
|
#include "screenshot.h"
|
2008-01-07 14:23:25 +00:00
|
|
|
#include "string_func.h"
|
2006-08-05 00:16:24 +00:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
2011-05-28 03:23:34 +00:00
|
|
|
#ifndef WIN32
|
2006-08-05 00:16:24 +00:00
|
|
|
# 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 */
|
2008-06-02 14:19:27 +00:00
|
|
|
SmallVector<FiosItem, 32> _fios_items;
|
2006-08-05 00:59:45 +00:00
|
|
|
static char *_fios_path;
|
2007-12-28 03:14:55 +00:00
|
|
|
SmallFiosItem _file_to_saveload;
|
2010-06-05 18:44:31 +00:00
|
|
|
SortingBits _savegame_sort_order = SORT_BY_DATE | SORT_DESCENDING;
|
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();
|
2009-01-16 12:59:47 +00:00
|
|
|
extern bool FiosGetDiskFreeSpace(const char *path, uint64 *tot);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* get the name of an oldstyle savegame */
|
2009-03-04 09:53:31 +00:00
|
|
|
extern void GetOldSaveGameName(const char *file, char *title, const char *last);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2006-08-05 00:16:24 +00:00
|
|
|
/**
|
2009-09-13 17:39:33 +00:00
|
|
|
* Compare two FiosItem's. Used with sort when sorting the file list.
|
|
|
|
* @param da A pointer to the first FiosItem to compare.
|
|
|
|
* @param db 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.
|
|
|
|
*/
|
2009-09-13 17:39:33 +00:00
|
|
|
int CDECL CompareFiosItems(const FiosItem *da, const FiosItem *db)
|
2006-08-05 00:16:24 +00:00
|
|
|
{
|
2009-03-04 10:02:00 +00:00
|
|
|
int r = 0;
|
2006-08-05 00:16:24 +00:00
|
|
|
|
2009-03-09 21:55:17 +00:00
|
|
|
if ((_savegame_sort_order & SORT_BY_NAME) == 0 && da->mtime != db->mtime) {
|
2006-08-05 00:16:24 +00:00
|
|
|
r = da->mtime < db->mtime ? -1 : 1;
|
2009-03-09 21:55:17 +00:00
|
|
|
} else {
|
|
|
|
r = strcasecmp(da->title, db->title);
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (_savegame_sort_order & SORT_DESCENDING) r = -r;
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/** Free the list of savegames. */
|
2007-03-07 11:47:46 +00:00
|
|
|
void FiosFreeSavegameList()
|
2006-08-05 00:16:24 +00:00
|
|
|
{
|
2008-06-02 14:19:27 +00:00
|
|
|
_fios_items.Clear();
|
|
|
|
_fios_items.Compact();
|
2010-03-23 22:37:18 +00:00
|
|
|
}
|
2006-08-05 00:16:24 +00:00
|
|
|
|
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)
|
|
|
|
*/
|
2009-01-16 12:59:47 +00:00
|
|
|
StringID FiosGetDescText(const char **path, uint64 *total_free)
|
2006-08-05 00:53:09 +00:00
|
|
|
{
|
|
|
|
*path = _fios_path;
|
2009-04-21 23:40:56 +00:00
|
|
|
return FiosGetDiskFreeSpace(*path, total_free) ? STR_SAVELOAD_BYTES_FREE : STR_ERROR_UNABLE_TO_READ_DRIVE;
|
2006-08-05 00:53:09 +00:00
|
|
|
}
|
|
|
|
|
2010-06-27 09:05:10 +00:00
|
|
|
/**
|
2011-05-27 21:20:07 +00:00
|
|
|
* Browse to a new path based on the passed \a item, starting at #_fios_path.
|
|
|
|
* @param *item Item telling us what to do.
|
|
|
|
* @return A filename w/path if we reached a file, otherwise \c NULL.
|
2010-06-27 09:05:10 +00:00
|
|
|
*/
|
2009-03-04 00:13:52 +00:00
|
|
|
const char *FiosBrowseTo(const FiosItem *item)
|
2006-08-05 00:53:09 +00:00
|
|
|
{
|
|
|
|
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-10-28 16:04:41 +00:00
|
|
|
snprintf(path, MAX_PATH, PATHSEP "");
|
2007-08-04 12:53:41 +00:00
|
|
|
#elif defined(WIN32) || defined(__OS2__)
|
2008-10-28 16:04:41 +00:00
|
|
|
snprintf(path, MAX_PATH, "%c:" PATHSEP, item->title[0]);
|
2006-08-05 00:53:09 +00:00
|
|
|
#endif
|
2010-07-29 14:26:28 +00:00
|
|
|
/* FALL THROUGH */
|
2008-04-23 13:36:52 +00:00
|
|
|
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);
|
2009-08-20 10:23:39 +00:00
|
|
|
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" */
|
2009-08-20 10:23:39 +00:00
|
|
|
} else if ((s = strrchr(path, ':')) != NULL) {
|
|
|
|
s[1] = '\0';
|
2006-08-05 00:53:09 +00:00
|
|
|
#endif
|
2009-08-20 10:23:39 +00:00
|
|
|
}
|
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:
|
2008-10-28 16:04:41 +00:00
|
|
|
snprintf(path, MAX_PATH, "%s", item->name);
|
2008-04-23 11:57:58 +00:00
|
|
|
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:
|
2009-03-04 01:09:48 +00:00
|
|
|
return item->name;
|
2006-08-05 00:53:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/**
|
2011-05-28 13:54:42 +00:00
|
|
|
* Construct a filename from its components in destination buffer \a buf.
|
|
|
|
* @param buf Destination buffer.
|
|
|
|
* @param path Directory path, may be \c NULL.
|
|
|
|
* @param name Filename.
|
|
|
|
* @param ext Filename extension (use \c "" for no extension).
|
|
|
|
* @param size Size of \a buf.
|
2011-05-27 21:20:07 +00:00
|
|
|
*/
|
2011-05-28 13:54:42 +00:00
|
|
|
static void FiosMakeFilename(char *buf, const char *path, const char *name, const char *ext, size_t size)
|
2006-08-05 00:16:24 +00:00
|
|
|
{
|
2011-05-28 13:54:42 +00:00
|
|
|
const char *period;
|
2006-08-05 00:16:24 +00:00
|
|
|
|
|
|
|
/* Don't append the extension if it is already there */
|
|
|
|
period = strrchr(name, '.');
|
2011-05-28 13:54:42 +00:00
|
|
|
if (period != NULL && strcasecmp(period, ext) == 0) ext = "";
|
2007-11-18 18:28:32 +00:00
|
|
|
#if defined(__MORPHOS__) || defined(__AMIGAOS__)
|
2011-05-28 13:54:42 +00:00
|
|
|
if (path != NULL) {
|
|
|
|
unsigned char sepchar = path[(strlen(path) - 1)];
|
2007-11-18 18:28:32 +00:00
|
|
|
|
|
|
|
if (sepchar != ':' && sepchar != '/') {
|
2011-05-28 13:54:42 +00:00
|
|
|
snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
|
2007-11-18 18:28:32 +00:00
|
|
|
} else {
|
2011-05-28 13:54:42 +00:00
|
|
|
snprintf(buf, size, "%s%s%s", path, name, ext);
|
2007-11-18 18:28:32 +00:00
|
|
|
}
|
|
|
|
} else {
|
2011-05-28 13:54:42 +00:00
|
|
|
snprintf(buf, size, "%s%s", name, ext);
|
2007-11-18 18:28:32 +00:00
|
|
|
}
|
|
|
|
#else
|
2011-05-28 13:54:42 +00:00
|
|
|
snprintf(buf, size, "%s" PATHSEP "%s%s", path, name, ext);
|
2007-11-18 18:28:32 +00:00
|
|
|
#endif
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
|
2011-05-28 13:54:42 +00:00
|
|
|
/**
|
|
|
|
* Make a save game or scenario filename from a name.
|
|
|
|
* @param buf Destination buffer for saving the filename.
|
|
|
|
* @param name Name of the file.
|
|
|
|
* @param size Length of buffer \a buf.
|
|
|
|
*/
|
|
|
|
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
|
|
|
|
{
|
|
|
|
const char *extension = (_game_mode == GM_EDITOR) ? ".scn" : ".sav";
|
|
|
|
|
|
|
|
FiosMakeFilename(buf, _fios_path, name, extension, size);
|
|
|
|
}
|
|
|
|
|
2011-05-28 13:55:05 +00:00
|
|
|
/**
|
|
|
|
* Construct a filename for a height map.
|
|
|
|
* @param buf Destination buffer.
|
|
|
|
* @param name Filename.
|
|
|
|
* @param size Size of \a buf.
|
|
|
|
*/
|
|
|
|
void FiosMakeHeightmapName(char *buf, const char *name, size_t size)
|
|
|
|
{
|
|
|
|
char ext[5];
|
|
|
|
ext[0] = '.';
|
|
|
|
strecpy(ext + 1, GetCurrentScreenshotExtension(), lastof(ext));
|
|
|
|
|
|
|
|
FiosMakeFilename(buf, _fios_path, name, ext, size);
|
|
|
|
}
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/**
|
|
|
|
* Delete a file.
|
|
|
|
* @param name Filename to delete.
|
|
|
|
*/
|
2006-08-05 00:16:24 +00:00
|
|
|
bool FiosDelete(const char *name)
|
|
|
|
{
|
|
|
|
char filename[512];
|
|
|
|
|
|
|
|
FiosMakeSavegameName(filename, name, lengthof(filename));
|
2009-03-14 00:25:59 +00:00
|
|
|
return unlink(filename) == 0;
|
2006-08-05 00:16:24 +00:00
|
|
|
}
|
|
|
|
|
2009-01-18 22:44:53 +00:00
|
|
|
typedef FiosType fios_getlist_callback_proc(SaveLoadDialogMode mode, const char *filename, const char *ext, char *title, const char *last);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2009-03-04 01:09:48 +00:00
|
|
|
/**
|
|
|
|
* Scanner to scan for a particular type of FIOS file.
|
|
|
|
*/
|
|
|
|
class FiosFileScanner : public FileScanner {
|
|
|
|
SaveLoadDialogMode mode; ///< The mode we want to search for
|
|
|
|
fios_getlist_callback_proc *callback_proc; ///< Callback to check whether the file may be added
|
|
|
|
public:
|
|
|
|
/**
|
|
|
|
* Create the scanner
|
|
|
|
* @param mode The mode we are in. Some modes don't allow 'parent'.
|
|
|
|
* @param callback_proc The function that is called where you need to do the filtering.
|
|
|
|
*/
|
|
|
|
FiosFileScanner(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc) :
|
|
|
|
mode(mode),
|
|
|
|
callback_proc(callback_proc)
|
|
|
|
{}
|
|
|
|
|
2011-09-08 09:48:52 +00:00
|
|
|
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename);
|
2009-03-04 01:09:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Try to add a fios item set with the given filename.
|
|
|
|
* @param filename the full path to the file to read
|
|
|
|
* @param basepath_length amount of characters to chop of before to get a relative filename
|
|
|
|
* @return true if the file is added.
|
|
|
|
*/
|
2011-09-08 09:48:52 +00:00
|
|
|
bool FiosFileScanner::AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
|
2009-03-04 01:09:48 +00:00
|
|
|
{
|
|
|
|
const char *ext = strrchr(filename, '.');
|
|
|
|
if (ext == NULL) return false;
|
|
|
|
|
|
|
|
char fios_title[64];
|
|
|
|
fios_title[0] = '\0'; // reset the title;
|
|
|
|
|
|
|
|
FiosType type = this->callback_proc(this->mode, filename, ext, fios_title, lastof(fios_title));
|
|
|
|
if (type == FIOS_TYPE_INVALID) return false;
|
|
|
|
|
|
|
|
for (const FiosItem *fios = _fios_items.Begin(); fios != _fios_items.End(); fios++) {
|
|
|
|
if (strcmp(fios->name, filename) == 0) return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
FiosItem *fios = _fios_items.Append();
|
2009-03-10 14:54:46 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
struct _stat sb;
|
|
|
|
if (_tstat(OTTD2FS(filename), &sb) == 0) {
|
|
|
|
#else
|
2009-03-04 01:09:48 +00:00
|
|
|
struct stat sb;
|
|
|
|
if (stat(filename, &sb) == 0) {
|
2009-03-10 14:54:46 +00:00
|
|
|
#endif
|
2009-03-04 01:09:48 +00:00
|
|
|
fios->mtime = sb.st_mtime;
|
|
|
|
} else {
|
|
|
|
fios->mtime = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
fios->type = type;
|
|
|
|
strecpy(fios->name, filename, lastof(fios->name));
|
|
|
|
|
2010-04-12 14:12:47 +00:00
|
|
|
/* If the file doesn't have a title, use its filename */
|
2009-03-04 01:09:48 +00:00
|
|
|
const char *t = fios_title;
|
|
|
|
if (StrEmpty(fios_title)) {
|
|
|
|
t = strrchr(filename, PATHSEPCHAR);
|
|
|
|
t = (t == NULL) ? filename : (t + 1);
|
|
|
|
}
|
|
|
|
strecpy(fios->title, t, lastof(fios->title));
|
2009-03-06 01:23:25 +00:00
|
|
|
str_validate(fios->title, lastof(fios->title));
|
2009-03-04 01:09:48 +00:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-08-01 19:22:34 +00:00
|
|
|
/**
|
|
|
|
* Fill the list of the files in a directory, according to some arbitrary rule.
|
2006-08-05 00:47:32 +00:00
|
|
|
* @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.
|
2009-03-04 23:12:15 +00:00
|
|
|
* @param subdir The directory from where to start (global) searching.
|
2009-03-04 01:09:48 +00:00
|
|
|
*/
|
2009-03-04 23:12:15 +00:00
|
|
|
static void FiosGetFileList(SaveLoadDialogMode mode, fios_getlist_callback_proc *callback_proc, Subdirectory subdir)
|
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
|
|
|
|
2008-06-02 14:19:27 +00:00
|
|
|
_fios_items.Clear();
|
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
/* A parent directory link exists if we are not in the root directory */
|
2011-01-22 23:08:32 +00:00
|
|
|
if (!FiosIsRoot(_fios_path)) {
|
2008-06-02 14:19:27 +00:00
|
|
|
fios = _fios_items.Append();
|
2006-08-05 00:47:32 +00:00
|
|
|
fios->type = FIOS_TYPE_PARENT;
|
|
|
|
fios->mtime = 0;
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(fios->name, "..", lastof(fios->name));
|
|
|
|
strecpy(fios->title, ".. (Parent directory)", lastof(fios->title));
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Show subdirectories */
|
2011-01-22 23:08:32 +00:00
|
|
|
if ((dir = ttd_opendir(_fios_path)) != NULL) {
|
2006-08-05 00:47:32 +00:00
|
|
|
while ((dirent = readdir(dir)) != NULL) {
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(d_name, FS2OTTD(dirent->d_name), lastof(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 '..' */
|
2008-12-05 18:02:04 +00:00
|
|
|
if (FiosIsValidFile(_fios_path, dirent, &sb) && S_ISDIR(sb.st_mode) &&
|
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) {
|
2008-06-02 14:19:27 +00:00
|
|
|
fios = _fios_items.Append();
|
2006-08-05 00:47:32 +00:00
|
|
|
fios->type = FIOS_TYPE_DIR;
|
|
|
|
fios->mtime = 0;
|
2008-11-02 11:20:15 +00:00
|
|
|
strecpy(fios->name, d_name, lastof(fios->name));
|
2006-11-28 14:42:31 +00:00
|
|
|
snprintf(fios->title, lengthof(fios->title), "%s" PATHSEP " (Directory)", d_name);
|
2009-03-06 01:23:25 +00:00
|
|
|
str_validate(fios->title, lastof(fios->title));
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
closedir(dir);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the subdirs always by name, ascending, remember user-sorting order */
|
|
|
|
{
|
2010-06-05 18:44:31 +00:00
|
|
|
SortingBits order = _savegame_sort_order;
|
2006-08-05 00:47:32 +00:00
|
|
|
_savegame_sort_order = SORT_BY_NAME | SORT_ASCENDING;
|
2009-09-13 17:39:33 +00:00
|
|
|
QSortT(_fios_items.Begin(), _fios_items.Length(), CompareFiosItems);
|
2006-08-05 00:47:32 +00:00
|
|
|
_savegame_sort_order = order;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* This is where to start sorting for the filenames */
|
2008-06-02 14:19:27 +00:00
|
|
|
sort_start = _fios_items.Length();
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* Show files */
|
2009-03-04 01:09:48 +00:00
|
|
|
FiosFileScanner scanner(mode, callback_proc);
|
2009-03-04 23:12:15 +00:00
|
|
|
if (subdir == NO_DIRECTORY) {
|
|
|
|
scanner.Scan(NULL, _fios_path, false);
|
|
|
|
} else {
|
|
|
|
scanner.Scan(NULL, subdir, true, true);
|
|
|
|
}
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2009-09-13 17:39:33 +00:00
|
|
|
QSortT(_fios_items.Get(sort_start), _fios_items.Length() - sort_start, CompareFiosItems);
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
/* Show drives */
|
2011-01-22 23:08:32 +00:00
|
|
|
FiosGetDrives();
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2008-06-02 14:19:27 +00:00
|
|
|
_fios_items.Compact();
|
2006-08-05 00:47:32 +00:00
|
|
|
}
|
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
/**
|
|
|
|
* Get the title of a file, which (if exists) is stored in a file named
|
|
|
|
* the same as the data file but with '.title' added to it.
|
|
|
|
* @param file filename to get the title for
|
|
|
|
* @param title the title buffer to fill
|
|
|
|
* @param last the last element in the title buffer
|
2011-08-24 13:35:46 +00:00
|
|
|
* @param subdir the sub directory to search in
|
2009-03-04 23:12:15 +00:00
|
|
|
*/
|
2011-08-24 13:35:46 +00:00
|
|
|
static void GetFileTitle(const char *file, char *title, const char *last, Subdirectory subdir)
|
2009-03-04 23:12:15 +00:00
|
|
|
{
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
strecpy(buf, file, lastof(buf));
|
|
|
|
strecat(buf, ".title", lastof(buf));
|
|
|
|
|
2011-08-24 13:35:46 +00:00
|
|
|
FILE *f = FioFOpenFile(buf, "r", subdir);
|
2009-03-04 23:12:15 +00:00
|
|
|
if (f == NULL) return;
|
|
|
|
|
|
|
|
size_t read = fread(title, 1, last - title, f);
|
|
|
|
assert(title + read <= last);
|
|
|
|
title[read] = '\0';
|
2009-03-06 01:23:25 +00:00
|
|
|
str_validate(title, last);
|
2009-03-05 22:14:27 +00:00
|
|
|
FioFCloseFile(f);
|
2009-03-04 23:12:15 +00:00
|
|
|
}
|
|
|
|
|
2006-08-05 00:47:32 +00:00
|
|
|
/**
|
|
|
|
* 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
|
2008-07-28 15:31:11 +00:00
|
|
|
* @param title Buffer if a callback wants to lookup the title of the file; NULL to skip the lookup
|
2009-01-18 22:44:53 +00:00
|
|
|
* @param last Last available byte in buffer (to prevent buffer overflows); not used when title == NULL
|
2006-08-05 00:47:32 +00:00
|
|
|
* @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a savegame
|
|
|
|
* @see FiosGetFileList
|
|
|
|
* @see FiosGetSavegameList
|
|
|
|
*/
|
2009-01-18 22:44:53 +00:00
|
|
|
FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
|
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 */
|
2009-03-04 23:12:15 +00:00
|
|
|
if (strcasecmp(ext, ".sav") == 0) {
|
2011-08-24 13:35:46 +00:00
|
|
|
GetFileTitle(file, title, last, SAVE_DIR);
|
2009-03-04 23:12:15 +00:00
|
|
|
return FIOS_TYPE_FILE;
|
|
|
|
}
|
2006-08-05 00:47:32 +00:00
|
|
|
|
|
|
|
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
|
|
|
if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
|
|
|
|
strcasecmp(ext, ".sv2") == 0) {
|
2009-03-04 09:53:31 +00:00
|
|
|
if (title != NULL) GetOldSaveGameName(file, title, last);
|
2006-08-05 00:47:32 +00:00
|
|
|
return FIOS_TYPE_OLDFILE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of savegames.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @see FiosGetFileList
|
|
|
|
*/
|
2008-06-02 14:19:27 +00:00
|
|
|
void 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
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
FiosGetFileList(mode, &FiosGetSavegameListCallback, NO_DIRECTORY);
|
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
|
2009-01-18 22:44:53 +00:00
|
|
|
* @param last Last available byte in buffer (to prevent buffer overflows)
|
2006-08-05 00:47:32 +00:00
|
|
|
* @return a FIOS_TYPE_* type of the found file, FIOS_TYPE_INVALID if not a scenario
|
|
|
|
* @see FiosGetFileList
|
|
|
|
* @see FiosGetScenarioList
|
|
|
|
*/
|
2009-01-18 22:44:53 +00:00
|
|
|
static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
|
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 */
|
2009-03-04 23:12:15 +00:00
|
|
|
if (strcasecmp(ext, ".scn") == 0) {
|
2011-08-24 13:35:46 +00:00
|
|
|
GetFileTitle(file, title, last, SCENARIO_DIR);
|
2009-03-04 23:12:15 +00:00
|
|
|
return FIOS_TYPE_SCENARIO;
|
|
|
|
}
|
2006-08-05 00:47:32 +00:00
|
|
|
|
2011-01-22 23:08:32 +00:00
|
|
|
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
|
2006-08-05 00:47:32 +00:00
|
|
|
if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
|
2009-03-04 09:53:31 +00:00
|
|
|
GetOldSaveGameName(file, title, last);
|
2006-08-05 00:47:32 +00:00
|
|
|
return FIOS_TYPE_OLD_SCENARIO;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of scenarios.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
* @see FiosGetFileList
|
|
|
|
*/
|
2008-06-02 14:19:27 +00:00
|
|
|
void 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
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
char base_path[MAX_PATH];
|
|
|
|
FioGetDirectory(base_path, sizeof(base_path), SCENARIO_DIR);
|
|
|
|
|
|
|
|
FiosGetFileList(mode, &FiosGetScenarioListCallback, (mode == SLD_LOAD_SCENARIO && strcmp(base_path, _fios_path) == 0) ? SCENARIO_DIR : NO_DIRECTORY);
|
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
|
|
|
|
2009-01-18 22:44:53 +00:00
|
|
|
static FiosType FiosGetHeightmapListCallback(SaveLoadDialogMode mode, const char *file, const char *ext, char *title, const char *last)
|
(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
|
|
|
|
*/
|
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
FiosType type = FIOS_TYPE_INVALID;
|
|
|
|
|
(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
|
|
|
#ifdef WITH_PNG
|
2009-03-04 23:12:15 +00:00
|
|
|
if (strcasecmp(ext, ".png") == 0) type = FIOS_TYPE_PNG;
|
(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
|
|
|
#endif /* WITH_PNG */
|
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
if (strcasecmp(ext, ".bmp") == 0) type = FIOS_TYPE_BMP;
|
(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
|
|
|
|
2009-04-10 20:20:37 +00:00
|
|
|
if (type == FIOS_TYPE_INVALID) return FIOS_TYPE_INVALID;
|
|
|
|
|
2011-11-14 21:28:43 +00:00
|
|
|
TarFileList::iterator it = _tar_filelist[SCENARIO_DIR].find(file);
|
|
|
|
if (it != _tar_filelist[SCENARIO_DIR].end()) {
|
2009-04-10 20:20:37 +00:00
|
|
|
/* If the file is in a tar and that tar is not in a heightmap
|
|
|
|
* directory we are for sure not supposed to see it.
|
|
|
|
* Examples of this are pngs part of documentation within
|
|
|
|
* collections of NewGRFs or 32 bpp graphics replacement PNGs.
|
|
|
|
*/
|
|
|
|
bool match = false;
|
|
|
|
Searchpath sp;
|
|
|
|
FOR_ALL_SEARCHPATHS(sp) {
|
|
|
|
char buf[MAX_PATH];
|
|
|
|
FioAppendDirectory(buf, sizeof(buf), sp, HEIGHTMAP_DIR);
|
|
|
|
|
|
|
|
if (strncmp(buf, it->second.tar_filename, strlen(buf)) == 0) {
|
|
|
|
match = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!match) return FIOS_TYPE_INVALID;
|
|
|
|
}
|
|
|
|
|
2011-08-24 13:35:46 +00:00
|
|
|
GetFileTitle(file, title, last, HEIGHTMAP_DIR);
|
2009-03-04 23:12:15 +00:00
|
|
|
|
|
|
|
return type;
|
(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
|
|
|
}
|
|
|
|
|
2011-05-27 21:20:07 +00:00
|
|
|
/**
|
|
|
|
* Get a list of heightmaps.
|
|
|
|
* @param mode Save/load mode.
|
|
|
|
*/
|
2008-06-02 14:19:27 +00:00
|
|
|
void 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
|
|
|
|
2009-03-04 23:12:15 +00:00
|
|
|
char base_path[MAX_PATH];
|
|
|
|
FioGetDirectory(base_path, sizeof(base_path), HEIGHTMAP_DIR);
|
|
|
|
|
|
|
|
FiosGetFileList(mode, &FiosGetHeightmapListCallback, strcmp(base_path, _fios_path) == 0 ? HEIGHTMAP_DIR : NO_DIRECTORY);
|
(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
|
|
|
}
|
2009-03-06 19:33:45 +00:00
|
|
|
|
|
|
|
#if defined(ENABLE_NETWORK)
|
|
|
|
#include "network/network_content.h"
|
2009-08-21 20:15:17 +00:00
|
|
|
#include "3rdparty/md5/md5.h"
|
2009-03-06 19:33:45 +00:00
|
|
|
|
|
|
|
/** Basic data to distinguish a scenario. Used in the server list window */
|
|
|
|
struct ScenarioIdentifier {
|
|
|
|
uint32 scenid; ///< ID for the scenario (generated by content)
|
|
|
|
uint8 md5sum[16]; ///< MD5 checksum of file
|
|
|
|
|
|
|
|
bool operator == (const ScenarioIdentifier &other) const
|
|
|
|
{
|
|
|
|
return this->scenid == other.scenid &&
|
|
|
|
memcmp(this->md5sum, other.md5sum, sizeof(this->md5sum)) == 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool operator != (const ScenarioIdentifier &other) const
|
|
|
|
{
|
|
|
|
return !(*this == other);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scanner to find the unique IDs of scenarios
|
|
|
|
*/
|
|
|
|
class ScenarioScanner : protected FileScanner, public SmallVector<ScenarioIdentifier, 8> {
|
|
|
|
bool scanned; ///< Whether we've already scanned
|
|
|
|
public:
|
|
|
|
/** Initialise */
|
|
|
|
ScenarioScanner() : scanned(false) {}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Scan, but only if it's needed.
|
|
|
|
* @param rescan whether to force scanning even when it's not necessary
|
|
|
|
*/
|
|
|
|
void Scan(bool rescan)
|
|
|
|
{
|
|
|
|
if (this->scanned && !rescan) return;
|
|
|
|
|
|
|
|
this->FileScanner::Scan(".id", SCENARIO_DIR, true, true);
|
|
|
|
this->scanned = true;
|
|
|
|
}
|
|
|
|
|
2011-09-08 09:48:52 +00:00
|
|
|
/* virtual */ bool AddFile(const char *filename, size_t basepath_length, const char *tar_filename)
|
2009-03-06 19:33:45 +00:00
|
|
|
{
|
2011-08-24 13:53:34 +00:00
|
|
|
FILE *f = FioFOpenFile(filename, "r", SCENARIO_DIR);
|
2009-03-06 19:33:45 +00:00
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
|
|
ScenarioIdentifier id;
|
2009-03-07 17:57:54 +00:00
|
|
|
int fret = fscanf(f, "%i", &id.scenid);
|
2009-03-06 19:33:45 +00:00
|
|
|
FioFCloseFile(f);
|
2009-03-07 17:57:54 +00:00
|
|
|
if (fret != 1) return false;
|
2009-03-06 19:33:45 +00:00
|
|
|
|
|
|
|
Md5 checksum;
|
|
|
|
uint8 buffer[1024];
|
2009-07-05 15:01:36 +00:00
|
|
|
char basename[MAX_PATH]; ///< \a filename without the extension.
|
2009-03-06 19:33:45 +00:00
|
|
|
size_t len, size;
|
|
|
|
|
|
|
|
/* open the scenario file, but first get the name.
|
|
|
|
* This is safe as we check on extension which
|
|
|
|
* must always exist. */
|
2009-07-05 15:01:36 +00:00
|
|
|
strecpy(basename, filename, lastof(basename));
|
|
|
|
*strrchr(basename, '.') = '\0';
|
|
|
|
f = FioFOpenFile(basename, "rb", SCENARIO_DIR, &size);
|
2009-03-06 19:33:45 +00:00
|
|
|
if (f == NULL) return false;
|
|
|
|
|
|
|
|
/* calculate md5sum */
|
|
|
|
while ((len = fread(buffer, 1, (size > sizeof(buffer)) ? sizeof(buffer) : size, f)) != 0 && size != 0) {
|
|
|
|
size -= len;
|
|
|
|
checksum.Append(buffer, len);
|
|
|
|
}
|
|
|
|
checksum.Finish(id.md5sum);
|
|
|
|
|
|
|
|
FioFCloseFile(f);
|
|
|
|
|
|
|
|
this->Include(id);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/** Scanner for scenarios */
|
|
|
|
static ScenarioScanner _scanner;
|
|
|
|
|
|
|
|
/**
|
2010-04-12 14:12:47 +00:00
|
|
|
* Check whether we've got a given scenario based on its unique ID.
|
2009-03-06 19:33:45 +00:00
|
|
|
* @param ci the content info to compare it to
|
|
|
|
* @param md5sum whether to look at the md5sum or the id
|
|
|
|
* @return true if we've got the scenario
|
|
|
|
*/
|
|
|
|
bool HasScenario(const ContentInfo *ci, bool md5sum)
|
|
|
|
{
|
|
|
|
_scanner.Scan(false);
|
|
|
|
|
|
|
|
for (ScenarioIdentifier *id = _scanner.Begin(); id != _scanner.End(); id++) {
|
|
|
|
if (md5sum ?
|
|
|
|
(memcmp(id->md5sum, ci->md5sum, sizeof(id->md5sum)) == 0) :
|
|
|
|
(id->scenid == ci->unique_id)) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Force a (re)scan of the scenarios.
|
|
|
|
*/
|
|
|
|
void ScanScenarios()
|
|
|
|
{
|
|
|
|
_scanner.Scan(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* ENABLE_NETWORK */
|