Пример #1
0
        private async static void WipeFile(string fileName)
        {
            var progressDialog = Dialogs.ProgressDialog(Resources.Program_WipingTitle, fileName);

            try
            {
                var tokenSource = new CancellationTokenSource();
                progressDialog.FormClosing += (sender, e) =>
                                              tokenSource.Cancel();
                Action <WipeProgress> progressChangedCallback = (x) =>
                                                                progressDialog.UpdateProgress(x.PercentProgress);
                progressDialog.Show();

                await Task.Run(() => Wipe.WipeFile(new FileInfo(fileName), 1, progressChangedCallback, tokenSource.Token));

                Dialogs.Info(Resources.Program_OperationCompleted, Resources.Program_OperationCompletedVerbose);
            }
            catch (UnauthorizedAccessException)
            {
                if (!HasAdminPrivelegies)
                {
                    RestartAsAdmin($"\"{fileName}\"");
                }
                else
                {
                    Dialogs.Error(Resources.Program_AccessError);
                }
            }
            catch (OperationCanceledException)
            {
                Dialogs.Info(Resources.Program_OperationCancelled, Resources.Program_OperationCancelledVerbose);
            }
            catch (Exception e)
            {
                Dialogs.Error(e);
            }
            finally
            {
                progressDialog.Close();

                Application.Exit();
            }
        }
Пример #2
0
        private void StartShredding()
        {
            btnShreddingEnable = false;
            Wipe wiper = new Wipe();

            wiper.WipeErrorEvent  += Wiper_WipeErrorEvent;
            wiper.PassInfoEvent   += Wiper_PassInfoEvent;
            wiper.SectorInfoEvent += Wiper_SectorInfoEvent;
            wiper.WipeDoneEvent   += Wiper_WipeDoneEvent;
            bool isWhiteListed = false;

            foreach (Model_Shred MdlShared in ShredFilesCollection)
            {
                FileAttributes attr = File.GetAttributes(MdlShared.FilePath);
                if (attr.HasFlag(FileAttributes.Directory))
                {
                    foreach (
                        string file in
                        Directory.EnumerateFiles(MdlShared.FilePath, "*.*", SearchOption.AllDirectories))
                    {
                        if (CommandLogic_Delete.I.IsWhitelisted(file))
                        {
                            isWhiteListed = true;
                            break;
                        }
                    }
                    if (isWhiteListed)
                    {
                        break;
                    }
                }
                else
                {
                    if (CommandLogic_Delete.I.IsWhitelisted(MdlShared.FilePath))
                    {
                        isWhiteListed = true;
                        break;
                    }
                }
            }
            if (isWhiteListed)
            {
                MessageBox.Show("Items on Whitelist will not be removed.", "mCleaner", MessageBoxButtons.OK);
            }

            foreach (Model_Shred MdlShared in ShredFilesCollection)
            {
                if (MdlShared.FilePath != "Recycle Bin")
                {
                    FileAttributes attr = File.GetAttributes(MdlShared.FilePath);
                    if (attr.HasFlag(FileAttributes.Directory))
                    {
                        this.ProgressText = "Started to Shred Folder" + MdlShared.FilePath + " Please Wait.";
                        bool blndeleteFolder = true;
                        foreach (string file in Directory.EnumerateFiles(MdlShared.FilePath, "*.*", SearchOption.AllDirectories))
                        {
                            this.ProgressText = "Started to Shred File " + file + " inside folder " + MdlShared.FilePath +
                                                " Please Wait.";
                            if (!CommandLogic_Delete.I.IsWhitelisted(file))
                            {
                                wiper.WipeFile(file, 2);
                            }
                            else
                            {
                                blndeleteFolder = false;
                            }
                        }
                        if (blndeleteFolder)
                        {
                            Directory.Delete(MdlShared.FilePath, true);
                        }
                    }
                    else
                    {
                        this.ProgressText = "Started to Shred File " + MdlShared.FilePath + " Please Wait.";
                        if (!CommandLogic_Delete.I.IsWhitelisted(MdlShared.FilePath))
                        {
                            wiper.WipeFile(MdlShared.FilePath, 2);
                        }
                    }
                }

                this.ProgressIndex++;
            }
            if (btnShredRecycleBinEnable)
            {
                this.ProgressText = "Started to Shreding recyclebin please Wait.";

                Thread.Sleep(2000);
                foreach (string file in Directory.EnumerateFiles("C:\\$RECYCLE.BIN", "*.*", SearchOption.AllDirectories))
                {
                    this.ProgressText = "Started to Shred File " + file + " please Wait.";
                    wiper.WipeFile(file, 2);
                }
            }


            btnShreddingEnable = false;
            this.ProgressText  = "Shredding is done.";
        }