1/*
2
3Copyright (C) 2015-2018 Night Dive Studios, LLC.
4
5This program is free software: you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation, either version 3 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
18*/
19//=========================================================
20//  PurgeTest.cp - Program to test the memory purging capabilities of the resource
21//						    library.
22//=========================================================
23
24#include <iostream.h>
25
26#include "res.h"
27
28//--------------------------------------
29void main(void);
30
31
32//---------------------------------------------------------
33//  Main routine.
34//---------------------------------------------------------
35void main(void)
36{
37	StandardFileReply	reply, reply2;
38	SFTypeList				typeList;
39	short						filenum, filenum2;
40
41	ResInit();
42
43	cout << "Select a resource file...\n\n" ;
44
45	typeList[0] = 'Sgam';
46	typeList[1] = 'rsrc';
47	StandardGetFile(nil, 2, typeList, &reply);
48	if (!reply.sfGood)
49		return;
50	else
51	{
52		filenum = ResOpenFile(&reply.sfFile);
53		cout << "Opened file, filenum = " << filenum << "\n";
54	}
55
56	cout << "Select another resource file (optional)...\n\n" ;
57	filenum2 = -1;
58	StandardGetFile(nil, 2, typeList, &reply2);
59	if (reply.sfGood)
60	{
61		filenum2 = ResOpenFile(&reply2.sfFile);
62		cout << "Opened file, filenum = " << filenum2 << "\n";
63	}
64
65	{
66		short		i;
67		Id 			id;
68		Ptr		p;
69		short 	rs;
70		ResDesc	*prd;
71
72		for (i = 0; i < 2; i++)
73		{
74			for (id = ID_MIN; id <= resDescMax; id++)
75			{
76				prd = RESDESC(id);
77				if (prd->filenum != 0)
78				{
79					rs = ResSize(id);
80					cout << "Geting resource " << id << " (size: " << rs << ")     ";
81
82					if (!ResInUse(id))
83						cout << "Resource not in use!\n";
84					else if (!ResPtr(id))
85						cout << "Resource not in memory!\n";
86					else
87						cout << endl;
88
89					p = (Ptr)ResLock(id);
90					cout << "Free mem: " << FreeMem() << "    ";
91					cout << "Max block size: " << MaxBlock() << endl;
92
93					ResUnlock(id);
94
95//					long  temp;
96//					Delay(40, &temp);
97				}
98			}
99			cout << "\nGo through 'em again...\n\n";
100		}
101
102		cout << "Closing files.\n" ;
103		ResCloseFile(filenum);
104		if (filenum2 != -1)
105			ResCloseFile(filenum2);
106	}
107
108	ResTerm();
109}
110