MCPcopy Create free account
hub / github.com/NetHack/NetHack / restore_savefile

Function restore_savefile

outdated/sys/mac/mrecover.c:1190–1287  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1188}
1189
1190static void
1191restore_savefile()
1192{
1193 static int savelev;
1194 long saveTemp, lev;
1195 xint8 levc;
1196 struct version_info version_data;
1197
1198 /* level 0 file contains:
1199 * pid of creating process (ignored here)
1200 * level number for current level of save file
1201 * name of save file nethack would have created
1202 * and game state
1203 */
1204
1205 lev = in.Recover - 1;
1206 if (lev == 0L) {
1207 gameRefNum = open_levelfile(0L);
1208
1209 if (in.Recover)
1210 (void) read_levelfile(gameRefNum, (Ptr) &hpid, sizeof(hpid));
1211
1212 if (in.Recover)
1213 saveTemp =
1214 read_levelfile(gameRefNum, (Ptr) &savelev, sizeof(savelev));
1215
1216 if (in.Recover && (saveTemp != sizeof(savelev))) {
1217 endRecover();
1218 note(noErr, alidNote, "\pSorry: \"checkpoint\" was not enabled");
1219 return;
1220 }
1221
1222 if (in.Recover)
1223 (void) read_levelfile(gameRefNum, (Ptr) savename,
1224 sizeof(savename));
1225 if (in.Recover)
1226 (void) read_levelfile(gameRefNum, (Ptr) &version_data,
1227 sizeof version_data);
1228
1229 /* save file should contain:
1230 * current level (including pets)
1231 * (non-level-based) game state
1232 * other levels
1233 */
1234 if (in.Recover)
1235 saveRefNum = create_savefile(savename);
1236
1237 if (in.Recover)
1238 levRefNum = open_levelfile(savelev);
1239
1240 if (in.Recover)
1241 (void) write_savefile(saveRefNum, (Ptr) &version_data,
1242 sizeof version_data);
1243 if (in.Recover)
1244 copy_bytes(levRefNum, saveRefNum);
1245
1246 if (in.Recover)
1247 close_file(&levRefNum);

Callers 1

continueRecoverFunction · 0.70

Calls 10

read_levelfileFunction · 0.85
endRecoverFunction · 0.85
noteFunction · 0.85
write_savefileFunction · 0.85
close_fileFunction · 0.85
unlink_fileFunction · 0.85
open_levelfileFunction · 0.70
create_savefileFunction · 0.70
copy_bytesFunction · 0.70
set_levelfile_nameFunction · 0.70

Tested by

no test coverage detected