/Development/Yaaf.Wp7.NativeAccess/ComWrapper/HTC/COM_RegRw/HTCRegistry.cs

# · C# · 285 lines · 121 code · 45 blank · 119 comment · 13 complexity · e561ede08e205c72772c03b269321bc1 MD5 · raw file

  1. namespace Yaaf.WP7.NativeAccess.ComWrapper.HTC.COM_RegRw
  2. {
  3. using System;
  4. using System.Text;
  5. using Microsoft.Phone.InteropServices;
  6. using Yaaf.WP7.NativeAccess.Helper;
  7. using Yaaf.WP7.NativeAccess.Registry;
  8. internal class HTCRegistry : IDisposable
  9. {
  10. // Fields
  11. private const string m_ComGuid = "020CF84D-5946-4C9B-A066-8C9EC348DEDD";
  12. private IRegRwInterface m_RegRwObject;
  13. public const int MAX_PATH = 260;
  14. public const int MAX_STRLEN = 0x100;
  15. // Methods
  16. public HTCRegistry()
  17. {
  18. Devices.Initialize();
  19. InteropHelper.RegisterDll("COM_RegRw.dll", m_ComGuid);
  20. this.m_RegRwObject = (IRegRwInterface)new CRegRwClass();
  21. this.Init();
  22. }
  23. private bool validateString(string A_0)
  24. {
  25. return ((MAX_STRLEN >= A_0.Length) && (0 <= A_0.Length));
  26. }
  27. private bool IsError(uint A_0)
  28. {
  29. return (A_0 != 0);
  30. }
  31. public uint Deinit()
  32. {
  33. uint num = 0;
  34. this.m_RegRwObject.Deinit(out num);
  35. return num;
  36. }
  37. public bool GetVersionInfo(string szSearchKey, out StringBuilder szRequestVersion)
  38. {
  39. uint num = 0;
  40. szRequestVersion = new StringBuilder(MAX_PATH);
  41. this.m_RegRwObject.GetVersionInfo(szSearchKey, szRequestVersion, out num);
  42. return this.IsError(num);
  43. }
  44. public uint Init()
  45. {
  46. uint num = 0;
  47. this.m_RegRwObject.Init(out num);
  48. return num;
  49. }
  50. public bool IsAPExist(string szProductID)
  51. {
  52. uint num = 0;
  53. this.m_RegRwObject.IsAPExist(szProductID, out num);
  54. return this.IsError(num);
  55. }
  56. public bool IsHTCDevice()
  57. {
  58. uint isHTCDevice = 0;
  59. this.m_RegRwObject.IsHTCDevice(out isHTCDevice);
  60. return (isHTCDevice == 0xb9d548dc);
  61. }
  62. public bool LaunchAP(string szProductID)
  63. {
  64. uint num = 0;
  65. this.m_RegRwObject.LaunchAP(szProductID, out num);
  66. return this.IsError(num);
  67. }
  68. public bool RegistryGetDWORD(RootKey eKey, string strSubKey, string strValueName, out uint uData)
  69. {
  70. uint num = 0;
  71. uData = 0;
  72. if (this.validateString(strSubKey) && this.validateString(strValueName))
  73. {
  74. this.m_RegRwObject.RegistryGetDWORD((uint)eKey, strSubKey, strValueName, out uData, out num);
  75. }
  76. return this.IsError(num);
  77. }
  78. public bool RegistryGetString(RootKey eKey, string strSubKey, string strValueName, out StringBuilder strData)
  79. {
  80. uint num = 0;
  81. strData = new StringBuilder(MAX_PATH);
  82. if (this.validateString(strSubKey) && this.validateString(strValueName))
  83. {
  84. this.m_RegRwObject.RegistryGetString((uint)eKey, strSubKey, strValueName, strData, out num);
  85. }
  86. return this.IsError(num);
  87. }
  88. public bool RegistrySetDWORD(RootKey eKey, string strSubKey, string strValueName, uint uData)
  89. {
  90. uint num = 0;
  91. if (this.validateString(strSubKey) && this.validateString(strValueName))
  92. {
  93. this.m_RegRwObject.RegistrySetDWORD((uint)eKey, strSubKey, strValueName, uData, out num);
  94. }
  95. return this.IsError(num);
  96. }
  97. public bool RegistrySetString(RootKey eKey, string strSubKey, string strValueName, string pszData)
  98. {
  99. uint num = 0;
  100. if ((this.validateString(strSubKey) && this.validateString(strValueName)) && this.validateString(pszData))
  101. {
  102. this.m_RegRwObject.RegistrySetString((uint)eKey, strSubKey, strValueName, pszData, out num);
  103. }
  104. return this.IsError(num);
  105. }
  106. public void Dispose()
  107. {
  108. this.Dispose(true);
  109. GC.SuppressFinalize(this);
  110. }
  111. ~HTCRegistry()
  112. {
  113. this.Dispose(false);
  114. }
  115. private void Dispose(bool disposing)
  116. {
  117. if (disposing)
  118. {
  119. this.Deinit();
  120. }
  121. }
  122. }
  123. //public sealed class HTCRegistry : IDisposable
  124. //{
  125. // // Fields
  126. // private const string m_ComGuid = "020CF84D-5946-4C9B-A066-8C9EC348DEDD";
  127. // private IRegRwInterface m_RegRwObject;
  128. // public const int MAX_PATH = 260;
  129. // public const int MAX_STRLEN = 0x100;
  130. // // Methods
  131. // public HTCRegistry()
  132. // {
  133. // Devices.Initialize();
  134. // if (ComBridge.RegisterComDll("COM_RegRw.dll", new Guid(m_ComGuid)) != 0)
  135. // {
  136. // throw new Exception("Register COM Dll Fail.");
  137. // }
  138. // this.m_RegRwObject = (IRegRwInterface)new CRegRwClass();
  139. // this.Init();
  140. // }
  141. // public uint Deinit()
  142. // {
  143. // uint uResult = 0;
  144. // this.m_RegRwObject.Deinit(out uResult);
  145. // return uResult;
  146. // }
  147. // public bool GetVersionInfo(string szSearchKey, out StringBuilder szRequestVersion)
  148. // {
  149. // uint uRet = 0;
  150. // szRequestVersion = new StringBuilder(MAX_PATH);
  151. // this.m_RegRwObject.GetVersionInfo(szSearchKey, szRequestVersion, out uRet);
  152. // return this.Return(uRet);
  153. // }
  154. // public uint Init()
  155. // {
  156. // uint uResult = 0;
  157. // this.m_RegRwObject.Init(out uResult);
  158. // return uResult;
  159. // }
  160. // public bool IsHTCDevice()
  161. // {
  162. // uint isHTCDevice = 0;
  163. // this.m_RegRwObject.IsHTCDevice(out isHTCDevice);
  164. // return (isHTCDevice == 0xb9d548dc);
  165. // }
  166. // public bool RegistryGetDWORD(RootKey eKey, string strSubKey, string strValueName, out uint uData)
  167. // {
  168. // uint uResult = 0;
  169. // uData = 0;
  170. // if (this.StringValid(strSubKey) && this.StringValid(strValueName))
  171. // {
  172. // this.m_RegRwObject.RegistryGetDword((uint)eKey, strSubKey, strValueName, out uData, out uResult);
  173. // }
  174. // return this.Return(uResult);
  175. // }
  176. // public bool RegistryGetString(RootKey eKey, string strSubKey, string strValueName, out StringBuilder strData)
  177. // {
  178. // uint uResult = 0;
  179. // strData = new StringBuilder(MAX_PATH);
  180. // if (this.StringValid(strSubKey) && this.StringValid(strValueName))
  181. // {
  182. // this.m_RegRwObject.RegistryGetString((uint)eKey, strSubKey, strValueName, strData, out uResult);
  183. // }
  184. // return this.Return(uResult);
  185. // }
  186. // public bool RegistrySetDWORD(RootKey eKey, string strSubKey, string strValueName, uint uData)
  187. // {
  188. // uint uResult = 0;
  189. // if (this.StringValid(strSubKey) && this.StringValid(strValueName))
  190. // {
  191. // this.m_RegRwObject.RegistrySetDword((uint)eKey, strSubKey, strValueName, uData, out uResult);
  192. // }
  193. // return this.Return(uResult);
  194. // }
  195. // public bool RegistrySetString(RootKey eKey, string strSubKey, string strValueName, string pszData)
  196. // {
  197. // uint uResult = 0;
  198. // if ((this.StringValid(strSubKey) && this.StringValid(strValueName)) && this.StringValid(pszData))
  199. // {
  200. // this.m_RegRwObject.RegistrySetString((uint)eKey, strSubKey, strValueName, pszData, out uResult);
  201. // }
  202. // return this.Return(uResult);
  203. // }
  204. // private bool Return(uint uRet)
  205. // {
  206. // return (uRet != 0);
  207. // }
  208. // private bool StringValid(string strCheck)
  209. // {
  210. // return ((MAX_STRLEN >= strCheck.Length) && (0 < strCheck.Length));
  211. // }
  212. // // Nested Types
  213. // public enum ACTION_TYPE
  214. // {
  215. // AT_NOACTION,
  216. // AT_NOTIFY,
  217. // AT_CLOSEAP
  218. // }
  219. // public enum RootKey
  220. // {
  221. // E_HKEY_CLASSES_ROOT,
  222. // E_HKEY_CURRENT_USER,
  223. // E_HKEY_LOCAL_MACHINE,
  224. // E_HKEY_USERS
  225. // }
  226. // public void Dispose()
  227. // {
  228. // this.Dispose(true);
  229. // GC.SuppressFinalize(this);
  230. // }
  231. // ~HTCRegistry()
  232. // {
  233. // this.Dispose(false);
  234. // }
  235. // private void Dispose(bool disposing)
  236. // {
  237. // this.Deinit();
  238. // }
  239. //}
  240. }