Exemplo n.º 1
0
        //Return DB specific profiles stored in database
        public static List <PwProfile> GetDBProfiles(this PwDatabase db)
        {
            List <string>    profileNames = db.GetDBProfileNames();
            List <PwProfile> profiles     = new List <PwProfile>();

            foreach (string profileName in profileNames)
            {
                try
                {
                    PwProfile profile = db.GetProfile(profileName);
                    if (profile != null)
                    {
                        profiles.Add(profile);
                    }
                }
                catch (Exception) { }
            }
            return(profiles);
        }
Exemplo n.º 2
0
        //Copy password profile to database
        public static bool CopyTo(this PwProfile profile, PwDatabase target)
        {
            PwProfile myProfile = profile.CloneDeep();

            if (myProfile.Name.EndsWith(Config.ProfileDBOnly))
            {
                myProfile.Name = myProfile.Name.Substring(0, myProfile.Name.Length - Config.ProfileDBOnly.Length);
            }
            PwProfile targetProfile = target.GetProfile(myProfile.Name);

            if ((targetProfile != null) && myProfile.IsEqual(targetProfile))
            {
                return(false);
            }
            string profileData = myProfile.Serialize();

            target.CustomData.Set(Config.ProfileConfig + myProfile.Name, profileData);
            return(true);
        }
Exemplo n.º 3
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);
            }
        }