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.

275 lines
7.3 KiB

  1. //Copyright (c) 1998 - 1999 Microsoft Corporation
  2. /******************************************************************************
  3. *
  4. * MIGRATE.C
  5. *
  6. * Migrate Windows 3.1 ini files, groups and reg.dat to NT registry
  7. *
  8. *
  9. *******************************************************************************/
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <windows.h>
  14. #include <winbasep.h>
  15. #include <winuserp.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <malloc.h>
  19. #include <winsta.h>
  20. #include <utilsub.h>
  21. #include "migrate.h"
  22. #include "printfoa.h"
  23. USHORT fIni = FALSE;
  24. USHORT fGroup = FALSE;
  25. USHORT fReg = FALSE;
  26. USHORT fHelp = FALSE;
  27. USHORT fDebug = FALSE;
  28. WCHAR IniPath[_MAX_PATH+1];
  29. WCHAR FullPath[_MAX_PATH+1];
  30. int FileCount;
  31. TOKMAP ptm[] = {
  32. {L" ", TMFLAG_OPTIONAL, TMFORM_STRING, _MAX_PATH, IniPath},
  33. {L"/ini", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fIni},
  34. {L"/group", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fGroup},
  35. {L"/regdata", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fReg},
  36. {L"/?", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fHelp},
  37. #if DBG
  38. {L"/debug", TMFLAG_OPTIONAL, TMFORM_BOOLEAN, sizeof(USHORT), &fDebug},
  39. #endif
  40. {0, 0, 0, 0, 0}
  41. };
  42. BOOL WINAPI Win31MigrationStatusCallback( PWSTR, PVOID );
  43. BOOL InitSystemFontInfo( VOID );
  44. void Usage( BOOLEAN );
  45. /*******************************************************************************
  46. *
  47. * main
  48. *
  49. ******************************************************************************/
  50. int __cdecl
  51. main(INT argc, CHAR **argv)
  52. {
  53. WCHAR *CmdLine;
  54. WCHAR **argvW;
  55. int i, rc, Root;
  56. BOOL Result;
  57. /*
  58. * We can't use argv[] because its always ANSI, regardless of UNICODE
  59. */
  60. CmdLine = GetCommandLineW();
  61. /*
  62. * convert from oem char set to ansi
  63. */
  64. OEM2ANSIW(CmdLine, wcslen(CmdLine));
  65. /*
  66. * Massage the new command line to look like an argv[] type
  67. * because ParseCommandLine() depends on this format
  68. */
  69. argvW = (WCHAR **)malloc( sizeof(WCHAR *) * (argc+1) );
  70. if(argvW == NULL) {
  71. PutStdErr( ERROR_NOT_ENOUGH_MEMORY, 0 );
  72. return(FAILURE);
  73. }
  74. argvW[0] = wcstok(CmdLine, L" ");
  75. for(i=1; i < argc; i++){
  76. argvW[i] = wcstok(0, L" ");
  77. }
  78. argvW[argc] = NULL;
  79. /*
  80. * parse the cmd line without parsing the program name (argc-1, argv+1)
  81. */
  82. rc = ParseCommandLine(argc-1, argvW+1, ptm, PCL_FLAG_NO_CLEAR_MEMORY);
  83. /*
  84. * Check for error from ParseCommandLine
  85. */
  86. if ( fHelp || rc ) {
  87. if ( fHelp || (rc & PARSE_FLAG_NO_PARMS) ) {
  88. Usage(FALSE);
  89. return(SUCCESS);
  90. } else {
  91. Usage(TRUE);
  92. return(FAILURE);
  93. }
  94. }
  95. /*
  96. * If path parameter was not specified, then default to current directory
  97. */
  98. if ( !(ptm[0].tmFlag & TMFLAG_PRESENT) )
  99. GetCurrentDirectoryW( sizeof(IniPath), IniPath );
  100. /*
  101. * Get full pathname and set INIDRIVE/INIPATH variables
  102. */
  103. GetFullPathNameW( IniPath, sizeof(FullPath), FullPath, NULL );
  104. Root = 2;
  105. if ( FullPath[0] == '\\' && FullPath[1] == '\\' ) {
  106. for ( i = 0; i < 2; Root++ )
  107. if ( FullPath[Root] == '\\' )
  108. i++;
  109. Root--;
  110. }
  111. FullPath[Root] = L'\0';
  112. SetEnvironmentVariableW( L"INIDRIVE", FullPath );
  113. FullPath[Root] = '\\';
  114. SetEnvironmentVariableW( L"INIPATH", &FullPath[Root] );
  115. if ( fIni ) {
  116. // printf( "Migrating .INI files from %S\n", FullPath );
  117. Message(IDS_MESSAGE_INI, FullPath);
  118. FileCount = 0;
  119. Result = SynchronizeWindows31FilesAndWindowsNTRegistry(
  120. Win31LogonEvent,
  121. WIN31_MIGRATE_INIFILES,
  122. Win31MigrationStatusCallback,
  123. NULL );
  124. if ( !Result && FileCount ) {
  125. // printf( "An error occured during .INI file migration\n" );
  126. ErrorPrintf(IDS_ERROR_INI);
  127. }
  128. }
  129. if ( fGroup ) {
  130. // printf( "Migrating .GRP files from %S\n", FullPath );
  131. Message(IDS_MESSAGE_GRP, FullPath);
  132. FileCount = 0;
  133. Result = SynchronizeWindows31FilesAndWindowsNTRegistry(
  134. Win31LogonEvent,
  135. WIN31_MIGRATE_GROUPS,
  136. Win31MigrationStatusCallback,
  137. NULL );
  138. if ( !Result && FileCount ) {
  139. // printf( "An error occured during .GRP file migration\n" );
  140. ErrorPrintf(IDS_ERROR_GRP);
  141. }
  142. }
  143. if ( fReg ) {
  144. // printf( "Migrating %S\\REG.DAT file\n", FullPath );
  145. Message(IDS_MESSAGE_REG, FullPath);
  146. FileCount = 0;
  147. Result = SynchronizeWindows31FilesAndWindowsNTRegistry(
  148. Win31SystemStartEvent,
  149. WIN31_MIGRATE_REGDAT,
  150. Win31MigrationStatusCallback,
  151. NULL );
  152. if ( !Result && FileCount ) {
  153. // printf( "An error occured during REG.DAT file migration\n" );
  154. ErrorPrintf(IDS_ERROR_REG);
  155. }
  156. #if 0
  157. InitSystemFontInfo();
  158. #endif
  159. }
  160. return(SUCCESS);
  161. } /* main() */
  162. BOOL WINAPI
  163. Win31MigrationStatusCallback(
  164. IN PWSTR Status,
  165. IN PVOID CallbackParameter
  166. )
  167. {
  168. FileCount++;
  169. // printf( " Processing %S\n", Status );
  170. Message(IDS_MESSAGE_PROCESS, Status);
  171. return( TRUE );
  172. }
  173. BOOL
  174. InitSystemFontInfo( VOID )
  175. {
  176. TCHAR *FontNames, *FontName;
  177. TCHAR FontPath[ MAX_PATH ];
  178. ULONG cb = 63 * 1024;
  179. FontNames = malloc( cb );
  180. if (FontNames == NULL) {
  181. return FALSE;
  182. }
  183. if (GetProfileString( TEXT("Fonts"), NULL, TEXT(""), FontNames, cb )) {
  184. FontName = FontNames;
  185. while (*FontName) {
  186. if (GetProfileString( TEXT("Fonts"), FontName, TEXT(""), FontPath, sizeof( FontPath ) )) {
  187. switch (AddFontResource( FontPath )) {
  188. case 0:
  189. KdPrint(("WINLOGON: Unable to add new font path: %ws\n", FontPath ));
  190. break;
  191. case 1:
  192. KdPrint(("WINLOGON: Found new font path: %ws\n", FontPath ));
  193. break;
  194. default:
  195. KdPrint(("WINLOGON: Found existing font path: %ws\n", FontPath ));
  196. RemoveFontResource( FontPath );
  197. break;
  198. }
  199. }
  200. while (*FontName++) ;
  201. }
  202. } else {
  203. KdPrint(("WINLOGON: Unable to read font info from win.ini - %u\n", GetLastError()));
  204. }
  205. free( FontNames );
  206. return TRUE;
  207. }
  208. /*******************************************************************************
  209. *
  210. * Usage
  211. *
  212. * Output the usage message for this utility.
  213. *
  214. * ENTRY:
  215. * bError (input)
  216. * TRUE if the 'invalid parameter(s)' message should preceed the usage
  217. * message and the output go to stderr; FALSE for no such error
  218. * string and output goes to stdout.
  219. *
  220. * EXIT:
  221. *
  222. *
  223. ******************************************************************************/
  224. void
  225. Usage( BOOLEAN bError )
  226. {
  227. if ( bError ) {
  228. ErrorPrintf(IDS_ERROR_INVALID_PARAMETERS);
  229. }
  230. ErrorPrintf(IDS_USAGE1);
  231. ErrorPrintf(IDS_USAGE2);
  232. ErrorPrintf(IDS_USAGE3);
  233. ErrorPrintf(IDS_USAGE4);
  234. ErrorPrintf(IDS_USAGE5);
  235. ErrorPrintf(IDS_USAGE6);
  236. ErrorPrintf(IDS_USAGE7);
  237. ErrorPrintf(IDS_USAGE8);
  238. }