Ok guys... I need some help. First off.... I've been at the debugging of this thing from 9AM until about an hour ago and have this one nagging error that I can't seem to trace. Here is the steps to reproduce:
1) Launch the program. Do pretty much anything filewise or do nothing... (File Options)
2) Create a snapshot. You can do it once, or create more than one. You can do it for more than one file. This doesn't affect the bug.
3) Back out of the File Options menu, enter Snapshots.
4) Select one of the snapshots, try to Revert it. What will occur is hit or miss... Sometimes (usually the first time), it will write out a very large file of garbage. Usually it will do this once, and then trying to revert again (exact same routine) will do it properly and write out the correct file.
After trying all day to debug this and being unable to, I'm sharing the code for you guys to peruse and see if maybe you can figure out what's going on. PS: Yes, I know my code may be weird in places and unoptimized, most of which is due to my attempts to fix this bug, so please go easy on your critiques of how lousily written it is... lol
https://github.com/acagliano/blastfis
Here is how the snapshot feature works:
Creating a snapshot file saves the program's size, name, type, and the system time to a structure, snapshot_t. Much like MateoC's gfx_sprite_t type, it uses an arbitrary ->data member for easy reference to the data. The size field is the size of the program, not the whole snapshot. The size of the whole snapshot is sizeof(snapshot_t) - 1 + sizeof(datasection).
Snapshot files are index-named, starting from AVsh0000 to AVshFFFF. The first snapshot created creates the file, the second one for the same file appends to it, and so on. After a snapshot is deleted or created, and when the program loads, the program parses the file list for any variables with AVsh as the start of the name and saves the snapshot name, program name, and program type to a temporary buffer for easy reference. All of the functions then parse that buffer to get the correct file out.