mirror of
https://github.com/OpenTTD/OpenTTD.git
synced 2025-08-25 15:39:09 +00:00
(svn r5764) - Cleanup: - Cleanup: Move the now unified FiosAlloc, compare_FiosItems, FiosFreeSavegameList, FiosMakeSavegameName, FiosDelete and FileExists to newly created file fios.c where it belongs.
- Fix: forgot to remove GetLanguageList from functions.h in previous commit
This commit is contained in:
67
unix.c
67
unix.c
@@ -48,36 +48,11 @@ ULONG __stack = (1024*1024)*2; // maybe not that much is needed actually ;)
|
||||
#include <SDL.h>
|
||||
#endif
|
||||
#endif
|
||||
static char *_fios_path;
|
||||
extern char *_fios_path;
|
||||
static char *_fios_save_path;
|
||||
static char *_fios_scn_path;
|
||||
static FiosItem *_fios_items;
|
||||
static int _fios_count, _fios_alloc;
|
||||
|
||||
static FiosItem *FiosAlloc(void)
|
||||
{
|
||||
if (_fios_count == _fios_alloc) {
|
||||
_fios_alloc += 256;
|
||||
_fios_items = realloc(_fios_items, _fios_alloc * sizeof(FiosItem));
|
||||
}
|
||||
return &_fios_items[_fios_count++];
|
||||
}
|
||||
|
||||
int compare_FiosItems(const void *a, const void *b)
|
||||
{
|
||||
const FiosItem *da = (const FiosItem *)a;
|
||||
const FiosItem *db = (const FiosItem *)b;
|
||||
int r;
|
||||
|
||||
if (_savegame_sort_order & SORT_BY_NAME) {
|
||||
r = strcasecmp(da->title, db->title);
|
||||
} else {
|
||||
r = da->mtime < db->mtime ? -1 : 1;
|
||||
}
|
||||
|
||||
if (_savegame_sort_order & SORT_DESCENDING) r = -r;
|
||||
return r;
|
||||
}
|
||||
extern FiosItem *_fios_items;
|
||||
extern int _fios_count, _fios_alloc;
|
||||
|
||||
#if !defined(__MORPHOS__) && !defined(__AMIGAOS__)
|
||||
#define ISROOT(__p) (__p[1] == '\0')
|
||||
@@ -297,15 +272,6 @@ FiosItem *FiosGetScenarioList(int *num, int mode)
|
||||
return _fios_items;
|
||||
}
|
||||
|
||||
|
||||
// Free the list of savegames
|
||||
void FiosFreeSavegameList(void)
|
||||
{
|
||||
free(_fios_items);
|
||||
_fios_items = NULL;
|
||||
_fios_alloc = _fios_count = 0;
|
||||
}
|
||||
|
||||
// Browse to
|
||||
char *FiosBrowseTo(const FiosItem *item)
|
||||
{
|
||||
@@ -387,33 +353,6 @@ StringID FiosGetDescText(const char **path, uint32 *tot)
|
||||
return STR_4005_BYTES_FREE;
|
||||
}
|
||||
|
||||
void FiosMakeSavegameName(char *buf, const char *name, size_t size)
|
||||
{
|
||||
const char* extension;
|
||||
const char* period;
|
||||
|
||||
extension = (_game_mode == GM_EDITOR ? ".scn" : ".sav");
|
||||
|
||||
// Don't append the extension, if it is already there
|
||||
period = strrchr(name, '.');
|
||||
if (period != NULL && strcasecmp(period, extension) == 0) extension = "";
|
||||
|
||||
snprintf(buf, size, "%s/%s%s", _fios_path, name, extension);
|
||||
}
|
||||
|
||||
bool FiosDelete(const char *name)
|
||||
{
|
||||
char path[512];
|
||||
|
||||
FiosMakeSavegameName(path, name, sizeof(path));
|
||||
return unlink(path) == 0;
|
||||
}
|
||||
|
||||
bool FileExists(const char *filename)
|
||||
{
|
||||
return access(filename, 0) == 0;
|
||||
}
|
||||
|
||||
#if defined(__BEOS__) || defined(__linux__)
|
||||
static void ChangeWorkingDirectory(char *exe)
|
||||
{
|
||||
|
Reference in New Issue
Block a user