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.

154 lines
3.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. // Copyright (C) Microsoft Corporation, 1999 - 1999.
  5. //
  6. // File: remcat.cxx
  7. //
  8. // Contents: Removable catalog registry support
  9. //
  10. // Classes: CRemovableCatalog
  11. //
  12. // History: 6-Apr-99 dlee Created.
  13. //
  14. //----------------------------------------------------------------------------
  15. #include <pch.cxx>
  16. #pragma hdrstop
  17. #include <isreg.hxx>
  18. #include <ciregkey.hxx>
  19. #include <removcat.hxx>
  20. extern WCHAR GetDriveLetterOfAnyScope( WCHAR const * pwcCatalog );
  21. //+-------------------------------------------------------------------------
  22. //
  23. // Method: CRemovableCatalog::Create, public
  24. //
  25. // Synopsis: Creates temporary registry entries for the catalog
  26. //
  27. // History: 6-Apr-99 dlee Created.
  28. //
  29. //--------------------------------------------------------------------------
  30. void CRemovableCatalog::Create()
  31. {
  32. // First, remove any existing values for the catalog
  33. Destroy();
  34. // Make the catalog key
  35. WCHAR awcCat[40];
  36. MakeCatalogName( awcCat );
  37. BOOL fExisted;
  38. {
  39. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, wcsRegCatalogsSubKey );
  40. reg.CreateKey( awcCat, fExisted );
  41. }
  42. // Add values for this catalog under the key
  43. WCHAR awcCatalog[200];
  44. wsprintf( awcCatalog, L"%ws\\%ws", wcsRegCatalogsSubKey, awcCat );
  45. WCHAR awcScopes[ 200 ];
  46. wsprintf( awcScopes, L"%ws\\%ws", awcCatalog, wcsCatalogScopes );
  47. {
  48. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, awcCatalog );
  49. // Set the catalog location
  50. WCHAR awcLocation[4];
  51. wcscpy( awcLocation, L"x:\\" );
  52. awcLocation[0] = _wcDrive;
  53. reg.Set( wcsCatalogLocation, awcLocation );
  54. //
  55. // Make the catalog read-only, mark it as removable, and force
  56. // path aliases so drive letters in paths returned in queries
  57. // match the drive letter of the removable drive.
  58. //
  59. reg.Set( wcsIsReadOnly, TRUE );
  60. reg.Set( wcsIsRemovableCatalog, TRUE );
  61. reg.Set( wcsForcePathAlias, TRUE );
  62. reg.CreateKey( wcsCatalogScopes, fExisted );
  63. }
  64. //
  65. // Add a fixup for the root of the volume in case the drive letter
  66. // is different from where the catalog was built.
  67. //
  68. WCHAR awcPath[ 20 ];
  69. wcscpy( awcPath, L"x:\\catalog.wci" );
  70. awcPath[0] = _wcDrive;
  71. WCHAR wcScope = GetDriveLetterOfAnyScope( awcPath );
  72. ciDebugOut(( DEB_ITRACE, "scope drive: '%wc'\n", wcScope ));
  73. if ( 0 != wcScope )
  74. {
  75. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, awcScopes );
  76. WCHAR awcValue[10];
  77. wcscpy( awcValue, L"x:\\,," );
  78. awcValue[0] = _wcDrive;
  79. WCHAR awcScope[10];
  80. wcscpy( awcScope, L"x:\\" );
  81. awcScope[0] = wcScope;
  82. reg.Set( awcScope, awcValue );
  83. }
  84. } //Create
  85. //+-------------------------------------------------------------------------
  86. //
  87. // Method: CRemovableCatalog::Destroy, public
  88. //
  89. // Synopsis: Destroys temporary registry entries for the catalog
  90. //
  91. // History: 6-Apr-99 dlee Created.
  92. //
  93. //--------------------------------------------------------------------------
  94. void CRemovableCatalog::Destroy()
  95. {
  96. // Ignore failures here...
  97. WCHAR awcCat[40];
  98. MakeCatalogName( awcCat );
  99. WCHAR awcCatalog[200];
  100. wsprintf( awcCatalog, L"%ws\\%ws", wcsRegCatalogsSubKey, awcCat );
  101. TRY
  102. {
  103. // Remove the scopes and properties keys
  104. {
  105. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, awcCatalog );
  106. reg.RemoveKey( wcsCatalogScopes );
  107. reg.RemoveKey( wcsCatalogProperties );
  108. }
  109. // Remove the catalog key
  110. {
  111. CWin32RegAccess reg( HKEY_LOCAL_MACHINE, wcsRegCatalogsSubKey );
  112. reg.RemoveKey( awcCat );
  113. }
  114. }
  115. CATCH( CException, e )
  116. {
  117. // ignore it -- we tried.
  118. }
  119. END_CATCH
  120. } //Destroy