| 1 |
#include "SaveStateCLI.hh" |
| 2 |
|
| 3 |
#include "CommandLineParser.hh" |
| 4 |
#include "TclObject.hh" |
| 5 |
|
| 6 |
#include <array> |
| 7 |
|
| 8 |
namespace openmsx { |
| 9 |
|
| 10 |
SaveStateCLI::SaveStateCLI(CommandLineParser& parser_) |
| 11 |
: parser(parser_) |
| 12 |
{ |
| 13 |
parser.registerOption("-savestate", *this); |
| 14 |
parser.registerFileType(std::array<std::string_view, 1>{"oms"}, *this); |
| 15 |
} |
| 16 |
|
| 17 |
void SaveStateCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine) |
| 18 |
{ |
| 19 |
parseFileType(getArgument(option, cmdLine), cmdLine); |
| 20 |
} |
| 21 |
|
| 22 |
std::string_view SaveStateCLI::optionHelp() const |
| 23 |
{ |
| 24 |
return "Load savestate and start emulation from there"; |
| 25 |
} |
| 26 |
|
| 27 |
void SaveStateCLI::parseFileType(const std::string& filename, |
| 28 |
std::span<std::string>& ) |
| 29 |
{ |
| 30 |
|
| 31 |
|
| 32 |
auto& interp = parser.getInterpreter(); |
| 33 |
|
| 34 |
TclObject command1 = makeTclList("restore_machine", filename); |
| 35 |
auto newId = command1.executeCommand(interp); |
| 36 |
|
| 37 |
TclObject command2 = makeTclList("machine"); |
| 38 |
if (auto currentId = command2.executeCommand(interp); |
| 39 |
!currentId.empty()) { |
| 40 |
TclObject command3 = makeTclList("delete_machine", currentId); |
| 41 |
command3.executeCommand(interp); |
| 42 |
} |
| 43 |
|
| 44 |
TclObject command4 = makeTclList("activate_machine", newId); |
| 45 |
command4.executeCommand(interp); |
| 46 |
} |
| 47 |
|
| 48 |
std::string_view SaveStateCLI::fileTypeHelp() const |
| 49 |
{ |
| 50 |
return "openMSX savestate"; |
| 51 |
} |
| 52 |
|
| 53 |
std::string_view SaveStateCLI::fileTypeCategoryName() const |
| 54 |
{ |
| 55 |
return "savestate"; |
| 56 |
} |
| 57 |
|
| 58 |
} |