Introduced running_machine::compose_saveload_filename() function to convert a filename (for state save/load) to a fully qualified path

This commit is contained in:
Nathan Woods 2016-07-10 16:25:10 -04:00
parent 1d1bef77f6
commit 4c25315d59
2 changed files with 36 additions and 14 deletions

View File

@ -549,6 +549,39 @@ std::string running_machine::get_statename(const char *option) const
return statename_str;
}
//-------------------------------------------------
// compose_saveload_filename - composes a filename
// for state loading/saving
//-------------------------------------------------
std::string running_machine::compose_saveload_filename(const char *filename, const char **searchpath)
{
std::string result;
// is this an absolute path?
if (osd_is_absolute_path(filename))
{
// if so, this is easy
if (searchpath != nullptr)
*searchpath = nullptr;
result = filename;
}
else
{
// this is a relative path; first specify the search path
if (searchpath != nullptr)
*searchpath = options().state_directory();
// take into account the statename option
const char *stateopt = options().state_name();
std::string statename = get_statename(stateopt);
result = string_format("%s%s%s.sta", statename, PATH_SEPARATOR, filename);
}
return result;
}
//-------------------------------------------------
// set_saveload_filename - specifies the filename
// for state loading/saving
@ -556,20 +589,8 @@ std::string running_machine::get_statename(const char *option) const
void running_machine::set_saveload_filename(const char *filename)
{
// free any existing request and allocate a copy of the requested name
if (osd_is_absolute_path(filename))
{
m_saveload_searchpath = nullptr;
m_saveload_pending_file.assign(filename);
}
else
{
m_saveload_searchpath = options().state_directory();
// take into account the statename option
const char *stateopt = options().state_name();
std::string statename = get_statename(stateopt);
m_saveload_pending_file = string_format("%s%s%s.sta", statename, PATH_SEPARATOR, filename);
}
// compose the save/load filename and persist it
m_saveload_pending_file = compose_saveload_filename(filename, &m_saveload_searchpath);
}

View File

@ -234,6 +234,7 @@ public:
void strlog(const char *str) const;
UINT32 rand();
const char *describe_context();
std::string compose_saveload_filename(const char *base_filename, const char **searchpath = nullptr);
// CPU information
cpu_device * firstcpu; // first CPU