示例#1
0
 //Update list of database specific password profiles after closing password generator form
 private void UpdateDBProfiles(List <PwProfile> oldProfiles, List <PwProfile> newProfiles, out bool changed)
 {
     changed = false;
     if ((m_host.Database == null) || !m_host.Database.IsOpen)
     {
         return;
     }
     if (oldProfiles.Count != newProfiles.Count)
     {
         changed = true;
         m_host.Database.RemoveDBProfiles();
         foreach (PwProfile profile in newProfiles)
         {
             profile.CopyTo(m_host.Database);
         }
         return;
     }
     for (int i = 0; i < newProfiles.Count; i++)
     {
         PwProfile profile = newProfiles[i].CloneDeep();
         if (profile.IsDBOnlyProfile())
         {
             profile.Name = profile.Name.Substring(0, profile.Name.Length - Config.ProfileDBOnly.Length);
         }
         PwProfile oldProfile = oldProfiles.Find(x => x.Name == profile.Name);
         changed |= !profile.IsEqual(oldProfile);
         if (changed)
         {
             break;
         }
     }
     for (int i = 0; i < oldProfiles.Count; i++)
     {
         PwProfile profile = oldProfiles[i].CloneDeep();
         if (!profile.IsDBOnlyProfile())
         {
             profile.Name += Config.ProfileDBOnly;
         }
         PwProfile newProfile = newProfiles.Find(x => x.Name == profile.Name);
         changed |= !profile.IsEqual(newProfile);
         if (changed)
         {
             break;
         }
     }
     if (!changed)
     {
         return;
     }
     m_host.Database.RemoveDBProfiles();
     foreach (PwProfile profile in newProfiles)
     {
         profile.CopyTo(m_host.Database);
     }
 }
示例#2
0
        private void OptionsFormClosed(object sender, Tools.OptionsFormsEventArgs e)
        {
            if (e.form.DialogResult != DialogResult.OK)
            {
                return;
            }
            bool           shown = false;
            PwProfSyncForm form  = (PwProfSyncForm)Tools.GetPluginFromOptions(this, out shown);

            if (!shown)
            {
                return;
            }
            List <string> profilesDB    = new List <string>();
            List <string> profilesOther = new List <string>();
            PwDatabase    otherDB       = null;
            bool          MoveProfiles  = true;

            form.GetWorklist(out profilesDB, out profilesOther, out otherDB, out MoveProfiles);
            form.Dispose();

            //Update password profiles in active database
            bool changed      = false;
            bool changedOther = false;

            foreach (string profileName in profilesDB)
            {
                if (profileName.EndsWith(Config.ProfileCopied))
                {
                    string profileNameClean = profileName.Substring(0, profileName.Length - Config.ProfileCopied.Length);
                    if (otherDB == null)
                    {
                        PwProfile profile = Program.Config.PasswordGenerator.UserProfiles.GetProfile(profileNameClean);
                        changed |= profile.CopyTo(m_host.Database);
                        if (MoveProfiles)
                        {
                            Program.Config.PasswordGenerator.UserProfiles.Remove(profile);
                        }
                    }
                    else
                    {
                        PwProfile profile = otherDB.GetProfile(profileNameClean);
                        if (profile != null)
                        {
                            changed |= profile.CopyTo(m_host.Database);
                            if (MoveProfiles)
                            {
                                otherDB.RemoveDBProfile(profileNameClean);
                                changedOther = true;
                            }
                        }
                    }
                }
            }
            //Update password profiles in global configuration or other database
            foreach (string profileName in profilesOther)
            {
                if (profileName.EndsWith(Config.ProfileCopied))
                {
                    string profileNameClean = profileName.Substring(0, profileName.Length - Config.ProfileCopied.Length);
                    if (otherDB == null)
                    {
                        PwProfile profile = Program.Config.PasswordGenerator.UserProfiles.GetProfile(profileNameClean + Config.ProfileDBOnly);
                        if (MoveProfiles)
                        {
                            profile.Name = profileNameClean;
                            m_host.Database.RemoveDBProfile(profileNameClean);
                            changed = true;
                        }
                        else
                        {
                            PwProfile newProfile = profile.CloneDeep();
                            newProfile.Name = profileNameClean;
                            Program.Config.PasswordGenerator.UserProfiles.Add(newProfile);
                        }
                    }
                    else
                    {
                        PwProfile profile = m_host.Database.GetProfile(profileNameClean);
                        if (profile != null)
                        {
                            changedOther |= profile.CopyTo(otherDB);
                            if (MoveProfiles)
                            {
                                m_host.Database.RemoveDBProfile(profileNameClean);
                                changed = true;
                            }
                        }
                    }
                }
            }
            if (changed)
            {
                m_host.Database.SettingsChanged = DateTime.UtcNow;
                m_host.Database.Modified        = true;
            }
            if (changedOther)
            {
                otherDB.SettingsChanged = DateTime.UtcNow;
                otherDB.Modified        = true;
            }
            if (changed || changedOther)
            {
                m_host.MainWindow.UpdateUI(false, null, false, null, false, null, false);
            }
        }