private static void StartStrategy() { var extractorOptions = ReadOptions(); var target = extractorOptions?.Target; var targetPath = extractorOptions?.TargetPath; ITargetStrategy targetStrategy; if (target.EqualTo("Folder")) { targetStrategy = new FolderTarget(targetPath); } else if (target.EqualTo("Solution")) { targetStrategy = new SolutionTarget(targetPath); } else if (target.EqualTo("Project")) { targetStrategy = new ProjectTarget(targetPath); } else { Warning($"Unknown target '{target}'"); return; } var outputStrategy = new SingleFolder(extractorOptions?.OutputFolder, targetStrategy); outputStrategy.Process(); }
protected override bool ResolveParameter(string param) { int equalPos = param.IndexOf('='); if (IsParam(param, "method", "m")) { if (equalPos == -1) throw new ArgumentException("--method must be specified with an Erasure " + "method GUID."); List<KeyValuePair<string, string> > subParams = GetSubParameters(param.Substring(equalPos + 1)); ErasureMethod = new Guid(subParams[0].Key); } else if (IsParam(param, "schedule", "s")) { if (equalPos == -1) throw new ArgumentException("--schedule must be specified with a Schedule " + "type."); List<KeyValuePair<string, string> > subParams = GetSubParameters(param.Substring(equalPos + 1)); switch (subParams[0].Key) { case "now": Schedule = Schedule.RunNow; break; case "manually": Schedule = Schedule.RunManually; break; case "restart": Schedule = Schedule.RunOnRestart; break; default: throw new ArgumentException("Unknown schedule type: " + subParams[0].Key); } } else if (IsParam(param, "recycled", "r")) { Targets.Add(new RecycleBinTarget()); } else if (IsParam(param, "unused", "u")) { if (equalPos == -1) throw new ArgumentException("--unused must be specified with the Volume " + "to erase."); UnusedSpaceTarget target = new UnusedSpaceTarget(); target.EraseClusterTips = false; List<KeyValuePair<string, string> > subParams = GetSubParameters(param.Substring(equalPos + 1)); foreach (KeyValuePair<string, string> kvp in subParams) if (kvp.Value == null && target.Drive == null) target.Drive = Path.GetFullPath(kvp.Key); else if (kvp.Key == "clusterTips") target.EraseClusterTips = true; else throw new ArgumentException("Unknown subparameter: " + kvp.Key); Targets.Add(target); } else if (IsParam(param, "dir", "d") || IsParam(param, "directory", null)) { if (equalPos == -1) throw new ArgumentException("--directory must be specified with the " + "directory to erase."); FolderTarget target = new FolderTarget(); List<KeyValuePair<string, string> > subParams = GetSubParameters(param.Substring(equalPos + 1)); foreach (KeyValuePair<string, string> kvp in subParams) if (kvp.Value == null && target.Path == null) target.Path = Path.GetFullPath(kvp.Key); else if (kvp.Key == "excludeMask") { if (kvp.Value == null) throw new ArgumentException("The exclude mask must be specified " + "if the excludeMask subparameter is specified"); target.ExcludeMask = kvp.Value; } else if (kvp.Key == "includeMask") { if (kvp.Value == null) throw new ArgumentException("The include mask must be specified " + "if the includeMask subparameter is specified"); target.IncludeMask = kvp.Value; } else if (kvp.Key == "delete") target.DeleteIfEmpty = true; else throw new ArgumentException("Unknown subparameter: " + kvp.Key); Targets.Add(target); } else if (IsParam(param, "file", "f")) { if (equalPos == -1) throw new ArgumentException("--file must be specified with the " + "file to erase."); FileTarget target = new FileTarget(); List<KeyValuePair<string, string> > subParams = GetSubParameters(param.Substring(equalPos + 1)); foreach (KeyValuePair<string, string> kvp in subParams) if (kvp.Value == null && target.Path == null) target.Path = Path.GetFullPath(kvp.Key); else throw new ArgumentException("Unknown subparameter: " + kvp.Key); Targets.Add(target); } else return false; return true; }
private void scheduler_DragDrop(object sender, DragEventArgs e) { if (!e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.None; else { string[] files = (string[])e.Data.GetData(DataFormats.FileDrop, false); if (e.Effect == DragDropEffects.Copy) { foreach (string file in files) using (FileStream stream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read)) { try { Program.eraserClient.Tasks.LoadFromStream(stream); } catch (SerializationException ex) { MessageBox.Show(S._("Could not import task list from {0}. The " + "error returned was: {1}", file, ex.Message), S._("Eraser"), MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1, S.IsRightToLeft(null) ? MessageBoxOptions.RtlReading | MessageBoxOptions.RightAlign : 0); } } } else if (e.Effect == DragDropEffects.Move) { Task task = new Task(); foreach (string file in files) { FileSystemObjectTarget target; if (Directory.Exists(file)) target = new FolderTarget(); else target = new FileTarget(); target.Path = file; task.Targets.Add(target); } Program.eraserClient.Tasks.Add(task); } } DropTargetHelper.Drop(e.Data, new Point(e.X, e.Y), e.Effect); }
private static void CommandAddTask(ConsoleArguments arg) { AddTaskArguments arguments = (AddTaskArguments)arg; Task task = new Task(); ErasureMethod method = arguments.ErasureMethod == Guid.Empty ? ErasureMethodManager.Default : ErasureMethodManager.GetInstance(arguments.ErasureMethod); switch (arguments.Schedule.ToUpperInvariant()) { case "NOW": task.Schedule = Schedule.RunNow; break; case "MANUALLY": task.Schedule = Schedule.RunManually; break; case "RESTART": task.Schedule = Schedule.RunOnRestart; break; default: throw new ArgumentException(string.Format(CultureInfo.CurrentCulture, "Unknown schedule type: {0}", arguments.Schedule), "--schedule"); } List<string> trueValues = new List<string>(new string[] { "yes", "true" }); string[] strings = new string[] { "(?<recycleBin>recyclebin)", "unused=(?<unusedVolume>.*)(?<unusedTips>,clusterTips(=(?<unusedTipsValue>true|false))?)?", "dir=(?<directoryName>.*)(?<directoryParams>(?<directoryExcludeMask>,-[^,]+)|(?<directoryIncludeMask>,\\+[^,]+)|(?<directoryDeleteIfEmpty>,deleteIfEmpty(=(?<directoryDeleteIfEmptyValue>true|false))?))*", "file=(?<fileName>.*)" }; Regex regex = new Regex(string.Join("|", strings), RegexOptions.Compiled | RegexOptions.IgnoreCase | RegexOptions.RightToLeft); foreach (string argument in arguments.PositionalArguments) { Match match = regex.Match(argument); if (match.Captures.Count == 0) { Console.WriteLine("Unknown argument: {0}, skipped.", argument); continue; } ErasureTarget target = null; if (match.Groups["recycleBin"].Success) { target = new RecycleBinTarget(); } else if (match.Groups["unusedVolume"].Success) { UnusedSpaceTarget unusedSpaceTarget = new UnusedSpaceTarget(); target = unusedSpaceTarget; unusedSpaceTarget.Drive = match.Groups["unusedVolume"].Value; if (!match.Groups["unusedTips"].Success) unusedSpaceTarget.EraseClusterTips = false; else if (!match.Groups["unusedTipsValue"].Success) unusedSpaceTarget.EraseClusterTips = true; else unusedSpaceTarget.EraseClusterTips = trueValues.IndexOf(match.Groups["unusedTipsValue"].Value) != -1; } else if (match.Groups["directoryName"].Success) { FolderTarget folderTarget = new FolderTarget(); target = folderTarget; folderTarget.Path = match.Groups["directoryName"].Value; if (!match.Groups["directoryDeleteIfEmpty"].Success) folderTarget.DeleteIfEmpty = false; else if (!match.Groups["directoryDeleteIfEmptyValue"].Success) folderTarget.DeleteIfEmpty = true; else folderTarget.DeleteIfEmpty = trueValues.IndexOf(match.Groups["directoryDeleteIfEmptyValue"].Value) != -1; if (match.Groups["directoryExcludeMask"].Success) folderTarget.ExcludeMask += match.Groups["directoryExcludeMask"].Value.Remove(0, 2) + ' '; if (match.Groups["directoryIncludeMask"].Success) folderTarget.IncludeMask += match.Groups["directoryIncludeMask"].Value.Remove(0, 2) + ' '; } else if (match.Groups["fileName"].Success) { FileTarget fileTarget = new FileTarget(); target = fileTarget; fileTarget.Path = match.Groups["fileName"].Value; } if (target == null) continue; target.Method = method; task.Targets.Add(target); } if (task.Targets.Count == 0) throw new ArgumentException("Tasks must contain at least one erasure target."); try { using (RemoteExecutorClient client = new RemoteExecutorClient()) { client.Run(); if (!client.IsConnected) { Process eraserInstance = Process.Start( Assembly.GetExecutingAssembly().Location, "--quiet"); eraserInstance.WaitForInputIdle(); client.Run(); if (!client.IsConnected) throw new IOException("Eraser cannot connect to the running " + "instance for erasures."); } client.Tasks.Add(task); } } catch (UnauthorizedAccessException e) { throw new UnauthorizedAccessException("Another instance of Eraser " + "is already running but it is running with higher privileges than " + "this instance of Eraser. Tasks cannot be added in this manner.\n\n" + "Close the running instance of Eraser and start it again without " + "administrator privileges, or run the command again as an " + "administrator.", e); } }