protected override void ProcessRecord() { base.ProcessRecord(); var ccleaner = new CCleaner { RunAsAdministrator = RunAsAdministrator }; try { if (ccleaner.DownloadNeeded) { if (!AllowDownload) { throw new DiskCleanupException("CCleaner was not found. Run this command again with the -AllowDownload parameter."); } _downloadTimer = Stopwatch.StartNew(); ccleaner.Download(WriteDownloadProgress, WriteUnzipProgress); if (ccleaner.DownloadNeeded) { throw new FileNotFoundException("CCleaner.exe could not be found after downloading. Its possible an error occurred while unzipping the archive, or a file name has been changed."); } } var asyncResult = ccleaner.BeginRun(null, null); while (!asyncResult.IsCompleted && !asyncResult.CompletedSynchronously) { var driveInfo = DriveInfo.GetDrives().Single(d => d.Name == Path.GetPathRoot(Environment.SystemDirectory)); WriteProgress(new ProgressRecord(0, "Running CCleaner...", $"Drive: {driveInfo.Name}{(string.IsNullOrEmpty(driveInfo.VolumeLabel) ? null : $" ({driveInfo.VolumeLabel})")} " + $"Total Size: {new FileSize(driveInfo.TotalSize, driveInfo.TotalSize)} ({driveInfo.TotalSize:N0}) bytes " + $"Free Space: {new FileSize(driveInfo.TotalFreeSpace, driveInfo.TotalFreeSpace)} ({driveInfo.TotalFreeSpace:N0}) bytes")); Thread.Sleep(250); } ccleaner.EndRun(asyncResult); }
public void Test_implementsSearchForNewer() { var cc = new CCleaner(false); Assert.IsTrue(cc.implementsSearchForNewer()); }