Example #1
0
 /// <summary>
 /// Gets the singleton instance of the Eraser UI Settings.
 /// </summary>
 /// <returns>The global instance of the Eraser UI settings.</returns>
 public static EraserSettings Get()
 {
     if (instance == null)
     {
         instance = new EraserSettings();
     }
     return(instance);
 }
Example #2
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (EraserSettings.Get().HideWhenMinimised&& e.CloseReason == CloseReason.UserClosing)
     {
         e.Cancel = true;
         Visible  = false;
     }
 }
Example #3
0
        private void MainForm_Resize(object sender, EventArgs e)
        {
            if (WindowState != FormWindowState.Minimized)
            {
                Bitmap   bmp = new Bitmap(Width, Height);
                Graphics dc  = Graphics.FromImage(bmp);
                DrawBackground(dc);

                CreateGraphics().DrawImage(bmp, new Point(0, 0));
            }
            else if (EraserSettings.Get().HideWhenMinimised)
            {
                Visible = false;
            }
        }
Example #4
0
 private void hideWhenMinimiseToolStripMenuItem_Click(object sender, EventArgs e)
 {
     EraserSettings.Get().HideWhenMinimised =
         hideWhenMinimisedToolStripMenuItem.Checked;
 }
Example #5
0
        public MainForm()
        {
            InitializeComponent();
            SettingsPage  = new SettingsPanel();
            SchedulerPage = new SchedulerPanel();
            contentPanel.Controls.Add(SchedulerPage);
            contentPanel.Controls.Add(SettingsPage);
            if (!IsHandleCreated)
            {
                CreateHandle();
            }

            Theming.ApplyTheme(this);
            Theming.ApplyTheme(notificationMenu);

            //We need to see if there are any tools to display
            foreach (IClientTool tool in Host.Instance.ClientTools)
            {
                tool.RegisterTool(tbToolsMenu);
            }
            if (tbToolsMenu.Items.Count == 0)
            {
                //There are none, hide the menu
                tbTools.Visible         = false;
                tbToolsDropDown.Visible = false;
            }

            //We also need to see if we have any notifier classes we need to register.
            foreach (INotifier notifier in Host.Instance.Notifiers)
            {
                notifier.Sink = this;
            }
            Host.Instance.Notifiers.Registered += Notifier_Registered;

            //For every task we need to register the Task Started and Task Finished
            //event handlers for progress notifications
            foreach (Task task in Program.eraserClient.Tasks)
            {
                OnTaskAdded(this, new TaskEventArgs(task));
            }
            Program.eraserClient.TaskAdded   += OnTaskAdded;
            Program.eraserClient.TaskDeleted += OnTaskDeleted;

            //Check if we have tasks running already.
            foreach (Task task in Program.eraserClient.Tasks)
            {
                if (task.Executing)
                {
                    OnTaskProcessing(task, EventArgs.Empty);
                    break;
                }
            }

            //Check the notification area context menu's minimise to tray item.
            hideWhenMinimisedToolStripMenuItem.Checked = EraserSettings.Get().HideWhenMinimised;

            //Set the docking style for each of the pages
            SchedulerPage.Dock   = DockStyle.Fill;
            SettingsPage.Visible = false;

            //Show the default page.
            ChangePage(MainFormPage.Scheduler);
        }
Example #6
0
 public static EraserSettings Get()
 {
     if (instance == null)
     instance = new EraserSettings();
        return instance;
 }
Example #7
0
        /// <summary>
        /// Handles the task completion event.
        /// </summary>
        void TaskFinished(object sender, EventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke((EventHandler)TaskFinished, sender, e);
                return;
            }

            //Stop the timer for progress updates
            progressTimer.Stop();

            //Get the list view item
            Task         task = (Task)sender;
            ListViewItem item = GetTaskItem(task);

            if (item == null)
            {
                return;
            }

            //Hide the progress bar
            if (schedulerProgress.Tag != null && schedulerProgress.Tag == item)
            {
                schedulerProgress.Tag     = null;
                schedulerProgress.Visible = false;
            }

            //Get the exit status of the task.
            LogLevel highestLevel = task.Log.Last().Highest;

            //Show a balloon to inform the user
            MainForm parent = (MainForm)FindForm();

            if (parent.WindowState == FormWindowState.Minimized || !parent.Visible)
            {
                string      message = null;
                ToolTipIcon icon    = ToolTipIcon.None;

                switch (highestLevel)
                {
                case LogLevel.Warning:
                    message = S._("The task {0} has completed with warnings.", task);
                    icon    = ToolTipIcon.Warning;
                    break;

                case LogLevel.Error:
                    message = S._("The task {0} has completed with errors.", task);
                    icon    = ToolTipIcon.Error;
                    break;

                case LogLevel.Fatal:
                    message = S._("The task {0} did not complete.", task);
                    icon    = ToolTipIcon.Error;
                    break;

                default:
                    message = S._("The task {0} has completed.", task);
                    icon    = ToolTipIcon.Info;
                    break;
                }

                parent.ShowNotificationBalloon(S._("Task completed"), message,
                                               icon);
            }

            //If the user requested us to remove completed one-time tasks, do so.
            if (EraserSettings.Get().ClearCompletedTasks&&
                (task.Schedule == Schedule.RunNow) && highestLevel < LogLevel.Warning)
            {
                Program.eraserClient.Tasks.Remove(task);
            }

            //Otherwise update the UI
            else
            {
                switch (highestLevel)
                {
                case LogLevel.Warning:
                    item.SubItems[2].Text = S._("Completed with warnings");
                    break;

                case LogLevel.Error:
                    item.SubItems[2].Text = S._("Completed with errors");
                    break;

                case LogLevel.Fatal:
                    item.SubItems[2].Text = S._("Not completed");
                    break;

                default:
                    item.SubItems[2].Text = S._("Completed");
                    break;
                }

                //Recategorize the task. Do not assume the task has maintained the
                //category since run-on-restart tasks will be changed to immediately
                //run tasks.
                CategorizeTask(task, item);

                //Update the status of the task.
                UpdateTask(item);
            }
        }
Example #8
0
        private void saveSettings_Click(object sender, EventArgs e)
        {
            EraserSettings settings = EraserSettings.Get();

            //Save the settings that don't fail first.
            Host.Instance.Settings.ForceUnlockLockedFiles = lockedForceUnlock.Checked;
            ManagerLibrary.Instance.Settings.ExecuteMissedTasksImmediately =
                schedulerMissedImmediate.Checked;
            settings.ClearCompletedTasks = schedulerClearCompleted.Checked;

            bool pluginApprovalsChanged = false;
            IDictionary <Guid, bool> pluginApprovals =
                ManagerLibrary.Instance.Settings.PluginApprovals;

            foreach (ListViewItem item in pluginsManager.Items)
            {
                PluginInfo plugin = (PluginInfo)item.Tag;
                Guid       guid   = plugin.AssemblyInfo.Guid;
                if (!pluginApprovals.ContainsKey(guid))
                {
                    if (plugin.Loaded != item.Checked)
                    {
                        pluginApprovals.Add(guid, item.Checked);
                        pluginApprovalsChanged = true;
                    }
                }
                else if (pluginApprovals[guid] != item.Checked)
                {
                    pluginApprovals[guid]  = item.Checked;
                    pluginApprovalsChanged = true;
                }
            }

            if (pluginApprovalsChanged)
            {
                MessageBox.Show(this, S._("Plugins which have just been approved will only be loaded " +
                                          "the next time Eraser is started."), S._("Eraser"), MessageBoxButtons.OK,
                                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                                Localisation.IsRightToLeft(this) ?
                                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
            }

            //Error checks for the rest that do.
            errorProvider.Clear();
            if (uiLanguage.SelectedIndex == -1)
            {
                errorProvider.SetError(uiLanguage, S._("An invalid language was selected."));
                return;
            }
            else if (eraseFilesMethod.SelectedIndex == -1)
            {
                errorProvider.SetError(eraseFilesMethod, S._("An invalid file erasure method " +
                                                             "was selected."));
                return;
            }
            else if (eraseDriveMethod.SelectedIndex == -1)
            {
                errorProvider.SetError(eraseDriveMethod, S._("An invalid drive erasure method " +
                                                             "was selected."));
                return;
            }
            else if (erasePRNG.SelectedIndex == -1)
            {
                errorProvider.SetError(erasePRNG, S._("An invalid randomness data source was " +
                                                      "selected."));
                return;
            }
            else if (plausibleDeniability.Checked && plausibleDeniabilityFiles.Items.Count == 0)
            {
                errorProvider.SetError(plausibleDeniabilityFiles, S._("Erasures with plausible deniability " +
                                                                      "was selected, but no files were selected to be used as decoys."));
                errorProvider.SetIconPadding(plausibleDeniabilityFiles, -16);
                return;
            }

            if (CultureInfo.CurrentUICulture.Name != ((CultureInfo)uiLanguage.SelectedItem).Name)
            {
                settings.Language = ((CultureInfo)uiLanguage.SelectedItem).Name;
                MessageBox.Show(this, S._("The new UI language will take only effect when " +
                                          "Eraser is restarted."), S._("Eraser"), MessageBoxButtons.OK,
                                MessageBoxIcon.Information, MessageBoxDefaultButton.Button1,
                                Localisation.IsRightToLeft(this) ?
                                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
            }
            settings.IntegrateWithShell = uiContextMenu.Checked;

            Host.Instance.Settings.DefaultFileErasureMethod =
                ((IErasureMethod)eraseFilesMethod.SelectedItem).Guid;
            Host.Instance.Settings.DefaultDriveErasureMethod =
                ((IErasureMethod)eraseDriveMethod.SelectedItem).Guid;

            IPrng newPRNG = (IPrng)erasePRNG.SelectedItem;

            if (newPRNG.Guid != Host.Instance.Prngs.ActivePrng.Guid)
            {
                MessageBox.Show(this, S._("The new randomness data source will only be used when " +
                                          "the next task is run.\nCurrently running tasks will use the old source."),
                                S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Information,
                                MessageBoxDefaultButton.Button1,
                                Localisation.IsRightToLeft(this) ?
                                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
                Host.Instance.Settings.ActivePrng = newPRNG.Guid;
            }

            Host.Instance.Settings.PlausibleDeniability = plausibleDeniability.Checked;
            IList <string> plausibleDeniabilityFilesList = Host.Instance.Settings.PlausibleDeniabilityFiles;

            plausibleDeniabilityFilesList.Clear();
            foreach (string str in this.plausibleDeniabilityFiles.Items)
            {
                plausibleDeniabilityFilesList.Add(str);
            }
        }
Example #9
0
        private void LoadSettings()
        {
            EraserSettings settings = EraserSettings.Get();

            foreach (CultureInfo lang in uiLanguage.Items)
            {
                if (lang.Name == settings.Language)
                {
                    uiLanguage.SelectedItem = lang;
                    break;
                }
            }

            foreach (IErasureMethod method in eraseFilesMethod.Items)
            {
                if (method.Guid == Host.Instance.Settings.DefaultFileErasureMethod)
                {
                    eraseFilesMethod.SelectedItem = method;
                    break;
                }
            }

            foreach (IErasureMethod method in eraseDriveMethod.Items)
            {
                if (method.Guid == Host.Instance.Settings.DefaultDriveErasureMethod)
                {
                    eraseDriveMethod.SelectedItem = method;
                    break;
                }
            }

            foreach (IPrng prng in erasePRNG.Items)
            {
                if (prng.Guid == Host.Instance.Settings.ActivePrng)
                {
                    erasePRNG.SelectedItem = prng;
                    break;
                }
            }

            foreach (string path in Host.Instance.Settings.PlausibleDeniabilityFiles)
            {
                plausibleDeniabilityFiles.Items.Add(path);
            }
            plausibleDeniability.Checked =
                Host.Instance.Settings.PlausibleDeniability;

            uiContextMenu.Checked     = settings.IntegrateWithShell;
            lockedForceUnlock.Checked =
                Host.Instance.Settings.ForceUnlockLockedFiles;
            schedulerMissedImmediate.Checked =
                ManagerLibrary.Instance.Settings.ExecuteMissedTasksImmediately;
            schedulerMissedIgnore.Checked =
                !ManagerLibrary.Instance.Settings.ExecuteMissedTasksImmediately;
            schedulerClearCompleted.Checked = settings.ClearCompletedTasks;

            List <string> defaultsList = new List <string>();

            //Select an intelligent default if the settings are invalid.
            if (uiLanguage.SelectedIndex == -1)
            {
                foreach (CultureInfo lang in uiLanguage.Items)
                {
                    if (lang.Name == "en")
                    {
                        uiLanguage.SelectedItem = lang;
                        break;
                    }
                }
            }
            if (eraseFilesMethod.SelectedIndex == -1)
            {
                if (eraseFilesMethod.Items.Count > 0)
                {
                    eraseFilesMethod.SelectedIndex = 0;
                    Host.Instance.Settings.DefaultFileErasureMethod =
                        ((IErasureMethod)eraseFilesMethod.SelectedItem).Guid;
                }
                defaultsList.Add(S._("Default file erasure method"));
            }
            if (eraseDriveMethod.SelectedIndex == -1)
            {
                if (eraseDriveMethod.Items.Count > 0)
                {
                    eraseDriveMethod.SelectedIndex = 0;
                    Host.Instance.Settings.DefaultDriveErasureMethod =
                        ((IErasureMethod)eraseDriveMethod.SelectedItem).Guid;
                }
                defaultsList.Add(S._("Default drive erasure method"));
            }
            if (erasePRNG.SelectedIndex == -1)
            {
                if (erasePRNG.Items.Count > 0)
                {
                    erasePRNG.SelectedIndex           = 0;
                    Host.Instance.Settings.ActivePrng =
                        ((IPrng)erasePRNG.SelectedItem).Guid;
                }
                defaultsList.Add(S._("Randomness data source"));
            }

            //Remind the user.
            if (defaultsList.Count != 0)
            {
                string defaults = string.Empty;
                foreach (string item in defaultsList)
                {
                    defaults += String.Format("\t{0}\n", item);
                }
                MessageBox.Show(S._("The following settings held invalid values:\n\n" +
                                    "{0}\nThese settings have now been set to naive defaults.\n\n" +
                                    "Please check that the new settings suit your required level of security.",
                                    defaults), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Warning,
                                MessageBoxDefaultButton.Button1,
                                Localisation.IsRightToLeft(this) ?
                                MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0);
                saveSettings_Click(null, null);
            }
        }
Example #10
0
        static int Main(string[] rawCommandLine)
        {
            //Immediately parse command line arguments. Start by substituting all
            //response files ("@filename") arguments with the arguments found in the
            //file
            List <string> commandLine = new List <string>(rawCommandLine.Length);

            foreach (string argument in rawCommandLine)
            {
                if (argument[0] == '@' && File.Exists(argument.Substring(1)))
                {
                    //The current parameter is a response file, parse the file
                    //for arguments and substitute it.
                    using (TextReader reader = new StreamReader(argument.Substring(1)))
                    {
                        commandLine.AddRange(Shell.ParseCommandLine(reader.ReadToEnd()));
                    }
                }
                else
                {
                    commandLine.Add(argument);
                }
            }

            string[] finalCommandLine             = commandLine.ToArray();
            ComLib.BoolMessageItem argumentParser = Args.Parse(finalCommandLine,
                                                               CommandLinePrefixes, CommandLineSeparators);
            Args parsedArguments = (Args)argumentParser.Item;

            //Set application defaults for consistent behaviour across GUI and
            //Console instances
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);

            //Load the Eraser.Manager library
            using (ManagerLibrary library = new ManagerLibrary(Settings.Get()))
            {
                //Set our UI language
                EraserSettings settings = EraserSettings.Get();
                Thread.CurrentThread.CurrentUICulture = new CultureInfo(settings.Language);

                //We default to a GUI if:
                // - The parser did not succeed.
                // - The parser resulted in an empty arguments list
                // - The parser's argument at index 0 is not equal to the first argument
                //   (this is when the user is passing GUI options -- command line options
                //   always start with the action, e.g. Eraser help, or Eraser addtask
                if (!argumentParser.Success || parsedArguments.IsEmpty ||
                    parsedArguments.Positional.Count == 0 ||
                    parsedArguments.Positional[0] != parsedArguments.Raw[0])
                {
                    GUIMain(finalCommandLine);
                }
                else
                {
                    return(CommandMain(finalCommandLine));
                }
            }

            //Return zero to signify success
            return(0);
        }