Exemplo n.º 1
0
        /// <summary>
        /// Attempts to delete files and directories in the trash.
        /// </summary>
        /// <param name="pkgmgr">package manager reference</param>
        public static void Purge(IPackageManager pkgmgr)
        {
            List<string> deleted = new List<string>();

            foreach (string p in pkgmgr.Trash.OrderBy(i => i)) {
                try {
                    if (File.Exists(p))
                        File.Delete(p);
                    else if (Directory.Exists(p) && pkgmgr.CheckPathOwned(p)) {
                        /* this can be removed from the trash */
                    } else if (Directory.Exists(p) && Directory.GetFiles(p).Length > 0)
                        continue;
                    else if (Directory.Exists(p))
                        Directory.Delete(p);
                    else {
                        /* orphaned file? */
                    }

                    deleted.Add(p);
                } catch {
                    continue;
                }
            }

            pkgmgr.DeleteTrashItems(deleted.ToArray());
        }