Add ability to pass all Registry options via cmd line.
-c Configuration.Printer_Filename=Printer2.txt Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
This commit is contained in:
parent
5029b91850
commit
c33ae2b26e
3 changed files with 45 additions and 10 deletions
|
@ -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<std::string> & options);
|
||||
|
||||
private:
|
||||
const std::string myFilename;
|
||||
const bool mySaveOnExit;
|
||||
|
@ -101,6 +116,15 @@ namespace
|
|||
myINI.put(path, value);
|
||||
}
|
||||
|
||||
void Configuration::addExtraOptions(const std::vector<std::string> & 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<Configuration> config(new Configuration(filename, saveOnExit));
|
||||
config->addExtraOptions(options.registryOptions);
|
||||
std::swap(Configuration::instance, config);
|
||||
}
|
||||
|
||||
BOOL RegLoadString (LPCTSTR section, LPCTSTR key, BOOL peruser,
|
||||
|
|
|
@ -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<int>()->default_value(options.sdlDriver), "SDL driver")
|
||||
("timer-interval,i", po::value<int>()->default_value(options.timerInterval), "Timer interval in ms")
|
||||
("timer-interval,i", po::value<int>()->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<std::vector<std::string>>(), "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<std::string>(), "Disk in 1st drive")
|
||||
("d2,2", po::value<std::string>(), "Disk in 2nd drive")
|
||||
("create,c", "Create missing disks");
|
||||
("d2,2", po::value<std::string>(), "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<int>();
|
||||
options.sdlDriver = vm["sdl-driver"].as<int>();
|
||||
|
||||
if (vm.count("config"))
|
||||
{
|
||||
options.registryOptions = vm["config"].as<std::vector<std::string> >();
|
||||
}
|
||||
|
||||
if (vm.count("d1"))
|
||||
{
|
||||
options.disk1 = vm["d1"].as<std::string>();
|
||||
|
@ -76,8 +85,6 @@ bool getEmulatorOptions(int argc, const char * argv [], const std::string & edit
|
|||
options.disk2 = vm["d2"].as<std::string>();
|
||||
}
|
||||
|
||||
options.createMissingDisks = vm.count("create") > 0;
|
||||
|
||||
if (vm.count("load-state"))
|
||||
{
|
||||
options.snapshot = vm["load-state"].as<std::string>();
|
||||
|
|
|
@ -1,13 +1,13 @@
|
|||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
|
||||
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<std::string> registryOptions;
|
||||
};
|
||||
|
||||
bool getEmulatorOptions(int argc, const char * argv [], const std::string & edition, EmulatorOptions & options);
|
||||
|
|
Loading…
Add table
Reference in a new issue