update dev300-m58
[ooovba.git] / svx / source / dialog / sendreportw32.cxx
blobe51ade42cd551c75d5941d1e40a798c0fb7eeb5e
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: sendreportw32.cxx,v $
10 * $Revision: 1.8 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_svx.hxx"
35 #define UNICODE
36 #define _UNICODE
38 #include <tools/svwin.h>
40 #define WIN32_LEAN_AND_MEAN
41 #include <tchar.h>
42 #include <stdio.h>
43 #include <systools/win32/uwinapi.h>
45 // need to undef min and max macros from MS headers here to make
46 // the std::min and std::max from stl visible again
47 #ifdef min
48 #undef min
49 #endif
50 #ifdef max
51 #undef max
52 #endif
54 #include "docrecovery.hxx"
56 //***************************************************************************
58 static LONG RegReadValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPVOID lpData, DWORD cbData )
60 HKEY hKey = NULL;
61 LONG lResult;
63 lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
65 if ( ERROR_SUCCESS == lResult )
67 lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)lpData, &cbData );
68 RegCloseKey( hKey );
71 return lResult;
74 //***************************************************************************
76 static LONG RegWriteValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType, LPCVOID lpData, DWORD cbData )
78 HKEY hKey = NULL;
79 LONG lResult;
81 lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
83 if ( ERROR_SUCCESS == lResult )
85 lResult = RegSetValueEx( hKey, lpValueName, NULL, dwType, (CONST BYTE *)lpData, cbData );
86 RegCloseKey( hKey );
89 return lResult;
92 //***************************************************************************
94 namespace svx{
95 namespace DocRecovery{
97 bool ErrorRepSendDialog::ReadParams()
99 _TCHAR szBuffer[2048];
101 if ( ERROR_SUCCESS == RegReadValue(
102 HKEY_CURRENT_USER,
103 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
104 TEXT("HTTPProxyServer"),
105 szBuffer,
106 sizeof(szBuffer) ) )
107 maParams.maHTTPProxyServer = (sal_Unicode *)szBuffer;
109 DWORD dwProxyPort;
110 if ( ERROR_SUCCESS == RegReadValue(
111 HKEY_CURRENT_USER,
112 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
113 TEXT("HTTPProxyPort"),
114 &dwProxyPort,
115 sizeof(dwProxyPort) ) )
117 _stprintf( szBuffer, _T("%d"), dwProxyPort );
118 maParams.maHTTPProxyPort = (sal_Unicode *)szBuffer;
121 if ( ERROR_SUCCESS == RegReadValue(
122 HKEY_CURRENT_USER,
123 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
124 TEXT("ReturnAddress"),
125 szBuffer,
126 sizeof(szBuffer) ) )
127 maEMailAddrED.SetText( (sal_Unicode *)szBuffer );
129 DWORD fAllowContact = FALSE;
130 RegReadValue(
131 HKEY_CURRENT_USER,
132 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
133 TEXT("AllowContact"),
134 &fAllowContact,
135 sizeof(fAllowContact) );
136 maContactCB.Check( (BOOL)fAllowContact );
138 DWORD uInternetConnection = 0;
139 RegReadValue(
140 HKEY_CURRENT_USER,
141 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
142 TEXT("HTTPConnection"),
143 &uInternetConnection,
144 sizeof(uInternetConnection) );
145 maParams.miHTTPConnectionType = uInternetConnection;
147 return true;
150 bool ErrorRepSendDialog::SaveParams()
152 const _TCHAR *lpHTTPProxyServer = reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyServer.GetBuffer());
153 RegWriteValue(
154 HKEY_CURRENT_USER,
155 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
156 TEXT("HTTPProxyServer"), REG_SZ,
157 lpHTTPProxyServer,
158 sizeof(TCHAR) * (_tcslen(lpHTTPProxyServer) + 1) );
160 _TCHAR* endptr = NULL;
161 DWORD dwProxyPort = _tcstoul( reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyPort.GetBuffer()), &endptr, 10 );
163 RegWriteValue(
164 HKEY_CURRENT_USER,
165 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
166 TEXT("HTTPProxyPort"), REG_DWORD,
167 &dwProxyPort,
168 sizeof(DWORD) );
170 DWORD fAllowContact = IsContactAllowed();
171 RegWriteValue(
172 HKEY_CURRENT_USER,
173 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
174 TEXT("AllowContact"), REG_DWORD,
175 &fAllowContact,
176 sizeof(DWORD) );
179 DWORD uInternetConnection = maParams.miHTTPConnectionType;
181 RegWriteValue(
182 HKEY_CURRENT_USER,
183 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
184 TEXT("HTTPConnection"), REG_DWORD,
185 &uInternetConnection,
186 sizeof(DWORD) );
188 const _TCHAR *lpEmail = reinterpret_cast<LPCTSTR>(GetEMailAddress().GetBuffer());
189 RegWriteValue(
190 HKEY_CURRENT_USER,
191 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
192 TEXT("ReturnAddress"), REG_SZ,
193 lpEmail,
194 sizeof(TCHAR) * (_tcslen(lpEmail) + 1) );
196 return true;
199 bool ErrorRepSendDialog::SendReport()
201 TCHAR szTempPath[MAX_PATH];
202 TCHAR szFileName[MAX_PATH];
204 GetTempPath( elementsof(szTempPath), szTempPath );
205 GetTempFileName( szTempPath, TEXT("DSC"), 0, szFileName );
207 FILE *fp = _tfopen( szFileName, _T("wb") );
209 if ( fp )
211 ByteString strUTF8( GetUsing(), RTL_TEXTENCODING_UTF8 );
213 fwrite( strUTF8.GetBuffer(), 1, strUTF8.Len(), fp );
214 fclose( fp );
217 SetEnvironmentVariable( TEXT("ERRORREPORT_SUBJECT"), reinterpret_cast<LPCTSTR>(GetDocType().GetBuffer()) );
218 SetEnvironmentVariable( TEXT("ERRORREPORT_BODYFILE"), szFileName );
220 _TCHAR szBuffer[1024];
221 TCHAR szPath[MAX_PATH];
222 LPTSTR lpFilePart;
223 PROCESS_INFORMATION ProcessInfo;
224 STARTUPINFO StartupInfo;
226 if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_PATH, szPath, &lpFilePart ) )
228 ZeroMemory( &StartupInfo, sizeof(StartupInfo) );
229 StartupInfo.cb = sizeof(StartupInfo.cb);
231 sntprintf( szBuffer, elementsof(szBuffer),
232 _T("%s -noui -load -send"),
233 szPath );
235 if (
236 CreateProcess(
237 NULL,
238 szBuffer,
239 NULL,
240 NULL,
241 FALSE,
243 NULL, NULL, &StartupInfo, &ProcessInfo )
246 DWORD dwExitCode;
248 WaitForSingleObject( ProcessInfo.hProcess, INFINITE );
249 if ( GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) && 0 == dwExitCode )
250 return true;
255 DeleteFile( szFileName );
258 return false;
262 } // namespace DocRecovery
263 } // namespace svx