Пример #1
0
 /// <summary>
 /// Radio Button - Delete Algorithm - selects checked
 /// </summary>
 public void rb_Checked(object sender, RoutedEventArgs e)
 {
     algorithm = (DeleteAlgorithm.DeleteAlgorithmEnum)((sender as RadioButton).Content);
 }
Пример #2
0
        /// <summary>
        /// Method to purge a volume
        /// Based on the U.S. Department of Defense's standard 'National Industrial Security Program Operating Manual' (DoD 5220.22-M ECE).
        /// </summary>
        /// <param name="selectedVolume"></param>
        public static async Task eraseVolume(CancellationToken ct, Volume selectedVolume, DeleteAlgorithm.DeleteAlgorithmEnum algorithm = DeleteAlgorithm.DeleteAlgorithmEnum.DoD_7)
        {
            // Variables
            var dummyFilesCount = Math.Floor((double)selectedVolume.AvailableFreeSpace / MAX_BUFFER_SIZE);

            byte[] pattern = new byte[] { 0x00, 0xFF, 0x72, 0x96, 0x00, 0xFF, 0x72 };
            int    loops   = 6;

            if (algorithm == DeleteAlgorithm.DeleteAlgorithmEnum.DoD_3)
            {
                loops   = 2;
                pattern = new byte[] { 0x00, 0xFF, 0x72 };
            }

            ThreadSafeRandom.Shuffle <byte>(pattern);
            Random random = ThreadSafeRandom.Random;

            // Set progressbar
            MainWindow.PGBar.Maximum = selectedVolume.AvailableFreeSpace;
            MainWindow.PGBar.Value   = 0;

            // available free space will be filled with random files
            for (int i = 1; i <= dummyFilesCount; i++)
            {
                // Write asynchronous to implement cancel button
                using (FileStream fs = File.Create(selectedVolume.Name + i, MAX_BUFFER_SIZE, FileOptions.Asynchronous))
                {
                    // Loop 3-7 times (DoD 5220.22-M / ECE)
                    for (int pass = 0; pass <= loops; ++pass)
                    {
                        fs.Position = 0;

                        if (ct.IsCancellationRequested)
                        {
                            ct.ThrowIfCancellationRequested();
                            return;
                        }

                        long   bufferSize = MAX_BUFFER_SIZE;
                        byte[] buffer     = new byte[bufferSize];

                        if (pass != 1 && (algorithm == DeleteAlgorithm.DeleteAlgorithmEnum.DoD_7 && pass != 5))
                        {
                            for (int bufferIndex = 0; bufferIndex < bufferSize; ++bufferIndex)
                            {
                                buffer[bufferIndex] = pattern[pass];
                            }
                        }
                        else
                        {
                            for (int bufferIndex = 0; bufferIndex < bufferSize; ++bufferIndex)
                            {
                                buffer[bufferIndex] = (byte)(random.Next() % 256);
                            }
                        }

                        // Create file
                        await fs.WriteAsync(buffer, 0, buffer.Length, ct);

                        // Delegate event for progressbar
                        MainWindow.PGBar.Dispatcher.Invoke(EmptyDelegate, DispatcherPriority.Background);
                        MainWindow.LabelProgress.Dispatcher.Invoke(EmptyDelegate, DispatcherPriority.Background);
                        fs.Flush(true);
                    }

                    // Increase progressbar
                    MainWindow.LabelProgress.Content = Math.Round(i / dummyFilesCount, 3) * 100 + " %";
                    MainWindow.PGBar.Value          += MAX_BUFFER_SIZE;
                }
            }

            // After everything is done, delete everything again
            VolumeController.deleteVolume(selectedVolume);
        }
Пример #3
0
 /// <summary>
 /// Radio Button - Delete Algorithm Unchecked
 /// </summary>
 public void rb_Unchecked(object sender, RoutedEventArgs e)
 {
     algorithm = DeleteAlgorithm.DeleteAlgorithmEnum.DoD_7;
 }