summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2007-03-12 15:40:12 +0000
committerrubidium <rubidium@openttd.org>2007-03-12 15:40:12 +0000
commit9a107b875252e7b5de06aca63b4f3f0bf2e21b74 (patch)
tree1690945310fc088b21e6399eb31aef8b25b3e7b5
parentc0ac3745a09c28c3119a40fd1b474a8ec11a443e (diff)
downloadopenttd-9a107b875252e7b5de06aca63b4f3f0bf2e21b74.tar.xz
(svn r9130) -Codechange: move the fileio functions that do open a file into a Fio slot together.
-rw-r--r--src/fileio.cpp74
1 files changed, 42 insertions, 32 deletions
diff --git a/src/fileio.cpp b/src/fileio.cpp
index d951980a7..c77eb269e 100644
--- a/src/fileio.cpp
+++ b/src/fileio.cpp
@@ -136,15 +136,6 @@ void FioCloseAll()
FioCloseFile(i);
}
-bool FioCheckFileExists(const char *filename)
-{
- FILE *f = FioFOpenFile(filename);
- if (f == NULL) return false;
-
- fclose(f);
- return true;
-}
-
#if defined(LIMITED_FDS)
static void FioFreeHandle()
{
@@ -169,6 +160,45 @@ static void FioFreeHandle()
}
#endif /* LIMITED_FDS */
+void FioOpenFile(int slot, const char *filename)
+{
+ FILE *f;
+
+#if defined(LIMITED_FDS)
+ FioFreeHandle();
+#endif /* LIMITED_FDS */
+ f = FioFOpenFile(filename);
+ if (f == NULL) error("Cannot open file '%s%s'", _paths.data_dir, filename);
+
+ FioCloseFile(slot); // if file was opened before, close it
+ _fio.handles[slot] = f;
+#if defined(LIMITED_FDS)
+ _fio.filename[slot] = filename;
+ _fio.usage_count[slot] = 0;
+ _fio.open_handles++;
+#endif /* LIMITED_FDS */
+ FioSeekToFile(slot << 24);
+}
+
+/**
+ * Check whether the given file exists
+ * @param filename the file to try for existance
+ * @return true if and only if the file can be opened
+ */
+bool FioCheckFileExists(const char *filename)
+{
+ FILE *f = FioFOpenFile(filename);
+ if (f == NULL) return false;
+
+ fclose(f);
+ return true;
+}
+
+/**
+ * Opens the file with the given name
+ * @param filename the file to open (in either data_dir or second_data_dir)
+ * @return the opened file or NULL when it failed.
+ */
FILE *FioFOpenFile(const char *filename)
{
FILE *f;
@@ -196,26 +226,6 @@ FILE *FioFOpenFile(const char *filename)
return f;
}
-void FioOpenFile(int slot, const char *filename)
-{
- FILE *f;
-
-#if defined(LIMITED_FDS)
- FioFreeHandle();
-#endif /* LIMITED_FDS */
- f = FioFOpenFile(filename);
- if (f == NULL) error("Cannot open file '%s%s'", _paths.data_dir, filename);
-
- FioCloseFile(slot); // if file was opened before, close it
- _fio.handles[slot] = f;
-#if defined(LIMITED_FDS)
- _fio.filename[slot] = filename;
- _fio.usage_count[slot] = 0;
- _fio.open_handles++;
-#endif /* LIMITED_FDS */
- FioSeekToFile(slot << 24);
-}
-
/**
* Create a directory with the given name
* @param name the new name of the directory
@@ -243,8 +253,8 @@ void AppendPathSeparator(char *buf, size_t buflen)
/* Length of string + path separator + '\0' */
if (s != 0 && buf[s - 1] != PATHSEPCHAR && s + 2 < buflen) {
- buf[s] = PATHSEPCHAR;
- buf[s + 1] = '\0';
+ buf[s] = PATHSEPCHAR;
+ buf[s + 1] = '\0';
}
}
@@ -270,7 +280,7 @@ void DeterminePaths()
_paths.save_dir = str_fmt("%ssave", _paths.personal_dir);
_paths.autosave_dir = str_fmt("%s" PATHSEP "autosave", _paths.save_dir);
_paths.scenario_dir = str_fmt("%sscenario", _paths.personal_dir);
- _paths.heightmap_dir = str_fmt("%s" PATHSEP "heightmap", _paths.heightmap_dir);
+ _paths.heightmap_dir = str_fmt("%s" PATHSEP "heightmap", _paths.scenario_dir);
_paths.gm_dir = str_fmt("%sgm" PATHSEP, _paths.game_data_dir);
_paths.data_dir = str_fmt("%sdata" PATHSEP, _paths.game_data_dir);
#if defined(CUSTOM_LANG_DIR)