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.

375 lines
11 KiB

  1. /*++
  2. Copyright (c) 1996 Microsoft Corporation
  3. Module Name:
  4. server.c
  5. Abstract:
  6. This file implements the server file copy code.
  7. Environment:
  8. WIN32 User Mode
  9. Author:
  10. Wesley Witt (wesw) 17-Feb-1996
  11. --*/
  12. #include "faxocm.h"
  13. #pragma hdrstop
  14. DWORD
  15. ServerGetStepCount(
  16. VOID
  17. )
  18. {
  19. #ifdef NT5FAXINSTALL
  20. return 0;
  21. #else
  22. return 5;
  23. #endif
  24. }
  25. DWORD
  26. ServerInstallation(
  27. HWND hwnd,
  28. LPWSTR SourceRoot
  29. )
  30. {
  31. DWORD ErrorCode = 0;
  32. DWORD OldInstallType;
  33. WCHAR FileName[256];
  34. BOOL CompleteInstall = FALSE;
  35. WCHAR FaxCommonPath[MAX_PATH+1];
  36. LPTSTR pCommonPath;
  37. WCHAR CommonChar;
  38. DWORD attrib;
  39. HKEY hKey;
  40. #define MakeSpecialDirectory(_DIR,_HIDE) *pCommonPath = CommonChar;\
  41. *(pCommonPath+1) = (WCHAR) 0;\
  42. ConcatenatePaths( FaxCommonPath, _DIR ) ;\
  43. MakeDirectory( FaxCommonPath );\
  44. if (_HIDE) HideDirectory(FaxCommonPath);\
  45. DeviceInitialization( hwnd );
  46. if (NtGuiMode) {
  47. DebugPrint(( TEXT("faxocm - starting lanmanserver") ));
  48. MyStartService( L"LanmanServer" );
  49. if (FaxDevices > 0) {
  50. CompleteInstall = TRUE;
  51. }
  52. } else {
  53. CompleteInstall = TRUE;
  54. }
  55. //
  56. // delete the fax modem inf
  57. //
  58. ExpandEnvironmentStrings( L"%systemroot%\\awmodem.inf", FileName, sizeof(FileName)/sizeof(WCHAR) );
  59. MyDeleteFile( FileName );
  60. DebugPrint(( TEXT("faxocm - setting registry") ));
  61. //
  62. // set the registry data
  63. //
  64. //
  65. // hack: during NT GUI-mode setup, we need to retrieve the user's name twice because
  66. // the name is entered by the user after we've retreived the data (so we get a bogus name if we don't do this!)
  67. //
  68. if (NtGuiMode) {
  69. HKEY hKey;
  70. LPWSTR RegisteredOwner;
  71. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, REGKEY_WINDOWSNT_CURRVER, TRUE, KEY_ALL_ACCESS );
  72. RegisteredOwner = GetRegistryString( hKey, REGVAL_REGISTERED_OWNER, EMPTY_STRING );
  73. RegCloseKey( hKey );
  74. if (RegisteredOwner && RegisteredOwner[0]) {
  75. wcscpy( WizData.UserName, RegisteredOwner );
  76. MemFree( RegisteredOwner );
  77. }
  78. }
  79. SetProgress( IDS_SETTING_REGISTRY );
  80. if (!SetServerRegistryData( SourceRoot )) {
  81. DebugPrint(( L"SetServerRegistryData() failed" ));
  82. ErrorCode = IDS_COULD_SET_REG_DATA;
  83. goto error_exit;
  84. }
  85. if (!SetClientRegistryData()) {
  86. DebugPrint(( L"SetClientRegistryData() failed" ));
  87. ErrorCode = IDS_COULD_SET_REG_DATA;
  88. goto error_exit;
  89. }
  90. SetSoundRegistryData();
  91. DeleteModemRegistryKey();
  92. //
  93. // set all of the install flags in the registry
  94. // this must be done before the fax service is
  95. // started so it can query the values
  96. //
  97. OldInstallType = InstallType;
  98. SetInstalledFlag( TRUE );
  99. SetInstallType( NtWorkstation ? FAX_INSTALL_WORKSTATION : FAX_INSTALL_SERVER );
  100. SetInstalledPlatforms( 0 );
  101. //
  102. // install the fax service
  103. //
  104. SetProgress( IDS_INSTALLING_FAXSVC );
  105. if (!Upgrade) {
  106. if (!InstallFaxService( TRUE, TRUE, NULL, NULL )) {
  107. DebugPrint(( L"InstallFaxService() failed" ));
  108. ErrorCode = GetLastError();
  109. goto error_exit;
  110. }
  111. } else {
  112. RenameFaxService();
  113. }
  114. //
  115. // do the exchange stuff
  116. //
  117. SetProgress( IDS_INSTALLING_EXCHANGE );
  118. DoExchangeInstall( hwnd );
  119. //
  120. // create the printer
  121. //
  122. SetProgress( IDS_CREATING_FAXPRT );
  123. if (!Upgrade) {
  124. if (CompleteInstall) {
  125. DebugPrint(( TEXT("faxocm - creating fax printer") ));
  126. if (!CreateLocalFaxPrinter( WizData.PrinterName )) {
  127. DebugPrint(( L"CreateLocalFaxPrinter() failed" ));
  128. if (!NtGuiMode) {
  129. StopFaxService();
  130. DeleteFaxService();
  131. SetInstalledFlag( FALSE );
  132. ErrorCode = IDS_COULD_NOT_CREATE_PRINTER;
  133. goto error_exit;
  134. }
  135. }
  136. }
  137. } else {
  138. if (NtGuiMode) {
  139. DeleteRegistryTree( HKEY_LOCAL_MACHINE, REGKEY_FAX_SECURITY );
  140. RecreateNt4FaxPrinters();
  141. RecreateNt5Beta3FaxPrinters();
  142. }
  143. }
  144. //
  145. // create the program group and it's items
  146. //
  147. DebugPrint(( TEXT("faxocm - creating program groups") ));
  148. SetProgress( IDS_CREATING_GROUPS );
  149. if (CompleteInstall) {
  150. //
  151. // safe to do this in an upgrade, since it's a noop if it's already there
  152. //
  153. CreateGroupItems( NULL );
  154. //
  155. // should be safe to do this in all cases since it will be a noop if it's not there
  156. //
  157. DeleteNt4Group();
  158. }
  159. if (NtGuiMode && (CompleteInstall == FALSE) ) {
  160. //
  161. // rename fax.cpl, so that it doesn't show up in the control panel
  162. //
  163. LPTSTR srcFile = ExpandEnvironmentString( TEXT("%systemroot%\\system32\\fax.cpl") );
  164. LPTSTR dstFile = ExpandEnvironmentString( TEXT("%systemroot%\\system32\\fax.cpk") );
  165. if (!MoveFileEx(srcFile, dstFile, MOVEFILE_REPLACE_EXISTING)) {
  166. MoveFileEx(srcFile, dstFile, MOVEFILE_REPLACE_EXISTING | MOVEFILE_DELAY_UNTIL_REBOOT);
  167. }
  168. MemFree( srcFile );
  169. MemFree( dstFile );
  170. }
  171. DebugPrint(( TEXT("faxocm - creating directories") ));
  172. //
  173. // share amd create the windows fax directory
  174. //
  175. if (!Upgrade) {
  176. if (WizData.ArchiveOutgoing) {
  177. if (*WizData.ArchiveDir) {
  178. //
  179. // specified in unattend
  180. //
  181. MakeDirectory( WizData.ArchiveDir );
  182. } else {
  183. if (!MyGetSpecialPath( CSIDL_COMMON_DOCUMENTS, FaxCommonPath ) ) {
  184. DebugPrint(( TEXT("Couldn't MyGetSpecialPath, ec = %d\n"), GetLastError() ));
  185. ErrorCode = IDS_COULD_NOT_SET_APP_PATH;
  186. goto error_exit;
  187. }
  188. ConcatenatePaths( FaxCommonPath, GetString(IDS_ARCHIVE_DIR) ) ;
  189. MakeDirectory( FaxCommonPath );
  190. wcscpy( WizData.ArchiveDir, FaxCommonPath);
  191. }
  192. //SetFaxShellExtension( WizData.ArchiveDir );
  193. }
  194. if (WizData.RoutingMask & LR_STORE) {
  195. if (*WizData.RouteDir) {
  196. //
  197. // specified in unattend
  198. //
  199. MakeDirectory(WizData.RouteDir);
  200. } else {
  201. if (!MyGetSpecialPath( CSIDL_COMMON_DOCUMENTS, FaxCommonPath ) ) {
  202. DebugPrint(( TEXT("Couldn't MyGetSpecialPath, ec = %d\n"), GetLastError() ));
  203. ErrorCode = IDS_COULD_NOT_SET_APP_PATH;
  204. goto error_exit;
  205. }
  206. ConcatenatePaths( FaxCommonPath, GetString(IDS_RECEIVE_DIR) ) ;
  207. MakeDirectory( FaxCommonPath );
  208. wcscpy( WizData.RouteDir, FaxCommonPath);
  209. }
  210. //SetFaxShellExtension( WizData.RouteDir );
  211. }
  212. if (!MyGetSpecialPath( CSIDL_COMMON_DOCUMENTS, FaxCommonPath ) ) {
  213. DebugPrint(( TEXT("Couldn't MyGetSpecialPath, ec = %d\n"), GetLastError() ));
  214. ErrorCode = IDS_COULD_NOT_SET_APP_PATH;
  215. goto error_exit;
  216. }
  217. ConcatenatePaths( FaxCommonPath, GetString(IDS_COVERPAGE_DIR) ) ;
  218. if (IsProductSuite()) {
  219. CreateNetworkShare( FaxCommonPath, TEXT("COVERPG$"), EMPTY_STRING );
  220. }
  221. pCommonPath = wcsrchr( FaxCommonPath, L'\\' );
  222. if (pCommonPath) {
  223. *pCommonPath = (WCHAR)0;
  224. }
  225. SuperHideDirectory(FaxCommonPath);
  226. if (!MyGetSpecialPath( CSIDL_COMMON_APPDATA, FaxCommonPath ) ) {
  227. DebugPrint(( TEXT("Couldn't MyGetSpecialPath, ec = %d\n"), GetLastError() ));
  228. ErrorCode = IDS_COULD_NOT_SET_APP_PATH;
  229. goto error_exit;
  230. }
  231. pCommonPath = &FaxCommonPath[wcslen(FaxCommonPath) -1];
  232. CommonChar = FaxCommonPath[wcslen(FaxCommonPath) -1];
  233. ConcatenatePaths( FaxCommonPath, FAX_DIR ) ;
  234. MakeDirectory( FaxCommonPath );
  235. MakeSpecialDirectory( FAX_RECEIVE_DIR, TRUE );
  236. MakeSpecialDirectory( FAX_QUEUE_DIR, TRUE );
  237. if (IsProductSuite()) {
  238. MakeSpecialDirectory( FAX_CLIENT_DIR, TRUE );
  239. MakeSpecialDirectory( FAX_CLIENT_DIR_I386, FALSE );
  240. MakeSpecialDirectory( FAX_CLIENT_DIR_ALPHA, FALSE );
  241. MakeSpecialDirectory( FAX_CLIENT_DIR_WIN95, FALSE );
  242. *pCommonPath = CommonChar;
  243. *(pCommonPath+1) = (WCHAR) 0;
  244. ConcatenatePaths( FaxCommonPath, FAX_DIR ) ;
  245. CreateNetworkShare( FaxCommonPath, FAX_SHARE, EMPTY_STRING );
  246. }
  247. } else {
  248. //
  249. // Remove the system attribute from the archive and receive folders
  250. // Delete desktop.ini from the archive and receive folders
  251. //
  252. if (MyGetSpecialPath( CSIDL_COMMON_DOCUMENTS, FaxCommonPath ) ) {
  253. ConcatenatePaths( FaxCommonPath, GetString(IDS_ARCHIVE_DIR) ) ;
  254. attrib = GetFileAttributes( FaxCommonPath );
  255. attrib &= ~FILE_ATTRIBUTE_SYSTEM;
  256. SetFileAttributes( FaxCommonPath, attrib );
  257. ConcatenatePaths( FaxCommonPath, TEXT("desktop.ini") );
  258. MoveFileEx( FaxCommonPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  259. }
  260. if (MyGetSpecialPath( CSIDL_COMMON_DOCUMENTS, FaxCommonPath ) ) {
  261. ConcatenatePaths( FaxCommonPath, GetString(IDS_RECEIVE_DIR) ) ;
  262. attrib = GetFileAttributes( FaxCommonPath );
  263. attrib &= ~FILE_ATTRIBUTE_SYSTEM;
  264. SetFileAttributes( FaxCommonPath, attrib );
  265. ConcatenatePaths( FaxCommonPath, TEXT("desktop.ini") );
  266. MoveFileEx( FaxCommonPath, NULL, MOVEFILE_DELAY_UNTIL_REBOOT);
  267. }
  268. //
  269. // Unregister the old faxshell.dll
  270. //
  271. DeleteRegistryKey( HKEY_CLASSES_ROOT, TEXT("Clsid\\{7f9609be-af9a-11d1-83e0-00c04fb6e984}") );
  272. hKey = OpenRegistryKey( HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Shell Extensions\\Approved"), TRUE, NULL );
  273. if (hKey) {
  274. RegDeleteValue( hKey, TEXT("{7f9609be-af9a-11d1-83e0-00c04fb6e984}") );
  275. RegCloseKey( hKey );
  276. }
  277. }
  278. return TRUE;
  279. error_exit:
  280. //
  281. // reset the install registry data
  282. //
  283. SetInstalledFlag( Installed );
  284. SetInstallType( OldInstallType );
  285. SetInstalledPlatforms( InstalledPlatforms );
  286. //
  287. // display the error message
  288. //
  289. PopUpMsg( hwnd, ErrorCode, TRUE, 0 );
  290. return FALSE;
  291. }