NeroPluginUtil.cpp 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274
  1. /******************************************************************************
  2. |* THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  3. |* ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  4. |* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  5. |* PARTICULAR PURPOSE.
  6. |*
  7. |* Copyright 1995-2005 Nero AG. All Rights Reserved.
  8. |*-----------------------------------------------------------------------------
  9. |* NeroSDK / AudioPluginManager
  10. |*
  11. |* FILE: NeroPluginUtil.cpp
  12. |*
  13. |* PURPOSE: Implementation of auxiliary helper functions for Nero plugins
  14. ******************************************************************************/
  15. #include "stdafx.h"
  16. #include "NeroPluginUtil.h"
  17. #include "afxinet.h" // URL parsing
  18. bool reg_SetPluginParam(const char *szVendor, const char *szProduct,
  19. const char *szPlugin, const char *szGroup,
  20. const char *szParam, DWORD dwValue)
  21. {
  22. if(!(szVendor && szProduct && szPlugin && szParam))
  23. {
  24. ASSERT(FALSE);
  25. return false;
  26. }
  27. HKEY hKey = NULL;
  28. if(!szGroup)
  29. szGroup = "";
  30. try
  31. {
  32. CString csSubKey;
  33. csSubKey.Format("Software\\%s\\%s\\%s\\%s",
  34. szVendor, szProduct, szPlugin, szGroup);
  35. if(RegOpenKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS &&
  36. RegCreateKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS)
  37. throw false;
  38. if(RegSetValueEx(hKey, szParam, NULL, REG_DWORD,
  39. (BYTE*)&dwValue, sizeof(DWORD)) != ERROR_SUCCESS)
  40. throw false;
  41. throw true;
  42. }
  43. catch(bool b)
  44. {
  45. if(hKey)
  46. RegCloseKey(hKey);
  47. return b;
  48. }
  49. }
  50. bool reg_GetPluginParam(const char *szVendor, const char *szProduct,
  51. const char *szPlugin, const char *szGroup,
  52. const char *szParam, DWORD &dwValue)
  53. {
  54. if(!(szVendor && szProduct && szPlugin && szParam))
  55. {
  56. ASSERT(FALSE);
  57. return false;
  58. }
  59. HKEY hKey = NULL;
  60. if(!szGroup)
  61. szGroup = "";
  62. try
  63. {
  64. CString csSubKey;
  65. csSubKey.Format("Software\\%s\\%s\\%s\\%s",
  66. szVendor, szProduct, szPlugin, szGroup);
  67. if(RegOpenKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS)
  68. throw false;
  69. DWORD dwType = 0,
  70. dwSize = sizeof(DWORD);
  71. if(RegQueryValueEx(hKey, szParam, NULL, &dwType,
  72. (BYTE*)&dwValue, &dwSize) != ERROR_SUCCESS)
  73. throw false;
  74. throw true;
  75. }
  76. catch(bool b)
  77. {
  78. if(hKey)
  79. RegCloseKey(hKey);
  80. return b;
  81. }
  82. }
  83. bool reg_SetPluginParam(const char *szVendor, const char *szProduct,
  84. const char *szPlugin, const char *szGroup,
  85. const char *szParam, const char *szValue)
  86. {
  87. if(!(szVendor && szProduct && szPlugin && szParam))
  88. {
  89. ASSERT(FALSE);
  90. return false;
  91. }
  92. HKEY hKey = NULL;
  93. if(!szGroup)
  94. szGroup = "";
  95. try
  96. {
  97. CString csSubKey;
  98. csSubKey.Format("Software\\%s\\%s\\%s\\%s",
  99. szVendor, szProduct, szPlugin, szGroup);
  100. if(RegOpenKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS &&
  101. RegCreateKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS)
  102. throw false;
  103. if(RegSetValueEx(hKey, szParam, NULL, REG_SZ,
  104. (BYTE*)szValue,
  105. strlen(szValue) + 1) != ERROR_SUCCESS)
  106. throw false;
  107. throw true;
  108. }
  109. catch(bool b)
  110. {
  111. if(hKey)
  112. RegCloseKey(hKey);
  113. return b;
  114. }
  115. }
  116. CString reg_GetPluginParam(const char *szVendor, const char *szProduct,
  117. const char *szPlugin, const char *szGroup,
  118. const char *szParam)
  119. {
  120. CString csValue;
  121. if(!(szVendor && szProduct && szPlugin && szParam))
  122. {
  123. ASSERT(FALSE);
  124. return csValue;
  125. }
  126. HKEY hKey = NULL;
  127. if(!szGroup)
  128. szGroup = "";
  129. try
  130. {
  131. CString csSubKey;
  132. csSubKey.Format("Software\\%s\\%s\\%s\\%s",
  133. szVendor, szProduct, szPlugin, szGroup);
  134. if(RegOpenKey(HKEY_CURRENT_USER, csSubKey, &hKey) != ERROR_SUCCESS)
  135. throw false;
  136. char szBuf[1000];
  137. DWORD dwType = 0,
  138. dwSize = sizeof(szBuf);
  139. if(!(RegQueryValueEx(hKey, szParam, NULL, &dwType,
  140. (BYTE*)szBuf, &dwSize) == ERROR_SUCCESS &&
  141. dwType == REG_SZ))
  142. throw false;
  143. csValue = szBuf;
  144. throw true;
  145. }
  146. catch(bool )
  147. {
  148. if(hKey)
  149. RegCloseKey(hKey);
  150. }
  151. return csValue;
  152. }
  153. // Returns true if the URL points to a local file.
  154. bool IsURLLocal(const char *szURL)
  155. {
  156. DWORD dwServiceType = 0;
  157. INTERNET_PORT port;
  158. CString csServer,
  159. csObject;
  160. return (AfxParseURL(szURL, dwServiceType, csServer, csObject, port) &&
  161. (dwServiceType == AFX_INET_SERVICE_FILE));
  162. }
  163. bool file_DoesExist(const char *szFile)
  164. {
  165. HANDLE hExist = CreateFile(szFile,
  166. 0,
  167. FILE_SHARE_DELETE|FILE_SHARE_READ|
  168. FILE_SHARE_WRITE,
  169. NULL,
  170. OPEN_EXISTING,
  171. 0,
  172. NULL);
  173. bool bExist = (hExist != INVALID_HANDLE_VALUE);
  174. if(bExist)
  175. CloseHandle(hExist);
  176. return bExist;
  177. }
  178. bool file_GetTime(const char *szFile, CTime &time)
  179. {
  180. HANDLE hFile = CreateFile(szFile,
  181. 0,
  182. FILE_SHARE_DELETE|FILE_SHARE_READ|
  183. FILE_SHARE_WRITE,
  184. NULL,
  185. OPEN_EXISTING,
  186. 0,
  187. NULL);
  188. if(hFile == INVALID_HANDLE_VALUE)
  189. return false;
  190. FILETIME ftCreation,
  191. ftLastAccess,
  192. ftLastTime;
  193. BOOL bRet = GetFileTime(hFile, &ftCreation, &ftLastAccess, &ftLastTime);
  194. time = ftLastAccess;
  195. CloseHandle(hFile);
  196. return (bRet? true: false);
  197. }
  198. DWORD file_GetSize(const char *szFile)
  199. {
  200. HANDLE hFile = CreateFile(szFile,
  201. 0,
  202. FILE_SHARE_DELETE|FILE_SHARE_READ|
  203. FILE_SHARE_WRITE,
  204. NULL,
  205. OPEN_EXISTING,
  206. 0,
  207. NULL);
  208. if(hFile == INVALID_HANDLE_VALUE)
  209. return 0;
  210. DWORD dwSize = GetFileSize(hFile, NULL);
  211. CloseHandle(hFile);
  212. return dwSize;
  213. }