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.

281 lines
9.4 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: config.h
  8. //
  9. //--------------------------------------------------------------------------
  10. #ifndef _INC_CSCVIEW_CONFIG_H
  11. #define _INC_CSCVIEW_CONFIG_H
  12. #ifndef _INC_CSCVIEW_REGISTRY_H
  13. # include "registry.h"
  14. #endif
  15. #ifndef _INC_CSCVIEW_UTILS_H
  16. # include "util.h"
  17. #endif
  18. class CConfig
  19. {
  20. public:
  21. ~CConfig(void) { }
  22. enum SyncAction
  23. {
  24. eSyncNone = -1, // No sync.
  25. eSyncPartial, // Sync only transient files at logoff.
  26. eSyncFull, // Sync all files at logoff.
  27. eNumSyncActions
  28. };
  29. enum OfflineAction
  30. {
  31. //
  32. // These MUST match the order of the IDS_GOOFFLINE_ACTION_XXXXX
  33. // string resource IDs.
  34. //
  35. eGoOfflineSilent = 0, // Silently transition share to offline mode.
  36. eGoOfflineFail, // Fail the share (NT4 behavior).
  37. eNumOfflineActions
  38. };
  39. //
  40. // Represents one custom go-offline action.
  41. //
  42. struct OfflineActionInfo
  43. {
  44. TCHAR szServer[MAX_PATH]; // Name of the associated server.
  45. int iAction; // Action code. One of enum OfflineAction.
  46. };
  47. //
  48. // Represents one entry in the customized server list.
  49. // "GOA" is "GoOfflineAction".
  50. //
  51. class CustomGOA
  52. {
  53. public:
  54. CustomGOA(void)
  55. : m_action(eGoOfflineSilent),
  56. m_bSetByPolicy(false) { m_szServer[0] = TEXT('\0'); }
  57. CustomGOA(LPCTSTR pszServer, OfflineAction action, bool bSetByPolicy)
  58. : m_action(action),
  59. m_bSetByPolicy(bSetByPolicy) { lstrcpyn(m_szServer, pszServer, ARRAYSIZE(m_szServer)); }
  60. bool operator == (const CustomGOA& rhs) const
  61. { return (m_action == rhs.m_action &&
  62. 0 == CompareByServer(rhs)); }
  63. bool operator != (const CustomGOA& rhs) const
  64. { return !(*this == rhs); }
  65. bool operator < (const CustomGOA& rhs) const;
  66. int CompareByServer(const CustomGOA& rhs) const;
  67. void SetServerName(LPCTSTR pszServer)
  68. { lstrcpyn(m_szServer, pszServer, ARRAYSIZE(m_szServer)); }
  69. void SetAction(OfflineAction action)
  70. { m_action = action; }
  71. void GetServerName(LPTSTR pszServer, UINT cchServer) const
  72. { lstrcpyn(pszServer, m_szServer, cchServer); }
  73. const LPCTSTR GetServerName(void) const
  74. { return m_szServer; }
  75. OfflineAction GetAction(void) const
  76. { return m_action; }
  77. bool SetByPolicy(void) const
  78. { return m_bSetByPolicy; }
  79. private:
  80. TCHAR m_szServer[MAX_PATH]; // The name of the server.
  81. OfflineAction m_action; // The action code.
  82. bool m_bSetByPolicy; // Was action set by policy?
  83. };
  84. //
  85. // Iterator for enumerating custom go-offline actions.
  86. //
  87. class OfflineActionIter
  88. {
  89. public:
  90. OfflineActionIter(const CConfig *pConfig = NULL);
  91. ~OfflineActionIter(void);
  92. HRESULT Next(OfflineActionInfo *pInfo);
  93. void Reset(void)
  94. { m_iAction = 0; }
  95. private:
  96. CConfig *m_pConfig;
  97. HDPA m_hdpaGOA;
  98. int m_iAction;
  99. };
  100. static CConfig& GetSingleton(void);
  101. bool CscEnabled(bool *pbSetByPolicy = NULL) const
  102. { return boolify(GetValue(iVAL_CSCENABLED, pbSetByPolicy)); }
  103. DWORD DefaultCacheSize(bool *pbSetByPolicy = NULL) const
  104. { return GetValue(iVAL_DEFCACHESIZE, pbSetByPolicy); }
  105. int EventLoggingLevel(bool *pbSetByPolicy = NULL) const
  106. { return int(GetValue(iVAL_EVENTLOGGINGLEVEL, pbSetByPolicy)); }
  107. bool FirstPinWizardShown(void) const
  108. { return boolify(GetValue(iVAL_FIRSTPINWIZARDSHOWN)); }
  109. void GetCustomGoOfflineActions(HDPA hdpaGOA, bool *pbSetByPolicy = NULL);
  110. int GoOfflineAction(bool *pbSetByPolicy = NULL) const
  111. { return int(GetValue(iVAL_GOOFFLINEACTION, pbSetByPolicy)); }
  112. int GoOfflineAction(LPCTSTR pszServer) const;
  113. int InitialBalloonTimeoutSeconds(bool *pbSetByPolicy = NULL) const
  114. { return int(GetValue(iVAL_INITIALBALLOONTIMEOUTSECONDS, pbSetByPolicy)); }
  115. bool NoCacheViewer(bool *pbSetByPolicy = NULL) const
  116. { return boolify(GetValue(iVAL_NOCACHEVIEWER, pbSetByPolicy)); }
  117. bool NoConfigCache(bool *pbSetByPolicy = NULL) const
  118. { return boolify(GetValue(iVAL_NOCONFIGCACHE, pbSetByPolicy)); }
  119. bool NoMakeAvailableOffline(bool *pbSetByPolicy = NULL) const
  120. { return boolify(GetValue(iVAL_NOMAKEAVAILABLEOFFLINE, pbSetByPolicy)); }
  121. bool NoReminders(bool *pbSetByPolicy = NULL) const
  122. { return boolify(GetValue(iVAL_NOREMINDERS, pbSetByPolicy)); }
  123. bool PurgeAtLogoff(bool *pbSetByPolicy = NULL) const
  124. { return boolify(GetValue(iVAL_PURGEATLOGOFF, pbSetByPolicy)); }
  125. bool PurgeOnlyAutoCachedFilesAtLogoff(bool *pbSetByPolicy = NULL) const
  126. { return boolify(GetValue(iVAL_PURGEONLYAUTOCACHEATLOGOFF, pbSetByPolicy)); }
  127. bool AlwaysPinSubFolders(bool *pbSetByPolicy = NULL) const
  128. { return boolify(GetValue(iVAL_ALWAYSPINSUBFOLDERS, pbSetByPolicy)); }
  129. bool NoAdminPinSpecialFolders(bool *pbSetByPolicy = NULL) const
  130. { return boolify(GetValue(iVAL_NOFRADMINPIN, pbSetByPolicy)); }
  131. bool EncryptCache(bool *pbSetByPolicy = NULL) const
  132. { return boolify(GetValue(iVAL_ENCRYPTCACHE, pbSetByPolicy)); }
  133. int ReminderBalloonTimeoutSeconds(bool *pbSetByPolicy = NULL) const
  134. { return int(GetValue(iVAL_REMINDERBALLOONTIMEOUTSECONDS, pbSetByPolicy)); }
  135. int ReminderFreqMinutes(bool *pbSetByPolicy = NULL) const
  136. { return int(GetValue(iVAL_REMINDERFREQMINUTES, pbSetByPolicy)); }
  137. int SyncAtLogoff(bool *pbSetByPolicy = NULL) const
  138. { return int(GetValue(iVAL_SYNCATLOGOFF, pbSetByPolicy)); }
  139. int SyncAtLogon(bool *pbSetByPolicy = NULL) const
  140. { return int(GetValue(iVAL_SYNCATLOGON, pbSetByPolicy)); }
  141. int SyncAtSuspend(bool *pbSetByPolicy = NULL) const
  142. { return int(GetValue(iVAL_SYNCATSUSPEND, pbSetByPolicy)); }
  143. int SlowLinkSpeed(bool *pbSetByPolicy = NULL) const
  144. { return int(GetValue(iVAL_SLOWLINKSPEED, pbSetByPolicy)); }
  145. OfflineActionIter CreateOfflineActionIter(void) const
  146. { return OfflineActionIter(this); }
  147. static HRESULT SaveCustomGoOfflineActions(RegKey& key, HDPA hdpaGOA);
  148. static void ClearCustomGoOfflineActions(HDPA hdpaGOA);
  149. private:
  150. //
  151. // Indexes into s_rgpszSubkeys[].
  152. //
  153. enum eSubkeys
  154. {
  155. iSUBKEY_PREF,
  156. iSUBKEY_POL,
  157. MAX_SUBKEYS
  158. };
  159. //
  160. // Indexes into s_rgpszValues[].
  161. //
  162. enum eValues
  163. {
  164. iVAL_DEFCACHESIZE,
  165. iVAL_CSCENABLED,
  166. iVAL_GOOFFLINEACTION,
  167. iVAL_NOCONFIGCACHE,
  168. iVAL_NOCACHEVIEWER,
  169. iVAL_NOMAKEAVAILABLEOFFLINE,
  170. iVAL_SYNCATLOGOFF,
  171. iVAL_SYNCATLOGON,
  172. iVAL_SYNCATSUSPEND,
  173. iVAL_NOREMINDERS,
  174. iVAL_REMINDERFREQMINUTES,
  175. iVAL_INITIALBALLOONTIMEOUTSECONDS,
  176. iVAL_REMINDERBALLOONTIMEOUTSECONDS,
  177. iVAL_EVENTLOGGINGLEVEL,
  178. iVAL_PURGEATLOGOFF,
  179. iVAL_PURGEONLYAUTOCACHEATLOGOFF,
  180. iVAL_FIRSTPINWIZARDSHOWN,
  181. iVAL_SLOWLINKSPEED,
  182. iVAL_ALWAYSPINSUBFOLDERS,
  183. iVAL_ENCRYPTCACHE,
  184. iVAL_NOFRADMINPIN,
  185. MAX_VALUES
  186. };
  187. //
  188. // Mask to specify source of a config value.
  189. //
  190. enum eSources
  191. {
  192. eSRC_PREF_CU = 0x00000001,
  193. eSRC_PREF_LM = 0x00000002,
  194. eSRC_POL_CU = 0x00000004,
  195. eSRC_POL_LM = 0x00000008,
  196. eSRC_POL = eSRC_POL_LM | eSRC_POL_CU,
  197. eSRC_PREF = eSRC_PREF_LM | eSRC_PREF_CU
  198. };
  199. static LPCTSTR s_rgpszSubkeys[MAX_SUBKEYS];
  200. static LPCTSTR s_rgpszValues[MAX_VALUES];
  201. DWORD GetValue(eValues iValue, bool *pbSetByPolicy = NULL) const;
  202. bool CustomGOAExists(HDPA hdpaGOA, const CustomGOA& goa);
  203. static bool IsValidGoOfflineAction(DWORD dwAction)
  204. { return ((OfflineAction)dwAction == eGoOfflineSilent ||
  205. (OfflineAction)dwAction == eGoOfflineFail); }
  206. static bool IsValidSyncAction(DWORD dwAction)
  207. { return ((SyncAction)dwAction == eSyncPartial ||
  208. (SyncAction)dwAction == eSyncFull); }
  209. //
  210. // Enforce use of GetSingleton() for instantiation.
  211. //
  212. CConfig(void) { }
  213. //
  214. // Prevent copy.
  215. //
  216. CConfig(const CConfig& rhs);
  217. CConfig& operator = (const CConfig& rhs);
  218. };
  219. #endif // _INC_CSCVIEW_CONFIG_H