mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r9130) -Codechange: move the fileio functions that do open a file into a Fio slot together.
This commit is contained in:
parent
9299e76a25
commit
1926b9038d
|
@ -136,15 +136,6 @@ void FioCloseAll()
|
||||||
FioCloseFile(i);
|
FioCloseFile(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FioCheckFileExists(const char *filename)
|
|
||||||
{
|
|
||||||
FILE *f = FioFOpenFile(filename);
|
|
||||||
if (f == NULL) return false;
|
|
||||||
|
|
||||||
fclose(f);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
#if defined(LIMITED_FDS)
|
#if defined(LIMITED_FDS)
|
||||||
static void FioFreeHandle()
|
static void FioFreeHandle()
|
||||||
{
|
{
|
||||||
|
@ -169,6 +160,45 @@ static void FioFreeHandle()
|
||||||
}
|
}
|
||||||
#endif /* LIMITED_FDS */
|
#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 *FioFOpenFile(const char *filename)
|
||||||
{
|
{
|
||||||
FILE *f;
|
FILE *f;
|
||||||
|
@ -196,26 +226,6 @@ FILE *FioFOpenFile(const char *filename)
|
||||||
return f;
|
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
|
* Create a directory with the given name
|
||||||
* @param name the new name of the directory
|
* @param name the new name of the directory
|
||||||
|
@ -270,7 +280,7 @@ void DeterminePaths()
|
||||||
_paths.save_dir = str_fmt("%ssave", _paths.personal_dir);
|
_paths.save_dir = str_fmt("%ssave", _paths.personal_dir);
|
||||||
_paths.autosave_dir = str_fmt("%s" PATHSEP "autosave", _paths.save_dir);
|
_paths.autosave_dir = str_fmt("%s" PATHSEP "autosave", _paths.save_dir);
|
||||||
_paths.scenario_dir = str_fmt("%sscenario", _paths.personal_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.gm_dir = str_fmt("%sgm" PATHSEP, _paths.game_data_dir);
|
||||||
_paths.data_dir = str_fmt("%sdata" PATHSEP, _paths.game_data_dir);
|
_paths.data_dir = str_fmt("%sdata" PATHSEP, _paths.game_data_dir);
|
||||||
#if defined(CUSTOM_LANG_DIR)
|
#if defined(CUSTOM_LANG_DIR)
|
||||||
|
|
Loading…
Reference in New Issue