From 0b8b0d44eabc4368cc74ce2a08bc48c81e5ec8ee Mon Sep 17 00:00:00 2001 From: "kenneth.skovhede@gmail.com" Date: Tue, 27 Sep 2011 05:35:49 +0000 Subject: [PATCH] Update issue #392 Status: Fixed There is now a more consistent parsing of boolean commandline parameters. git-svn-id: https://duplicati.googlecode.com/svn/trunk@918 59da171f-624f-0410-aa54-27559c288bec --- Duplicati/CommandLine/BackendTester/Program.cs | 11 ++++------- Duplicati/GUI/MainForm.cs | 6 +++--- Duplicati/GUI/Program.cs | 7 ++++--- Duplicati/Library/Backend/FTP/FTPBackend.cs | 11 +++-------- Duplicati/Library/Backend/File/FileBackend.cs | 8 +------- Duplicati/Library/Backend/SSH/SSHBackend.cs | 8 +++----- Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs | 8 ++------ Duplicati/Library/Backend/WEBDAV/WEBDAV.cs | 10 +++------- Duplicati/Library/Encryption/AESEncryption.cs | 4 +--- Duplicati/Library/Encryption/GPGEncryption.cs | 4 +++- Duplicati/Library/Main/Options.cs | 6 +----- Duplicati/Library/Modules/Builtin/HttpOptions.cs | 8 ++++---- Duplicati/Library/Snapshots/Program.cs | 2 +- 13 files changed, 33 insertions(+), 60 deletions(-) diff --git a/Duplicati/CommandLine/BackendTester/Program.cs b/Duplicati/CommandLine/BackendTester/Program.cs index d48a23b40..244fc0a8d 100644 --- a/Duplicati/CommandLine/BackendTester/Program.cs +++ b/Duplicati/CommandLine/BackendTester/Program.cs @@ -99,10 +99,7 @@ namespace Duplicati.CommandLine.BackendTester else allowedChars += ExtendedChars; - bool autoCreateFolders = false; - string v; - if (options.TryGetValue("auto-create-folder", out v)) - autoCreateFolders = Library.Utility.Utility.ParseBool(v, true); + bool autoCreateFolders = Library.Utility.Utility.ParseBoolOption(options, "auto-create-folder"); Library.Interface.IBackend backend = Library.DynamicLoader.BackendLoader.GetBackend(args[0], options); if (backend == null) @@ -139,8 +136,8 @@ namespace Duplicati.CommandLine.BackendTester foreach (Library.Interface.IFileEntry fe in curlist) if (!fe.IsFolder) { - if (options.ContainsKey("auto-clean") && first) - if (options.ContainsKey("force")) + if (Library.Utility.Utility.ParseBoolOption(options, "auto-clean") && first) + if (Library.Utility.Utility.ParseBoolOption(options, "force")) { Console.WriteLine("Auto clean, removing file: {0}", fe.Name); backend.Delete(fe.Name); @@ -159,7 +156,7 @@ namespace Duplicati.CommandLine.BackendTester int max_file_size = 1024 * 1024 * 50; int min_filename_size = 5; int max_filename_size = 80; - bool disableStreaming = options.ContainsKey("disable-streaming-transfers"); + bool disableStreaming = Library.Utility.Utility.ParseBoolOption(options, "disable-streaming-transfers"); if (options.ContainsKey("number-of-files")) number_of_files = int.Parse(options["number-of-files"]); diff --git a/Duplicati/GUI/MainForm.cs b/Duplicati/GUI/MainForm.cs index 614c16cd1..7f8a6c711 100644 --- a/Duplicati/GUI/MainForm.cs +++ b/Duplicati/GUI/MainForm.cs @@ -503,18 +503,18 @@ namespace Duplicati.GUI return false; } - if (options.ContainsKey("full")) + if (Library.Utility.Utility.ParseBoolOption(options, "full")) Program.WorkThread.AddTask(new FullBackupTask(schedules[0])); else Program.WorkThread.AddTask(new IncrementalBackupTask(schedules[0])); } } - if (options.ContainsKey("show-status")) + if (Library.Utility.Utility.ParseBoolOption(options, "show-status")) ShowStatus(); //Resume if requested - if (options.ContainsKey("resume")) + if (Library.Utility.Utility.ParseBoolOption(options, "resume")) Program.LiveControl.Resume(); return false; diff --git a/Duplicati/GUI/Program.cs b/Duplicati/GUI/Program.cs index 338b648ec..60a5f4176 100644 --- a/Duplicati/GUI/Program.cs +++ b/Duplicati/GUI/Program.cs @@ -190,7 +190,7 @@ namespace Duplicati.GUI //debug mode uses a lock file located in the app folder Environment.SetEnvironmentVariable(DATAFOLDER_ENV_NAME, System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location)); #else - bool portableMode = commandlineOptions.ContainsKey("portable-mode") ? Library.Utility.Utility.ParseBool(commandlineOptions["portable-mode"], true) : false; + bool portableMode = Library.Utility.Utility.ParseBoolOption(commandlineOptions, "portable-mode"); if (portableMode) { @@ -244,9 +244,10 @@ namespace Duplicati.GUI #if DEBUG //Default is to not use encryption for debugging - Program.UseDatabaseEncryption = commandlineOptions.ContainsKey("unencrypted-database") ? !Library.Utility.Utility.ParseBool(commandlineOptions["unencrypted-database"], true) : false; + Program.UseDatabaseEncryption = !Library.Utility.Utility.ParseBoolOption(commandlineOptions, "unencrypted-database"); #else - Program.UseDatabaseEncryption = commandlineOptions.ContainsKey("unencrypted-database") ? !Library.Utility.Utility.ParseBool(commandlineOptions["unencrypted-database"], true) : true; + //Default is to use encryption for release + Program.UseDatabaseEncryption = !(commandlineOptions.ContainsKey("unencrypted-database") ? Library.Utility.Utility.ParseBoolOption(commandlineOptions, "unencrypted-database") : true); #endif con.ConnectionString = "Data Source=" + DatabasePath; diff --git a/Duplicati/Library/Backend/FTP/FTPBackend.cs b/Duplicati/Library/Backend/FTP/FTPBackend.cs index b5079907a..f44d98ee1 100644 --- a/Duplicati/Library/Backend/FTP/FTPBackend.cs +++ b/Duplicati/Library/Backend/FTP/FTPBackend.cs @@ -78,12 +78,7 @@ namespace Duplicati.Library.Backend } } - string sslString; - if (options.TryGetValue("use-ssl", out sslString)) - m_useSSL = Utility.Utility.ParseBool(sslString, true); - else - m_useSSL = false; - + m_useSSL = Utility.Utility.ParseBoolOption(m_options, "use-ssl"); m_options = options; m_url = url; @@ -293,9 +288,9 @@ namespace Duplicati.Library.Backend req.Credentials = m_userInfo; req.KeepAlive = false; - if (m_options.ContainsKey("ftp-passive")) + if (Utility.Utility.ParseBoolOption(m_options, "ftp-passive")) req.UsePassive = true; - if (m_options.ContainsKey("ftp-regular")) + if (Utility.Utility.ParseBoolOption(m_options, "ftp-regular")) req.UsePassive = false; if (m_useSSL) diff --git a/Duplicati/Library/Backend/File/FileBackend.cs b/Duplicati/Library/Backend/File/FileBackend.cs index 2ec5fd5ff..e9f25d0ae 100644 --- a/Duplicati/Library/Backend/File/FileBackend.cs +++ b/Duplicati/Library/Backend/File/FileBackend.cs @@ -126,13 +126,7 @@ namespace Duplicati.Library.Backend throw new Exception(string.Format(Strings.FileBackend.NoDestinationWithMarkerFileError, markerfile, string.Join(System.IO.Path.PathSeparator.ToString(), paths.ToArray()))); } - - string tmp; - m_moveFile = false; - - if (options.TryGetValue(OPTION_MOVE_FILE, out tmp)) - m_moveFile = Utility.Utility.ParseBool(tmp, true); - + m_moveFile = Utility.Utility.ParseBoolOption(options, OPTION_MOVE_FILE); m_hasAutenticated = false; } diff --git a/Duplicati/Library/Backend/SSH/SSHBackend.cs b/Duplicati/Library/Backend/SSH/SSHBackend.cs index 019e7eecd..0e342fec5 100644 --- a/Duplicati/Library/Backend/SSH/SSHBackend.cs +++ b/Duplicati/Library/Backend/SSH/SSHBackend.cs @@ -96,11 +96,9 @@ namespace Duplicati.Library.Backend m_path = u.AbsolutePath; - if (options.ContainsKey(USE_UNMANAGED_OPTION)) - m_useManaged = false; + m_useManaged = !Utility.Utility.ParseBoolOption(options, USE_UNMANAGED_OPTION); - if (options.ContainsKey(SSH_NO_CD_OPTION)) - m_noCdCommand = true; + m_noCdCommand = Utility.Utility.ParseBoolOption(options, SSH_NO_CD_OPTION); if (m_isLinux) { @@ -146,7 +144,7 @@ namespace Duplicati.Library.Backend else m_transfer_timeout = 1000 * 60 * 15; - m_write_log_info = options.ContainsKey("debug-to-console"); + m_write_log_info = Utility.Utility.ParseBoolOption(options, "debug-to-console"); } #region IBackendInterface Members diff --git a/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs b/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs index 3a5e0e368..cd6c71b5b 100644 --- a/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs +++ b/Duplicati/Library/Backend/TahoeLAFS/TahoeBackend.cs @@ -1,4 +1,4 @@ -#region Disclaimer / License +#region Disclaimer / License // Copyright (C) 2011, Kenneth Skovhede // http://www.hexad.dk, opensource@hexad.dk // @@ -50,11 +50,7 @@ namespace Duplicati.Library.Backend if (!string.IsNullOrEmpty(u.Query)) throw new Exception(Strings.TahoeBackend.UriHasQueryError); - string sslString; - if (options.TryGetValue("use-ssl", out sslString)) - m_useSSL = Utility.Utility.ParseBool(sslString, true); - else - m_useSSL = false; + m_useSSL = Utility.Utility.ParseBoolOption(m_options, "use-ssl"); m_options = options; diff --git a/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs b/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs index a093cf7f7..0a827caa7 100644 --- a/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs +++ b/Duplicati/Library/Backend/WEBDAV/WEBDAV.cs @@ -86,13 +86,9 @@ namespace Duplicati.Library.Backend } m_options = options; - m_useIntegratedAuthentication = m_options.ContainsKey("integrated-authentication"); - m_forceDigestAuthentication = m_options.ContainsKey("force-digest-authentication"); - string sslString; - if (m_options.TryGetValue("use-ssl", out sslString)) - m_useSSL = Utility.Utility.ParseBool(sslString, true); - else - m_useSSL = false; + m_useIntegratedAuthentication = Utility.Utility.ParseBoolOption(m_options, "integrated-authentication"); + m_forceDigestAuthentication = Utility.Utility.ParseBoolOption(m_options, "force-digest-authentication"); + m_useSSL = Utility.Utility.ParseBoolOption(m_options, "use-ssl"); m_url = (m_useSSL ? "https" : "http") + url.Substring(u.Scheme.Length); if (!m_url.EndsWith("/")) diff --git a/Duplicati/Library/Encryption/AESEncryption.cs b/Duplicati/Library/Encryption/AESEncryption.cs index ee9fa7496..e33fcfad4 100644 --- a/Duplicati/Library/Encryption/AESEncryption.cs +++ b/Duplicati/Library/Encryption/AESEncryption.cs @@ -60,9 +60,7 @@ namespace Duplicati.Library.Encryption /// The key used for encryption. The key gets stretched through SHA hashing to fit the key size requirements public AESEncryption(string passphrase, Dictionary options) { - if (options.ContainsKey(COMMAND_LINE_NO_FALLBACK)) - m_allowFallback = !Utility.Utility.ParseBool(options[COMMAND_LINE_NO_FALLBACK], true); - + m_allowFallback = !Utility.Utility.ParseBoolOption(options, COMMAND_LINE_NO_FALLBACK); m_key = passphrase; } diff --git a/Duplicati/Library/Encryption/GPGEncryption.cs b/Duplicati/Library/Encryption/GPGEncryption.cs index 770c8d92c..111d45bce 100644 --- a/Duplicati/Library/Encryption/GPGEncryption.cs +++ b/Duplicati/Library/Encryption/GPGEncryption.cs @@ -129,9 +129,11 @@ namespace Duplicati.Library.Encryption //NOTE: For reasons unknown, GPG commandline options are divided into "options" and "commands". //NOTE: The "options" must be placed before "commands" or it wont work! + //Special handling of this option, it should have been --enable-armor instead bool disableArmor = true; + if (options.ContainsKey(COMMANDLINE_OPTIONS_DISABLE_ARMOR)) - disableArmor = Utility.Utility.ParseBool(options[COMMANDLINE_OPTIONS_DISABLE_ARMOR], true); + Utility.Utility.ParseBoolOption(options, COMMANDLINE_OPTIONS_DISABLE_ARMOR); if (!disableArmor) { diff --git a/Duplicati/Library/Main/Options.cs b/Duplicati/Library/Main/Options.cs index 04a242516..6355bd3c8 100644 --- a/Duplicati/Library/Main/Options.cs +++ b/Duplicati/Library/Main/Options.cs @@ -976,11 +976,7 @@ namespace Duplicati.Library.Main /// The interpreted value of the option private bool GetBool(string name) { - string value; - if (m_options.TryGetValue(name, out value)) - return Utility.Utility.ParseBool(value, true); - else - return false; + return Utility.Utility.ParseBoolOption(m_options, name); } } diff --git a/Duplicati/Library/Modules/Builtin/HttpOptions.cs b/Duplicati/Library/Modules/Builtin/HttpOptions.cs index 2280acb93..2fa8e8913 100644 --- a/Duplicati/Library/Modules/Builtin/HttpOptions.cs +++ b/Duplicati/Library/Modules/Builtin/HttpOptions.cs @@ -73,15 +73,15 @@ namespace Duplicati.Library.Modules.Builtin { m_dispose = true; - bool accepAllCertificates = commandlineOptions.ContainsKey(OPTION_ACCEPT_ANY_CERTIFICATE) && Utility.Utility.ParseBool(commandlineOptions[OPTION_ACCEPT_ANY_CERTIFICATE], true); + bool accepAllCertificates = Utility.Utility.ParseBoolOption(commandlineOptions, OPTION_ACCEPT_ANY_CERTIFICATE); string certHash; commandlineOptions.TryGetValue(OPTION_ACCEPT_SPECIFIED_CERTIFICATE, out certHash); m_certificateValidator = new Library.Utility.SslCertificateValidator(accepAllCertificates, certHash); - - bool disableNagle = commandlineOptions.ContainsKey(OPTION_DISABLE_NAGLING) && Utility.Utility.ParseBool(commandlineOptions[OPTION_DISABLE_NAGLING], true); - bool disableExpect100 = commandlineOptions.ContainsKey(OPTION_DISABLE_EXPECT100) && Utility.Utility.ParseBool(commandlineOptions[OPTION_DISABLE_EXPECT100], true); + + bool disableNagle = Utility.Utility.ParseBoolOption(commandlineOptions, OPTION_DISABLE_NAGLING); + bool disableExpect100 = Utility.Utility.ParseBoolOption(commandlineOptions, OPTION_DISABLE_EXPECT100); m_useNagle = System.Net.ServicePointManager.UseNagleAlgorithm; m_useExpect = System.Net.ServicePointManager.Expect100Continue; diff --git a/Duplicati/Library/Snapshots/Program.cs b/Duplicati/Library/Snapshots/Program.cs index aa00d9fa2..112c67eef 100644 --- a/Duplicati/Library/Snapshots/Program.cs +++ b/Duplicati/Library/Snapshots/Program.cs @@ -78,7 +78,7 @@ Where is the folder where files will be locked/created etc"); return; } - if (options.ContainsKey("usn-test")) + if (Library.Utility.Utility.ParseBoolOption(options, "usn-test")) { using (USNHelper usn = new USNHelper(args[0])) {