Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

94 lines
1.8 KiB

  1. using System;
  2. using System.Resources;
  3. namespace mbsh
  4. {
  5. /// <summary>
  6. /// Handles the command line arguments for the application.
  7. /// </summary>
  8. public class CArgHandler
  9. {
  10. enum HelpType {None, Usage}
  11. public CArgHandler(string[] args)
  12. {
  13. /// <summary>
  14. /// Constructor will take the command line arguments
  15. /// </summary>
  16. // First make sure we don't have too many arguments
  17. if (args.Length > CMbshApp.c_iMaxArgs)
  18. {
  19. m_helpType = HelpType.Usage;
  20. return;
  21. }
  22. for (int index = 0; index < args.Length; index++)
  23. {
  24. bool bArgHandled = false;
  25. // does the user need help?
  26. if (!NeedsHelp)
  27. {
  28. for (int numConst = 0; numConst < c_HelpArgs.Length; numConst++)
  29. {
  30. if (args[index].Equals(c_HelpArgs[numConst]))
  31. {
  32. m_helpType = HelpType.Usage;
  33. bArgHandled = true;
  34. break;
  35. }
  36. }
  37. }
  38. // did the user set the metabase path?
  39. if (!bArgHandled)
  40. {
  41. m_mbPath = args[index];
  42. bArgHandled = true;
  43. }
  44. }
  45. }
  46. public string MBPath
  47. {
  48. get
  49. {
  50. return m_mbPath;
  51. }
  52. }
  53. public void GiveHelp()
  54. {
  55. // Get a resource manager
  56. ResourceManager resources = new ResourceManager("Mbsh.Mbsh", System.Reflection.Assembly.GetExecutingAssembly());
  57. switch (m_helpType)
  58. {
  59. default:
  60. Console.WriteLine(resources.GetString("mainHelp"));
  61. break;
  62. }
  63. }
  64. private HelpType m_helpType = HelpType.None;
  65. private string[] c_HelpArgs = {"-help", "/help", "-h", "/h", "-?", "/?"};
  66. private string m_mbPath = CMbshApp.c_DefaultMBPath;
  67. public bool NeedsHelp
  68. {
  69. get
  70. {
  71. if (m_helpType == HelpType.None)
  72. {
  73. return false;
  74. }
  75. else
  76. {
  77. return true;
  78. }
  79. }
  80. }
  81. }
  82. }