| 1 | using System; |
|---|
| 2 | using System.Collections.Generic; |
|---|
| 3 | using System.Windows.Forms; |
|---|
| 4 | |
|---|
| 5 | using Eraser.Manager; |
|---|
| 6 | using Microsoft.Win32; |
|---|
| 7 | using System.IO; |
|---|
| 8 | using System.Runtime.Serialization.Formatters.Binary; |
|---|
| 9 | using System.Globalization; |
|---|
| 10 | |
|---|
| 11 | namespace Eraser |
|---|
| 12 | { |
|---|
| 13 | static class Program |
|---|
| 14 | { |
|---|
| 15 | /// <summary> |
|---|
| 16 | /// The main entry point for the application. |
|---|
| 17 | /// </summary> |
|---|
| 18 | [STAThread] |
|---|
| 19 | static void Main() |
|---|
| 20 | { |
|---|
| 21 | Application.EnableVisualStyles(); |
|---|
| 22 | Application.SetCompatibleTextRenderingDefault(false); |
|---|
| 23 | Application.SafeTopLevelCaptionFormat = "Eraser"; |
|---|
| 24 | |
|---|
| 25 | using (ManagerLibrary library = new ManagerLibrary()) |
|---|
| 26 | using (eraserClient = new DirectExecutor()) |
|---|
| 27 | { |
|---|
| 28 | //Set the defaults for the library |
|---|
| 29 | library.Settings = new Settings(); |
|---|
| 30 | |
|---|
| 31 | //Load the task list |
|---|
| 32 | RegistryKey key = Application.UserAppDataRegistry; |
|---|
| 33 | byte[] savedTaskList = (byte[])key.GetValue("TaskList", new byte[] { }); |
|---|
| 34 | using (MemoryStream stream = new MemoryStream(savedTaskList)) |
|---|
| 35 | { |
|---|
| 36 | try |
|---|
| 37 | { |
|---|
| 38 | if (savedTaskList.Length != 0) |
|---|
| 39 | eraserClient.LoadTaskList(stream); |
|---|
| 40 | } |
|---|
| 41 | catch (Exception) |
|---|
| 42 | { |
|---|
| 43 | key.DeleteValue("TaskList"); |
|---|
| 44 | MessageBox.Show("Could not load task list. All task entries have " + |
|---|
| 45 | "been lost.", "Eraser", MessageBoxButtons.OK, |
|---|
| 46 | MessageBoxIcon.Error); |
|---|
| 47 | } |
|---|
| 48 | } |
|---|
| 49 | |
|---|
| 50 | //Create the main form |
|---|
| 51 | MainForm form = new MainForm(); |
|---|
| 52 | |
|---|
| 53 | //Run tasks which are meant to be run on restart |
|---|
| 54 | int restartPos = Environment.CommandLine.ToLower().IndexOf("restart"); |
|---|
| 55 | if ((restartPos > 1 && |
|---|
| 56 | Environment.CommandLine[restartPos - 1] == '/') || |
|---|
| 57 | (restartPos > 2 && |
|---|
| 58 | Environment.CommandLine[restartPos - 1] == '-' && |
|---|
| 59 | Environment.CommandLine[restartPos - 2] == '-')) |
|---|
| 60 | { |
|---|
| 61 | eraserClient.QueueRestartTasks(); |
|---|
| 62 | } |
|---|
| 63 | |
|---|
| 64 | //Run the program |
|---|
| 65 | Application.Run(form); |
|---|
| 66 | |
|---|
| 67 | //Save the task list |
|---|
| 68 | using (MemoryStream stream = new MemoryStream()) |
|---|
| 69 | { |
|---|
| 70 | eraserClient.SaveTaskList(stream); |
|---|
| 71 | key.SetValue("TaskList", stream.ToArray(), RegistryValueKind.Binary); |
|---|
| 72 | } |
|---|
| 73 | } |
|---|
| 74 | } |
|---|
| 75 | |
|---|
| 76 | public static DirectExecutor eraserClient; |
|---|
| 77 | } |
|---|
| 78 | |
|---|
| 79 | public class Settings : Manager.Settings |
|---|
| 80 | { |
|---|
| 81 | public Settings() |
|---|
| 82 | { |
|---|
| 83 | RegistryKey key = Application.UserAppDataRegistry; |
|---|
| 84 | ActivePRNG = new Guid((string) |
|---|
| 85 | key.GetValue("PRNG", Guid.Empty.ToString())); |
|---|
| 86 | EraseLockedFilesOnRestart = |
|---|
| 87 | (int)key.GetValue("EraseOnRestart", (object)1) != 0; |
|---|
| 88 | ConfirmEraseOnRestart = |
|---|
| 89 | (int)key.GetValue("ConfirmEraseOnRestart", (object)0) != 0; |
|---|
| 90 | DefaultFileErasureMethod = new Guid((string) |
|---|
| 91 | key.GetValue("DefaultFileErasureMethod", Guid.Empty.ToString())); |
|---|
| 92 | DefaultUnusedSpaceErasureMethod = new Guid((string) |
|---|
| 93 | key.GetValue("DefaultUnusedSpaceErasureMethod", Guid.Empty.ToString())); |
|---|
| 94 | ExecuteMissedTasksImmediately = |
|---|
| 95 | (int)key.GetValue("ExecuteMissedTasksImmediately", (object)1) != 0; |
|---|
| 96 | PlausibleDeniability = |
|---|
| 97 | (int)key.GetValue("PlausibleDeniability", (object)1) != 0; |
|---|
| 98 | UILanguage = (string)key.GetValue("UILanguage", string.Empty); |
|---|
| 99 | Util.S.Language = new CultureInfo(UILanguage); |
|---|
| 100 | |
|---|
| 101 | //Load the plugin settings. |
|---|
| 102 | byte[] pluginSettings = (byte[])key.GetValue("PluginSettings", new byte[] { }); |
|---|
| 103 | if (pluginSettings.Length != 0) |
|---|
| 104 | using (MemoryStream stream = new MemoryStream(pluginSettings)) |
|---|
| 105 | { |
|---|
| 106 | try |
|---|
| 107 | { |
|---|
| 108 | this.pluginSettings = (Dictionary<Guid, Dictionary<string, object>>) |
|---|
| 109 | new BinaryFormatter().Deserialize(stream); |
|---|
| 110 | } |
|---|
| 111 | catch (Exception) |
|---|
| 112 | { |
|---|
| 113 | key.DeleteValue("PluginSettings"); |
|---|
| 114 | MessageBox.Show("Could not load plugin settings. All settings " + |
|---|
| 115 | "have been lost", "Eraser", MessageBoxButtons.OK, |
|---|
| 116 | MessageBoxIcon.Error); |
|---|
| 117 | } |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|
| 121 | ~Settings() |
|---|
| 122 | { |
|---|
| 123 | RegistryKey key = Application.UserAppDataRegistry; |
|---|
| 124 | key.SetValue("PRNG", ActivePRNG); |
|---|
| 125 | key.SetValue("EraseOnRestart", EraseLockedFilesOnRestart, |
|---|
| 126 | RegistryValueKind.DWord); |
|---|
| 127 | key.SetValue("ConfirmEraseOnRestart", ConfirmEraseOnRestart, |
|---|
| 128 | RegistryValueKind.DWord); |
|---|
| 129 | key.SetValue("DefaultFileErasureMethod", DefaultFileErasureMethod); |
|---|
| 130 | key.SetValue("DefaultUnusedSpaceErasureMethod", |
|---|
| 131 | DefaultUnusedSpaceErasureMethod); |
|---|
| 132 | key.SetValue("ExecuteMissedTasksImmediately", |
|---|
| 133 | ExecuteMissedTasksImmediately, RegistryValueKind.DWord); |
|---|
| 134 | key.SetValue("PlausibleDeniability", PlausibleDeniability, |
|---|
| 135 | RegistryValueKind.DWord); |
|---|
| 136 | key.SetValue("UILanguage", UILanguage); |
|---|
| 137 | |
|---|
| 138 | using (MemoryStream stream = new MemoryStream()) |
|---|
| 139 | { |
|---|
| 140 | new BinaryFormatter().Serialize(stream, pluginSettings); |
|---|
| 141 | key.SetValue("PluginSettings", stream.ToArray(), RegistryValueKind.Binary); |
|---|
| 142 | } |
|---|
| 143 | } |
|---|
| 144 | } |
|---|
| 145 | } |
|---|