(svn r9130) -Codechange: move the fileio functions that do open a file into a Fio slot together.
authorrubidium
Mon, 12 Mar 2007 15:40:12 +0000
changeset 6625 3348b52bd823
parent 6624 554e5aee6c3f
child 6626 9520de80f461
(svn r9130) -Codechange: move the fileio functions that do open a file into a Fio slot together.
src/fileio.cpp
--- a/src/fileio.cpp	Mon Mar 12 15:25:33 2007 +0000
+++ b/src/fileio.cpp	Mon Mar 12 15:40:12 2007 +0000
@@ -136,15 +136,6 @@
 		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 @@
 }
 #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 @@
 	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 @@
 
 	/* 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 @@
 	_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)