Ejemplo n.º 1
0
        private void Menu_DeleteClones_Click(object sender, EventArgs e)
        {
            var dr = WinFormsUtil.Prompt(MessageBoxButtons.YesNo,
                                         MsgDBDeleteCloneWarning + Environment.NewLine +
                                         MsgDBDeleteCloneAdvice, MsgContinue);

            if (dr != DialogResult.Yes)
            {
                return;
            }

            var deleted = 0;
            var db      = RawDB.Where(pk => pk.Identifier.StartsWith(DatabasePath + Path.DirectorySeparatorChar, StringComparison.Ordinal))
                          .OrderByDescending(file => File.GetLastWriteTimeUtc(file.Identifier));

            var clones = SearchUtil.GetExtraClones(db);

            foreach (var pk in clones)
            {
                try { File.Delete(pk.Identifier); ++deleted; }
                catch (Exception ex) { WinFormsUtil.Error(MsgDBDeleteCloneFail + Environment.NewLine + ex.Message + Environment.NewLine + pk.Identifier); }
            }

            if (deleted == 0)
            {
                WinFormsUtil.Alert(MsgDBDeleteCloneNone); return;
            }

            WinFormsUtil.Alert(string.Format(MsgFileDeleteCount, deleted), MsgWindowClose);
            Close();
        }