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.

366 lines
8.2 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. install.c
  5. Abstract:
  6. This module contains installation functions.
  7. Author:
  8. Andrew Ritz (andrewr) 9-Dec-1997
  9. Revision History:
  10. --*/
  11. #include "faxapi.h"
  12. #pragma hdrstop
  13. extern HINSTANCE MyhInstance;
  14. BOOL CreatePrinterandGroups();
  15. BOOL CreateLocalFaxPrinter(LPWSTR FaxPrinterName,LPWSTR SourceRoot);
  16. VOID CreateGroupItems(LPWSTR ServerName);
  17. BOOL AddMethodKey(
  18. HKEY hKey,
  19. LPCWSTR MethodName,
  20. LPCWSTR FriendlyName,
  21. LPCWSTR FunctionName,
  22. LPCWSTR Guid,
  23. DWORD Priority
  24. ) ;
  25. WINFAXAPI
  26. BOOL
  27. WINAPI
  28. FaxRegisterServiceProviderW(
  29. IN LPCWSTR DeviceProvider,
  30. IN LPCWSTR FriendlyName,
  31. IN LPCWSTR ImageName,
  32. IN LPCWSTR TspName
  33. )
  34. {
  35. HKEY hKey;
  36. BOOL RetVal = TRUE;
  37. WCHAR KeyName[256];
  38. if (!DeviceProvider || !FriendlyName || !ImageName ||!TspName) {
  39. SetLastError(ERROR_INVALID_PARAMETER);
  40. return FALSE;
  41. }
  42. wsprintf(KeyName,L"%s\\%s\\%s",REGKEY_SOFTWARE,REGKEY_DEVICE_PROVIDERS,DeviceProvider);
  43. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,
  44. KeyName,
  45. TRUE,
  46. 0);
  47. if (!hKey) {
  48. return FALSE;
  49. }
  50. //
  51. // add values
  52. //
  53. if (! (SetRegistryString(hKey,REGVAL_FRIENDLY_NAME,FriendlyName) &&
  54. SetRegistryStringExpand(hKey,REGVAL_IMAGE_NAME,ImageName) &&
  55. SetRegistryString(hKey,REGVAL_PROVIDER_NAME,TspName) )) {
  56. goto error_exit;
  57. }
  58. RegCloseKey(hKey);
  59. //
  60. // create printer, program group, etc.
  61. //
  62. if (!CreatePrinterandGroups()) {
  63. return FALSE;
  64. }
  65. return TRUE;
  66. error_exit:
  67. //
  68. // delete the subkey on failure
  69. //
  70. wsprintf(KeyName,L"%s\\%s",REGKEY_SOFTWARE,REGKEY_DEVICE_PROVIDERS);
  71. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,KeyName,FALSE,0);
  72. RegDeleteKey(hKey, DeviceProvider );
  73. RegCloseKey(hKey);
  74. return FALSE;
  75. }
  76. WINFAXAPI
  77. BOOL
  78. WINAPI
  79. FaxRegisterRoutingExtensionW(
  80. IN HANDLE FaxHandle,
  81. IN LPCWSTR ExtensionName,
  82. IN LPCWSTR FriendlyName,
  83. IN LPCWSTR ImageName,
  84. IN PFAX_ROUTING_INSTALLATION_CALLBACKW CallBack,
  85. IN LPVOID Context
  86. )
  87. {
  88. HKEY hKey = NULL;
  89. BOOL RetVal = FALSE;
  90. WCHAR KeyName[256];
  91. PFAX_GLOBAL_ROUTING_INFO RoutingInfo;
  92. DWORD dwMethods;
  93. WCHAR MethodName[64];
  94. WCHAR MethodFriendlyName[64];
  95. WCHAR MethodFunctionName[64];
  96. WCHAR MethodGuid[64];
  97. if (!ValidateFaxHandle(FaxHandle, FHT_SERVICE)) {
  98. SetLastError(ERROR_INVALID_HANDLE);
  99. return FALSE;
  100. }
  101. if (!ExtensionName || !FriendlyName || !ImageName ||!CallBack) {
  102. SetLastError(ERROR_INVALID_PARAMETER);
  103. return FALSE;
  104. }
  105. //
  106. // local installation only
  107. //
  108. if (!IsLocalFaxConnection(FaxHandle) ) {
  109. SetLastError(ERROR_INVALID_FUNCTION);
  110. return FALSE;
  111. }
  112. //
  113. // get the number of current methods for priority
  114. //
  115. if (!FaxEnumGlobalRoutingInfo(FaxHandle,&RoutingInfo,&dwMethods) ){
  116. DebugPrint((TEXT("FaxEnumGlobalRoutingInfo() failed, ec = %d\n"),GetLastError() ));
  117. return FALSE;
  118. }
  119. FaxFreeBuffer(RoutingInfo);
  120. wsprintf(KeyName,L"%s\\%s\\%s",REGKEY_SOFTWARE,REGKEY_ROUTING_EXTENSIONS,ExtensionName);
  121. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,
  122. KeyName,
  123. TRUE,
  124. 0);
  125. if (!hKey) {
  126. return FALSE;
  127. }
  128. //
  129. // add values
  130. //
  131. if (! (SetRegistryString(hKey,REGVAL_FRIENDLY_NAME,FriendlyName) &&
  132. SetRegistryStringExpand(hKey,REGVAL_IMAGE_NAME,ImageName) )) {
  133. RetVal = FALSE;
  134. goto error_exit;
  135. }
  136. RegCloseKey (hKey);
  137. wcscat(KeyName, L"\\");
  138. wcscat(KeyName, REGKEY_ROUTING_METHODS);
  139. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,
  140. KeyName,
  141. TRUE,
  142. 0);
  143. if (!hKey) {
  144. goto error_exit;
  145. }
  146. while (TRUE) {
  147. ZeroMemory( MethodName, sizeof(MethodName) );
  148. ZeroMemory( MethodFriendlyName, sizeof(MethodFriendlyName) );
  149. ZeroMemory( MethodFunctionName, sizeof(MethodFunctionName) );
  150. ZeroMemory( MethodGuid, sizeof(MethodGuid) );
  151. __try {
  152. RetVal = CallBack(FaxHandle,
  153. Context,
  154. MethodName,
  155. MethodFriendlyName,
  156. MethodFunctionName,
  157. MethodGuid
  158. );
  159. if (!RetVal) {
  160. break;
  161. }
  162. dwMethods++;
  163. if (!AddMethodKey(hKey,MethodName,MethodFriendlyName,MethodFunctionName,MethodGuid,dwMethods) ) {
  164. goto error_exit;
  165. }
  166. } __except (EXCEPTION_EXECUTE_HANDLER) {
  167. goto error_exit;
  168. }
  169. }
  170. RegCloseKey( hKey );
  171. return TRUE;
  172. error_exit:
  173. if (hKey) {
  174. RegCloseKey( hKey );
  175. }
  176. //
  177. // delete the subkey on failure
  178. //
  179. wsprintf(KeyName,L"%s\\%s",REGKEY_SOFTWARE,REGKEY_ROUTING_METHODS);
  180. hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,KeyName,FALSE,0);
  181. RegDeleteKey(hKey, ExtensionName );
  182. RegCloseKey(hKey);
  183. return FALSE;
  184. }
  185. BOOL AddMethodKey(
  186. HKEY hKey,
  187. LPCWSTR MethodName,
  188. LPCWSTR FriendlyName,
  189. LPCWSTR FunctionName,
  190. LPCWSTR Guid,
  191. DWORD Priority
  192. )
  193. {
  194. HKEY hKeyNew;
  195. hKeyNew = OpenRegistryKey(hKey,
  196. MethodName,
  197. TRUE,
  198. 0);
  199. if (!hKeyNew) {
  200. return FALSE;
  201. }
  202. //
  203. // add values
  204. //
  205. if (! (SetRegistryString(hKeyNew, REGVAL_FRIENDLY_NAME,FriendlyName) &&
  206. SetRegistryString(hKeyNew, REGVAL_FUNCTION_NAME,FunctionName) &&
  207. SetRegistryString(hKeyNew, REGVAL_GUID,Guid) &&
  208. SetRegistryDword(hKeyNew, REGVAL_PRIORITY,Priority) )) {
  209. goto error_exit;
  210. }
  211. RegCloseKey(hKeyNew);
  212. return TRUE;
  213. error_exit:
  214. RegCloseKey(hKeyNew);
  215. RegDeleteKey(hKey, MethodName);
  216. return FALSE;
  217. }
  218. BOOL CreatePrinterandGroups()
  219. {
  220. WCHAR PrinterName[64];
  221. HKEY hKeySource;
  222. LPWSTR SourcePath;
  223. HMODULE hModSetup;
  224. LPWSTR FaxPrinter;
  225. FARPROC CreateLocalFaxPrinter;
  226. FARPROC CreateGroupItems;
  227. //
  228. // check if we have a fax printer installed, add one if we don't have one.
  229. //
  230. if ((FaxPrinter = GetFaxPrinterName())) {
  231. MemFree(FaxPrinter);
  232. //return EnsureFaxServiceIsStarted(NULL);
  233. return TRUE;
  234. }
  235. else {
  236. //
  237. // printer installation routines in faxocm.dll module.
  238. //
  239. hModSetup = LoadLibrary(L"faxocm.dll");
  240. if (!hModSetup) {
  241. return FALSE;
  242. }
  243. CreateLocalFaxPrinter = GetProcAddress(hModSetup, "CreateLocalFaxPrinter");
  244. CreateGroupItems = GetProcAddress(hModSetup, "CreateGroupItems");
  245. if (!CreateLocalFaxPrinter || !CreateGroupItems) {
  246. FreeLibrary(hModSetup);
  247. return FALSE;
  248. }
  249. //
  250. // create a fax printer
  251. //
  252. LoadString( MyhInstance, IDS_DEFAULT_PRINTER_NAME, PrinterName, sizeof(PrinterName)/sizeof(WCHAR) );
  253. hKeySource = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_WINDOWSNT_CURRVER, FALSE, KEY_READ );
  254. if (hKeySource) {
  255. SourcePath = GetRegistryString( hKeySource, REGVAL_SOURCE_PATH, EMPTY_STRING );
  256. RegCloseKey( hKeySource );
  257. } else {
  258. SourcePath = StringDup( EMPTY_STRING );
  259. }
  260. if (SourcePath) {
  261. if (!CreateLocalFaxPrinter( PrinterName, SourcePath )) {
  262. DebugPrint(( L"CreateLocalFaxPrinter() failed" ));
  263. }
  264. MemFree( SourcePath );
  265. }
  266. //
  267. // add program group items
  268. //
  269. CreateGroupItems( NULL );
  270. FreeLibrary(hModSetup);
  271. //
  272. // start the fax service, which should add new devices
  273. //
  274. //return EnsureFaxServiceIsStarted(NULL);
  275. return TRUE;
  276. }
  277. }