Source code of Windows XP (NT5)
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.

289 lines
7.0 KiB

  1. //
  2. // Application Verifier UI
  3. // Copyright (c) Microsoft Corporation, 2001
  4. //
  5. //
  6. //
  7. // module: CmdLine.cpp
  8. // author: DMihai
  9. // created: 02/22/2001
  10. //
  11. // Description:
  12. //
  13. // Command line support
  14. //
  15. #include "stdafx.h"
  16. #include "appverif.h"
  17. #include "CmdLine.h"
  18. #include "AVUtil.h"
  19. #include "Setting.h"
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25. /////////////////////////////////////////////////////////////////////////////
  26. VOID CmdLinePrintHelpInformation()
  27. {
  28. AVTPrintfResourceFormat( IDS_HELP_LINE1, VER_PRODUCTVERSION_STR );
  29. puts( VER_LEGALCOPYRIGHT_STR );
  30. AVPrintStringFromResources( IDS_HELP_LINE3 );
  31. AVPrintStringFromResources( IDS_HELP_LINE4 );
  32. AVPrintStringFromResources( IDS_HELP_LINE5 );
  33. AVPrintStringFromResources( IDS_HELP_LINE6 );
  34. AVPrintStringFromResources( IDS_HELP_LINE7 );
  35. AVPrintStringFromResources( IDS_HELP_LINE8 );
  36. AVPrintStringFromResources( IDS_HELP_LINE9 );
  37. AVPrintStringFromResources( IDS_HELP_LINE10 );
  38. AVPrintStringFromResources( IDS_HELP_LINE11 );
  39. AVPrintStringFromResources( IDS_HELP_LINE12 );
  40. }
  41. /////////////////////////////////////////////////////////////////////////////
  42. //
  43. // See if the user asked for help and print out the help strings
  44. //
  45. BOOL CmdLineExecuteIfHelp( INT argc,
  46. TCHAR *argv[] )
  47. {
  48. BOOL bPrintedHelp;
  49. TCHAR szCmdLineSwitch[ 64 ];
  50. bPrintedHelp = FALSE;
  51. VERIFY( AVLoadString( IDS_HELP_CMDLINE_SWITCH,
  52. szCmdLineSwitch,
  53. ARRAY_LENGTH( szCmdLineSwitch ) ) );
  54. //
  55. // Search for help switch in the command line
  56. //
  57. if( argc == 2 && _tcsicmp( argv[ 1 ], szCmdLineSwitch) == 0)
  58. {
  59. CmdLinePrintHelpInformation();
  60. bPrintedHelp = TRUE;
  61. }
  62. return bPrintedHelp;
  63. }
  64. /////////////////////////////////////////////////////////////////////////////
  65. //
  66. // See if we need to dump the statistics to the console
  67. //
  68. BOOL CmdLineExecuteIfQuerySettings( INT argc,
  69. TCHAR *argv[] )
  70. {
  71. BOOL bFoundCmdLineSwitch;
  72. TCHAR szCmdLineSwitch[ 64 ];
  73. bFoundCmdLineSwitch = FALSE;
  74. VERIFY( AVLoadString( IDS_QUERYSETT_CMDLINE_SWITCH,
  75. szCmdLineSwitch,
  76. ARRAY_LENGTH( szCmdLineSwitch ) ) );
  77. //
  78. // Search for our switch in the command line
  79. //
  80. if( argc == 2 && _tcsicmp( argv[1], szCmdLineSwitch) == 0)
  81. {
  82. bFoundCmdLineSwitch = TRUE;
  83. AVDumpRegistrySettingsToConsole();
  84. }
  85. return bFoundCmdLineSwitch;
  86. }
  87. /////////////////////////////////////////////////////////////////////////////
  88. VOID CmdLineGetFlagsAppsReset( INT argc,
  89. TCHAR *argv[],
  90. DWORD &dwNewFlags,
  91. CStringArray &astrNewApps,
  92. BOOL &bHaveReset )
  93. {
  94. INT nCrtArg;
  95. INT nCrtVerifierFlag;
  96. BOOL bThisIsAppName;
  97. TCHAR szResetCmdLineOption[ 64 ];
  98. TCHAR szReservedCmdLineOption[ 64 ];
  99. dwNewFlags = 0;
  100. //
  101. // Load the switches from the resources
  102. //
  103. VERIFY( AVLoadString( IDS_RESET_CMDLINE_SWITCH,
  104. szResetCmdLineOption,
  105. ARRAY_LENGTH( szResetCmdLineOption ) ) );
  106. //
  107. // Parse all the cmd line arguments, looking for ours
  108. //
  109. for( nCrtArg = 1; nCrtArg < argc; nCrtArg += 1 )
  110. {
  111. bThisIsAppName = TRUE;
  112. if( _tcsicmp( argv[ nCrtArg ], szResetCmdLineOption ) == 0 )
  113. {
  114. //
  115. // Have /reset
  116. //
  117. bHaveReset = TRUE;
  118. bThisIsAppName = FALSE;
  119. }
  120. else
  121. {
  122. for( nCrtVerifierFlag = 0; nCrtVerifierFlag < ARRAY_LENGTH( g_AllNamesAndBits ); nCrtVerifierFlag += 1 )
  123. {
  124. //
  125. // Load the cmd line argument reserved for this bit
  126. //
  127. VERIFY( AVLoadString( g_AllNamesAndBits[ nCrtVerifierFlag ].m_uCmdLineStringId,
  128. szReservedCmdLineOption,
  129. ARRAY_LENGTH( szReservedCmdLineOption ) ) );
  130. if( _tcsicmp( argv[ nCrtArg ], szReservedCmdLineOption ) == 0 )
  131. {
  132. //
  133. // Enable this bit since we found it in the cmd line
  134. //
  135. dwNewFlags |= g_AllNamesAndBits[ nCrtVerifierFlag ].m_dwBit;
  136. bThisIsAppName = FALSE;
  137. }
  138. }
  139. }
  140. //
  141. // If the current cmd line arg is not a reserve one consider it's an app name
  142. //
  143. if( FALSE != bThisIsAppName )
  144. {
  145. astrNewApps.Add( argv[ nCrtArg ] );
  146. }
  147. }
  148. if( 0 == dwNewFlags )
  149. {
  150. //
  151. // If the user didn't specify any flags we will
  152. // enable all the standard checks
  153. //
  154. dwNewFlags = AV_ALL_STANDARD_VERIFIER_FLAGS;
  155. }
  156. }
  157. /////////////////////////////////////////////////////////////////////////////
  158. DWORD CmdLineExecute( INT argc, TCHAR *argv[] )
  159. {
  160. DWORD dwExitCode;
  161. BOOL bFoundCmdLineSwitch;
  162. BOOL bHaveReset;
  163. DWORD dwNewFlags;
  164. INT_PTR nAppsNo;
  165. INT_PTR nCrtApp;
  166. CStringArray astrNewApps;
  167. dwExitCode = AV_EXIT_CODE_SUCCESS;
  168. //
  169. // See if the user asked for help
  170. //
  171. bFoundCmdLineSwitch = CmdLineExecuteIfHelp( argc,
  172. argv );
  173. if( TRUE == bFoundCmdLineSwitch )
  174. {
  175. //
  176. // We are done printing out the help strings
  177. //
  178. goto Done;
  179. }
  180. //
  181. // See if the user asked to dump the current registry settings
  182. //
  183. bFoundCmdLineSwitch = CmdLineExecuteIfQuerySettings( argc,
  184. argv );
  185. if( TRUE == bFoundCmdLineSwitch )
  186. {
  187. //
  188. // We are done with the settings query
  189. //
  190. goto Done;
  191. }
  192. //
  193. // Get the new flags and apps if they have been specified
  194. //
  195. bHaveReset = FALSE;
  196. CmdLineGetFlagsAppsReset(
  197. argc,
  198. argv,
  199. dwNewFlags,
  200. astrNewApps,
  201. bHaveReset );
  202. //
  203. // Transform our array of names in the global g_NewSettings data
  204. //
  205. g_NewSettings.m_SettingsType = AVSettingsTypeCustom;
  206. nAppsNo = astrNewApps.GetSize();
  207. for( nCrtApp = 0; nCrtApp < nAppsNo; nCrtApp += 1 )
  208. {
  209. g_NewSettings.m_aApplicationData. AddNewAppDataConsoleMode( astrNewApps.GetAt( nCrtApp ),
  210. dwNewFlags );
  211. }
  212. //
  213. // Save the new settings.
  214. //
  215. // If bHaveReset is set to TRUE the old app verifier settings for
  216. // apps not mentioned in this command line will be deleted.
  217. //
  218. if( AVSaveNewSettings( bHaveReset ) )
  219. {
  220. dwExitCode = AV_EXIT_CODE_RESTART;
  221. }
  222. else
  223. {
  224. dwExitCode = AV_EXIT_CODE_ERROR;
  225. }
  226. Done:
  227. return dwExitCode;
  228. }