Exemple #1
0
        private void OptionsFormShown(object sender, Tools.OptionsFormsEventArgs e)
        {
            PwProfSyncForm form = new PwProfSyncForm();

            form.SetHomeDB(m_host.Database);
            Tools.AddPluginToOptionsForm(this, form);
        }
Exemple #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);
            }
        }