Windows WIP.

This commit is contained in:
Steven Fuller 2008-05-09 02:11:36 -07:00 committed by Patryk Obara
parent c51b91cfe7
commit e9788e390d
14 changed files with 476 additions and 282 deletions

View file

@ -337,7 +337,7 @@ typedef struct
unsigned char ElapsedTime_Seconds;
unsigned char Difficulty;
FILETIME TimeStamp;
time_t TimeStamp;
} SAVE_SLOT_HEADER;
#define NUMBER_OF_SAVE_SLOTS 8

View file

@ -69,8 +69,10 @@ typedef struct
{
char Name[MAX_SIZE_OF_USERS_NAME+1];
SYSTEMTIME TimeLastUpdated;
FILETIME FileTime;
time_t FileTime;
// used to be an incomplete SYSTEMTIME struct, TimeLastUpdated
int unused[6];
/* KJL 15:14:12 10/12/98 - array to hold level completion data
3 species, pad out to 16 levels each */

View file

@ -277,7 +277,9 @@ List<int> LoadedNPC::image_groups;
extern "C"
{
extern BOOL Current_Level_Requires_Mirror_Image();
extern int AllowGoldWeapons;
};
void InitNPCs(RIFFHANDLE h)
{
@ -572,8 +574,6 @@ void InitNPCs(RIFFHANDLE h)
if(AvP.PlayerType==I_Marine || Load_HNPC[HNPC_Marine])
{
extern int AllowGoldWeapons;
// if the mdisk.rif file exists, add it. Note: Only the Gold version
// has this file, so the OpenGameFile is called just to check if it
// is available.

View file

@ -1,6 +1,6 @@
#define _BSD_SOURCE
//#include <unistd.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -533,6 +533,179 @@ int CloseGameDirectory(void *dir)
return -1;
}
/*
Game-specific helper function.
*/
static int try_game_directory(char *dir, char *file)
{
char tmppath[PATH_MAX];
strncpy(tmppath, dir, PATH_MAX-32);
tmppath[PATH_MAX-32] = 0;
strcat(tmppath, file);
return access(tmppath, R_OK) == 0;
}
/*
Game-specific helper function.
*/
static int check_game_directory(char *dir)
{
if (!dir || !*dir) {
return 0;
}
if (!try_game_directory(dir, "/avp_huds")) {
return 0;
}
if (!try_game_directory(dir, "/avp_huds/alien.rif")) {
return 0;
}
if (!try_game_directory(dir, "/avp_rifs")) {
return 0;
}
if (!try_game_directory(dir, "/avp_rifs/temple.rif")) {
return 0;
}
if (!try_game_directory(dir, "/fastfile")) {
return 0;
}
if (!try_game_directory(dir, "/fastfile/ffinfo.txt")) {
return 0;
}
return 1;
}
/*
Game-specific initialization
*/
void InitGameDirectories(char *argv0)
{
extern char *SecondTex_Directory;
extern char *SecondSoundDir;
char tmppath[PATH_MAX];
char *homedir, *gamedir, *localdir, *tmp;
char *path;
size_t len, copylen;
SecondTex_Directory = "graphics/";
SecondSoundDir = "sound/";
homedir = getenv("HOME");
if (homedir == NULL)
homedir = ".";
localdir = (char *)malloc(strlen(homedir)+10);
strcpy(localdir, homedir);
strcat(localdir, "/");
strcat(localdir, ".avp");
tmp = NULL;
/*
1. $AVP_DATA overrides all
2. executable path from argv[0]
3. realpath of executable path from argv[0]
4. $PATH
5. current directory
*/
/* 1. $AVP_DATA */
gamedir = getenv("AVP_DATA");
/* $AVP_DATA overrides all, so no check */
if (gamedir == NULL) {
/* 2. executable path from argv[0] */
tmp = strdup(argv0);
if (tmp == NULL) {
/* ... */
fprintf(stderr, "InitGameDirectories failure\n");
exit(EXIT_FAILURE);
}
gamedir = strrchr(tmp, '/');
if (gamedir) {
*gamedir = 0;
gamedir = tmp;
if (!check_game_directory(gamedir)) {
gamedir = NULL;
}
}
}
if (gamedir == NULL) {
/* 3. realpath of executable path from argv[0] */
assert(tmp != NULL);
gamedir = realpath(tmp, tmppath);
if (!check_game_directory(gamedir)) {
gamedir = NULL;
}
}
if (gamedir == NULL) {
/* 4. $PATH */
path = getenv("PATH");
if (path) {
while (*path) {
len = strcspn(path, ":");
copylen = min(len, PATH_MAX-1);
strncpy(tmppath, path, copylen);
tmppath[copylen] = 0;
if (check_game_directory(tmppath)) {
gamedir = tmppath;
break;
}
path += len;
path += strspn(path, ":");
}
}
}
if (gamedir == NULL) {
/* 5. current directory */
gamedir = ".";
}
assert(gamedir != NULL);
/* last chance sanity check */
if (!check_game_directory(gamedir)) {
fprintf(stderr, "Unable to find the AvP gamedata.\n");
fprintf(stderr, "The directory last examined was: %s\n", gamedir);
fprintf(stderr, "Has the game been installed and\n");
fprintf(stderr, "are all game files lowercase?\n");
exit(EXIT_FAILURE);
}
SetGameDirectories(localdir, gamedir);
free(localdir);
if (tmp) {
free(tmp);
}
/* delete some log files */
DeleteGameFile("dx_error.log");
}
#ifdef FILES_DRIVER
int main(int argc, char *argv[])
{

View file

@ -37,6 +37,7 @@ int CreateGameDirectory(const char *dirname);
void *OpenGameDirectory(const char *dirname, const char *pattern, int type);
GameDirectoryFile *ScanGameDirectory(void *dir);
int CloseGameDirectory(void *dir);
void InitGameDirectories(char *argv0);
#ifdef __cplusplus
};

View file

@ -4,27 +4,31 @@
#if defined(_MSC_VER)
// just include the windows header to get everything.
#undef Yes
#undef No
#undef Yes // sigh
#undef No // sigh
#include <windows.h>
#include <tchar.h>
#include <mbstring.h>
#define Yes 1 // sigh
#define No 0 // sigh
#pragma warning( disable: 4996 ) // unsafe function (strcpy, fopen, etc.) used
#define Yes 1
#define No 0
#include "files.h"
#if !defined(PATH_MAX)
#define PATH_MAX MAX_PATH
#endif
// gonna deal with this one later.
#define PACKED
// unused directplay code.
typedef int DPID;
// not sure where this was originally defined.
#define RGBA_MAKE(r, g, b, a) ((((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
// unused placeholder directplay code.
typedef int DPID;
typedef struct DPNAME
{
int dwSize;
@ -125,6 +129,8 @@ extern "C" {
#define _tcslen strlen
#define _tcscpy strcpy
#define _snprintf snprintf
size_t _mbclen(const unsigned char *s);
#define RGBA_MAKE(r, g, b, a) ((((a) << 24) | ((r) << 16) | ((g) << 8) | (b)))
@ -137,6 +143,7 @@ typedef int HINSTANCE;
typedef int WPARAM;
typedef int LPARAM;
typedef int HANDLE;
typedef int HRESULT;
typedef int BOOL;
typedef unsigned char BYTE;
@ -166,21 +173,6 @@ typedef __int64 int64_t;
typedef unsigned __int64 uint64_t;
#endif
typedef time_t FILETIME;
/* this SYSTEMTIME is incorrect, but it is also currently unused */
typedef struct SYSTEMTIME
{
int wYear; /* should be uint16_t, not int32_t */
int wMonth;
int wDay;
/* int wDayOfWeek; */
int wHour;
int wMinute;
int wSecond;
/* int wMilliseconds; */
} SYSTEMTIME;
#define VK_BACK 1
#define VK_END 2
#define VK_HOME 3
@ -230,6 +222,7 @@ int SetEndOfFile(HANDLE file);
unsigned int timeGetTime();
unsigned int GetTickCount();
typedef struct DPNAME
{
int dwSize;
@ -240,8 +233,6 @@ typedef struct DPNAME
#define DP_OK 0
typedef int HRESULT;
#define DPRECEIVE_ALL 1
#define DPSYS_ADDPLAYERTOGROUP 2
#define DPSYS_CREATEPLAYERORGROUP 3

View file

@ -10,7 +10,7 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
#include <getopt.h>
///#include <getopt.h>
#include "fixer.h"
@ -66,10 +66,10 @@ JOYINFOEX JoystickData;
JOYCAPS JoystickCaps;
/* defaults */
static int WantFullscreen = 1;
static int WantFullscreen = 0;
int WantSound = 1;
static int WantCDRom = 1;
static int WantJoystick = 1;
static int WantCDRom = 0;
static int WantJoystick = 0;
/* originally was "/usr/lib/libGL.so.1:/usr/lib/tls/libGL.so.1:/usr/X11R6/lib/libGL.so" */
static const char * opengl_library = NULL;
@ -336,7 +336,7 @@ char *GetVideoModeDescription3()
{
static char buf[64];
snprintf(buf, 64, "%dx%d", VideoModeList[CurrentVideoMode].w, VideoModeList[CurrentVideoMode].h);
_snprintf(buf, 64, "%dx%d", VideoModeList[CurrentVideoMode].w, VideoModeList[CurrentVideoMode].h);
return buf;
}
@ -1097,187 +1097,23 @@ void FlipBuffers()
char *AvpCDPath = 0;
static int try_game_directory(char *dir, char *file)
{
char tmppath[PATH_MAX];
strncpy(tmppath, dir, PATH_MAX-32);
tmppath[PATH_MAX-32] = 0;
strcat(tmppath, file);
return access(tmppath, R_OK) == 0;
}
static int check_game_directory(char *dir)
{
if (!dir || !*dir) {
return 0;
}
if (!try_game_directory(dir, "/avp_huds")) {
return 0;
}
if (!try_game_directory(dir, "/avp_huds/alien.rif")) {
return 0;
}
if (!try_game_directory(dir, "/avp_rifs")) {
return 0;
}
if (!try_game_directory(dir, "/avp_rifs/temple.rif")) {
return 0;
}
if (!try_game_directory(dir, "/fastfile")) {
return 0;
}
if (!try_game_directory(dir, "/fastfile/ffinfo.txt")) {
return 0;
}
return 1;
}
void InitGameDirectories(char *argv0)
{
extern char *SecondTex_Directory;
extern char *SecondSoundDir;
char tmppath[PATH_MAX];
char *homedir, *gamedir, *localdir, *tmp;
char *path;
size_t len, copylen;
SecondTex_Directory = "graphics/";
SecondSoundDir = "sound/";
homedir = getenv("HOME");
if (homedir == NULL)
homedir = ".";
localdir = (char *)malloc(strlen(homedir)+10);
strcpy(localdir, homedir);
strcat(localdir, "/");
strcat(localdir, ".avp");
tmp = NULL;
/*
1. $AVP_DATA overrides all
2. executable path from argv[0]
3. realpath of executable path from argv[0]
4. $PATH
5. current directory
*/
/* 1. $AVP_DATA */
gamedir = getenv("AVP_DATA");
/* $AVP_DATA overrides all, so no check */
if (gamedir == NULL) {
/* 2. executable path from argv[0] */
tmp = strdup(argv0);
if (tmp == NULL) {
/* ... */
fprintf(stderr, "InitGameDirectories failure\n");
exit(EXIT_FAILURE);
}
gamedir = strrchr(tmp, '/');
if (gamedir) {
*gamedir = 0;
gamedir = tmp;
if (!check_game_directory(gamedir)) {
gamedir = NULL;
}
}
}
if (gamedir == NULL) {
/* 3. realpath of executable path from argv[0] */
assert(tmp != NULL);
gamedir = realpath(tmp, tmppath);
if (!check_game_directory(gamedir)) {
gamedir = NULL;
}
}
if (gamedir == NULL) {
/* 4. $PATH */
path = getenv("PATH");
if (path) {
while (*path) {
len = strcspn(path, ":");
copylen = min(len, PATH_MAX-1);
strncpy(tmppath, path, copylen);
tmppath[copylen] = 0;
if (check_game_directory(tmppath)) {
gamedir = tmppath;
break;
}
path += len;
path += strspn(path, ":");
}
}
}
if (gamedir == NULL) {
/* 5. current directory */
gamedir = ".";
}
assert(gamedir != NULL);
/* last chance sanity check */
if (!check_game_directory(gamedir)) {
fprintf(stderr, "Unable to find the AvP gamedata.\n");
fprintf(stderr, "The directory last examined was: %s\n", gamedir);
fprintf(stderr, "Has the game been installed and\n");
fprintf(stderr, "are all game files lowercase?\n");
exit(EXIT_FAILURE);
}
SetGameDirectories(localdir, gamedir);
free(localdir);
if (tmp) {
free(tmp);
}
/* delete some log files */
DeleteGameFile("dx_error.log");
}
static const struct option getopt_long_options[] = {
{ "help", 0, NULL, 'h' },
{ "version", 0, NULL, 'v' },
{ "fullscreen", 0, NULL, 'f' },
{ "windowed", 0, NULL, 'w' },
{ "nosound", 0, NULL, 's' },
{ "nocdrom", 0, NULL, 'c' },
{ "nojoy", 0, NULL, 'j' },
{ "debug", 0, NULL, 'd' },
{ "withgl", 1, NULL, 'g' },
/*
{ "loadrifs", 1, NULL, 'l' },
{ "server", 0, someval, 1 },
{ "client", 1, someval, 2 },
*/
{ NULL, 0, NULL, 0 },
};
///static const struct option getopt_long_options[] = {
///{ "help", 0, NULL, 'h' },
///{ "version", 0, NULL, 'v' },
///{ "fullscreen", 0, NULL, 'f' },
///{ "windowed", 0, NULL, 'w' },
///{ "nosound", 0, NULL, 's' },
///{ "nocdrom", 0, NULL, 'c' },
///{ "nojoy", 0, NULL, 'j' },
///{ "debug", 0, NULL, 'd' },
///{ "withgl", 1, NULL, 'g' },
////*
///{ "loadrifs", 1, NULL, 'l' },
///{ "server", 0, someval, 1 },
///{ "client", 1, someval, 2 },
///*/
///{ NULL, 0, NULL, 0 },
///};
static const char *usage_string =
"Aliens vs Predator Linux - http://www.icculus.org/avp/\n"
@ -1296,43 +1132,43 @@ int main(int argc, char *argv[])
{
int c;
opterr = 0;
while ((c = getopt_long(argc, argv, "hvfwscdg:", getopt_long_options, NULL)) != -1) {
switch(c) {
case 'h':
printf("%s", usage_string);
exit(EXIT_SUCCESS);
case 'v':
printf("%s", AvPVersionString);
exit(EXIT_SUCCESS);
case 'f':
WantFullscreen = 1;
break;
case 'w':
WantFullscreen = 0;
break;
case 's':
WantSound = 0;
break;
case 'c':
WantCDRom = 0;
break;
case 'j':
WantJoystick = 0;
break;
case 'd': {
extern int DebuggingCommandsActive;
DebuggingCommandsActive = 1;
}
break;
case 'g':
opengl_library = optarg;
break;
default:
printf("%s", usage_string);
exit(EXIT_FAILURE);
}
}
/// opterr = 0;
/// while ((c = getopt_long(argc, argv, "hvfwscdg:", getopt_long_options, NULL)) != -1) {
/// switch(c) {
/// case 'h':
/// printf("%s", usage_string);
/// exit(EXIT_SUCCESS);
/// case 'v':
/// printf("%s", AvPVersionString);
/// exit(EXIT_SUCCESS);
/// case 'f':
/// WantFullscreen = 1;
/// break;
/// case 'w':
/// WantFullscreen = 0;
/// break;
/// case 's':
/// WantSound = 0;
/// break;
/// case 'c':
/// WantCDRom = 0;
/// break;
/// case 'j':
/// WantJoystick = 0;
/// break;
/// case 'd': {
/// extern int DebuggingCommandsActive;
/// DebuggingCommandsActive = 1;
/// }
/// break;
/// case 'g':
/// opengl_library = optarg;
/// break;
/// default:
/// printf("%s", usage_string);
/// exit(EXIT_FAILURE);
/// }
/// }
InitGameDirectories(argv[0]);

View file

@ -141,8 +141,9 @@ static int check_token(const char *string, const char *token)
void load_ogl_functions(int mode)
{
const char * ogl_missing_func;
const char* ogl_missing_func;
const char* ext;
ogl_missing_func = NULL;
LoadOGLProc(PFNGLALPHAFUNCPROC, glAlphaFunc);
@ -244,7 +245,7 @@ void load_ogl_functions(int mode)
exit(EXIT_FAILURE);
}
const char *ext = (const char *) pglGetString(GL_EXTENSIONS);
ext = (const char *) pglGetString(GL_EXTENSIONS);
ogl_have_paletted_texture = check_token(ext, "GL_EXT_paletted_texture");
ogl_have_secondary_color = check_token(ext, "GL_EXT_secondary_color");
@ -262,7 +263,7 @@ void load_ogl_functions(int mode)
if (!ogl_missing_func) {
GLint size;
pglColorTableEXT(GL_PROXY_TEXTURE_2D, GL_RGBA, 256, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
pglColorTableEXT(GL_PROXY_TEXTURE_2D, GL_RGBA, 256, GL_BGRA_EXT, GL_UNSIGNED_BYTE, NULL);
pglGetColorTableParameterivEXT(GL_PROXY_TEXTURE_2D, GL_COLOR_TABLE_WIDTH_EXT, &size);
if (size != 256) {

View file

@ -99,7 +99,7 @@ typedef void (APIENTRY * PFNGLGETCOLORTABLEPARAMETERIVEXTPROC) (GLenum target, G
typedef void (APIENTRY * PFNGLGETCOLORTABLEPARAMETERFVEXTPROC) (GLenum target, GLenum pname, GLfloat *params);
*/
/*
#if defined(_MSC_VER)
typedef void (APIENTRY * PFNGLSECONDARYCOLOR3BEXTPROC) (GLbyte red, GLbyte green, GLbyte blue);
typedef void (APIENTRY * PFNGLSECONDARYCOLOR3BVEXTPROC) (const GLbyte *v);
typedef void (APIENTRY * PFNGLSECONDARYCOLOR3DEXTPROC) (GLdouble red, GLdouble green, GLdouble blue);
@ -117,7 +117,7 @@ typedef void (APIENTRY * PFNGLSECONDARYCOLOR3UIVEXTPROC) (const GLuint *v);
typedef void (APIENTRY * PFNGLSECONDARYCOLOR3USEXTPROC) (GLushort red, GLushort green, GLushort blue);
typedef void (APIENTRY * PFNGLSECONDARYCOLOR3USVEXTPROC) (const GLushort *v);
typedef void (APIENTRY * PFNGLSECONDARYCOLORPOINTEREXTPROC) (GLint size, GLenum type, GLsizei stride, const GLvoid *pointer);
*/
#endif
extern PFNGLALPHAFUNCPROC pglAlphaFunc;
extern PFNGLARRAYELEMENTPROC pglArrayElement;

View file

@ -168,7 +168,7 @@ int PlatStartSoundSys()
attrlist[3] = AL_FALSE;
attrlist[4] = 0;
snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
_snprintf(buf, sizeof(buf), "'( (sampling-rate %d ))\n", AvpFrequency);
AvpSoundDevice = alcOpenDevice(buf);
if (AvpSoundDevice == NULL)

View file

@ -539,7 +539,7 @@ AwTl::SurfUnion AwBackupTexture::CreateTexture(AwTl::CreateTextureParms const &
y = m_nHeight-1;
}
for (int i, rowcount = m_nHeight; rowcount; --rowcount, i++)
for (int i = 0, rowcount = m_nHeight; rowcount; --rowcount, i++)
{
PtrUnion src_rowP = GetRowPtr(y);
db_assert1(src_rowP.voidP);

View file

@ -61,11 +61,8 @@ static HuffEncode EncodingTable[257];
/* KJL 17:16:03 17/09/98 - Compression */
static void PerformSymbolCensus(unsigned char *sourcePtr, int length);
#ifdef __WATCOMC__
static int HuffItemsSortSub(const void *cmp1, const void *cmp2);
#else
static int __cdecl HuffItemsSortSub(const void *cmp1, const void *cmp2);
#endif
static void SortCensusData(void);
static void BuildHuffmanTree(void);
static void MakeHuffTreeFromHuffItems(HuffNode *base, HuffItem *source, int count);
@ -125,11 +122,7 @@ static void PerformSymbolCensus(unsigned char *sourcePtr, int length)
while (--length);
}
#ifdef __WATCOMC__
static int HuffItemsSortSub(const void *cmp1, const void *cmp2)
#else
static int __cdecl HuffItemsSortSub(const void *cmp1, const void *cmp2)
#endif
{
if (((HuffItem *)cmp1)->Count > ((HuffItem *)cmp2)->Count)
return 1;
@ -321,6 +314,7 @@ static int HuffEncodeBytes(int *dest, unsigned char *source, int count, HuffEnco
if (!count) return 0;
accum = 0;
start = dest;
sourcelim = sourceend = source + count;
available = 32;
@ -387,7 +381,7 @@ lpstart: val = *source++;
}
}
*dest++ = accum >> available;
return (dest - start) * 4;
return (int)((dest - start) * 4);
}
@ -398,11 +392,11 @@ lpstart: val = *source++;
/* KJL 17:16:24 17/09/98 - Decompression */
static int DecodeTable[1<<MAX_DEPTH];
static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list);
static int HuffmanDecode(unsigned char *dest, int *source, int *table, int length);
static void MakeHuffmanDecodeTable(const int *depth, int depthmax, const unsigned char *list);
static int HuffmanDecode(unsigned char *dest, const int *source, const int *table, int length);
extern char *HuffmanDecompress(HuffmanPackage *inpackage)
extern char *HuffmanDecompress(const HuffmanPackage *inpackage)
{
unsigned char *uncompressedData = NULL;
// Step 1: Make the decoding table
@ -418,12 +412,12 @@ extern char *HuffmanDecompress(HuffmanPackage *inpackage)
return (char*)uncompressedData;
}
static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list)
static void MakeHuffmanDecodeTable(const int *depth, int depthmax, const unsigned char *list)
{
int thisdepth, depthbit, repcount, repspace, lenbits, temp, count;
int *outp;
int o = 0;
unsigned char *p;
const unsigned char *p;
int *outtbl = DecodeTable;
lenbits = 0;
@ -431,7 +425,7 @@ static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list
repspace = 1;
thisdepth = 0;
depthbit = 4;
p = (unsigned char *)list + 255;
p = list + 255;
while (1)
{
do
@ -476,17 +470,18 @@ static void MakeHuffmanDecodeTable(int *depth, int depthmax, unsigned char *list
#define EDXMASK ((((1 << (MAX_DEPTH + 1)) - 1) ^ 1) ^ -1)
static int HuffmanDecode(unsigned char *dest, int *source, int *table, int length)
static int HuffmanDecode(unsigned char *dest, const int *source, const int *table, int length)
{
unsigned char *start;
int available, reserve, fill, wid;
unsigned int bits=0, resbits;
unsigned char *p;
const unsigned char *p;
start = dest;
available = 0;
reserve = 0;
wid = 0;
wid = 0;
resbits = 0;
do
{
available += wid;
@ -512,11 +507,11 @@ static int HuffmanDecode(unsigned char *dest, int *source, int *table, int lengt
{
bits >>= wid;
*dest++ = p[1];
lpent: p = (unsigned char *)(((short *)table)+(bits & ~EDXMASK));
lpent: p = (const unsigned char *)(((const short *)table)+(bits & ~EDXMASK));
}
while ((available -= (wid = *p)) >= 0 && (dest-start)!=length);
}
while (available > -32 && (dest-start)!=length);
return dest - start;
return (int)(dest - start);
}

View file

@ -7,6 +7,7 @@
#endif
#define MAX_DEPTH 11
typedef struct
{
char Identifier[8];
@ -16,11 +17,12 @@ typedef struct
unsigned char ByteAssignment[256];
} HuffmanPackage;
/* KJL 17:16:03 17/09/98 - Compression */
extern HuffmanPackage *HuffmanCompression(unsigned char *sourcePtr, int length);
/* KJL 16:53:53 19/09/98 - Decompression */
extern char *HuffmanDecompress(HuffmanPackage *inpackage);
extern char *HuffmanDecompress(const HuffmanPackage *inpackage);
#define COMPRESSED_RIF_IDENTIFIER "REBCRIF1"

193
src/winfiles.c Normal file
View file

@ -0,0 +1,193 @@
#define _CRT_SECURE_NO_WARNINGS
#include <windows.h>
#include "files.h"
static char *local_dir;
static char *global_dir;
/*
Sets the local and global directories used by the other functions.
Local = ~/.dir, where config and user-installed files are kept.
Global = installdir, where installed data is stored.
*/
int SetGameDirectories(const char *local, const char *global)
{
local_dir = _strdup(local);
global_dir = _strdup(global);
// TODO - create local directory if it doesn't exist
return 0;
}
#define DIR_SEPARATOR "\\"
static char *FixFilename(const char *filename, const char *prefix, int force)
{
char *f, *ptr;
int flen;
int plen;
plen = strlen(prefix) + 1;
flen = strlen(filename) + plen + 1;
f = (char *)malloc(flen);
strcpy(f, prefix);
strcat(f, DIR_SEPARATOR);
strcat(f, filename);
/* only the filename part needs to be modified */
ptr = &f[plen+1];
while (*ptr) {
if ((*ptr == '/') || (*ptr == '\\') || (*ptr == ':')) {
*ptr = DIR_SEPARATOR[0];
} else if (*ptr == '\r' || *ptr == '\n') {
*ptr = 0;
break;
} else {
if (force) {
*ptr = tolower(*ptr);
}
}
ptr++;
}
return f;
}
/*
Open a file of type type, with mode mode.
Mode can be:
#define FILEMODE_READONLY 0x01
#define FILEMODE_WRITEONLY 0x02
#define FILEMODE_READWRITE 0x04
#define FILEMODE_APPEND 0x08
Type is (mode = ReadOnly):
#define FILETYPE_PERM 0x08 // try the global dir only
#define FILETYPE_OPTIONAL 0x10 // try the global dir first, then try the local dir
#define FILETYPE_CONFIG 0x20 // try the local dir only
Type is (mode = WriteOnly or ReadWrite):
FILETYPE_PERM: error
FILETYPE_OPTIONAL: error
FILETYPE_CONFIG: try the local dir only
*/
FILE *OpenGameFile(const char *filename, int mode, int type)
{
char *rfilename;
char *openmode;
FILE *fp;
if ((type != FILETYPE_CONFIG) && (mode != FILEMODE_READONLY))
return NULL;
switch(mode) {
case FILEMODE_READONLY:
openmode = "rb";
break;
case FILEMODE_WRITEONLY:
openmode = "wb";
break;
case FILEMODE_READWRITE:
openmode = "w+";
break;
case FILEMODE_APPEND:
openmode = "ab";
break;
default:
return NULL;
}
if (type != FILETYPE_CONFIG) {
rfilename = FixFilename(filename, global_dir, 0);
fp = fopen(rfilename, openmode);
free(rfilename);
if (fp != NULL) {
return fp;
}
rfilename = FixFilename(filename, global_dir, 1);
fp = fopen(rfilename, openmode);
free(rfilename);
if (fp != NULL) {
return fp;
}
}
if (type != FILETYPE_PERM) {
rfilename = FixFilename(filename, local_dir, 0);
fp = fopen(rfilename, openmode);
free(rfilename);
if (fp != NULL) {
return fp;
}
rfilename = FixFilename(filename, local_dir, 1);
fp = fopen(rfilename, openmode);
free(rfilename);
return fp;
}
return NULL;
}
int CloseGameFile(FILE *pfd)
{
return fclose(pfd);
}
int GetGameFileAttributes(const char *filename, int type)
{
// TODO
return 0;
}
int DeleteGameFile(const char *filename)
{
// TODO
return 0;
}
int CreateGameDirectory(const char *dirname)
{
// TODO
return 0;
}
void *OpenGameDirectory(const char *dirname, const char *pattern, int type)
{
// TODO
return NULL;
}
GameDirectoryFile *ScanGameDirectory(void *dir)
{
// TODO
return NULL;
}
int CloseGameDirectory(void *dir)
{
// TODO
return 0;
}
void InitGameDirectories(char *argv0)
{
SetGameDirectories("local/", "./");
}