public static ParsedCommands ParseUntrustedCommands(string cmdLineString) { var commands = new ParsedCommands(); var parsedArgs = Parse(cmdLineString); foreach (var kvp in parsedArgs) { Debug.WriteLine("arg {0} = {1}", kvp.Key, kvp.Value); var command = new ParsedCommand(); switch (kvp.Key) { case "-Directory": command.Type = ParsedCommandType.OpenDirectory; break; default: command.Type = ParsedCommandType.Unkwon; break; } command.Payload = kvp.Value; commands.Add(command); } return(commands); }
public static ParsedCommands ParseUntrustedArgs(string cmdLineString) { ParsedCommands commands = new ParsedCommands(); Parse(cmdLineString); foreach (KeyValuePair <string, string> kvp in ParsedArgs) { Debug.WriteLine("arg {0} = {1}", kvp.Key, kvp.Value); ParsedCommand command = new ParsedCommand(); switch (kvp.Key) { case "SelectItem": command.Type = ParsedCommandType.SelectItem; break; case "LoadConfig": command.Type = ParsedCommandType.LoadConfig; break; case "LoadFile": command.Type = ParsedCommandType.LoadFile; break; default: command.Type = ParsedCommandType.Unknown; break; } command.Payload = kvp.Value; commands.Add(command); } return(commands); }
private static ParsedCommands ParseSplitArguments(List <KeyValuePair <string, string[]> > parsedArgs) { var commands = new ParsedCommands(); foreach (var kvp in parsedArgs) { Debug.WriteLine("arg {0} = {1}", kvp.Key, kvp.Value); var command = new ParsedCommand(); switch (kvp.Key) { case string s when "Directory".Equals(s, StringComparison.OrdinalIgnoreCase): command.Type = ParsedCommandType.OpenDirectory; break; case string s when "OutputPath".Equals(s, StringComparison.OrdinalIgnoreCase): command.Type = ParsedCommandType.OutputPath; break; case string s when "Select".Equals(s, StringComparison.OrdinalIgnoreCase): command.Type = ParsedCommandType.SelectItem; break; case string s when "Tag".Equals(s, StringComparison.OrdinalIgnoreCase): command.Type = ParsedCommandType.TagFiles; break; default: //case "Cmdless": try { if (kvp.Value[0].StartsWith("::{", StringComparison.Ordinal) || kvp.Value[0].StartsWith("shell:", StringComparison.OrdinalIgnoreCase)) { command.Type = ParsedCommandType.ExplorerShellCommand; } else if (Path.IsPathRooted(kvp.Value[0])) { command.Type = ParsedCommandType.OpenPath; } else { command.Type = ParsedCommandType.Unknown; } } catch (Exception ex) { Debug.WriteLine($"Exception in CommandLineParser.cs\\ParseUntrustedCommands with message: {ex.Message}"); command.Type = ParsedCommandType.Unknown; } break; } command.Args.AddRange(kvp.Value); commands.Add(command); } return(commands); }
protected override void OnActivated(IActivatedEventArgs args) { switch (args.Kind) { case ActivationKind.CommandLineLaunch: CommandLineActivatedEventArgs cmdLineArgs = args as CommandLineActivatedEventArgs; CommandLineActivationOperation operation = cmdLineArgs.Operation; string cmdLineString = operation.Arguments; string activationPath = operation.CurrentDirectoryPath; Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); Window.Current.Content = rootFrame; } ParsedCommands parsedCommands = CommandLineParser.ParseUntrustedArgs(cmdLineString); if (parsedCommands != null && parsedCommands.Count > 0) { foreach (ParsedCommand command in parsedCommands) { switch (command.Type) { case ParsedCommandType.SelectItem: rootFrame.Navigate(typeof(SelectItemPage), command.Payload); break; case ParsedCommandType.LoadConfig: rootFrame.Navigate(typeof(LoadConfigPage), command.Payload); break; case ParsedCommandType.LoadFile: string filePath = Path.Combine(activationPath, command.Payload); rootFrame.Navigate(typeof(LoadFilePage), filePath); break; case ParsedCommandType.Unknown: rootFrame.Navigate(typeof(HelpPage), cmdLineString); break; } } } else { rootFrame.Navigate(typeof(MainPage)); } Window.Current.Activate(); break; } }
public static ParsedCommands ParseUntrustedArgs(string cmdLineString) { ParsedCommands commands = new ParsedCommands(); Parse(cmdLineString); foreach (KeyValuePair <string, string> kvp in ParsedArgs) { commands.Add(kvp); } return(commands); }
private static ParsedCommands ParseSplitArguments(List <KeyValuePair <string, string> > parsedArgs) { var commands = new ParsedCommands(); foreach (var kvp in parsedArgs) { Debug.WriteLine("arg {0} = {1}", kvp.Key, kvp.Value); var command = new ParsedCommand(); switch (kvp.Key) { case "-Directory": command.Type = ParsedCommandType.OpenDirectory; break; default: //case "-Cmdless": try { if (kvp.Value.StartsWith("::{") || kvp.Value.StartsWith("shell:")) { command.Type = ParsedCommandType.ExplorerShellCommand; } else if (Path.IsPathRooted(kvp.Value)) { command.Type = ParsedCommandType.OpenPath; } else { command.Type = ParsedCommandType.Unknown; } } catch (Exception ex) { Debug.WriteLine($"Exception in CommandLineParser.cs\\ParseUntrustedCommands with message: {ex.Message}"); command.Type = ParsedCommandType.Unknown; } break; } command.Payload = kvp.Value; commands.Add(command); } return(commands); }