1*f6e50924SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*f6e50924SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*f6e50924SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*f6e50924SAndrew Rist * distributed with this work for additional information 6*f6e50924SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*f6e50924SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*f6e50924SAndrew Rist * "License"); you may not use this file except in compliance 9*f6e50924SAndrew Rist * with the License. You may obtain a copy of the License at 10*f6e50924SAndrew Rist * 11*f6e50924SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*f6e50924SAndrew Rist * 13*f6e50924SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*f6e50924SAndrew Rist * software distributed under the License is distributed on an 15*f6e50924SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*f6e50924SAndrew Rist * KIND, either express or implied. See the License for the 17*f6e50924SAndrew Rist * specific language governing permissions and limitations 18*f6e50924SAndrew Rist * under the License. 19*f6e50924SAndrew Rist * 20*f6e50924SAndrew Rist *************************************************************/ 21*f6e50924SAndrew Rist 22*f6e50924SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir 25cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 26cdf0e10cSrcweir #include "precompiled_svx.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #define UNICODE 29cdf0e10cSrcweir #define _UNICODE 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <tools/svwin.h> 32cdf0e10cSrcweir 33cdf0e10cSrcweir #define WIN32_LEAN_AND_MEAN 34cdf0e10cSrcweir #include <tchar.h> 35cdf0e10cSrcweir #include <stdio.h> 36cdf0e10cSrcweir #include <systools/win32/uwinapi.h> 37cdf0e10cSrcweir 38cdf0e10cSrcweir // need to undef min and max macros from MS headers here to make 39cdf0e10cSrcweir // the std::min and std::max from stl visible again 40cdf0e10cSrcweir #ifdef min 41cdf0e10cSrcweir #undef min 42cdf0e10cSrcweir #endif 43cdf0e10cSrcweir #ifdef max 44cdf0e10cSrcweir #undef max 45cdf0e10cSrcweir #endif 46cdf0e10cSrcweir 47cdf0e10cSrcweir #include "docrecovery.hxx" 48cdf0e10cSrcweir 49cdf0e10cSrcweir //*************************************************************************** 50cdf0e10cSrcweir 51cdf0e10cSrcweir static LONG RegReadValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPVOID lpData, DWORD cbData ) 52cdf0e10cSrcweir { 53cdf0e10cSrcweir HKEY hKey = NULL; 54cdf0e10cSrcweir LONG lResult; 55cdf0e10cSrcweir 56cdf0e10cSrcweir lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey ); 57cdf0e10cSrcweir 58cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 59cdf0e10cSrcweir { 60cdf0e10cSrcweir lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)lpData, &cbData ); 61cdf0e10cSrcweir RegCloseKey( hKey ); 62cdf0e10cSrcweir } 63cdf0e10cSrcweir 64cdf0e10cSrcweir return lResult; 65cdf0e10cSrcweir } 66cdf0e10cSrcweir 67cdf0e10cSrcweir //*************************************************************************** 68cdf0e10cSrcweir 69cdf0e10cSrcweir static LONG RegWriteValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType, LPCVOID lpData, DWORD cbData ) 70cdf0e10cSrcweir { 71cdf0e10cSrcweir HKEY hKey = NULL; 72cdf0e10cSrcweir LONG lResult; 73cdf0e10cSrcweir 74cdf0e10cSrcweir lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL ); 75cdf0e10cSrcweir 76cdf0e10cSrcweir if ( ERROR_SUCCESS == lResult ) 77cdf0e10cSrcweir { 78cdf0e10cSrcweir lResult = RegSetValueEx( hKey, lpValueName, NULL, dwType, (CONST sal_uInt8 *)lpData, cbData ); 79cdf0e10cSrcweir RegCloseKey( hKey ); 80cdf0e10cSrcweir } 81cdf0e10cSrcweir 82cdf0e10cSrcweir return lResult; 83cdf0e10cSrcweir } 84cdf0e10cSrcweir 85cdf0e10cSrcweir //*************************************************************************** 86cdf0e10cSrcweir 87cdf0e10cSrcweir namespace svx{ 88cdf0e10cSrcweir namespace DocRecovery{ 89cdf0e10cSrcweir 90cdf0e10cSrcweir bool ErrorRepSendDialog::ReadParams() 91cdf0e10cSrcweir { 92cdf0e10cSrcweir _TCHAR szBuffer[2048]; 93cdf0e10cSrcweir 94cdf0e10cSrcweir if ( ERROR_SUCCESS == RegReadValue( 95cdf0e10cSrcweir HKEY_CURRENT_USER, 96cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 97cdf0e10cSrcweir TEXT("HTTPProxyServer"), 98cdf0e10cSrcweir szBuffer, 99cdf0e10cSrcweir sizeof(szBuffer) ) ) 100cdf0e10cSrcweir maParams.maHTTPProxyServer = (sal_Unicode *)szBuffer; 101cdf0e10cSrcweir 102cdf0e10cSrcweir DWORD dwProxyPort; 103cdf0e10cSrcweir if ( ERROR_SUCCESS == RegReadValue( 104cdf0e10cSrcweir HKEY_CURRENT_USER, 105cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 106cdf0e10cSrcweir TEXT("HTTPProxyPort"), 107cdf0e10cSrcweir &dwProxyPort, 108cdf0e10cSrcweir sizeof(dwProxyPort) ) ) 109cdf0e10cSrcweir { 110cdf0e10cSrcweir _stprintf( szBuffer, _T("%d"), dwProxyPort ); 111cdf0e10cSrcweir maParams.maHTTPProxyPort = (sal_Unicode *)szBuffer; 112cdf0e10cSrcweir } 113cdf0e10cSrcweir 114cdf0e10cSrcweir if ( ERROR_SUCCESS == RegReadValue( 115cdf0e10cSrcweir HKEY_CURRENT_USER, 116cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 117cdf0e10cSrcweir TEXT("ReturnAddress"), 118cdf0e10cSrcweir szBuffer, 119cdf0e10cSrcweir sizeof(szBuffer) ) ) 120cdf0e10cSrcweir maEMailAddrED.SetText( (sal_Unicode *)szBuffer ); 121cdf0e10cSrcweir 122cdf0e10cSrcweir DWORD fAllowContact = sal_False; 123cdf0e10cSrcweir RegReadValue( 124cdf0e10cSrcweir HKEY_CURRENT_USER, 125cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 126cdf0e10cSrcweir TEXT("AllowContact"), 127cdf0e10cSrcweir &fAllowContact, 128cdf0e10cSrcweir sizeof(fAllowContact) ); 129cdf0e10cSrcweir maContactCB.Check( (sal_Bool)fAllowContact ); 130cdf0e10cSrcweir 131cdf0e10cSrcweir DWORD uInternetConnection = 0; 132cdf0e10cSrcweir RegReadValue( 133cdf0e10cSrcweir HKEY_CURRENT_USER, 134cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 135cdf0e10cSrcweir TEXT("HTTPConnection"), 136cdf0e10cSrcweir &uInternetConnection, 137cdf0e10cSrcweir sizeof(uInternetConnection) ); 138cdf0e10cSrcweir maParams.miHTTPConnectionType = uInternetConnection; 139cdf0e10cSrcweir 140cdf0e10cSrcweir return true; 141cdf0e10cSrcweir } 142cdf0e10cSrcweir 143cdf0e10cSrcweir bool ErrorRepSendDialog::SaveParams() 144cdf0e10cSrcweir { 145cdf0e10cSrcweir const _TCHAR *lpHTTPProxyServer = reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyServer.GetBuffer()); 146cdf0e10cSrcweir RegWriteValue( 147cdf0e10cSrcweir HKEY_CURRENT_USER, 148cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 149cdf0e10cSrcweir TEXT("HTTPProxyServer"), REG_SZ, 150cdf0e10cSrcweir lpHTTPProxyServer, 151cdf0e10cSrcweir sizeof(TCHAR) * (_tcslen(lpHTTPProxyServer) + 1) ); 152cdf0e10cSrcweir 153cdf0e10cSrcweir _TCHAR* endptr = NULL; 154cdf0e10cSrcweir DWORD dwProxyPort = _tcstoul( reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyPort.GetBuffer()), &endptr, 10 ); 155cdf0e10cSrcweir 156cdf0e10cSrcweir RegWriteValue( 157cdf0e10cSrcweir HKEY_CURRENT_USER, 158cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 159cdf0e10cSrcweir TEXT("HTTPProxyPort"), REG_DWORD, 160cdf0e10cSrcweir &dwProxyPort, 161cdf0e10cSrcweir sizeof(DWORD) ); 162cdf0e10cSrcweir 163cdf0e10cSrcweir DWORD fAllowContact = IsContactAllowed(); 164cdf0e10cSrcweir RegWriteValue( 165cdf0e10cSrcweir HKEY_CURRENT_USER, 166cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 167cdf0e10cSrcweir TEXT("AllowContact"), REG_DWORD, 168cdf0e10cSrcweir &fAllowContact, 169cdf0e10cSrcweir sizeof(DWORD) ); 170cdf0e10cSrcweir 171cdf0e10cSrcweir 172cdf0e10cSrcweir DWORD uInternetConnection = maParams.miHTTPConnectionType; 173cdf0e10cSrcweir 174cdf0e10cSrcweir RegWriteValue( 175cdf0e10cSrcweir HKEY_CURRENT_USER, 176cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 177cdf0e10cSrcweir TEXT("HTTPConnection"), REG_DWORD, 178cdf0e10cSrcweir &uInternetConnection, 179cdf0e10cSrcweir sizeof(DWORD) ); 180cdf0e10cSrcweir 181cdf0e10cSrcweir const _TCHAR *lpEmail = reinterpret_cast<LPCTSTR>(GetEMailAddress().GetBuffer()); 182cdf0e10cSrcweir RegWriteValue( 183cdf0e10cSrcweir HKEY_CURRENT_USER, 184cdf0e10cSrcweir TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"), 185cdf0e10cSrcweir TEXT("ReturnAddress"), REG_SZ, 186cdf0e10cSrcweir lpEmail, 187cdf0e10cSrcweir sizeof(TCHAR) * (_tcslen(lpEmail) + 1) ); 188cdf0e10cSrcweir 189cdf0e10cSrcweir return true; 190cdf0e10cSrcweir } 191cdf0e10cSrcweir 192cdf0e10cSrcweir bool ErrorRepSendDialog::SendReport() 193cdf0e10cSrcweir { 194cdf0e10cSrcweir TCHAR szTempPath[MAX_PATH]; 195cdf0e10cSrcweir TCHAR szFileName[MAX_PATH]; 196cdf0e10cSrcweir 197cdf0e10cSrcweir GetTempPath( elementsof(szTempPath), szTempPath ); 198cdf0e10cSrcweir GetTempFileName( szTempPath, TEXT("DSC"), 0, szFileName ); 199cdf0e10cSrcweir 200cdf0e10cSrcweir FILE *fp = _tfopen( szFileName, _T("wb") ); 201cdf0e10cSrcweir 202cdf0e10cSrcweir if ( fp ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir ByteString strUTF8( GetUsing(), RTL_TEXTENCODING_UTF8 ); 205cdf0e10cSrcweir 206cdf0e10cSrcweir fwrite( strUTF8.GetBuffer(), 1, strUTF8.Len(), fp ); 207cdf0e10cSrcweir fclose( fp ); 208cdf0e10cSrcweir } 209cdf0e10cSrcweir 210cdf0e10cSrcweir SetEnvironmentVariable( TEXT("ERRORREPORT_SUBJECT"), reinterpret_cast<LPCTSTR>(GetDocType().GetBuffer()) ); 211cdf0e10cSrcweir SetEnvironmentVariable( TEXT("ERRORREPORT_BODYFILE"), szFileName ); 212cdf0e10cSrcweir 213cdf0e10cSrcweir _TCHAR szBuffer[1024]; 214cdf0e10cSrcweir TCHAR szPath[MAX_PATH]; 215cdf0e10cSrcweir LPTSTR lpFilePart; 216cdf0e10cSrcweir PROCESS_INFORMATION ProcessInfo; 217cdf0e10cSrcweir STARTUPINFO StartupInfo; 218cdf0e10cSrcweir 219cdf0e10cSrcweir if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_PATH, szPath, &lpFilePart ) ) 220cdf0e10cSrcweir { 221cdf0e10cSrcweir ZeroMemory( &StartupInfo, sizeof(StartupInfo) ); 222cdf0e10cSrcweir StartupInfo.cb = sizeof(StartupInfo.cb); 223cdf0e10cSrcweir 224cdf0e10cSrcweir sntprintf( szBuffer, elementsof(szBuffer), 225cdf0e10cSrcweir _T("%s -noui -load -send"), 226cdf0e10cSrcweir szPath ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir if ( 229cdf0e10cSrcweir CreateProcess( 230cdf0e10cSrcweir NULL, 231cdf0e10cSrcweir szBuffer, 232cdf0e10cSrcweir NULL, 233cdf0e10cSrcweir NULL, 234cdf0e10cSrcweir sal_False, 235cdf0e10cSrcweir 0, 236cdf0e10cSrcweir NULL, NULL, &StartupInfo, &ProcessInfo ) 237cdf0e10cSrcweir ) 238cdf0e10cSrcweir { 239cdf0e10cSrcweir DWORD dwExitCode; 240cdf0e10cSrcweir 241cdf0e10cSrcweir WaitForSingleObject( ProcessInfo.hProcess, INFINITE ); 242cdf0e10cSrcweir if ( GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) && 0 == dwExitCode ) 243cdf0e10cSrcweir return true; 244cdf0e10cSrcweir 245cdf0e10cSrcweir } 246cdf0e10cSrcweir } 247cdf0e10cSrcweir 248cdf0e10cSrcweir DeleteFile( szFileName ); 249cdf0e10cSrcweir 250cdf0e10cSrcweir 251cdf0e10cSrcweir return false; 252cdf0e10cSrcweir } 253cdf0e10cSrcweir 254cdf0e10cSrcweir 255cdf0e10cSrcweir } // namespace DocRecovery 256cdf0e10cSrcweir } // namespace svx 257