add code to make a backup savestate every time a slot savestate is loaded. I don't need to spell out for you which users this is for, and why they need it.

This commit is contained in:
zeromus 2020-10-15 16:46:16 -04:00
parent d854909b04
commit 0d65ea6050
4 changed files with 40 additions and 10 deletions

View File

@ -44,14 +44,6 @@ public:
static Slot1InfoSimple info("R4", "Slot1 R4 emulation", 0x03);
return &info;
}
//called once when the emulator starts up, or when the device springs into existence
virtual bool init()
{
//strange to do this here but we need to make sure its done at some point
srand(time(NULL));
return true;
}
virtual void connect()
{

View File

@ -230,6 +230,9 @@ ENDL
bool CommandLine::parse(int argc,char **argv)
{
//closest thing to a portable main() we have, I guess.
srand((unsigned)time(nullptr));
std::string _render3d;
int opt_help = 0;

View File

@ -411,8 +411,6 @@ void PathInfo::formatname(char *output)
time_t now = time(NULL);
tm *time_struct = localtime(&now);
srand((unsigned)now);
for (char* p = screenshotFormat,
*end = p + sizeof(screenshotFormat); p < end; p++)
{

View File

@ -57,6 +57,7 @@
#ifdef HOST_WINDOWS
#include "frontend/windows/main.h"
extern char IniName[MAX_PATH];
#endif
int lastSaveState = 0; //Keeps track of last savestate used for quick save/load functions
@ -726,8 +727,44 @@ void loadstate_slot(int num)
path.getpathnoext(path.STATE_SLOTS, filename);
//save the state before we load the state, to give people a path for recovery in case they hit the wrong key
#ifdef HOST_WINDOWS
if(!GetPrivateProfileInt("General", "BackupSavestateSuppress", 0, IniName))
#endif
{
if(movieMode == MOVIEMODE_INACTIVE)
{
std::string dirname = (std::string)filename + " (backups)";
#ifdef HOST_WINDOWS
static const char PSS = '\\';
#else
static const char PSS = '/';
#endif
mkdir(dirname.c_str(),0777);
static unsigned seed;
for(;;)
{
std::string fname = dirname + PSS;
char mini[100];
sprintf(mini,"%u",seed);
fname += mini + (std::string)".dst";
FILE* f = fopen(fname.c_str(),"rb");
if(f)
{
seed = rand()*16000+rand();
fclose(f);
continue;
}
seed++;
savestate_save(fname.c_str());
break;
}
}
}
if (strlen(filename) + strlen(".dsx") + strlen("-2147483648") /* = biggest string for num */ > MAX_PATH) return;
sprintf(filename + strlen(filename), ".ds%d", num);
if (savestate_load(filename))
{
driver->SetLineColor(255, 255, 255);