diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/commandline.cpp | 44 | ||||
| -rw-r--r-- | src/commandline.h | 4 | ||||
| -rw-r--r-- | src/main.cpp | 7 | ||||
| -rw-r--r-- | src/singleinstance.cpp | 10 | ||||
| -rw-r--r-- | src/singleinstance.h | 12 |
5 files changed, 40 insertions, 37 deletions
diff --git a/src/commandline.cpp b/src/commandline.cpp index 588b5085..f84906e9 100644 --- a/src/commandline.cpp +++ b/src/commandline.cpp @@ -15,8 +15,6 @@ std::optional<int> CommandLine::run(const std::wstring& line) { try { - po::variables_map vm; - auto args = po::split_winmain(line); if (!args.empty()) { // remove program name @@ -29,10 +27,10 @@ std::optional<int> CommandLine::run(const std::wstring& line) .allow_unregistered() .run(); - po::store(parsed, vm); + po::store(parsed, m_vm); - if (vm.count("command")) { - const auto commandName = vm["command"].as<std::string>(); + if (m_vm.count("command")) { + const auto commandName = m_vm["command"].as<std::string>(); for (auto&& c : m_commands) { if (c->name() == commandName) { @@ -55,20 +53,20 @@ std::optional<int> CommandLine::run(const std::wstring& line) parsed = parser.run(); - po::store(parsed, vm); + po::store(parsed, m_vm); - if (vm.count("help")) { + if (m_vm.count("help")) { env::Console console; std::cout << usage(c.get()) << "\n"; return 0; } - return c->run(line, vm, opts); + return c->run(line, m_vm, opts); } } } - if (vm.count("help")) { + if (m_vm.count("help")) { env::Console console; std::cout << usage() << "\n"; return 0; @@ -91,7 +89,8 @@ std::optional<int> CommandLine::run(const std::wstring& line) void CommandLine::createOptions() { m_visibleOptions.add_options() - ("help", "shows this message"); + ("help", "shows this message") + ("multiple", "allows multiple instances of MO to run; see below"); po::options_description options; options.add_options() @@ -137,9 +136,34 @@ std::string CommandLine::usage(const Command* c) const << "Global options:\n" << m_visibleOptions << "\n"; + if (!c) { + oss << "\n" << more() << "\n"; + } + return oss.str(); } +bool CommandLine::multiple() const +{ + return (m_vm.count("multiple") > 0); +} + +std::string CommandLine::more() const +{ + return + "--multiple can be used to allow multiple instances of MO to run\n" + "simultaneously. This is unsupported and can create all sorts of weird\n" + "problems. To minimize the problems:\n" + "\n" + " 1) Never have multiple MO instances opened that manage the same game\n" + " instance.\n" + " 2) If an executable is launched from an instance, only this instance\n" + " may launch executables until all instances are closed.\n" + "\n" + "It is recommended to close _all_ instances of MO as soon as multiple\n" + "instances become unnecessary."; +} + std::string Command::name() const { diff --git a/src/commandline.h b/src/commandline.h index b45a86c6..deeb9923 100644 --- a/src/commandline.h +++ b/src/commandline.h @@ -94,12 +94,16 @@ public: std::optional<int> run(const std::wstring& line); std::string usage(const Command* c=nullptr) const; + bool multiple() const; + private: po::options_description m_visibleOptions, m_allOptions; po::positional_options_description m_positional; std::vector<std::unique_ptr<Command>> m_commands; + po::variables_map m_vm; void createOptions(); + std::string more() const; }; } // namespace diff --git a/src/main.cpp b/src/main.cpp index 68dcfe11..a1a4be01 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -852,12 +852,7 @@ int main(int argc, char *argv[]) SingleInstance::Flags siFlags = SingleInstance::NoFlags; - if (arguments.contains("update")) { - arguments.removeAll("update"); - siFlags |= SingleInstance::ForcePrimary; - } - - if (arguments.contains("--multiple")) { + if (cl.multiple()) { arguments.removeAll("--multiple"); siFlags |= SingleInstance::AllowMultiple; } diff --git a/src/singleinstance.cpp b/src/singleinstance.cpp index d38095df..e32c8de1 100644 --- a/src/singleinstance.cpp +++ b/src/singleinstance.cpp @@ -34,16 +34,6 @@ SingleInstance::SingleInstance(Flags flags, QObject *parent) : m_SharedMem.setKey(s_Key);
if (!m_SharedMem.create(1)) {
- if (flags.testFlag(ForcePrimary)) {
- while (m_SharedMem.error() == QSharedMemory::AlreadyExists) {
- Sleep(500);
- if (m_SharedMem.create(1)) {
- m_OwnsSM = true;
- break;
- }
- }
- }
-
if (m_SharedMem.error() == QSharedMemory::AlreadyExists) {
if (!flags.testFlag(AllowMultiple)) {
m_SharedMem.attach();
diff --git a/src/singleinstance.h b/src/singleinstance.h index 5c7cdf85..d500a056 100644 --- a/src/singleinstance.h +++ b/src/singleinstance.h @@ -40,19 +40,9 @@ public: {
NoFlags = 0x00,
-
- // when set, this will be treated as the primary instance even if
- // another instance is running. This is used after an update since the
- // other instance is assumed to be in the process of quitting
- //
- // todo: this makes no sense. The second instance after an update needs
- // to delete the files from before the update so the first instance
- // needs to quit first anyway
- ForcePrimary = 0x01,
-
// if another instance is running, run this one disconnected from the
// shared memory
- AllowMultiple = 0x02
+ AllowMultiple = 0x01
};
using Flags = QFlags<Flag>;
|
