Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/duplicati/duplicati.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <michal@naiman.eu>2017-05-21 17:56:48 +0300
committerMax <michal@naiman.eu>2017-05-21 17:56:48 +0300
commitc387de0e1beb7e1ae55451af150bcb6d70ffbd63 (patch)
treebcb0e5c2607cd6f49f113b8f99a796783fd05a20 /Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs
parent294ce69c73144030082c28ce4af3f82124c92f87 (diff)
GetDatabaseConnection unification
Diffstat (limited to 'Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs')
-rw-r--r--Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs74
1 files changed, 1 insertions, 73 deletions
diff --git a/Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs b/Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs
index 5d02e4255..b41937aee 100644
--- a/Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs
+++ b/Duplicati/GUI/Duplicati.GUI.TrayIcon/Program.cs
@@ -298,7 +298,7 @@ namespace Duplicati.GUI.TrayIcon
con.ConnectionString = "Data Source=" + databasePath;
//Attempt to open the database, handling any encryption present
- OpenDatabase(con, useDatabaseEncryption, dbPassword);
+ Server.Program.OpenDatabase(con, useDatabaseEncryption, dbPassword);
Duplicati.Library.SQLiteHelper.DatabaseUpgrader.UpgradeDatabase(con, databasePath,
typeof(Duplicati.Server.Database.Connection));
@@ -315,78 +315,6 @@ namespace Duplicati.GUI.TrayIcon
return new Duplicati.Server.Database.Connection(con);
}
- /// <summary>
- /// Helper method with logic to handle opening a database in possibly encrypted format
- /// </summary>
- /// <param name="con">The SQLite connection object</param>
- /// <param name="useDatabaseEncryption">Specify if database is encrypted</param>
- /// <param name="password">Encryption password</param>
- private static void OpenDatabase(System.Data.IDbConnection con, bool useDatabaseEncryption, string password)
- {
- System.Reflection.MethodInfo setPwdMethod = con.GetType().GetMethod("SetPassword", new Type[] { typeof(string) });
- string attemptedPassword;
-
- if (!useDatabaseEncryption || string.IsNullOrEmpty(password))
- attemptedPassword = null; //No encryption specified, attempt to open without
- else
- attemptedPassword = password; //Encryption specified, attempt to open with
-
- if (setPwdMethod != null)
- setPwdMethod.Invoke(con, new object[] { attemptedPassword });
-
- try
- {
- //Attempt to open in preferred state
- con.Open();
-
- // Do a dummy query to make sure we have a working db
- using (var cmd = con.CreateCommand())
- {
- cmd.CommandText = "SELECT COUNT(*) FROM SQLITE_MASTER";
- cmd.ExecuteScalar();
- }
- }
- catch
- {
- try
- {
- //We can't try anything else without a password
- if (string.IsNullOrEmpty(password))
- throw;
-
- //Open failed, now try the reverse
- if (attemptedPassword == null)
- attemptedPassword = password;
- else
- attemptedPassword = null;
-
- con.Close();
- setPwdMethod.Invoke(con, new object[] { attemptedPassword });
- con.Open();
-
- // Do a dummy query to make sure we have a working db
- using (var cmd = con.CreateCommand())
- {
- cmd.CommandText = "SELECT COUNT(*) FROM SQLITE_MASTER";
- cmd.ExecuteScalar();
- }
- }
- catch
- {
- try { con.Close(); }
- catch { }
- }
-
- //If the db is not open now, it won't open
- if (con.State != System.Data.ConnectionState.Open)
- throw; //Report original error
-
- //The open method succeeded with the non-default method, now change the password
- System.Reflection.MethodInfo changePwdMethod = con.GetType().GetMethod("ChangePassword", new Type[] { typeof(string) });
- changePwdMethod.Invoke(con, new object[] { useDatabaseEncryption ? password : null });
- }
- }
-
private static TrayIconBase RunTrayIcon(string toolkit)
{
if (toolkit == TOOLKIT_WINDOWS_FORMS)