diff --git a/source/frontends/common2/configuration.cpp b/source/frontends/common2/configuration.cpp index f0487724..306c48ec 100644 --- a/source/frontends/common2/configuration.cpp +++ b/source/frontends/common2/configuration.cpp @@ -13,6 +13,19 @@ namespace { + void parseOption(const std::string & s, std::string & path, std::string & value) + { + const size_t pos = s.find('='); + if (pos == std::string::npos) + { + throw std::runtime_error("Invalid option format: " + s + ", expected: section.key=value"); + } + path = s.substr(0, pos); + std::replace(path.begin(), path.end(), '_', ' '); + value = s.substr(pos + 1); + std::replace(value.begin(), value.end(), '_', ' '); + } + struct KeyEncodedLess { static std::string decodeKey(const std::string & key) @@ -50,6 +63,8 @@ namespace const ini_t & getProperties() const; + void addExtraOptions(const std::vector & options); + private: const std::string myFilename; const bool mySaveOnExit; @@ -101,6 +116,15 @@ namespace myINI.put(path, value); } + void Configuration::addExtraOptions(const std::vector & options) + { + for (const std::string & option : options) + { + std::string path, value; + parseOption(option, path, value); + myINI.put(path, value); + } + } } void InitializeRegistry(const EmulatorOptions & options) @@ -130,7 +154,9 @@ void InitializeRegistry(const EmulatorOptions & options) } } - Configuration::instance.reset(new Configuration(filename, saveOnExit)); + std::shared_ptr config(new Configuration(filename, saveOnExit)); + config->addExtraOptions(options.registryOptions); + std::swap(Configuration::instance, config); } BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser, diff --git a/source/frontends/common2/programoptions.cpp b/source/frontends/common2/programoptions.cpp index 121f77bf..0a877c15 100644 --- a/source/frontends/common2/programoptions.cpp +++ b/source/frontends/common2/programoptions.cpp @@ -10,22 +10,26 @@ namespace po = boost::program_options; bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options) { - const std::string name = "Apple Emulator for " + edition + " (based on AppleWin " + getVersion() + ")\n"; + const std::string name = "Apple Emulator for " + edition + " (based on AppleWin " + getVersion() + ")"; po::options_description desc(name); desc.add_options() ("help,h", "Print this help message") - ("conf", "Save configuration on exit") ("multi-threaded,m", "Multi threaded") ("loose-mutex,l", "Loose mutex") ("sdl-driver", po::value()->default_value(options.sdlDriver), "SDL driver") - ("timer-interval,i", po::value()->default_value(options.timerInterval), "Timer interval in ms") + ("timer-interval,i", po::value()->default_value(options.timerInterval), "Timer interval in ms"); + + po::options_description configDesc("configuration"); + configDesc.add_options() + ("save-conf", "Save configuration on exit") + ("config,c", po::value>(), "Registry options section.path=value") ("qt-ini,q", "Use Qt ini file (read only)"); + desc.add(configDesc); po::options_description diskDesc("Disk"); diskDesc.add_options() ("d1,1", po::value(), "Disk in 1st drive") - ("d2,2", po::value(), "Disk in 2nd drive") - ("create,c", "Create missing disks"); + ("d2,2", po::value(), "Disk in 2nd drive"); desc.add(diskDesc); po::options_description snapshotDesc("Snapshot"); @@ -59,13 +63,18 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit return false; } - options.saveConfigurationOnExit = vm.count("conf"); + options.saveConfigurationOnExit = vm.count("save-conf"); options.useQtIni = vm.count("qt-ini"); options.multiThreaded = vm.count("multi-threaded"); options.looseMutex = vm.count("loose-mutex"); options.timerInterval = vm["timer-interval"].as(); options.sdlDriver = vm["sdl-driver"].as(); + if (vm.count("config")) + { + options.registryOptions = vm["config"].as >(); + } + if (vm.count("d1")) { options.disk1 = vm["d1"].as(); @@ -76,8 +85,6 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit options.disk2 = vm["d2"].as(); } - options.createMissingDisks = vm.count("create") > 0; - if (vm.count("load-state")) { options.snapshot = vm["load-state"].as(); diff --git a/source/frontends/common2/programoptions.h b/source/frontends/common2/programoptions.h index 80d86163..098bcd31 100644 --- a/source/frontends/common2/programoptions.h +++ b/source/frontends/common2/programoptions.h @@ -1,13 +1,13 @@ #pragma once #include +#include struct EmulatorOptions { std::string disk1; std::string disk2; - bool createMissingDisks = false; std::string snapshot; @@ -32,6 +32,8 @@ struct EmulatorOptions bool fixedSpeed = false; // default adaptive int sdlDriver = -1; // default = -1 to let SDL choose + + std::vector registryOptions; }; bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options);