File: MemFileFest.cpp

package info (click to toggle)
postal1 2015.git20250526%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 14,024 kB
  • sloc: cpp: 130,877; ansic: 38,942; python: 874; makefile: 351; sh: 61
file content (126 lines) | stat: -rw-r--r-- 4,466 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
// MemFileFest.cpp
// Project: Nostril (aka Postal)
// 
// History:
//		09/12/97 JMI	Started.
//
//		09/12/97	JMI	Added SHAREWARE_RELEASE files.
//
//		09/12/97	JMI	Now only the end of the requested resource name has to
//							match the full embedded file's name.
//
//		09/17/97 MJR	Renamed to the more-correct ONLINE_DEMO_RELEASE.
//
//		06/24/01 MJR	Got rid of alternate CompUSA level.
//
//////////////////////////////////////////////////////////////////////////////
//
//	Manages a group of memory resources that represent disk files.  Currently
// used for .RLM files to limit the usefulness of crippleware demos.
//
//////////////////////////////////////////////////////////////////////////////

#include "RSPiX.h"

#include "CompileOptions.h"

#include "MemFileFest.h"

//////////////////////////////////////////////////////////////////////////////
// Macros.
//////////////////////////////////////////////////////////////////////////////

#define NUM_ELEMENTS(a)	(sizeof(a) / sizeof(a[0]) )

//////////////////////////////////////////////////////////////////////////////
// Typedefs.
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Variables.
//////////////////////////////////////////////////////////////////////////////

// Only compile this hefty chunk of shit if we're only allowing specific realm
#if defined(ENABLE_PLAY_SPECIFIC_REALMS_ONLY)
	#include "GConsite.h"
	#include "EConsite.h"
	#include "MConsite.h"
	#include "HConsite.h"
	#include "PConsite.h"

	FATEntry	ms_memdisk[]	= 
		{
			{	pszCheckPtGConsite,	au8CheckPtGConsite,	sizeof(au8CheckPtGConsite),	},

			{	pszEConsite,			au8EConsite,			sizeof(au8EConsite),				},

			{	pszMConsite,			au8MConsite,			sizeof(au8MConsite),				},

			{	pszHConsite,			au8HConsite,			sizeof(au8HConsite),				},

			{	pszPConsite,			au8PConsite,			sizeof(au8PConsite),				},
		};

//////////////////////////////////////////////////////////////////////////////
// Functions.
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Given a filename, open an RFile to the corresponding resource data.
//////////////////////////////////////////////////////////////////////////////
extern int16_t GetMemFileResource(	// Returns 0 on successful open.
	const char*		pszResName,		// In:  Res filename.
	RFile::Endian	endian,			// In:  Endian nature for RFile.
	RFile*			pfile)			// In:  File to open with.
	{
	int16_t	sRes	= 1;	// Assume failure for simplicity.
	ASSERT(pfile);
	ASSERT(pszResName);

	int16_t	sIndex;
	bool	bFound;
	int32_t	lReqResNameLen	= strlen(pszResName);
	for (sIndex = 0, bFound = false; sIndex < NUM_ELEMENTS(ms_memdisk) && bFound == false; sIndex++)
		{
		int32_t lEmbeddedResNameLen	= strlen(ms_memdisk[sIndex].pszResName);
		// If the requested name is long enough . . .
		if (lReqResNameLen >= lEmbeddedResNameLen)
			{
			// If this is the specified res name (the specified name only has to
			// match from the end back lEmbeddedResNameLen characters) . . .
			if (rspStricmp(pszResName + lReqResNameLen - lEmbeddedResNameLen, ms_memdisk[sIndex].pszResName) == 0)
				{
				// Found it.
				bFound	= true;

				// Open the resource data . . .
				sRes	= pfile->Open(ms_memdisk[sIndex].pau8Res, ms_memdisk[sIndex].lResSize, endian);
				}
			}
		}
	
	return sRes;
	}

#endif	// ENABLE_PLAY_SPECIFIC_REALMS_ONLY

//////////////////////////////////////////////////////////////////////////////
// EOF
//////////////////////////////////////////////////////////////////////////////