OXYGENHUB
◆ main openmsx / src / ide / HDImageCLI.cc
1.5 KiB · C++ · last changed chore(): initial commit 1 month ago source blame history raw
1
#include "HDImageCLI.hh"
2
3
#include "CommandLineParser.hh"
4
#include "MSXException.hh"
5
6
#include <algorithm>
7
#include <utility>
8
#include <vector>
9
10
namespace openmsx {
11
12
namespace {
13
	struct IdImage {
14
		int id;
15
		std::string image;
16
	};
17
}
18
static std::vector<IdImage> images;
19
20
HDImageCLI::HDImageCLI(CommandLineParser& parser_)
21
	: parser(parser_)
22
{
23
	parser.registerOption("-hda", *this, CommandLineParser::Phase::BEFORE_MACHINE);
24
	// TODO: offer more options in case you want to specify 2 hard disk images?
25
}
26
27
void HDImageCLI::parseOption(const std::string& option, std::span<std::string>& cmdLine)
28
{
29
	// Machine has not been loaded yet. Only remember the image.
30
	int id = option[3] - 'a';
31
	images.emplace_back(id, getArgument(option, cmdLine));
32
}
33
34
std::string HDImageCLI::getImageForId(int id)
35
{
36
	// HD queries image. Return (and clear) the remembered value, or return
37
	// an empty string.
38
	std::string result;
39
	if (auto it = std::ranges::find(images, id, &IdImage::id);
40
	    it != end(images)) {
41
		result = std::move(it->image);
42
		images.erase(it);
43
	}
44
	return result;
45
}
46
47
void HDImageCLI::parseDone()
48
{
49
	// After parsing all remembered values should be cleared. If not there
50
	// was no hard disk as specified.
51
	if (!images.empty()) {
52
		auto hd = char(::toupper('a' + images.front().id));
53
		throw MSXException("No hard disk ", hd, " present.");
54
	}
55
}
56
57
std::string_view HDImageCLI::optionHelp() const
58
{
59
	return "Use hard disk image in argument for the IDE or SCSI extensions";
60
}
61
62
} // namespace openmsx