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.

368 lines
10 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1998 - 1999.
  5. //
  6. // File: tcatcnfg.cxx
  7. //
  8. // Contents: Test program for catalog configuration
  9. //
  10. // History: 24 Nov 1998 AlanW Created
  11. //
  12. //--------------------------------------------------------------------------
  13. #include "pch.cxx"
  14. #pragma hdrstop
  15. #include "catcnfg.hxx"
  16. WCHAR g_awcProfilePath[MAX_PATH];
  17. const WCHAR wszRegProfileKey[] =
  18. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
  19. const WCHAR wszRegProfileValue[] = L"ProfilesDirectory";
  20. //
  21. // DLL module instance handle
  22. //
  23. HINSTANCE MyModuleHandle = (HINSTANCE)INVALID_HANDLE_VALUE;
  24. ULONG isInfoLevel;
  25. inline ULONG MB( ULONGLONG cb )
  26. {
  27. const ONE_MB = (1024*1024);
  28. return (ULONG) ((cb+ONE_MB/2) / ONE_MB);
  29. }
  30. void PrintDriveInfo( CCatalogConfig & CatConfig );
  31. void ExcludeSpecialLocations( CCatalogConfig & Cat );
  32. WCHAR g_awcSystemDir[MAX_PATH];
  33. __cdecl main()
  34. {
  35. CError Err;
  36. GetSystemDirectory( g_awcSystemDir,
  37. sizeof g_awcSystemDir / sizeof WCHAR );
  38. CCatalogConfig CatConfig(Err);
  39. CatConfig.InitDriveList();
  40. //printf("\nBefore pagefile reservation:\n" );
  41. //PrintDriveInfo( CatConfig );
  42. //CatConfig.ReservePageFileData();
  43. printf("\nBefore catalog configuration:\n" );
  44. PrintDriveInfo( CatConfig );
  45. //
  46. // Find the default profile path (Usually %windir%\Profiles)
  47. //
  48. CWin32RegAccess regProfileKey( HKEY_LOCAL_MACHINE, wszRegProfileKey );
  49. g_awcProfilePath[0] = L'\0';
  50. WCHAR wcTemp[MAX_PATH+1];
  51. if ( regProfileKey.Get( wszRegProfileValue, wcTemp, NUMELEM(wcTemp) ) )
  52. {
  53. unsigned ccTemp2 = ExpandEnvironmentStrings( wcTemp,
  54. g_awcProfilePath,
  55. NUMELEM(g_awcProfilePath) );
  56. }
  57. CatConfig.ConfigureDefaultCatalog(g_awcProfilePath);
  58. ExcludeSpecialLocations( CatConfig );
  59. printf("\nAfter catalog configuration:\n" );
  60. PrintDriveInfo( CatConfig );
  61. printf("\nCatalog drive:\n\t%ws\n", CatConfig.GetCatalogDrive());
  62. WCHAR const * pwszScope;
  63. for (unsigned i = 0; pwszScope = CatConfig.GetIncludedScope( i ); i++)
  64. {
  65. if ( 0 == i )
  66. printf("\nIncluded scopes:\n");
  67. printf("\t%ws\n", pwszScope );
  68. }
  69. for (i = 0; pwszScope = CatConfig.GetExcludedScope( i ); i++)
  70. {
  71. if ( 0 == i )
  72. printf("\nExcluded scopes:\n");
  73. printf("\t%ws\n", pwszScope );
  74. }
  75. return 0;
  76. }
  77. void PrintDriveInfo( CCatalogConfig & CatConfig )
  78. {
  79. printf("Drive\tFree MB Resv MB Tot. MB\n");
  80. CDriveInformation const * pDriveInfo = 0;
  81. for ( unsigned i=0;
  82. pDriveInfo = CatConfig.GetDriveInfo(i);
  83. i++ )
  84. {
  85. printf("%s\t%7d\t%7d\t%7d",
  86. pDriveInfo->GetDriveName(),
  87. MB(pDriveInfo->GetAvailableSpace()),
  88. MB(pDriveInfo->GetReservedSpace()),
  89. MB(pDriveInfo->GetTotalSpace()) );
  90. if ( pDriveInfo->IsNtfs() )
  91. printf(" NTFS");
  92. else if ( !pDriveInfo->IsBootDrive() )
  93. printf(" FAT");
  94. if ( pDriveInfo->IsSystemDrive() )
  95. printf(" SystemDrive");
  96. if ( pDriveInfo->IsBootDrive() )
  97. printf(" BootDrive");
  98. //if ( pDriveInfo->IsNtfs() )
  99. // printf(" SupportsSecurity");
  100. //if ( pDriveInfo->SupportsCompression() )
  101. // printf(" SupportsCompression");
  102. if ( pDriveInfo->HasPageFile() )
  103. printf(" PageFile");
  104. printf("\n");
  105. }
  106. return;
  107. }
  108. //+-------------------------------------------------------------------------
  109. //
  110. // Function: ISError
  111. //
  112. // Synopsis: Reports a non-recoverable Index Server Install error
  113. //
  114. // Arguments: id -- resource identifier for the error string
  115. //
  116. // History: 8-Jan-97 dlee Created
  117. //
  118. //--------------------------------------------------------------------------
  119. void ISError( UINT id, CError &Err, LogSeverity Severity )
  120. {
  121. // CResString msg( id );
  122. // CResString title( IS_MSG_INDEX_SERVER );
  123. Err.Report( Severity, L"Error 0x%08x\n", id );
  124. if ( LogSevFatalError == Severity )
  125. {
  126. //isDebugOut(( "ISError, abort install: '%ws'\n", msg.Get() ));
  127. //g_fInstallAborted = TRUE;
  128. exit( 1 );
  129. }
  130. } //ISError
  131. CError::CError( )
  132. {
  133. }
  134. CError::~CError( )
  135. {
  136. }
  137. void CError::Report( LogSeverity Severity, WCHAR const * MessageString, ...)
  138. {
  139. va_list va;
  140. va_start(va, MessageString);
  141. wvsprintf(_awcMsg, MessageString, va);
  142. va_end(va);
  143. wprintf(L"setupqry: %s\r\n", _awcMsg);
  144. }
  145. //+-------------------------------------------------------------------------
  146. //
  147. // Function: ExcludeSpecialLocations, private
  148. //
  149. // Synopsis: Writes profile-based exclude scopes into the registry
  150. //
  151. // Arguments: none
  152. //
  153. // History: 28-Aug-1998 KyleP Created
  154. //
  155. //--------------------------------------------------------------------------
  156. WCHAR const wszRegShellSpecialPathsKey[] =
  157. L".DEFAULT\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
  158. WCHAR const * const awszRegShellSpecialPathsValue[] = {
  159. L"AppData",
  160. L"Cache",
  161. L"Local Settings"
  162. };
  163. WCHAR const wszUserProfile[] = L"%USERPROFILE%";
  164. void ExcludeSpecialLocations( CCatalogConfig & Cat )
  165. {
  166. // CWin32RegAccess regScopes( HKEY_LOCAL_MACHINE, wcsRegSystemScopesSubKey );
  167. //
  168. // First, find the default profile path (Usually %windir%\Profiles)
  169. //
  170. WCHAR wcTemp[MAX_PATH+1];
  171. if ( g_awcProfilePath[0] )
  172. {
  173. WCHAR wcTemp2[MAX_PATH+1];
  174. wcscpy( wcTemp2, g_awcProfilePath );
  175. unsigned ccTemp2 = wcslen( wcTemp2 );
  176. //
  177. // Append the wildcard, for user profile directory
  178. //
  179. wcscpy( wcTemp2 + ccTemp2, L"\\*\\" );
  180. ccTemp2 += 3;
  181. //
  182. // Go through and look for special shell paths, which just happen
  183. // to include all our special cases too.
  184. //
  185. CWin32RegAccess regShellSpecialPathsKey( HKEY_USERS, wszRegShellSpecialPathsKey );
  186. for ( unsigned i = 0;
  187. i < NUMELEM(awszRegShellSpecialPathsValue);
  188. i++ )
  189. {
  190. if ( regShellSpecialPathsKey.Get( awszRegShellSpecialPathsValue[i],
  191. wcTemp, NUMELEM(wcTemp) ) )
  192. {
  193. if ( RtlEqualMemory( wszUserProfile, wcTemp, sizeof(wszUserProfile) - sizeof(WCHAR) ) )
  194. {
  195. wcscpy( wcTemp2 + ccTemp2, wcTemp + NUMELEM(wszUserProfile) );
  196. wcscpy( wcTemp, wcTemp2 );
  197. }
  198. else if ( wcschr( wcTemp, L'%' ) != 0 )
  199. {
  200. WCHAR wcTemp3[MAX_PATH+1];
  201. unsigned ccTemp3 = ExpandEnvironmentStrings(
  202. wcTemp,
  203. wcTemp3,
  204. NUMELEM(wcTemp3) );
  205. if ( 0 != ccTemp3 )
  206. wcscpy( wcTemp, wcTemp3 );
  207. }
  208. wcscat( wcTemp, L"\\*" );
  209. isDebugOut(( "Exclude: %ws\n", wcTemp ));
  210. Cat.AddExcludedDirOrPattern( wcTemp );
  211. }
  212. }
  213. }
  214. }
  215. #if 0
  216. //+-------------------------------------------------------------------------
  217. //
  218. // Function: ExcludeSpecialLocations, private
  219. //
  220. // Synopsis: Writes profile-based exclude scopes into the registry
  221. //
  222. // Arguments: none
  223. //
  224. // History: 28-Aug-1998 KyleP Created
  225. //
  226. //--------------------------------------------------------------------------
  227. WCHAR const wszRegProfileKey[] =
  228. L"Software\\Microsoft\\Windows NT\\CurrentVersion\\ProfileList";
  229. WCHAR const wszRegProfileValue[] = L"ProfilesDirectory";
  230. WCHAR const wszRegShellSpecialPathsKey[] =
  231. L".DEFAULT\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\User Shell Folders";
  232. WCHAR const * const awszRegShellSpecialPathsValue[] = {
  233. L"AppData",
  234. L"Cache",
  235. L"Local Settings"
  236. };
  237. WCHAR const wszUserProfile[] = L"%USERPROFILE%";
  238. void ExcludeSpecialLocations( CCatalogConfig & Cat )
  239. {
  240. // CWin32RegAccess regScopes( HKEY_LOCAL_MACHINE, wcsRegSystemScopesSubKey );
  241. //
  242. // First, find the default profile path (Usually %windir%\Profiles)
  243. //
  244. CWin32RegAccess regProfileKey( HKEY_LOCAL_MACHINE, wszRegProfileKey );
  245. WCHAR wcTemp[MAX_PATH+1];
  246. if ( regProfileKey.Get( wszRegProfileValue, wcTemp, NUMELEM(wcTemp) ) )
  247. {
  248. WCHAR wcTemp2[MAX_PATH+1];
  249. unsigned ccTemp2 = ExpandEnvironmentStrings( wcTemp, wcTemp2, NUMELEM(wcTemp2) );
  250. if ( 0 != ccTemp2 )
  251. {
  252. //
  253. // Append the wildcard, for user profile directory
  254. //
  255. ccTemp2--; // don't include null terminator
  256. wcscpy( wcTemp2 + ccTemp2, L"\\*\\" );
  257. ccTemp2 += 3;
  258. //
  259. // Go through and look for special shell paths, which just happen
  260. // to include all our special cases too.
  261. //
  262. CWin32RegAccess regShellSpecialPathsKey( HKEY_USERS, wszRegShellSpecialPathsKey );
  263. for ( unsigned i = 0;
  264. i < NUMELEM(awszRegShellSpecialPathsValue);
  265. i++ )
  266. {
  267. if ( regShellSpecialPathsKey.Get( awszRegShellSpecialPathsValue[i], wcTemp, NUMELEM(wcTemp) ) )
  268. {
  269. if ( RtlEqualMemory( wszUserProfile, wcTemp, sizeof(wszUserProfile) - sizeof(WCHAR) ) )
  270. {
  271. wcscpy( wcTemp2 + ccTemp2, wcTemp + NUMELEM(wszUserProfile) );
  272. wcscpy( wcTemp, wcTemp2 );
  273. }
  274. else if ( wcschr( wcTemp, L'%' ) != 0 )
  275. {
  276. WCHAR wcTemp3[MAX_PATH+1];
  277. unsigned ccTemp3 = ExpandEnvironmentStrings( wcTemp, wcTemp3, NUMELEM(wcTemp3) );
  278. if ( 0 != ccTemp3 )
  279. wcscpy( wcTemp, wcTemp3 );
  280. }
  281. wcscat( wcTemp, L"\\*" );
  282. isDebugOut(( "Exclude: %ws\n", wcTemp ));
  283. Cat.AddExcludedDirOrPattern( wcTemp );
  284. }
  285. }
  286. }
  287. }
  288. }
  289. #endif //0