Leaked source code of windows server 2003
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.

271 lines
8.2 KiB

  1. /*******************************************************************************
  2. *
  3. * (C) COPYRIGHT MICROSOFT CORPORATION, 1998, 1999, 2000
  4. *
  5. * TITLE: SSDATA.CPP
  6. *
  7. * VERSION: 1.0
  8. *
  9. * AUTHOR: ShaunIv
  10. *
  11. * DATE: 1/13/1999
  12. *
  13. * DESCRIPTION: Encapsulates reading and writing setting for this screensaver
  14. * from the registry
  15. *
  16. *******************************************************************************/
  17. #include "precomp.h"
  18. #pragma hdrstop
  19. #include "ssdata.h"
  20. #include <shlobj.h>
  21. #include "simreg.h"
  22. #include "ssutil.h"
  23. // These are defined so I can build using vc5 headers
  24. #if !defined(CSIDL_WINDOWS)
  25. #define CSIDL_WINDOWS 0x0024 // GetWindowsDirectory()
  26. #endif
  27. #if !defined(CSIDL_MYPICTURES)
  28. #define CSIDL_MYPICTURES 0x0027 // C:\Program Files\My Pictures
  29. #endif
  30. CMyDocsScreenSaverData::CMyDocsScreenSaverData( HKEY hKeyRoot, const CSimpleString &strRegistryKeyName )
  31. : m_hKeyRoot(hKeyRoot),
  32. m_strRegistryKeyName(strRegistryKeyName),
  33. m_strImageDirectory(TEXT("")),
  34. m_nPaintTimerInterval(0),
  35. m_nChangeTimerInterval(0),
  36. m_bDisplayFilename(0),
  37. m_nMaxScreenPercent(0),
  38. m_bDisableTransitions(0),
  39. m_bAllowStretching(false),
  40. m_bAllowKeyboardControl(true),
  41. m_nMaxFailedFiles(0),
  42. m_nMaxSuccessfulFiles(0),
  43. m_nMaxDirectories(0),
  44. m_pszImageDirectoryValue(TEXT("ImageDirectory")),
  45. m_pszPaintIntervalValue(TEXT("PaintInterval")),
  46. m_pszChangeIntervalValue(TEXT("ChangeInterval")),
  47. m_pszDisplayFilename(TEXT("DisplayFilename")),
  48. m_pszMaxScreenPercent(TEXT("MaxScreenPercent")),
  49. m_pszDisableTransitions(TEXT("DisableTransitions")),
  50. m_pszAllowStretching(TEXT("AllowStretching")),
  51. m_pszAllowKeyboardControl(TEXT("AllowKeyboardControl")),
  52. m_pszMaxFailedFiles(TEXT("MaxFailedFiles")),
  53. m_pszMaxSuccessfulFiles(TEXT("MaxSuccessfulFiles")),
  54. m_pszMaxDirectories(TEXT("MaxDirectories"))
  55. {
  56. Read();
  57. }
  58. CMyDocsScreenSaverData::~CMyDocsScreenSaverData(void)
  59. {
  60. }
  61. void CMyDocsScreenSaverData::Read(void)
  62. {
  63. CSimpleReg reg( m_hKeyRoot, m_strRegistryKeyName, false, KEY_READ );
  64. m_strImageDirectory = reg.Query( m_pszImageDirectoryValue, GetDefaultImageDir() );
  65. m_nPaintTimerInterval = reg.Query( m_pszPaintIntervalValue, nDefaultPaintInterval );
  66. m_nChangeTimerInterval = reg.Query( m_pszChangeIntervalValue, nDefaultChangeInterval );
  67. m_bDisplayFilename = (reg.Query( m_pszDisplayFilename, bDefaultDisplayFilename ) != 0);
  68. m_nMaxScreenPercent = reg.Query( m_pszMaxScreenPercent, nDefaultScreenPercent );
  69. m_bDisableTransitions = (reg.Query( m_pszDisableTransitions, bDefaultDisableTransitions ) != 0);
  70. m_bAllowStretching = (reg.Query( m_pszAllowStretching, bDefaultAllowStretching ) != 0);
  71. m_bAllowKeyboardControl = (reg.Query( m_pszAllowKeyboardControl, bDefaultAllowKeyboardControl ) != 0);
  72. m_nMaxFailedFiles = reg.Query( m_pszMaxFailedFiles, nDefaultMaxFailedFiles );
  73. m_nMaxSuccessfulFiles = reg.Query( m_pszMaxSuccessfulFiles, nDefaultMaxSuccessfulFiles );
  74. m_nMaxDirectories = reg.Query( m_pszMaxDirectories, nDefaultMaxDirectories );
  75. }
  76. void CMyDocsScreenSaverData::Write(void)
  77. {
  78. CSimpleReg reg( m_hKeyRoot, m_strRegistryKeyName, true, KEY_WRITE );
  79. //
  80. // If we don't have a directory, we will delete the value to cause the default to be used instead
  81. //
  82. if (!m_strImageDirectory.Length())
  83. {
  84. reg.Delete( m_pszImageDirectoryValue );
  85. }
  86. else
  87. {
  88. reg.Set( m_pszImageDirectoryValue, m_strImageDirectory );
  89. }
  90. reg.Set( m_pszPaintIntervalValue, m_nPaintTimerInterval );
  91. reg.Set( m_pszChangeIntervalValue, m_nChangeTimerInterval );
  92. reg.Set( m_pszDisplayFilename, (DWORD)m_bDisplayFilename );
  93. reg.Set( m_pszMaxScreenPercent, m_nMaxScreenPercent );
  94. reg.Set( m_pszDisableTransitions, (DWORD)m_bDisableTransitions );
  95. reg.Set( m_pszAllowStretching, (DWORD)m_bAllowStretching );
  96. reg.Set( m_pszAllowKeyboardControl, (DWORD)m_bAllowKeyboardControl );
  97. reg.Set( m_pszMaxFailedFiles, m_nMaxFailedFiles );
  98. reg.Set( m_pszMaxSuccessfulFiles, m_nMaxSuccessfulFiles );
  99. reg.Set( m_pszMaxDirectories, m_nMaxDirectories );
  100. }
  101. CSimpleString CMyDocsScreenSaverData::ImageDirectory(void) const
  102. {
  103. return(m_strImageDirectory);
  104. }
  105. void CMyDocsScreenSaverData::ImageDirectory( const CSimpleString &str )
  106. {
  107. m_strImageDirectory = str;
  108. }
  109. UINT CMyDocsScreenSaverData::ChangeInterval(void) const
  110. {
  111. return(m_nChangeTimerInterval);
  112. }
  113. void CMyDocsScreenSaverData::ChangeInterval( UINT nInterval )
  114. {
  115. m_nChangeTimerInterval = nInterval;
  116. }
  117. UINT CMyDocsScreenSaverData::PaintInterval(void) const
  118. {
  119. return(m_nPaintTimerInterval);
  120. }
  121. void CMyDocsScreenSaverData::PaintInterval( UINT nInterval )
  122. {
  123. m_nPaintTimerInterval = nInterval;
  124. }
  125. bool CMyDocsScreenSaverData::DisplayFilename(void) const
  126. {
  127. return(m_bDisplayFilename);
  128. }
  129. void CMyDocsScreenSaverData::DisplayFilename( bool bDisplayFilename )
  130. {
  131. m_bDisplayFilename = bDisplayFilename;
  132. }
  133. int CMyDocsScreenSaverData::MaxScreenPercent(void) const
  134. {
  135. return m_nMaxScreenPercent;
  136. }
  137. void CMyDocsScreenSaverData::MaxScreenPercent( int nMaxScreenPercent )
  138. {
  139. m_nMaxScreenPercent = nMaxScreenPercent;
  140. }
  141. bool CMyDocsScreenSaverData::DisableTransitions(void) const
  142. {
  143. return m_bDisableTransitions;
  144. }
  145. void CMyDocsScreenSaverData::DisableTransitions( bool bDisableTransitions )
  146. {
  147. m_bDisableTransitions = bDisableTransitions;
  148. }
  149. bool CMyDocsScreenSaverData::AllowStretching(void) const
  150. {
  151. return m_bAllowStretching;
  152. }
  153. void CMyDocsScreenSaverData::AllowStretching( bool bAllowStretching )
  154. {
  155. m_bAllowStretching = bAllowStretching;
  156. }
  157. bool CMyDocsScreenSaverData::AllowKeyboardControl(void) const
  158. {
  159. return m_bAllowKeyboardControl;
  160. }
  161. void CMyDocsScreenSaverData::AllowKeyboardControl( bool bAllowKeyboardControl )
  162. {
  163. m_bAllowKeyboardControl = bAllowKeyboardControl;
  164. }
  165. int CMyDocsScreenSaverData::MaxFailedFiles(void) const
  166. {
  167. return m_nMaxFailedFiles;
  168. }
  169. void CMyDocsScreenSaverData::MaxFailedFiles( int nMaxFailedFiles )
  170. {
  171. m_nMaxFailedFiles = nMaxFailedFiles;
  172. }
  173. int CMyDocsScreenSaverData::MaxSuccessfulFiles(void) const
  174. {
  175. return m_nMaxSuccessfulFiles;
  176. }
  177. void CMyDocsScreenSaverData::MaxSuccessfulFiles( int nMaxSuccessfulFiles )
  178. {
  179. m_nMaxSuccessfulFiles = nMaxSuccessfulFiles;
  180. }
  181. int CMyDocsScreenSaverData::MaxDirectories(void) const
  182. {
  183. return m_nMaxDirectories;
  184. }
  185. void CMyDocsScreenSaverData::MaxDirectories( int nMaxDirectories )
  186. {
  187. m_nMaxDirectories = nMaxDirectories;
  188. }
  189. CSimpleString CMyDocsScreenSaverData::GetDefaultImageDir(void)
  190. {
  191. CSimpleString strResult(TEXT(""));
  192. LPITEMIDLIST pidl;
  193. TCHAR szPath[MAX_PATH];
  194. LPMALLOC pMalloc;
  195. HRESULT hr = SHGetMalloc(&pMalloc);
  196. if (SUCCEEDED(hr))
  197. {
  198. hr = SHGetSpecialFolderLocation( NULL, CSIDL_MYPICTURES, &pidl );
  199. if (SUCCEEDED(hr))
  200. {
  201. if (SHGetPathFromIDList( pidl, szPath ))
  202. {
  203. if (lstrlen(szPath))
  204. strResult = szPath;
  205. }
  206. pMalloc->Free(pidl);
  207. }
  208. if (0 == strResult.Length())
  209. {
  210. hr = SHGetSpecialFolderLocation( NULL, CSIDL_PERSONAL, &pidl );
  211. if (SUCCEEDED(hr))
  212. {
  213. if (SHGetPathFromIDList( pidl, szPath ))
  214. {
  215. if (lstrlen(szPath))
  216. strResult = szPath;
  217. }
  218. pMalloc->Free(pidl);
  219. }
  220. }
  221. if (0 == strResult.Length())
  222. {
  223. hr = SHGetSpecialFolderLocation( NULL, CSIDL_WINDOWS, &pidl );
  224. if (SUCCEEDED(hr))
  225. {
  226. if (SHGetPathFromIDList( pidl, szPath ))
  227. {
  228. if (lstrlen(szPath))
  229. strResult = szPath;
  230. }
  231. pMalloc->Free(pidl);
  232. }
  233. }
  234. pMalloc->Release();
  235. }
  236. WIA_TRACE((TEXT("CImageScreenSaver::GetDefaultDirectory: returned %s\n"),strResult.String()));
  237. return(strResult);
  238. }