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.

223 lines
5.3 KiB

  1. #include "StdAfx.h"
  2. #include "clmt.h"
  3. #include <shellapi.h>
  4. #define CMD_ERR_CONFLICT_OPERATION 1
  5. const TCHAR *pstrUsage[] =
  6. {
  7. _T("Cross Language Migration Tool:\n\n"),
  8. _T("CLMT start running the tool.\n"),
  9. _T("CLMT /Cure Use this option if an application fails to start after running \n"),
  10. _T(" CLMT, and you want the fix to apply to all user and group \n"),
  11. _T(" profiles on this machine. This option creates reparse points \n"),
  12. _T(" between all localized and English folders that have been \n"),
  13. _T(" converted to English by this tool. It can only be used on \n"),
  14. _T(" NTFS file systems.\n"),
  15. _T(" Please see the Readme.txt file for more information.\n"),
  16. NULL
  17. };
  18. void Usage()
  19. {
  20. register i = 0;
  21. while (pstrUsage[i] != NULL)
  22. {
  23. _ftprintf(stderr, TEXT("%s"), pstrUsage[i++]);
  24. }
  25. fflush(stderr);
  26. }
  27. BOOL ProcessCommandLine(LPDWORD lpMode)
  28. {
  29. LPTSTR* lplpArgv;
  30. LPTSTR* argv;
  31. INT nArgc;
  32. DWORD dwErr;
  33. BOOL bRet = TRUE;
  34. lplpArgv = CommandLineToArgvW(GetCommandLine(), &nArgc);
  35. argv = lplpArgv;
  36. dwErr = 0;
  37. *lpMode = 0;
  38. while (--nArgc > 0 && ++argv)
  39. {
  40. if (argv[0][0] != TEXT('/'))
  41. {
  42. bRet = FALSE;
  43. break;
  44. }
  45. if (MyStrCmpI(&argv[0][1], TEXT("NOWINNT32")) == 0)
  46. {
  47. //
  48. // This is "/NOWINNT32" parameters
  49. // Will not run Winnt32 Checkupgrade option
  50. //
  51. g_fRunWinnt32 = FALSE;
  52. }
  53. else if (MyStrCmpI(&argv[0][1], TEXT("cure")) == 0)
  54. {
  55. //
  56. // This is "/Cure" parameters
  57. //
  58. if (*lpMode > 0)
  59. {
  60. dwErr = CMD_ERR_CONFLICT_OPERATION;
  61. break;
  62. }
  63. *lpMode = CLMT_CURE_PROGRAM_FILES;
  64. }
  65. else if (MyStrCmpI(&argv[0][1], TEXT("cureall")) == 0)
  66. {
  67. //
  68. // This is "/Cureall" parameters
  69. //
  70. if (*lpMode > 0)
  71. {
  72. dwErr = CMD_ERR_CONFLICT_OPERATION;
  73. break;
  74. }
  75. *lpMode = CLMT_CURE_ALL;
  76. }
  77. else if (MyStrCmpI(&argv[0][1], TEXT("NoAppChk")) == 0)
  78. {
  79. //
  80. // This is "/NoAppChk" parameters
  81. //
  82. g_fNoAppChk = TRUE;
  83. }
  84. else if (MyStrCmpI(&argv[0][1], TEXT("reminder")) == 0)
  85. {
  86. //
  87. // This is "/reminder" parameters
  88. //
  89. if (*lpMode > 0)
  90. {
  91. dwErr = CMD_ERR_CONFLICT_OPERATION;
  92. break;
  93. }
  94. *lpMode = CLMT_REMINDER;
  95. }
  96. else if (MyStrCmpI(&argv[0][1], TEXT("INF")) == 0)
  97. {
  98. //
  99. // This is "/INF <inf file>" parameters
  100. // Tell the tool to use user-supply CLMT.INF
  101. //
  102. nArgc--;
  103. if (nArgc <= 0)
  104. {
  105. bRet = FALSE;
  106. break;
  107. }
  108. else
  109. {
  110. argv++;
  111. if (argv[0][0] == TEXT('/'))
  112. {
  113. // next argument is not file name
  114. bRet = FALSE;
  115. break;
  116. }
  117. else
  118. {
  119. if (FAILED(StringCchCopy(g_szInfFile, ARRAYSIZE(g_szInfFile), argv[0])))
  120. {
  121. bRet = FALSE;
  122. break;
  123. }
  124. g_fUseInf = TRUE;
  125. }
  126. }
  127. }
  128. else if (MyStrCmpI(&argv[0][1], TEXT("final")) == 0)
  129. {
  130. //
  131. // This is "/final" parameters
  132. //
  133. if (*lpMode > 0)
  134. {
  135. if (*lpMode == CLMT_CURE_PROGRAM_FILES)
  136. {
  137. *lpMode = CLMT_CURE_AND_CLEANUP;
  138. }
  139. else
  140. {
  141. dwErr = CMD_ERR_CONFLICT_OPERATION;
  142. break;
  143. }
  144. }
  145. else
  146. {
  147. *lpMode = CLMT_CLEANUP_AFTER_UPGRADE;
  148. }
  149. }
  150. else
  151. {
  152. bRet = FALSE;
  153. break;
  154. }
  155. }
  156. GlobalFree(lplpArgv);
  157. if (*lpMode == 0 && bRet == TRUE)
  158. {
  159. //
  160. // No switch is specified, we assume this is a DOMIG operation
  161. //
  162. *lpMode = CLMT_DOMIG;
  163. }
  164. if (dwErr == CMD_ERR_CONFLICT_OPERATION)
  165. {
  166. _ftprintf(stderr, TEXT("Only one operation can be specified in command line!\n\n"));
  167. bRet = FALSE;
  168. }
  169. return bRet;
  170. }
  171. int __cdecl _tmain()
  172. {
  173. DWORD dwStatus;
  174. // Set locale for run-time functions (user-default code page)
  175. _tsetlocale(LC_ALL, TEXT(""));
  176. SetConsoleCtrlHandler(NULL,TRUE);
  177. if (ProcessCommandLine(&dwStatus))
  178. {
  179. g_dwRunningStatus = dwStatus;
  180. return DoMig(dwStatus);
  181. }
  182. else
  183. {
  184. Usage();
  185. return 0;
  186. }
  187. }