AppleWin/source/frontends/common2/utils.cpp
Andrea Odetti 1d07215f78 Add ability to Save/Load Snapshot F11/F12.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
2020-12-06 18:03:41 +00:00

32 lines
745 B
C++

#include <frontends/common2/utils.h>
#include "StdAfx.h"
#include "SaveState.h"
#include <libgen.h>
#include <unistd.h>
void setSnapshotFilename(const std::string & filename, const bool load)
{
// same logic as qapple
// setting chdir allows to load relative disks from the snapshot file (tests?)
// but if the snapshot file itself is relative, it wont work after a chdir
// so we convert to absolute first
char * absPath = realpath(filename.c_str(), nullptr);
if (absPath)
{
char * temp = strdup(absPath);
const char * dir = dirname(temp);
// dir points inside temp!
chdir(dir);
Snapshot_SetFilename(absPath);
free(temp);
free(absPath);
if (load)
{
Snapshot_LoadState();
}
}
}