Exemplo n.º 1
0
        /// <summary>
        /// Open a database. This function opens the specified database and updates
        /// the user interface.
        /// </summary>
        public void OpenDatabase(IOConnectionInfo ioc, CompositeKey cmpKey)
        {
            // Close active db
             CloseDatabase ();

             if (db != null && db.IsOpen)
            return;

             //IOConnectionInfo ioc = IOConnectionInfo.FromPath(ConfigurationManager.AppSettings["dbPath"]);

             //if (ioConnection == null)
             //{
             //   if (bOpenLocal)
             //   {
             //      OpenFileDialog ofdDb = UIUtil.CreateOpenFileDialog(KPRes.OpenDatabaseFile,
             //         UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt,
             //         KPRes.KdbxFiles, true), 1, null, false, false);

             //      //GlobalWindowManager.AddDialog(ofdDb);
             //      //DialogResult dr = ofdDb.ShowDialog();
             //      //GlobalWindowManager.RemoveDialog(ofdDb);
             //      //if (dr != DialogResult.OK) return;

             //      ioc = IOConnectionInfo.FromPath(ofdDb.FileName);
             //   }
             //   else
             //   {
             //      ioc = CompleteConnectionInfo(new IOConnectionInfo(), false,
             //         true, true, true);
             //      if (ioc == null) return;
             //   }
             //}
             //else // ioConnection != null
             //{
             //   ioc = CompleteConnectionInfo(ioConnection, false, true, true, false);
             //   if (ioc == null) return;
             //}

             if (!ioc.CanProbablyAccess ()) {
            // TODO
            //MessageService.ShowWarning(ioc.GetDisplayName(), KPRes.FileNotFoundError);
            //return;
             }

             //if (OpenDatabaseRestoreIfOpened(ioc)) return;

             PwDatabase pwOpenedDb = null;

             if (cmpKey == null) {
            // get the master key
            CompositeKey key = CreateCompositeKey (System.Configuration.ConfigurationManager.AppSettings ["dbKey"]);
            pwOpenedDb = OpenDatabaseInternal (ioc, key);
             }
             else { // cmpKey != null
            pwOpenedDb = OpenDatabaseInternal (ioc, cmpKey);
             }

             //string strName = pwOpenedDb.IOConnectionInfo.GetDisplayName();
             //this.Text = strName;

             //m_mruList.AddItem(strName, pwOpenedDb.IOConnectionInfo.CloneDeep(), true);

             db = pwOpenedDb;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Open a database. This function opens the specified database and updates
        /// the user interface.
        /// </summary>
        public void OpenDatabase(IOConnectionInfo ioc, CompositeKey cmpKey)
        {
            // Close active db
            CloseDatabase();

            if (db != null && db.IsOpen)
            {
                return;
            }


            //IOConnectionInfo ioc = IOConnectionInfo.FromPath(ConfigurationManager.AppSettings["dbPath"]);

            //if (ioConnection == null)
            //{
            //   if (bOpenLocal)
            //   {
            //      OpenFileDialog ofdDb = UIUtil.CreateOpenFileDialog(KPRes.OpenDatabaseFile,
            //         UIUtil.CreateFileTypeFilter(AppDefs.FileExtension.FileExt,
            //         KPRes.KdbxFiles, true), 1, null, false, false);

            //      //GlobalWindowManager.AddDialog(ofdDb);
            //      //DialogResult dr = ofdDb.ShowDialog();
            //      //GlobalWindowManager.RemoveDialog(ofdDb);
            //      //if (dr != DialogResult.OK) return;

            //      ioc = IOConnectionInfo.FromPath(ofdDb.FileName);
            //   }
            //   else
            //   {
            //      ioc = CompleteConnectionInfo(new IOConnectionInfo(), false,
            //         true, true, true);
            //      if (ioc == null) return;
            //   }
            //}
            //else // ioConnection != null
            //{
            //   ioc = CompleteConnectionInfo(ioConnection, false, true, true, false);
            //   if (ioc == null) return;
            //}

            if (!ioc.CanProbablyAccess())
            {
                // TODO
                //MessageService.ShowWarning(ioc.GetDisplayName(), KPRes.FileNotFoundError);
                //return;
            }

            //if (OpenDatabaseRestoreIfOpened(ioc)) return;

            PwDatabase pwOpenedDb = null;

            if (cmpKey == null)
            {
                // get the master key
                CompositeKey key = CreateCompositeKey(System.Configuration.ConfigurationManager.AppSettings ["dbKey"]);
                pwOpenedDb = OpenDatabaseInternal(ioc, key);
            }
            else // cmpKey != null
            {
                pwOpenedDb = OpenDatabaseInternal(ioc, cmpKey);
            }


            //string strName = pwOpenedDb.IOConnectionInfo.GetDisplayName();
            //this.Text = strName;

            //m_mruList.AddItem(strName, pwOpenedDb.IOConnectionInfo.CloneDeep(), true);

            db = pwOpenedDb;
        }