coolerfarmer

Untitled

Jun 26th, 2014
5,565
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.93 KB | None | 0 0
  1. private static void ProcessArgs(IEnumerable<string> args)
  2. {
  3. string output = null;
  4. var dirs = new Stack<string>();
  5. var files = new Stack<string>();
  6. string searchPattern = "*.*";
  7. var option = SearchOption.AllDirectories;
  8.  
  9. foreach (string arg in args)
  10. {
  11. string argument = arg.ToLower().Trim();
  12.  
  13. // Get output path
  14. Match match = Regex.Match(argument, @"/output=(?<Path>[^""]+)");
  15. {
  16. if (match.Success)
  17. {
  18. output = match.Groups["Path"].Value;
  19. continue;
  20. }
  21. }
  22. // Get input files
  23. match = Regex.Match(argument, @"/inputfile=(?<Path>[^""]+)");
  24. if (match.Success)
  25. {
  26. files.Push(match.Groups["Path"].Value);
  27. continue;
  28. }
  29. // Get input files
  30. match = Regex.Match(argument, @"/inputdir=(?<Path>[^""]+)");
  31. if (match.Success)
  32. {
  33. dirs.Push(match.Groups["Path"].Value);
  34. continue;
  35. }
  36. // Get search option
  37. if (argument == "/true")
  38. {
  39. option = SearchOption.AllDirectories;
  40. }
  41. else if (argument == "/false")
  42. {
  43. option = SearchOption.TopDirectoryOnly;
  44. }
  45. // Get search pattern
  46. match = Regex.Match(argument, @"/searchpattern=(?<Pat>[^""]+)");
  47. if (match.Success)
  48. {
  49. searchPattern = match.Groups["Pat"].Value;
  50. }
  51. }
  52.  
  53. if (output == null)
  54. {
  55. ShowErrorMessage("No output path specified in arguments");
  56. return;
  57. }
  58.  
  59. if (files.Count == 0 && dirs.Count == 0)
  60. {
  61. ShowErrorMessage("No paths to content specified");
  62. return;
  63. }
  64.  
  65. foreach (string dir in dirs.Where(d => !Directory.Exists(d)))
  66. {
  67. ShowErrorMessage(@"The directory """ + dir + @""" does not exist");
  68. return;
  69. }
  70.  
  71. foreach (string file in files.Where(f => !Directory.Exists(f)))
  72. {
  73. ShowErrorMessage(@"The file """ + file + @""" does not exist");
  74. return;
  75. }
  76.  
  77. var combiner = new SourceCombiner(output);
  78. combiner.SearchOption = option;
  79. combiner.SearchPattern = searchPattern;
  80. combiner.AppendFiles(files.ToArray());
  81. combiner.AppendDirectories(dirs.ToArray());
  82. combiner.Save();
  83. }
Advertisement
Add Comment
Please, Sign In to add comment