A few months ago I was saving a game and the power went out. Of course when I tried to load it again it didn't work due to corruption. So that got me thinking "Is there any possible way to make it so you will never get a corrupt save file. Hey even better if I never lost any data!"
After a while of thinking up of various ways I think that I may have come up with a nearly flawless solution. It involves 2 copies of the save file but one is deleted after every time you save.
How I think it should work (in theory) is when you click save (or however you save something depending on the situation) all data will be written to a *.baup file (BAckUP) once all information is written to that file it is then copied to the main file *.*. Once the *.* file has finished being written to the *.baup file will be deleted. The next time you enter the program it would check for .baup. If it was found it would delete the old *.* file and replace it with the baup file.
So how will it help? Here is the situation I came up with. The problem I have come up with is what if the baup file was not saved properly or corrupted?. The answer would be at the end of every Baup file would be some sort of "signature" to signify all data was written. If that was not there the program would delete the BAUP file and be left with the old data. This is the only part that I can't seem to find a fix for to prevent no data loss.
If you can see any other problems or help with the problem I am currently encountering in theory it would be appreciated if I could get help solving it.
ID:152002
Jun 14 2008, 4:51 am
|
|
In response to Lyndonarmitage1
|
|
Lyndonarmitage1 wrote:
Are you talking about byond or things in general? I'm talking about things in general. If your talking about things in general then how would making another file help save the file? Closer to the second one. I mean you save an update and if successful overwrite the original so if power is cut and your saving the update you won't loose the original or if it was cut when saving to the original when you load the save back up it would check if the update still existed and then overwrite the original with the update. |
In response to Upinflames
|
|
Exactly what I meant :D I would have thought most things do something akin to this.
|
Tangential but relevant, the typical file extension that many people use for backups is ".bak" (e.g., "filename.bak").
Another common standard is ".ext.old" (e.g., the "filename.sav.old" is a backup of "filename.sav"). A third common standard is "~filename.ext" (e.g., "~filename.sav" is a backup of "filename.sav"). Four-letter extensions, though technically usable on modern systems, tend to break convention. |
In response to Upinflames
|
|
mob If it saves successfully, it'll attempt to create a backup. The next time it attempts to save, if the world is killed before you manage to save, your backup will still exist, even if your primary savefile is now corrupt. The chances of your world being killed before it manages to write the information is pretty low. It'd have to die literally less than a second before you hit save. note: I'm not sure if fcopy deletes the file if it exists (the file you're trying to copy the existing file to), so you might have to delete it manually using fdel. |
Upinflames wrote:
How I think it should work (in theory) is when you click save (or however you save something depending on the situation) all data will be written to a *.baup file (BAckUP) once all information is written to that file it is then copied to the main file *.*. Once the *.* file has finished being written to the *.baup file will be deleted. The next time you enter the program it would check for .baup. If it was found it would delete the old *.* file and replace it with the baup file. I beleive that Pokeymans Diamond/Pearl uses a system fairly close to this. |
If it's byond a fool proof way of saving is autosaving over periods of time and making backup saves automatically.
If your talking about things in general then how would making another file help save the file?
From what I understand you are making a simple case of saving a single file into saving two files and deleting one. That seems pretty useless unless you mean it saves a copy of the changed file (not really a backup more of an update) and if that save is successful it overwrites the original. So the original file would still exist if there was a power cut but the file that was being saved is instead corrupted.
Observation: A real fool proof solution to stop loss of data through saving is to save often and make backups.