summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2009-03-04 09:53:31 +0000
committerrubidium <rubidium@openttd.org>2009-03-04 09:53:31 +0000
commit0d8da02ec1ec610931c2fdbe05a29e7ee3a49144 (patch)
tree9a2c02d0b0de1ad7374ee64afe0beadcb8f2b21f /src
parentf0de54bc10d158bbb1ae58b628c0896a56880540 (diff)
downloadopenttd-0d8da02ec1ec610931c2fdbe05a29e7ee3a49144.tar.xz
(svn r15610) -Change: allow loading of heightmaps and savegames (any form) that are in .tar files
Diffstat (limited to 'src')
-rw-r--r--src/fileio.cpp4
-rw-r--r--src/fios.cpp6
-rw-r--r--src/heightmap.cpp5
-rw-r--r--src/saveload/oldloader.cpp14
-rw-r--r--src/saveload/saveload.cpp9
5 files changed, 19 insertions, 19 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index a976135d0..3ad29b6f2 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -358,7 +358,7 @@ FILE *FioFOpenFile(const char *filename, const char *mode, Subdirectory subdir,
}
/* We can only use .tar in case of data-dir, and read-mode */
- if (f == NULL && (subdir == DATA_DIR || subdir == AI_DIR || subdir == AI_LIBRARY_DIR) && mode[0] == 'r') {
+ if (f == NULL && mode[0] == 'r') {
static const uint MAX_RESOLVED_LENGTH = 2 * (100 + 100 + 155) + 1; // Enough space to hold two filenames plus link. See 'TarHeader'.
char resolved_name[MAX_RESOLVED_LENGTH];
@@ -777,6 +777,8 @@ void ScanForTarFiles()
num += ScanPathForTarFiles(path, strlen(path));
FioAppendDirectory(path, MAX_PATH, sp, AI_LIBRARY_DIR);
num += ScanPathForTarFiles(path, strlen(path));
+ FioAppendDirectory(path, MAX_PATH, sp, SCENARIO_DIR);
+ num += ScanPathForTarFiles(path, strlen(path));
}
DEBUG(misc, 1, "Scan complete, found %d files", num);
}
diff --git a/src/fios.cpp b/src/fios.cpp
index 548efbfec..8c68a9e62 100644
--- a/src/fios.cpp
+++ b/src/fios.cpp
@@ -37,7 +37,7 @@ extern void FiosGetDrives();
extern bool FiosGetDiskFreeSpace(const char *path, uint64 *tot);
/* get the name of an oldstyle savegame */
-extern void GetOldSaveGameName(const char *path, const char *file, char *title, const char *last);
+extern void GetOldSaveGameName(const char *file, char *title, const char *last);
/**
* Compare two FiosItem's. Used with qsort when sorting the file list.
@@ -343,7 +343,7 @@ FiosType FiosGetSavegameListCallback(SaveLoadDialogMode mode, const char *file,
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO) {
if (strcasecmp(ext, ".ss1") == 0 || strcasecmp(ext, ".sv1") == 0 ||
strcasecmp(ext, ".sv2") == 0) {
- if (title != NULL) GetOldSaveGameName(_fios_path, file, title, last);
+ if (title != NULL) GetOldSaveGameName(file, title, last);
return FIOS_TYPE_OLDFILE;
}
}
@@ -392,7 +392,7 @@ static FiosType FiosGetScenarioListCallback(SaveLoadDialogMode mode, const char
if (mode == SLD_LOAD_GAME || mode == SLD_LOAD_SCENARIO || mode == SLD_NEW_GAME) {
if (strcasecmp(ext, ".sv0") == 0 || strcasecmp(ext, ".ss0") == 0 ) {
- GetOldSaveGameName(_fios_path, file, title, last);
+ GetOldSaveGameName(file, title, last);
return FIOS_TYPE_OLD_SCENARIO;
}
}
diff --git a/src/heightmap.cpp b/src/heightmap.cpp
index b690438d4..36e962dde 100644
--- a/src/heightmap.cpp
+++ b/src/heightmap.cpp
@@ -12,6 +12,7 @@
#include "gfx_func.h"
#include "fios.h"
#include "settings_type.h"
+#include "fileio_func.h"
#include "table/strings.h"
@@ -98,7 +99,7 @@ static bool ReadHeightmapPNG(char *filename, uint *x, uint *y, byte **map)
png_structp png_ptr = NULL;
png_infop info_ptr = NULL;
- fp = fopen(filename, "rb");
+ fp = FioFOpenFile(filename, "rb");
if (fp == NULL) {
ShowErrorMessage(STR_PNGMAP_ERR_FILE_NOT_FOUND, STR_PNGMAP_ERROR, 0, 0);
return false;
@@ -221,7 +222,7 @@ static bool ReadHeightmapBMP(char *filename, uint *x, uint *y, byte **map)
/* Init BmpData */
memset(&data, 0, sizeof(data));
- f = fopen(filename, "rb");
+ f = FioFOpenFile(filename, "rb");
if (f == NULL) {
ShowErrorMessage(STR_PNGMAP_ERR_FILE_NOT_FOUND, STR_BMPMAP_ERROR, 0, 0);
return false;
diff --git a/src/saveload/oldloader.cpp b/src/saveload/oldloader.cpp
index dd55a9e29..7def93796 100644
--- a/src/saveload/oldloader.cpp
+++ b/src/saveload/oldloader.cpp
@@ -9,6 +9,7 @@
#include "../strings_type.h"
#include "../string_func.h"
#include "../settings_type.h"
+#include "../fileio_func.h"
#include "table/strings.h"
@@ -224,7 +225,6 @@ static inline bool CheckOldSavegameType(FILE *f, char *temp, const char *last, u
{
assert(last - temp + 1 >= (int)len);
- fseek(f, 0, SEEK_SET);
if (fread(temp, 1, len, f) != len) {
temp[0] = '\0'; // if reading failed, make the name empty
return false;
@@ -243,8 +243,11 @@ static SavegameType DetermineOldSavegameType(FILE *f, char *title, const char *l
SavegameType type = SGT_TTO;
+ /* Can't fseek to 0 as in tar files that is not correct */
+ long pos = ftell(f);
if (!CheckOldSavegameType(f, temp, lastof(temp), TTO_HEADER_SIZE)) {
type = SGT_TTD;
+ fseek(f, pos, SEEK_SET);
if (!CheckOldSavegameType(f, temp, lastof(temp), TTD_HEADER_SIZE)) {
type = SGT_INVALID;
}
@@ -273,7 +276,7 @@ bool LoadOldSaveGame(const char *file)
InitLoading(&ls);
/* Open file */
- ls.file = fopen(file, "rb");
+ ls.file = FioFOpenFile(file, "rb");
if (ls.file == NULL) {
DEBUG(oldloader, 0, "Cannot open file '%s'", file);
@@ -303,12 +306,9 @@ bool LoadOldSaveGame(const char *file)
return true;
}
-void GetOldSaveGameName(const char *path, const char *file, char *title, const char *last)
+void GetOldSaveGameName(const char *file, char *title, const char *last)
{
- char filename[MAX_PATH];
-
- snprintf(filename, lengthof(filename), "%s" PATHSEP "%s", path, file);
- FILE *f = fopen(filename, "rb");
+ FILE *f = FioFOpenFile(file, "rb");
if (f == NULL) {
*title = '\0';
diff --git a/src/saveload/saveload.cpp b/src/saveload/saveload.cpp
index 8b6b8e198..31f3b3c2d 100644
--- a/src/saveload/saveload.cpp
+++ b/src/saveload/saveload.cpp
@@ -1737,6 +1737,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
assert(mode == SL_LOAD);
DEBUG(desync, 1, "load: %s\n", filename);
+ /* Can't fseek to 0 as in tar files that is not correct */
+ long pos = ftell(_sl.fh);
if (fread(hdr, sizeof(hdr), 1, _sl.fh) != 1) SlError(STR_GAME_SAVELOAD_ERROR_FILE_NOT_READABLE);
/* see if we have any loader for this type. */
@@ -1744,13 +1746,8 @@ SaveOrLoadResult SaveOrLoad(const char *filename, int mode, Subdirectory sb)
/* No loader found, treat as version 0 and use LZO format */
if (fmt == endof(_saveload_formats)) {
DEBUG(sl, 0, "Unknown savegame type, trying to load it as the buggy format");
- #if defined(WINCE)
- /* Of course some system had not to support rewind ;) */
- fseek(_sl.fh, 0L, SEEK_SET);
clearerr(_sl.fh);
- #else
- rewind(_sl.fh);
- #endif
+ fseek(_sl.fh, pos, SEEK_SET);
_sl_version = 0;
_sl_minor_version = 0;
fmt = _saveload_formats + 1; // LZO