/*++ Copyright (c) 1996 Microsoft Corporation Module Name: util.c Abstract: This file implements utility functions. Environment: WIN32 User Mode Author: Wesley Witt (wesw) 17-Feb-1996 --*/ #include "faxocm.h" #include "tchar.h" #pragma hdrstop typedef struct _STRING_TABLE { DWORD ResourceId; BOOL UseTitle; LPWSTR String; } STRING_TABLE, *PSTRING_TABLE; static STRING_TABLE StringTable[] = { { IDS_TITLE_WKS, FALSE, NULL }, { IDS_TITLE_SRV, FALSE, NULL }, { IDS_TITLE_PP, FALSE, NULL }, { IDS_TITLE_RA, FALSE, NULL }, { IDS_WRN_TITLE, TRUE, NULL }, { IDS_ERR_TITLE, TRUE, NULL }, { IDS_COULD_NOT_CREATE_PRINTER, FALSE, NULL }, { IDS_COULD_SET_REG_DATA, FALSE, NULL }, { IDS_CREATING_FAXPRT, FALSE, NULL }, { IDS_CREATING_GROUPS, FALSE, NULL }, { IDS_DEFAULT_CSID, FALSE, NULL }, { IDS_DEFAULT_DIR, FALSE, NULL }, { IDS_DEFAULT_PRINTER_NAME, FALSE, NULL }, { IDS_DEFAULT_TSID, FALSE, NULL }, { IDS_DELETING_FAX_SERVICE, FALSE, NULL }, { IDS_DELETING_GROUPS, FALSE, NULL }, { IDS_DELETING_REGISTRY, FALSE, NULL }, { IDS_INBOUND_DIR, FALSE, NULL }, { IDS_INSTALLING_EXCHANGE, FALSE, NULL }, { IDS_INSTALLING_FAXSVC, FALSE, NULL }, { IDS_QUERY_CANCEL, FALSE, NULL }, { IDS_SETTING_REGISTRY, FALSE, NULL }, { IDS_EULA_SUBTITLE, FALSE, NULL }, { IDS_EULA_TITLE, FALSE, NULL }, { IDS_FAX_DISPLAY_NAME, FALSE, NULL }, { IDS_FAXAB_DISPLAY_NAME, FALSE, NULL }, { IDS_FAXXP_DISPLAY_NAME, FALSE, NULL }, { IDS_MODEM_PROVIDER_NAME, FALSE, NULL }, { IDS_FAX_UNINSTALL_NAME, FALSE, NULL }, { IDS_PERSONAL_COVERPAGE, FALSE, NULL }, { IDS_RECEIVE_DIR, FALSE, NULL }, { IDS_ARCHIVE_DIR, FALSE, NULL }, { IDS_COMMONAPPDIR, FALSE, NULL }, { IDS_COVERPAGE, FALSE, NULL }, { IDS_COVERPAGEDESC, FALSE, NULL }, { IDS_MONITOR, FALSE, NULL }, { IDS_INCOMING, FALSE, NULL }, { IDS_OUTGOING, FALSE, NULL }, { IDS_SERVICE_DESCRIPTION, FALSE, NULL }, { IDS_COVERPAGE_DIR, FALSE, NULL }, { IDS_RT_EMAIL_FRIENDLY, FALSE, NULL }, { IDS_RT_FOLDER_FRIENDLY, FALSE, NULL }, { IDS_RT_INBOX_FRIENDLY, FALSE, NULL }, { IDS_RT_PRINT_FRIENDLY, FALSE, NULL } }; #define CountStringTable (sizeof(StringTable)/sizeof(STRING_TABLE)) VOID SetTitlesInStringTable( VOID ) { DWORD i; WCHAR Buffer[1024]; DWORD Index = 0; for (i=0; iright > cxScreen) { delta = prc->right - prc->left; prc->right = cxScreen; prc->left = prc->right - delta; } if (prc->left < 0) { delta = prc->right - prc->left; prc->left = 0; prc->right = prc->left + delta; } if (prc->bottom > cyScreen) { delta = prc->bottom - prc->top; prc->bottom = cyScreen; prc->top = prc->bottom - delta; } if (prc->top < 0) { delta = prc->bottom - prc->top; prc->top = 0; prc->bottom = prc->top + delta; } } VOID CenterWindow( HWND hwnd, HWND hwndToCenterOver ) { RECT rc; RECT rcOwner; RECT rcCenter; HWND hwndOwner; GetWindowRect( hwnd, &rc ); if (hwndToCenterOver) { hwndOwner = hwndToCenterOver; GetClientRect( hwndOwner, &rcOwner ); } else { hwndOwner = GetWindow( hwnd, GW_OWNER ); if (!hwndOwner) { hwndOwner = GetDesktopWindow(); } GetWindowRect( hwndOwner, &rcOwner ); } // // Calculate the starting x,y for the new // window so that it would be centered. // rcCenter.left = rcOwner.left + (((rcOwner.right - rcOwner.left) - (rc.right - rc.left)) / 2); rcCenter.top = rcOwner.top + (((rcOwner.bottom - rcOwner.top) - (rc.bottom - rc.top)) / 2); rcCenter.right = rcCenter.left + (rc.right - rc.left); rcCenter.bottom = rcCenter.top + (rc.bottom - rc.top); FitRectToScreen( &rcCenter ); SetWindowPos(hwnd, NULL, rcCenter.left, rcCenter.top, 0, 0, SWP_NOACTIVATE | SWP_NOSIZE | SWP_NOZORDER); } BOOL CreateLocalFaxPrinter( LPWSTR FaxPrinterName ) { STARTUPINFO si; PROCESS_INFORMATION pi; WCHAR TmpCmdLine[512]; WCHAR CmdLine[512]; DWORD ExitCode; BOOL Rval = TRUE; MONITOR_INFO_2 MonitorInfo; PPRINTER_INFO_2 PrinterInfo; DWORD i; DWORD Count; WCHAR SourcePath[MAX_PATH]; // // check to see if a fax printer already exists // if so, do nothing but return success // PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &Count, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ); if (PrinterInfo) { for (i=0; i=Count) { DebugPrint(( TEXT("faxocm did not find old port monitor") )); return TRUE; } PrinterInfo = (PPRINTER_INFO_2) MyEnumPrinters( NULL, 2, &Count, PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS ); if (!PrinterInfo) { goto e0; } for (i=0; i= MAX_PATH)) { OldCD[0] = 0; } OleInitialize(NULL); if (SetupFindFirstLine(InfHandle,szOleControlDlls,NULL,&InfLine)) { do { SetupGetStringField( &InfLine, 1, Filename, sizeof(Filename)/sizeof(WCHAR), &d ); if (Filename[0]) { // // Form a full path to the dll // ExpandEnvironmentStrings( L"%windir%\\system32\\", FullPath, sizeof(FullPath)/sizeof(WCHAR) ); SetCurrentDirectory( FullPath ); wcscat( FullPath, Filename ); if(ControlDll = LoadLibrary(FullPath)) { if (RegisterRoutine = (PREGISTERROUTINE) GetProcAddress(ControlDll,"DllRegisterServer")) { __try { RegisterRoutine(); } __except (EXCEPTION_EXECUTE_HANDLER) { b = FALSE; } } else { b = FALSE; } FreeLibrary(ControlDll); } else { b = FALSE; } } else { b = FALSE; } } while(SetupFindNextLine(&InfLine,&InfLine)); } if(OldCD[0]) { SetCurrentDirectory(OldCD); } OleUninitialize(); return b; } LPWSTR VerifyInstallPath( LPWSTR SourcePath ) { HKEY hKey; WCHAR SourceFile[MAX_PATH]; int len; // // make sure our source path contains necessary files. // wcscpy(SourceFile,SourcePath); len = wcslen(SourcePath); if (SourceFile[len-1] != '\\' ) { SourceFile[len] = '\\'; SourceFile[len+1] = (WCHAR) 0; } wcscat(SourceFile,L"faxdrv.dll"); if (GetFileAttributes(SourceFile) != (DWORD) -1 ) { return SourcePath; } // // our source path must be incorrect, use the registered NT source path // MemFree(SourcePath); hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE,REGKEY_WINDOWSNT_CURRVER,FALSE,0); if (!hKey) { DebugPrint(( TEXT("Could'nt OpenRegistryKey, ec = %d\n"),GetLastError() )); return NULL; } SourcePath = GetRegistryString(hKey,REGVAL_SOURCE_PATH,NULL); RegCloseKey(hKey); return SourcePath; } BOOL SetFaxShellExtension( LPCWSTR Path ) { WCHAR FileName[MAX_PATH]; DWORD attrib; // // create the file // wsprintf(FileName, L"%s\\desktop.ini", Path); WritePrivateProfileString( L".ShellClassInfo", L"UICLSID", FAXSHELL_CLSID, FileName ); // // hide it // attrib = GetFileAttributes( FileName ); attrib |= FILE_ATTRIBUTE_HIDDEN; if (SetFileAttributes( FileName, attrib ) ) { // // better to use PathMakeSystemFolder, but don't want to get shlwapi involved, // so we just set the system flag for the folder. // attrib = GetFileAttributes( Path ); attrib |= FILE_ATTRIBUTE_SYSTEM; return ( SetFileAttributes( Path, attrib ) ); } else { return FALSE; } } BOOL IsNt4or351Upgrade( VOID ) { // // we know that after installing NT5, the pid3.0 digital product id should be stored. we can // determine if nt5 was installed by looking for this value // HKEY hKey; LONG rslt; BYTE data[1000]; DWORD dwType; DWORD cbData = sizeof(data); rslt = RegOpenKey(HKEY_LOCAL_MACHINE,WINNT_CURVER,&hKey); if (rslt != ERROR_SUCCESS) { return FALSE; } rslt = RegQueryValueEx(hKey,DIGID,NULL,&dwType,data,&cbData); RegCloseKey(hKey); return (rslt != ERROR_SUCCESS); } BOOL MyGetSpecialPath( INT Id, LPWSTR Buffer ) { WCHAR TempBuffer[MAX_PATH]; HKEY hKey; LONG rslt; BYTE data[1000]; DWORD dwType; DWORD cbData = sizeof(data); if (GetSpecialPath(Id,Buffer)) { return TRUE; } // // if it fails, then let's try to hack hack hack our way around this // rslt = RegOpenKey(HKEY_LOCAL_MACHINE,WINNT_CURVER REGKEY_PROFILES ,&hKey); if (rslt != ERROR_SUCCESS) { return FALSE; } rslt = RegQueryValueEx(hKey,REGVAL_PROFILES,NULL,&dwType,data,&cbData); RegCloseKey(hKey); if (rslt != ERROR_SUCCESS) { // // // return FALSE; } ExpandEnvironmentStrings((LPCTSTR) data,TempBuffer,sizeof(TempBuffer)); if (Id == CSIDL_COMMON_APPDATA) { ConcatenatePaths( TempBuffer, GetString(IDS_COMMONAPPDIR) ); lstrcpy( Buffer, TempBuffer); return TRUE; } return FALSE; } BOOL SuperHideDirectory( PWSTR Directory ) { // // super-hide means that even if the user says "show all files", the directory won't show up. // DWORD attrib; if (!Directory) { return FALSE; } // // hide it // attrib = GetFileAttributes( Directory ); attrib |= (FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_SYSTEM); return ( SetFileAttributes( Directory, attrib ) ); } BOOL MyInitializeMapi( BOOL MinimalInit ) { HKEY hKey = NULL; LPTSTR szNoMailClient = NULL; LPTSTR szPreFirstRun = NULL; BOOL bRslt = FALSE; hKey = OpenRegistryKey(HKEY_LOCAL_MACHINE, TEXT("SOFTWARE\\Clients\\Mail"), FALSE, KEY_ALL_ACCESS); if (hKey != NULL) { szNoMailClient = GetRegistryString(hKey, TEXT("NoMailClient"), TEXT("")); if (_tcscmp(szNoMailClient, TEXT("")) == 0) { MemFree(szNoMailClient); szNoMailClient = NULL; } else { RegDeleteValue(hKey, TEXT("NoMailClient")); } szPreFirstRun = GetRegistryString(hKey, TEXT("PreFirstRun"), TEXT("")); if (_tcscmp(szPreFirstRun, TEXT("")) == 0) { MemFree(szPreFirstRun); szPreFirstRun = NULL; } else { RegDeleteValue(hKey, TEXT("PreFirstRun")); } } bRslt = InitializeMapi(MinimalInit); if (szNoMailClient != NULL) { SetRegistryString(hKey, TEXT("NoMailClient"), szNoMailClient); MemFree(szNoMailClient); } if (szPreFirstRun != NULL) { SetRegistryString(hKey, TEXT("PreFirstRun"), szPreFirstRun); MemFree(szPreFirstRun); } if (hKey != NULL) { RegCloseKey(hKey); } return bRslt; }