public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Verify that robocopy is present on the system if (!WindowsOps.VerifyRobocopy()) { // Display error message if Robocopy isn't found var dlg = new RobocopyDlg(); dlg.ShowDialog(); // If the user didn't choose to ignore, close FilExile if (dlg.DialogResult != DialogResult.Ignore) { Application.Exit(); Environment.Exit(1); } } if (args.Length > 0) { _cla = new CommandLineArgs(args); if (_cla.HelpFlag) CommandLineInterface.DisplayHelp(); else CommandLineInterface.Run(args[0], _cla); } else { Application.Run(new Dialogs.Main()); } }
/// <summary> /// Parses the passed command line arguments, handles if a batch job was specified, /// runs the deletion operation. Main entry point for the class. /// </summary> /// <param name="path">0th argument passed in (file or folder to delete)</param> /// <param name="cla">The structured command line arguments</param> public static void Run(string path, CommandLineArgs cla) { _ca = new CompletionAction(); // First, parse the command line arguments and assign them to varibles ParseArgs(cla); // If we aren't running a batch job... if (!_batch) { Target target = new Target(path); // If the target exists if (target.Exists) { // Try deleting the target try { DeletionOps.MultithreadingSetup mt = new DeletionOps.MultithreadingSetup(_multithreading, _numThreads); DeletionOps.Logging log = new DeletionOps.Logging(_logging, _logTo); _error = DeletionOps.Delete(target, mt, log, !_quiet); } catch (Exception ex) { // If the user specifies quiet mode, don't display exception if (!_quiet) Console.WriteLine(ex.ToString()); _error = 1; } finally { // If it was a success if (_error == 0) { CleanupDirectory(target); // No command is specified, run the completion action if (string.IsNullOrEmpty(_command)) _ca.Run(false, _forceAction); // Otherwise, run the custom command else if (!string.IsNullOrEmpty(_command)) RunCommand(); } } } // If the target doesn't exist and we're not in quiet mode, write the error else if (!target.Exists && !_quiet) Console.WriteLine(SharedResources.Properties.Resources.TargetNotFound); } else { // If the user passed a job file and it exists, execute it if (File.Exists(_jobFile)) RunJobDeletion(); // Otherwise display an error else if (!_quiet) Console.WriteLine(SharedResources.Properties.Resources.JobFileNotFound); } }
public static void Main(string[] args) { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Verify that robocopy is present on the system if (!Properties.Settings.Default.disableRobocopyCheck && !WindowsOps.VerifyRobocopy()) { // Display error message if Robocopy isn't found var dlg = new RobocopyDlg(); dlg.ShowDialog(); // If the user didn't choose to ignore, close FilExile if (dlg.DialogResult != DialogResult.Ignore) { Application.Exit(); Environment.Exit(1); } } try { // If any command line arguments are passed, prepare them for parsing if (args.Length > 0) { _cla = new CommandLineArgs(args); AttachConsole(AttachParentProcess); if (_cla.HelpFlag) CommandLineInterface.DisplayHelp(); else CommandLineInterface.Run(args[0], _cla); } // Otherwise, launch the FilExile GUI else { Application.Run(new Dialogs.Main()); } } finally { FreeConsole(); } }
/// <summary> /// Parses the CommandLineArgs and assigns their arguments to variables /// </summary> /// <param name="cla">CommandLineArgs</param> private static void ParseArgs(CommandLineArgs cla) { // Job file _batch = cla.HasFlag("job"); if (_batch) cla.GetFlagAndArguments("job", ref _jobFile); // Quiet mode _quiet = cla.HasFlag("q"); // Logging _logging = cla.HasFlag("l"); if (_logging) cla.GetFlagAndArguments("l", ref _logTo); // Multithreading if (cla.HasFlag("mt")) { cla.GetFlagAndArguments("mt", ref _mtOptions); if (int.TryParse(_mtOptions, out _numThreads)) { _multithreading = _numThreads > 0; if (_numThreads > 128) _numThreads = 8; } else if (string.Equals(_mtOptions, "off")) _multithreading = false; } // Completion action if (!cla.HasFlag("end")) return; int iCompletionAction; // Grab the arguments passed with the flag cla.GetFlagAndArguments("end", ref _command); // If the user entered a number, they were trying to choose a predetermined completion action if (int.TryParse(_command, out iCompletionAction)) { // If they didn't choose properly, select the default _ca.Value = !_ca.IsValidOptionForCli(iCompletionAction) ? 0 : iCompletionAction; } //Check for the force flag (we only care about this if they have specified a completion action) _forceAction = cla.HasFlag("f"); }