From 83ef9370892ea6e66b859c4ddc0457097b022475 Mon Sep 17 00:00:00 2001
From: Sude <lgogdownloader@gmail.com>
Date: Fri, 5 Sep 2014 14:02:08 +0300
Subject: [PATCH] Allow unrecognized options in config file

---
 main.cpp | 15 ++++++++++++++-
 1 file changed, 14 insertions(+), 1 deletion(-)

diff --git a/main.cpp b/main.cpp
index 5442d36..2ce6350 100644
--- a/main.cpp
+++ b/main.cpp
@@ -98,6 +98,7 @@ int main(int argc, char *argv[])
     std::string orphans_regex_default = ".*\\.(zip|exe|bin|dmg|old|deb|tar\\.gz|pkg)$"; // Limit to files with these extensions (".old" is for renamed older version files)
     std::string check_orphans_text = "Check for orphaned files (files found on local filesystem that are not found on GOG servers). Sets regular expression filter (Perl syntax) for files to check. If no argument is given then the regex defaults to '" + orphans_regex_default + "'";
 
+    std::vector<std::string> unrecognized_options_cfg;
     bpo::variables_map vm;
     bpo::options_description options_cli_all("Options");
     bpo::options_description options_cli_no_cfg;
@@ -187,9 +188,11 @@ int main(int argc, char *argv[])
             }
             else
             {
-                bpo::store(bpo::parse_config_file(ifs, options_cfg_all), vm);
+                bpo::parsed_options parsed = bpo::parse_config_file(ifs, options_cfg_all, true);
+                bpo::store(parsed, vm);
                 bpo::notify(vm);
                 ifs.close();
+                unrecognized_options_cfg = bpo::collect_unrecognized(parsed.options, bpo::include_positional);
             }
         }
         if (boost::filesystem::exists(config.sBlacklistFilePath))
@@ -306,6 +309,16 @@ int main(int argc, char *argv[])
         if (config.sDirectory.at(config.sDirectory.length()-1)!='/')
             config.sDirectory += "/";
 
+    if (!unrecognized_options_cfg.empty() && (!config.bSaveConfig || !config.bResetConfig))
+    {
+        std::cerr << "Unrecognized options in " << config.sConfigFilePath << std::endl;
+        for (unsigned int i = 0; i < unrecognized_options_cfg.size(); i+=2)
+        {
+            std::cerr << unrecognized_options_cfg[i] << " = " << unrecognized_options_cfg[i+1] << std::endl;
+        }
+        std::cerr << std::endl;
+    }
+
     Downloader downloader(config);
     int initResult = downloader.init();