示例#1
0
      public override void EraseClusterTips(VolumeInfo info, ErasureMethod method,
 ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback)
      {
          List<string> files = new List<string>();
             if (!info.IsMounted)
          throw new InvalidOperationException(S._("Could not erase cluster tips in {0} " +
           "as the volume is not mounted.", info.VolumeId));
             ListFiles(new DirectoryInfo(info.MountPoints[0]), files, searchCallback);
             for (int i = 0, j = files.Count; i != j; ++i)
             {
          StreamInfo streamInfo = new StreamInfo(files[i]);
          FileAttributes fileAttr = streamInfo.Attributes;
          try
          {
           streamInfo.Attributes = FileAttributes.Normal;
           EraseFileClusterTips(files[i], method);
          }
          catch (UnauthorizedAccessException)
          {
           Logger.Log(S._("{0} did not have its cluster tips erased because you do not " +
            "have the required permissions to erase the file cluster tips.", files[i]),
            LogLevel.Information);
          }
          catch (IOException e)
          {
           Logger.Log(S._("{0} did not have its cluster tips erased. The error returned " +
            "was: {1}", files[i], e.Message), LogLevel.Error);
          }
          finally
          {
           streamInfo.Attributes = fileAttr;
          }
          eraseCallback(i, files.Count, files[i]);
             }
      }
示例#2
0
        public override void EraseClusterTips(VolumeInfo info, IErasureMethod method,
                                              ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback)
        {
            //List all the files which can be erased.
            List <string> files = new List <string>();

            if (!info.IsMounted)
            {
                throw new InvalidOperationException(S._("Could not erase cluster tips in {0} " +
                                                        "as the volume is not mounted.", info.VolumeId));
            }
            ListFiles(info.MountPoints[0], files, searchCallback);

            //For every file, erase the cluster tips.
            for (int i = 0, j = files.Count; i != j; ++i)
            {
                //Get the file attributes for restoring later
                StreamInfo streamInfo = new StreamInfo(files[i]);
                if (!streamInfo.Exists)
                {
                    continue;
                }

                try
                {
                    EraseFileClusterTips(streamInfo, method);
                }
                catch (UnauthorizedAccessException)
                {
                    Logger.Log(S._("{0} did not have its cluster tips erased because you do not " +
                                   "have the required permissions to erase the file cluster tips.", files[i]),
                               LogLevel.Information);
                }
                catch (IOException e)
                {
                    Logger.Log(S._("{0} did not have its cluster tips erased. The error returned " +
                                   "was: {1}", files[i], e.Message), LogLevel.Warning);
                }

                eraseCallback(i, files.Count, files[i]);
            }
        }
示例#3
0
      private void ListFiles(DirectoryInfo info, List<string> files, Logger log,
 ClusterTipsSearchProgress searchCallback)
      {
          try
             {
          if ((info.Attributes & FileAttributes.ReparsePoint) != 0)
          {
           log.LastSessionEntries.Add(new LogEntry(S._("Files in {0} did " +
            "not have their cluster tips erased because it is a hard link or " +
            "a symbolic link.", info.FullName), LogLevel.Information));
           return;
          }
          foreach (FileInfo file in info.GetFiles())
           if (Util.File.IsProtectedSystemFile(file.FullName))
            log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " +
             "its cluster tips erased, because it is a system file",
             file.FullName), LogLevel.Information));
           else if ((file.Attributes & FileAttributes.ReparsePoint) != 0)
            log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " +
             "its cluster tips erased because it is a hard link or a " +
             "symbolic link.", file.FullName), LogLevel.Information));
           else if ((file.Attributes & FileAttributes.Compressed) != 0 ||
            (file.Attributes & FileAttributes.Encrypted) != 0 ||
            (file.Attributes & FileAttributes.SparseFile) != 0)
           {
            log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have " +
             "its cluster tips erased because it is compressed, encrypted " +
             "or a sparse file.", file.FullName), LogLevel.Information));
           }
           else
           {
            try
            {
             foreach (string i in Util.File.GetADSes(file))
          files.Add(file.FullName + ':' + i);
             files.Add(file.FullName);
            }
            catch (UnauthorizedAccessException e)
            {
             log.LastSessionEntries.Add(new LogEntry(S._("{0} did not " +
          "have its cluster tips erased because of the following " +
          "error: {1}", info.FullName, e.Message), LogLevel.Error));
            }
            catch (IOException e)
            {
             log.LastSessionEntries.Add(new LogEntry(S._("{0} did not " +
          "have its cluster tips erased because of the following " +
          "error: {1}", info.FullName, e.Message), LogLevel.Error));
            }
           }
          foreach (DirectoryInfo subDirInfo in info.GetDirectories())
          {
           searchCallback(subDirInfo.FullName);
           ListFiles(subDirInfo, files, log, searchCallback);
          }
             }
             catch (UnauthorizedAccessException e)
             {
          log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " +
           "cluster tips erased because of the following error: {1}",
           info.FullName, e.Message), LogLevel.Error));
             }
             catch (IOException e)
             {
          log.LastSessionEntries.Add(new LogEntry(S._("{0} did not have its " +
           "cluster tips erased because of the following error: {1}",
           info.FullName, e.Message), LogLevel.Error));
             }
      }
        public override void Execute()
        {
            //Check for sufficient privileges to run the unused space erasure.
            if (!Security.IsAdministrator())
            {
                if (Environment.OSVersion.Platform == PlatformID.Win32NT &&
                    Environment.OSVersion.Version >= new Version(6, 0))
                {
                    Logger.Log(S._("The program does not have the required permissions to erase " +
                                   "the unused space on disk. Run the program as an administrator and retry " +
                                   "the operation."), LogLevel.Error);
                }
                else
                {
                    Logger.Log(S._("The program does not have the required permissions to erase " +
                                   "the unused space on disk."), LogLevel.Error);
                }

                return;
            }

            //Check whether System Restore has any available checkpoints.
            if (SystemRestore.GetInstances().Count != 0)
            {
                Logger.Log(S._("This computer has had System Restore or Volume Shadow Copies " +
                               "enabled. This may allow copies of files stored on the disk to be recovered " +
                               "and pose a security concern.", Drive), LogLevel.Warning);
            }

            //If the user is under disk quotas, log a warning message
            if (VolumeInfo.FromMountPoint(Drive).HasQuota)
            {
                Logger.Log(S._("The drive {0} has disk quotas active. This will prevent the " +
                               "complete erasure of unused space and may pose a security concern.",
                               Drive), LogLevel.Warning);
            }

            //Get the erasure method if the user specified he wants the default.
            IErasureMethod method = EffectiveMethod;

            //Make a folder to dump our temporary files in
            DirectoryInfo info      = new DirectoryInfo(Drive);
            VolumeInfo    volInfo   = VolumeInfo.FromMountPoint(Drive);
            IFileSystem   fsManager = Host.Instance.FileSystems[volInfo];

            //Start sampling the speed of the task.
            Progress = new SteppedProgressManager();

            //Erase the cluster tips of every file on the drive.
            if (EraseClusterTips)
            {
                //Define the callback handlers
                ProgressManager tipSearch = new ProgressManager();
                tipSearch.MarkIndeterminate();
                Progress.Steps.Add(new SteppedProgressManagerStep(tipSearch,
                                                                  0.0f, S._("Searching for files' cluster tips...")));
                ClusterTipsSearchProgress searchProgress = delegate(string path)
                {
                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }

                    tipSearch.Tag = path;
                };

                ProgressManager tipProgress = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(tipProgress, 0.1f,
                                                                  S._("Erasing cluster tips...")));
                ClusterTipsEraseProgress eraseProgress =
                    delegate(int currentFile, int totalFiles, string currentFilePath)
                {
                    tipSearch.MarkComplete();
                    tipProgress.Total     = totalFiles;
                    tipProgress.Completed = currentFile;
                    tipProgress.Tag       = currentFilePath;

                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }
                };

                //Start counting statistics
                fsManager.EraseClusterTips(VolumeInfo.FromMountPoint(Drive),
                                           method, searchProgress, eraseProgress);
                tipProgress.MarkComplete();
            }

            bool lowDiskSpaceNotifications = Shell.LowDiskSpaceNotificationsEnabled;

            info = info.CreateSubdirectory(Path.GetFileName(
                                               FileSystemBase.GenerateRandomFileName(info, 18)));
            try
            {
                //Set the folder's compression flag off since we want to use as much
                //space as possible
                if (info.IsCompressed())
                {
                    info.Uncompress();
                }

                //Disable the low disk space notifications
                Shell.LowDiskSpaceNotificationsEnabled = false;

                //Fill the disk
                EraseUnusedSpace(volInfo, info, fsManager, method);

                //Erase old resident file system table files
                ProgressManager residentProgress = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(residentProgress,
                                                                  0.05f, S._("Old resident file system table files")));
                fsManager.EraseOldFileSystemResidentFiles(volInfo, info, method,
                                                          delegate(int currentFile, int totalFiles)
                {
                    residentProgress.Completed = currentFile;
                    residentProgress.Total     = totalFiles;

                    if (Task.Canceled)
                    {
                        throw new OperationCanceledException(S._("The task was cancelled."));
                    }
                }
                                                          );

                residentProgress.MarkComplete();
            }
            finally
            {
                //Remove the folder holding all our temporary files.
                ProgressManager tempFiles = new ProgressManager();
                Progress.Steps.Add(new SteppedProgressManagerStep(tempFiles,
                                                                  0.0f, S._("Removing temporary files...")));

                fsManager.DeleteFolder(info, true);
                tempFiles.MarkComplete();

                //Reset the low disk space notifications
                Shell.LowDiskSpaceNotificationsEnabled = lowDiskSpaceNotifications;
            }

            //Then clean the old file system entries
            ProgressManager structureProgress = new ProgressManager();

            Progress.Steps.Add(new SteppedProgressManagerStep(structureProgress,
                                                              0.05f, S._("Erasing unused directory structures...")));
            fsManager.EraseDirectoryStructures(volInfo,
                                               delegate(int currentFile, int totalFiles)
            {
                if (Task.Canceled)
                {
                    throw new OperationCanceledException(S._("The task was cancelled."));
                }

                //Compute the progress
                structureProgress.Total     = totalFiles;
                structureProgress.Completed = currentFile;
            }
                                               );

            structureProgress.MarkComplete();
            Progress = null;
        }
示例#5
0
      public abstract void EraseClusterTips(VolumeInfo info, ErasureMethod method,
 Logger log, ClusterTipsSearchProgress searchCallback,
 ClusterTipsEraseProgress eraseCallback);
示例#6
0
        private void ListFiles(DirectoryInfo info, List <string> files,
                               ClusterTipsSearchProgress searchCallback)
        {
            try
            {
                //Skip this directory if it is a reparse point
                if ((info.Attributes & FileAttributes.ReparsePoint) != 0)
                {
                    Logger.Log(S._("Files in {0} did not have their cluster tips erased because " +
                                   "it is a hard link or a symbolic link.", info.FullName),
                               LogLevel.Information);
                    return;
                }

                foreach (FileInfo file in info.GetFiles())
                {
                    if (file.IsProtectedSystemFile())
                    {
                        Logger.Log(S._("{0} did not have its cluster tips erased, because it is " +
                                       "a system file", file.FullName), LogLevel.Information);
                    }
                    else if ((file.Attributes & FileAttributes.ReparsePoint) != 0)
                    {
                        Logger.Log(S._("{0} did not have its cluster tips erased because it is a " +
                                       "hard link or a symbolic link.", file.FullName), LogLevel.Information);
                    }
                    else if ((file.Attributes & FileAttributes.Compressed) != 0 ||
                             (file.Attributes & FileAttributes.Encrypted) != 0 ||
                             (file.Attributes & FileAttributes.SparseFile) != 0)
                    {
                        Logger.Log(S._("{0} did not have its cluster tips erased because it is " +
                                       "compressed, encrypted or a sparse file.", file.FullName),
                                   LogLevel.Information);
                    }
                    else
                    {
                        try
                        {
                            foreach (StreamInfo stream in file.GetADSes())
                            {
                                files.Add(stream.FullName);
                            }

                            files.Add(file.FullName);
                        }
                        catch (UnauthorizedAccessException e)
                        {
                            Logger.Log(S._("{0} did not have its cluster tips erased because of " +
                                           "the following error: {1}", file.FullName, e.Message),
                                       LogLevel.Information);
                        }
                        catch (IOException e)
                        {
                            Logger.Log(S._("{0} did not have its cluster tips erased because of " +
                                           "the following error: {1}", file.FullName, e.Message),
                                       LogLevel.Warning);
                        }
                    }
                }

                foreach (DirectoryInfo subDirInfo in info.GetDirectories())
                {
                    searchCallback(subDirInfo.FullName);
                    ListFiles(subDirInfo, files, searchCallback);
                }
            }
            catch (UnauthorizedAccessException e)
            {
                Logger.Log(S._("Files in {0} did not have its cluster tips erased because of the " +
                               "following error: {1}", info.FullName, e.Message), LogLevel.Information);
            }
            catch (IOException e)
            {
                Logger.Log(S._("Files in {0} did not have its cluster tips erased because of the " +
                               "following error: {1}", info.FullName, e.Message), LogLevel.Warning);
            }
        }
示例#7
0
 public abstract void EraseClusterTips(VolumeInfo info, IErasureMethod method,
                                       ClusterTipsSearchProgress searchCallback, ClusterTipsEraseProgress eraseCallback);