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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
|
#include "Files.h"
short Files::OpenFile(Str255 Name)
{
short volume;
char filename[33];
short tFile;
tFile=-1;
Point ptOrigin = { 0, 0 };
volume = 0;
sprintf (filename, "%s", Name);
SetVol( nil, volume );
CtoPstr( filename );
FSOpen( (Pstr) filename, volume,&tFile );
PtoCstr( (Pstr) filename );
sFile=tFile;
return( tFile );
}
short Files::OpenNewFile( SFReply *psfReply,
OSType osTypeCreator,
OSType osTypeType )
{
sFile = 0;
OSErr osErr;
SetVol( nil, psfReply->vRefNum );
osErr = Create( psfReply->fName, psfReply->vRefNum, osTypeCreator, osTypeType );
if ( osErr == dupFNErr )
{
FSDelete( psfReply->fName, psfReply->vRefNum );
Create( psfReply->fName, psfReply->vRefNum, osTypeCreator, osTypeType );
}
FSOpen( psfReply->fName, psfReply->vRefNum, &sFile );
return( sFile );
}
short Files::PromptForSaveAS( short sPromptID,
short sNameID,
Str255 str255NamePrompt,
OSType osTypeCreator,
OSType osTypeType,
SFReply *psfReply )
{
Str255 str255Prompt;
Str255 str255Name;
sFile = 0;
Point ptOrigin = { 0, 0 };
GetIndString( str255Prompt, FILE_STRINGS, sPromptID );
if ( !str255NamePrompt )
GetIndString( str255Name, FILE_STRINGS, sNameID );
else
memcpy( str255Name, str255NamePrompt, *str255NamePrompt + 1 );
SFPutFile( ptOrigin, str255Prompt, str255Name, nil, psfReply );
if ( psfReply->good )
{
sFile = OpenNewFile( psfReply, osTypeCreator, osTypeType );
}
return( sFile );
}
short Files::OpenSavedGame(Str255 Name)
{
Point ptOrigin = { 0, 0 };
sSavedGameVolume = 0;
sprintf (szSavedGameName, "%s", Name);
SetVol( nil, sSavedGameVolume );
CtoPstr( szSavedGameName );
FSOpen( (Pstr) szSavedGameName, sSavedGameVolume,&sFile );
PtoCstr( (Pstr) szSavedGameName );
return( sFile );
}
short Files::OpenFileDialog()
{
Point ptOrigin = { 0, 0 };
sFile = 0;
SFReply sfReply;
SFTypeList sfTypeList = { 'DMAP', '\p', '\p', '\p' };
SFGetFile( ptOrigin, "\p", nil, 1, sfTypeList, nil, &sfReply );
if ( sfReply.good )
{
PtoCstr( sfReply.fName );
strcpy( szSavedGameName, (Cstr) sfReply.fName );
}
if ( sfReply.good )
{
sSavedGameVolume = sfReply.vRefNum;
SetVol( nil, sSavedGameVolume );
CtoPstr( szSavedGameName );
FSOpen( (Pstr) szSavedGameName, sSavedGameVolume,&sFile );
PtoCstr( (Pstr) szSavedGameName );
}
return( sFile );
}
void Files::StartSave()
{
int x,y;
SFReply sfReply;
sFile = 0;
long lSize;
long lLongSize = sizeof( long );
CtoPstr( szSavedGameName );
sFile = PromptForSaveAS( SAVE_GAME_STRING, 0, (Pstr)szSavedGameName,'DAVD', 'DMAP', &sfReply );
PtoCstr((Pstr) szSavedGameName );
if ( sFile )
{
sSavedGameVolume = sfReply.vRefNum;
PtoCstr( sfReply.fName );
strcpy( szSavedGameName, (Cstr)sfReply.fName );
}
else
{
sfReply.vRefNum = sSavedGameVolume;
strcpy( (Cstr) sfReply.fName, szSavedGameName );
CtoPstr( (Cstr)sfReply.fName );
sFile = OpenNewFile( &sfReply, 'GLF2', 'SKLT' );
}
}
void Files::EndSave()
{
int x,y;
SFReply sfReply;
long lSize;
long lLongSize = sizeof( long );
if ( sFile )
FSClose( sFile );
}
void Files::StartLoad()
{
Boolean bLoaded = false;
long lSize;
long lLongSize = sizeof( long );
int x,y,kl;
sFile=OpenFileDialog();
}
void Files::EndLoad()
{
if (sFile)
FSClose( sFile );
}
|