Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
rcfile.cpp
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : wwlib *
24 * *
25 * $Archive:: /Commando/Code/wwlib/rcfile.cpp $*
26 * *
27 * Author:: Greg Hjelstrom *
28 * *
29 * $Modtime:: 7/09/99 1:37p $*
30 * *
31 * $Revision:: 5 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#include "rcfile.h"
39#include <stdlib.h>
40
41const char * RESOURCE_FILE_TYPE_NAME = "File";
42
43
44ResourceFileClass::ResourceFileClass(HMODULE hmodule, char const *filename) :
50{
51 Set_Name(filename);
52 HRSRC hresource = FindResource(hmodule,ResourceName,RESOURCE_FILE_TYPE_NAME);
53
54 if (hresource) {
55 HGLOBAL hglob = LoadResource(hmodule,hresource);
56 if (hglob) {
57 FileBytes = (unsigned char *)LockResource(hglob);
58 if (FileBytes) {
60 EndOfFile = FileBytes + SizeofResource(hmodule,hresource);
61 }
62 }
63 }
64}
65
71
72char const * ResourceFileClass::Set_Name(char const *filename)
73{
74 if (ResourceName) {
75 free(ResourceName);
77 }
78 if (filename) {
79 ResourceName = strdup(filename);
80 }
81 return ResourceName;
82}
83
84int ResourceFileClass::Read(void *buffer, int size)
85{
86 if (!FilePtr) return 0;
87
88 if (FilePtr + size > EndOfFile) {
89 size = EndOfFile - FilePtr;
90 }
91 memcpy(buffer,FilePtr,size);
92 FilePtr += size;
93 return size;
94}
95
97{
98 switch (dir) {
99 case SEEK_SET:
100 FilePtr = FileBytes + pos;
101 break;
102
103 case SEEK_CUR:
104 FilePtr = FilePtr + pos;
105 break;
106
107 case SEEK_END:
108 FilePtr = EndOfFile + pos;
109 break;
110 }
111
112 if (FilePtr > EndOfFile) {
114 }
115 if (FilePtr < FileBytes) {
117 }
118
119 return FilePtr - FileBytes;
120}
121
123{
124 return EndOfFile - FileBytes;
125}
126
127void ResourceFileClass::Error(int /*error*/, int /*canretry*/, char const * /*filename*/)
128{
129}
#define NULL
Definition BaseType.h:92
#define SEEK_SET
Definition WWFILE.H:55
#define SEEK_CUR
Definition WWFILE.H:56
#define SEEK_END
Definition WWFILE.H:57
char dir[_MAX_DIR]
Definition autorun.cpp:215
virtual int Size(void)
Definition rcfile.cpp:122
virtual char const * Set_Name(char const *filename)
Definition rcfile.cpp:72
HMODULE hModule
Definition rcfile.h:87
ResourceFileClass(HMODULE hmodule, char const *filename)
Definition rcfile.cpp:44
unsigned char * FileBytes
Definition rcfile.h:89
unsigned char * FilePtr
Definition rcfile.h:90
unsigned char * EndOfFile
Definition rcfile.h:91
virtual int Read(void *buffer, int size)
Definition rcfile.cpp:84
char * ResourceName
Definition rcfile.h:85
virtual ~ResourceFileClass(void)
Definition rcfile.cpp:66
virtual int Seek(int pos, int dir=SEEK_CUR)
Definition rcfile.cpp:96
virtual void Error(int error, int canretry=false, char const *filename=NULL)
Definition rcfile.cpp:127
const char * RESOURCE_FILE_TYPE_NAME
Definition rcfile.cpp:41