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.

150 lines
4.1 KiB

  1. // gfldset.cpp
  2. //
  3. // A class that manages global folder settings.
  4. #include "priv.h"
  5. #include "sccls.h"
  6. class CGlobalFolderSettings : public IGlobalFolderSettings
  7. {
  8. public:
  9. // *** IUnknown methods ***
  10. STDMETHOD(QueryInterface)(THIS_ REFIID riid, LPVOID * ppvObj);
  11. STDMETHOD_(ULONG,AddRef)(THIS);
  12. STDMETHOD_(ULONG,Release)(THIS);
  13. // *** IGlobalFolderSettings meTHODs ***
  14. STDMETHOD(Get)(THIS_ DEFFOLDERSETTINGS *pdfs, int cbDfs);
  15. STDMETHOD(Set)(THIS_ const DEFFOLDERSETTINGS *pdfs, int cbDfs, UINT flags);
  16. protected:
  17. friend HRESULT CGlobalFolderSettings_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi);
  18. CGlobalFolderSettings();
  19. ~CGlobalFolderSettings();
  20. LONG m_cRef;
  21. };
  22. STDAPI CGlobalFolderSettings_CreateInstance(IUnknown* pUnkOuter, IUnknown** ppunk, LPCOBJECTINFO poi)
  23. {
  24. // class factory will take care of denying aggregation and giving a null
  25. // back on failure
  26. ASSERT(pUnkOuter == NULL);
  27. CGlobalFolderSettings* pid = new CGlobalFolderSettings();
  28. if (pid)
  29. {
  30. *ppunk = SAFECAST(pid, IGlobalFolderSettings*);
  31. return S_OK;
  32. }
  33. else
  34. {
  35. return E_OUTOFMEMORY;
  36. }
  37. }
  38. /////////////////////////////////////////////////////////////////////////////////////////////////////
  39. CGlobalFolderSettings::CGlobalFolderSettings() : m_cRef(1)
  40. {
  41. }
  42. /////////////////////////////////////////////////////////////////////////////////////////////////////
  43. CGlobalFolderSettings::~CGlobalFolderSettings()
  44. {
  45. }
  46. /////////////////////////////////////////////////////////////////////////////////////////////////////
  47. STDMETHODIMP CGlobalFolderSettings::QueryInterface ( REFIID riid, LPVOID * ppvObj )
  48. {
  49. if ( riid == IID_IUnknown || riid == IID_IGlobalFolderSettings)
  50. {
  51. *ppvObj = SAFECAST( this, IGlobalFolderSettings *);
  52. AddRef();
  53. }
  54. else
  55. {
  56. return E_NOINTERFACE;
  57. }
  58. return NOERROR;
  59. }
  60. /////////////////////////////////////////////////////////////////////////////////////////////////////
  61. STDMETHODIMP_( ULONG ) CGlobalFolderSettings:: AddRef ()
  62. {
  63. InterlockedIncrement( &m_cRef );
  64. return m_cRef;
  65. }
  66. /////////////////////////////////////////////////////////////////////////////////////////////////////
  67. STDMETHODIMP_( ULONG ) CGlobalFolderSettings:: Release ()
  68. {
  69. if ( InterlockedDecrement( &m_cRef ) == 0 )
  70. {
  71. delete this;
  72. return 0;
  73. }
  74. return m_cRef;
  75. }
  76. /////////////////////////////////////////////////////////////////////////////////////////////////////
  77. STDMETHODIMP CGlobalFolderSettings::Get(DEFFOLDERSETTINGS *pdfs, int cbDfs)
  78. {
  79. if (cbDfs < sizeof(DEFFOLDERSETTINGS_W2K))
  80. {
  81. return E_INVALIDARG;
  82. }
  83. else if (cbDfs > sizeof(DEFFOLDERSETTINGS))
  84. {
  85. ZeroMemory(pdfs, cbDfs);
  86. }
  87. CopyMemory(pdfs, &g_dfs, min(cbDfs, sizeof(g_dfs)));
  88. return S_OK;
  89. }
  90. /////////////////////////////////////////////////////////////////////////////////////////////////////
  91. STDMETHODIMP CGlobalFolderSettings::Set(const DEFFOLDERSETTINGS *pdfs, int cbDfs, UINT flags)
  92. {
  93. if (flags & ~GFSS_VALID) {
  94. ASSERT(!"Invalid flags passed to CGlobalFolderSettings::Set");
  95. return E_INVALIDARG;
  96. }
  97. //
  98. // Special hack: If you pass (NULL, 0) then it means "reset to
  99. // default".
  100. //
  101. if (pdfs == NULL)
  102. {
  103. if (cbDfs == 0)
  104. {
  105. static DEFFOLDERSETTINGS dfs = INIT_DEFFOLDERSETTINGS;
  106. dfs.vid = g_bRunOnNT5 ? VID_LargeIcons : DFS_VID_Default;
  107. pdfs = &dfs;
  108. cbDfs = sizeof(dfs);
  109. }
  110. else
  111. {
  112. return E_INVALIDARG;
  113. }
  114. }
  115. else if (cbDfs < sizeof(DEFFOLDERSETTINGS_W2K))
  116. {
  117. ASSERT(!"Invalid cbDfs passed to CGlobalFolderSettings::Set");
  118. return E_INVALIDARG;
  119. }
  120. // Preserve the dwDefRevCount, otherwise we'll never be able
  121. // to tell if the structure has been revised!
  122. DWORD dwDefRevCount = g_dfs.dwDefRevCount;
  123. CopyMemory(&g_dfs, pdfs, min(cbDfs, sizeof(g_dfs)));
  124. g_dfs.dwDefRevCount = dwDefRevCount;
  125. SaveDefaultFolderSettings(flags);
  126. return S_OK;
  127. }