AppleWin/source/frontends/common2/utils.cpp
Andrea Odetti 8e6fc89384 From AW's master, AppleWin.cpp split.
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
2020-11-27 13:48:53 +00:00

28 lines
699 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)
{
// 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);
Snapshot_LoadState();
}
}