ID:1530366
 
(See the best response by Pirion.)
Code:
   mob
verb
Save_Game()
if(key)
if(!src.loc)
return
if(src.loc==locate(37,239,28))
return
var/savefile/F=new("SaveBackup/[src.ckey]")
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
Write(F)
proc
Save() // This is the proc that saves the player
// if(Savable)
if(key)
if(!src.loc)
return
if(src.loc==locate(37,239,28))
return
var/savefile/F=new("Save/[src.ckey]")
F["x"]<<src.x
F["y"]<<src.y
F["z"]<<src.z
Write(F)


Problem description:

I've got two ways of saving, one by a verb that saves in a backup, one that saves automatically. Recently, the savefiles have been getting corrupted for some reason, so I wanted to throw a check in to see if the savefile was corrupt. I'm at a dead end here, how would I check if the savefile is corrupt/empty? Trying to get it to check if the first save is corrupt/missing, then it'll open the second.

        Load()
if(client)
if(fexists("Save/[src.ckey]") || fexists("SaveBackup/[src.ckey]"))
var/savefile/F=new("Save/[src.ckey]",2000)
Best response
I guess if it is empty, you can loop though F.dir, to see if there are any directories in F.

A side note, using Write() is not safe. You should use F << src which protects against saving references to other mobs in the save file.