From d6e1ecb393f4d0dda64a257e4527aa9be8725f02 Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 15 Jul 2014 17:07:08 +0100 Subject: [PATCH] Boost.ProgramOptions no longer required again. Handling of the command line parameter `--game=` now uses CEF's functions. Also refactored CEF settings initialisation. --- src/gui/app.cpp | 29 ----------------- src/gui/app.h | 1 - src/gui/main_win.cpp | 74 +++++++++++++++++++++----------------------- 3 files changed, 36 insertions(+), 68 deletions(-) diff --git a/src/gui/app.cpp b/src/gui/app.cpp index a14d697a..d39cfd61 100644 --- a/src/gui/app.cpp +++ b/src/gui/app.cpp @@ -192,35 +192,6 @@ namespace loot { } } - CefSettings LootApp::GetCefSettings() const { - CefSettings cef_settings; - - //Disable CEF command line args. - cef_settings.command_line_args_disabled = true; - - // Don't set CEF locale, as it tries to load resources and crashes - // if they can't be found. - /*if (_settings["Language"]) { - loot::Language lang(_settings["Language"].as()); - CefString(&cef_settings.locale).FromString(lang.Locale()); - }*/ - - // Set CEF logging. - CefString(&cef_settings.log_file).FromString("CEFDebugLog.txt"); - if (!_settings["Debug Verbosity"] || _settings["Debug Verbosity"].as() == 0) - cef_settings.log_severity = LOGSEVERITY_DISABLE; - - // Enable remote debugging. - //cef_settings.single_process = true; - cef_settings.remote_debugging_port = 8080; - - - // Use cef_settings.resources_dir_path to specify Resources folder path. - // Use cef_settings.locales_dir_path to specify locales folder path. - - return cef_settings; - } - CefRefPtr LootApp::GetBrowserProcessHandler() { return this; } diff --git a/src/gui/app.h b/src/gui/app.h index 11beb8a2..2ce350ef 100644 --- a/src/gui/app.h +++ b/src/gui/app.h @@ -41,7 +41,6 @@ namespace loot { LootApp(); void Init(std::string& cmdLineGame); - CefSettings GetCefSettings() const; // Override CefApp methods. virtual CefRefPtr GetBrowserProcessHandler() OVERRIDE; diff --git a/src/gui/main_win.cpp b/src/gui/main_win.cpp index e21891f9..e3354ee4 100644 --- a/src/gui/main_win.cpp +++ b/src/gui/main_win.cpp @@ -35,16 +35,42 @@ #include #include #include -#include namespace fs = boost::filesystem; -namespace po = boost::program_options; using namespace std; using namespace loot; using boost::locale::translate; using boost::format; +CefSettings GetCefSettings() { + CefSettings cef_settings; + + //Disable CEF command line args. + cef_settings.command_line_args_disabled = true; + + // Don't set CEF locale, as it tries to load resources and crashes + // if they can't be found. + /*if (_settings["Language"]) { + loot::Language lang(_settings["Language"].as()); + CefString(&cef_settings.locale).FromString(lang.Locale()); + }*/ + + // Set CEF logging. + CefString(&cef_settings.log_file).FromString("CEFDebugLog.txt"); + /*if (!_settings["Debug Verbosity"] || _settings["Debug Verbosity"].as() == 0) + cef_settings.log_severity = LOGSEVERITY_DISABLE; +*/ + // Enable remote debugging. + //cef_settings.single_process = true; + cef_settings.remote_debugging_port = 8080; + + // Use cef_settings.resources_dir_path to specify Resources folder path. + // Use cef_settings.locales_dir_path to specify locales folder path. + + return cef_settings; +} + int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow) { // Do all the standard CEF setup stuff. @@ -85,49 +111,21 @@ int APIENTRY wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmd //---------------------------------------- string gameStr; - // declare the supported options - po::options_description opts("Options"); - opts.add_options() - ("help,h", "produces this help message") - ("version,V", "prints the version banner") - ("game,g", po::value(&gameStr), - "Override game autodetection. Valid values are the folder " - "names defined in the settings file."); - // parse command line arguments - po::variables_map vm; - try{ - vector args = po::split_winmain(lpCmdLine); - po::store(po::wcommand_line_parser(args).options(opts).run(), vm); - po::notify(vm); - } - catch (po::multiple_occurrences &){ - std::cout << "Cannot specify options multiple times; please use the '--help' option to see usage instructions"; - return 1; - } - catch (exception & e){ - std::cout << e.what() << "; please use the '--help' option to see usage instructions"; - return 1; - } - - if (vm.count("help")) { - std::cout << opts << std::endl; - if (hMutex != NULL) - ReleaseMutex(hMutex); - return 0; - } - if (vm.count("version")) { - std::cout << "LOOT v" << g_version_major << "." << g_version_minor << "." << g_version_patch << std::endl; - if (hMutex != NULL) - ReleaseMutex(hMutex); - return 0; + // Record command line arguments. + CefRefPtr command_line = CefCommandLine::CreateCommandLine(); +#if defined(OS_WIN) + command_line->InitFromString(::GetCommandLineW()); +#endif + if (command_line->HasSwitch("game")) { // Format is: --game= + gameStr = command_line->GetSwitchValue("game"); } // Back to CEF //------------ // Initialise CEF settings. - CefSettings cef_settings = app.get()->GetCefSettings(); + CefSettings cef_settings = GetCefSettings(); // Initialize CEF. CefInitialize(main_args, cef_settings, app.get(), sandbox_info);