Changeset - r6088:dd09788d020f
[Not reviewed]
master
0 4 0
Darkvater - 17 years ago 2007-02-20 09:46:10
darkvater@openttd.org
(svn r8823) -Fix (r8821): wrapping opendir to ottd-specific function failed on non-windows because this wrapper was only active for win32 (thx Rubidium)
4 files changed with 4 insertions and 10 deletions:
0 comments (0 inline, 0 general)
src/fios.cpp
Show inline comments
 
/* $Id$ */
 

	
 
/** @file fios.c
 
 * This file contains functions for building file lists for the save/load dialogs.
 
 */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "hal.h"
 
#include "string.h"
 
#include "variables.h"
 
#include "functions.h"
 
#include "heightmap.h"
 
#include "helpers.hpp"
 
#include "table/strings.h"
 
#include "fios.h"
 
#include <sys/types.h>
 
#include <sys/stat.h>
 

	
 
#ifdef WIN32
 
# include <io.h>
 
#else
 
# include <unistd.h>
 
# include <dirent.h>
 
#endif /* WIN32 */
 

	
 
/* Variables to display file lists */
 
int _fios_num;
 

	
 
static char *_fios_path;
 
static FiosItem *_fios_items;
 
static int _fios_count, _fios_alloc;
 

	
 
/* OS-specific functions are taken from their respective files (win32/unix/os2 .c) */
 
extern bool FiosIsRoot(const char *path);
 
extern bool FiosIsValidFile(const char *path, const struct dirent *ent, struct stat *sb);
 
extern void FiosGetDrives(void);
 
extern bool FiosGetDiskFreeSpace(const char *path, uint32 *tot);
 

	
 
/* get the name of an oldstyle savegame */
 
extern void GetOldSaveGameName(char *title, const char *path, const char *file);
 

	
 
/**
 
 * Allocate a new FiosItem.
 
 * @return A pointer to the newly allocated FiosItem.
 
 */
 
FiosItem *FiosAlloc(void)
 
{
 
	if (_fios_count == _fios_alloc) {
 
		_fios_alloc += 256;
 
		_fios_items = ReallocT(_fios_items, _fios_alloc);
 
	}
 
	return &_fios_items[_fios_count++];
 
}
 

	
 
/**
 
 * Compare two FiosItem's. Used with qsort when sorting the file list.
 
 * @param a A pointer to the first FiosItem to compare.
 
 * @param a A pointer to the second FiosItem to compare.
 
 * @return -1, 0 or 1, depending on how the two items should be sorted.
 
 */
 
int CDECL 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;
 
	}
src/fios.h
Show inline comments
 
@@ -35,63 +35,67 @@ FiosItem *FiosGetSavegameList(int mode);
 
// Get a list of scenarios
 
FiosItem *FiosGetScenarioList(int mode);
 
// Get a list of Heightmaps
 
FiosItem *FiosGetHeightmapList(int mode);
 
// Free the list of savegames
 
void FiosFreeSavegameList(void);
 
// Browse to. Returns a filename w/path if we reached a file.
 
char *FiosBrowseTo(const FiosItem *item);
 
// Return path, free space and stringID
 
StringID FiosGetDescText(const char **path, uint32 *total_free);
 
// Delete a name
 
bool FiosDelete(const char *name);
 
// Make a filename from a name
 
void FiosMakeSavegameName(char *buf, const char *name, size_t size);
 
// Allocate a new FiosItem
 
FiosItem *FiosAlloc(void);
 

	
 
int CDECL compare_FiosItems(const void *a, const void *b);
 

	
 
/* Implementation of opendir/readdir/closedir for Windows */
 
#if defined(WIN32)
 
#include <windows.h>
 
typedef struct DIR DIR;
 

	
 
typedef struct dirent { // XXX - only d_name implemented
 
	wchar_t *d_name; /* name of found file */
 
	/* little hack which will point to parent DIR struct which will
 
	 * save us a call to GetFileAttributes if we want information
 
	 * about the file (for example in function fio_bla */
 
	DIR *dir;
 
} dirent;
 

	
 
struct DIR {
 
	HANDLE hFind;
 
	/* the dirent returned by readdir.
 
	 * note: having only one global instance is not possible because
 
	 * multiple independent opendir/readdir sequences must be supported. */
 
	dirent ent;
 
	WIN32_FIND_DATAW fd;
 
	/* since opendir calls FindFirstFile, we need a means of telling the
 
	 * first call to readdir that we already have a file.
 
	 * that's the case iff this is true */
 
	bool at_first_entry;
 
};
 

	
 
DIR *opendir(const wchar_t *path);
 
struct dirent *readdir(DIR *d);
 
int closedir(DIR *d);
 
#else
 
/* Use system-supplied opendir/readdir/closedir functions */
 
# include <sys/types.h>
 
# include <dirent.h>
 
#endif /* defined(WIN32) */
 

	
 
/**
 
 * A wrapper around opendir() which will convert the string from
 
 * OPENTTD encoding to that of the filesystem. For all purposes this
 
 * function behaves the same as the original opendir function
 
 * @param path string to open directory of
 
 * @return DIR pointer
 
 */
 
static inline DIR *ttd_opendir(const char *path)
 
{
 
	return opendir(OTTD2FS(path));
 
}
 

	
 
#endif /* FIOS_H */
src/newgrf_config.cpp
Show inline comments
 
/* $Id$ */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "functions.h"
 
#include "macros.h"
 
#include "debug.h"
 
#include "variables.h"
 
#include "string.h"
 
#include "saveload.h"
 
#include "md5.h"
 
#include "network/network_data.h"
 
#include "newgrf.h"
 
#include "newgrf_config.h"
 
#include "helpers.hpp"
 

	
 
#include "fileio.h"
 
#include "fios.h"
 
#include <sys/types.h>
 
#include <sys/stat.h>
 

	
 
#ifdef WIN32
 
# include <io.h>
 
#else
 
# include <unistd.h>
 
# include <dirent.h>
 
#endif /* WIN32 */
 

	
 

	
 
GRFConfig *_all_grfs;
 
GRFConfig *_grfconfig;
 
GRFConfig *_grfconfig_newgame;
 
GRFConfig *_grfconfig_static;
 

	
 

	
 
/* Calculate the MD5 Sum for a GRF */
 
static bool CalcGRFMD5Sum(GRFConfig *config)
 
{
 
	FILE *f;
 
	char filename[MAX_PATH];
 
	md5_state_t md5state;
 
	md5_byte_t buffer[1024];
 
	size_t len;
 

	
 
	/* open the file */
 
	snprintf(filename, lengthof(filename), "%s%s", _paths.data_dir, config->filename);
 
	f = fopen(filename, "rb");
 
	if (f == NULL) return false;
 

	
 
	/* calculate md5sum */
 
	md5_init(&md5state);
 
	while ((len = fread(buffer, 1, sizeof(buffer), f)) != 0) {
 
		md5_append(&md5state, buffer, len);
 
	}
 
	md5_finish(&md5state, config->md5sum);
 

	
 
	fclose(f);
 

	
 
	return true;
 
}
 

	
 

	
 
/* Find the GRFID and calculate the md5sum */
 
bool FillGRFDetails(GRFConfig *config, bool is_static)
 
{
 
	if (!FioCheckFileExists(config->filename)) {
 
		SETBIT(config->flags, GCF_NOT_FOUND);
 
		return false;
 
	}
 

	
 
	/* Find and load the Action 8 information */
 
	/* 62 is the last file slot before sample.cat.
 
	 * Should perhaps be some "don't care" value */
 
	LoadNewGRFFile(config, 62, GLS_FILESCAN);
src/strings.cpp
Show inline comments
 
/* $Id$ */
 

	
 
#include "stdafx.h"
 
#include "openttd.h"
 
#include "currency.h"
 
#include "functions.h"
 
#include "string.h"
 
#include "strings.h"
 
#include "table/strings.h"
 
#include "namegen.h"
 
#include "station.h"
 
#include "town.h"
 
#include "vehicle.h"
 
#include "news.h"
 
#include "screenshot.h"
 
#include "waypoint.h"
 
#include "industry.h"
 
#include "variables.h"
 
#include "newgrf_text.h"
 
#include "table/landscape_const.h"
 
#include "table/control_codes.h"
 
#include "music.h"
 
#include "date.h"
 
#include "industry.h"
 
#include "helpers.hpp"
 

	
 
#ifdef WIN32
 
/* for opendir/readdir/closedir */
 
# include "fios.h"
 
#else
 
# include <sys/types.h>
 
# include <dirent.h>
 
#endif /* WIN32 */
 

	
 
char _userstring[128];
 

	
 
static char *StationGetSpecialString(char *buff, int x, const char* last);
 
static char *GetSpecialTownNameString(char *buff, int ind, uint32 seed, const char* last);
 
static char *GetSpecialPlayerNameString(char *buff, int ind, const int32 *argv, const char* last);
 

	
 
static char *FormatString(char *buff, const char *str, const int32 *argv, uint casei, const char* last);
 

	
 
typedef struct LanguagePack {
 
	uint32 ident;
 
	uint32 version;     // 32-bits of auto generated version info which is basically a hash of strings.h
 
	char name[32];      // the international name of this language
 
	char own_name[32];  // the localized name of this language
 
	char isocode[16];   // the ISO code for the language (not country code)
 
	uint16 offsets[32]; // the offsets
 
	byte plural_form;   // how to compute plural forms
 
	byte pad[3];        // pad header to be a multiple of 4
 
	char data[VARARRAY_SIZE];
 
} LanguagePack;
 

	
 
static char **_langpack_offs;
 
static LanguagePack *_langpack;
 
static uint _langtab_num[32]; // Offset into langpack offs
 
static uint _langtab_start[32]; // Offset into langpack offs
 

	
 

	
 
// Read an int64 from the argv array.
 
static inline int64 GetInt64(const int32 **argv)
 
{
 
	int64 result;
 

	
 
	assert(argv);
 
	result = (uint32)(*argv)[0] + ((uint64)(uint32)(*argv)[1] << 32);
 
	(*argv)+=2;
 
	return result;
 
}
 

	
 
// Read an int32 from the argv array.
 
static inline int32 GetInt32(const int32 **argv)
 
{
 
	assert(argv);
 
	return *(*argv)++;
 
}
 

	
 
// Read an array from the argv array.
 
static inline const int32 *GetArgvPtr(const int32 **argv, int n)
 
{
0 comments (0 inline, 0 general)