Version 3.6.0.4, tag libreoffice-3.6.0.4
[LibreOffice.git] / svx / source / dialog / sendreportw32.cxx
blob129e7cbd3cf021f2c78c07d782172b7e3df95468
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
31 #define UNICODE
32 #define _UNICODE
33 #include <prewin.h>
34 #include <postwin.h>
35 #include <tchar.h>
36 #include <stdio.h>
37 #include <systools/win32/uwinapi.h>
38 #include <sal/macros.h>
40 // need to undef min and max macros from MS headers here to make
41 // the std::min and std::max from stl visible again
42 #ifdef min
43 #undef min
44 #endif
45 #ifdef max
46 #undef max
47 #endif
49 #include "docrecovery.hxx"
51 //***************************************************************************
53 static LONG RegReadValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPVOID lpData, DWORD cbData )
55 HKEY hKey = NULL;
56 LONG lResult;
58 lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
60 if ( ERROR_SUCCESS == lResult )
62 lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)lpData, &cbData );
63 RegCloseKey( hKey );
66 return lResult;
69 //***************************************************************************
71 static LONG RegWriteValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType, LPCVOID lpData, DWORD cbData )
73 HKEY hKey = NULL;
74 LONG lResult;
76 lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
78 if ( ERROR_SUCCESS == lResult )
80 lResult = RegSetValueEx( hKey, lpValueName, 0, dwType, (CONST sal_uInt8 *)lpData, cbData );
81 RegCloseKey( hKey );
84 return lResult;
87 //***************************************************************************
89 namespace svx{
90 namespace DocRecovery{
92 bool ErrorRepSendDialog::ReadParams()
94 _TCHAR szBuffer[2048];
96 if ( ERROR_SUCCESS == RegReadValue(
97 HKEY_CURRENT_USER,
98 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
99 TEXT("HTTPProxyServer"),
100 szBuffer,
101 sizeof(szBuffer) ) )
102 maParams.maHTTPProxyServer = (sal_Unicode *)szBuffer;
104 DWORD dwProxyPort;
105 if ( ERROR_SUCCESS == RegReadValue(
106 HKEY_CURRENT_USER,
107 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
108 TEXT("HTTPProxyPort"),
109 &dwProxyPort,
110 sizeof(dwProxyPort) ) )
112 _stprintf( szBuffer, _T("%d"), dwProxyPort );
113 maParams.maHTTPProxyPort = (sal_Unicode *)szBuffer;
116 if ( ERROR_SUCCESS == RegReadValue(
117 HKEY_CURRENT_USER,
118 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
119 TEXT("ReturnAddress"),
120 szBuffer,
121 sizeof(szBuffer) ) )
122 maEMailAddrED.SetText( (sal_Unicode *)szBuffer );
124 DWORD fAllowContact = sal_False;
125 RegReadValue(
126 HKEY_CURRENT_USER,
127 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
128 TEXT("AllowContact"),
129 &fAllowContact,
130 sizeof(fAllowContact) );
131 maContactCB.Check( (sal_Bool)fAllowContact );
133 DWORD uInternetConnection = 0;
134 RegReadValue(
135 HKEY_CURRENT_USER,
136 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
137 TEXT("HTTPConnection"),
138 &uInternetConnection,
139 sizeof(uInternetConnection) );
140 maParams.miHTTPConnectionType = uInternetConnection;
142 return true;
145 bool ErrorRepSendDialog::SaveParams()
147 const _TCHAR *lpHTTPProxyServer = reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyServer.GetBuffer());
148 RegWriteValue(
149 HKEY_CURRENT_USER,
150 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
151 TEXT("HTTPProxyServer"), REG_SZ,
152 lpHTTPProxyServer,
153 sizeof(TCHAR) * (_tcslen(lpHTTPProxyServer) + 1) );
155 _TCHAR* endptr = NULL;
156 DWORD dwProxyPort = _tcstoul( reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyPort.GetBuffer()), &endptr, 10 );
158 RegWriteValue(
159 HKEY_CURRENT_USER,
160 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
161 TEXT("HTTPProxyPort"), REG_DWORD,
162 &dwProxyPort,
163 sizeof(DWORD) );
165 DWORD fAllowContact = IsContactAllowed();
166 RegWriteValue(
167 HKEY_CURRENT_USER,
168 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
169 TEXT("AllowContact"), REG_DWORD,
170 &fAllowContact,
171 sizeof(DWORD) );
174 DWORD uInternetConnection = maParams.miHTTPConnectionType;
176 RegWriteValue(
177 HKEY_CURRENT_USER,
178 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
179 TEXT("HTTPConnection"), REG_DWORD,
180 &uInternetConnection,
181 sizeof(DWORD) );
183 const _TCHAR *lpEmail = reinterpret_cast<LPCTSTR>(GetEMailAddress().GetBuffer());
184 RegWriteValue(
185 HKEY_CURRENT_USER,
186 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
187 TEXT("ReturnAddress"), REG_SZ,
188 lpEmail,
189 sizeof(TCHAR) * (_tcslen(lpEmail) + 1) );
191 return true;
194 bool ErrorRepSendDialog::SendReport()
196 TCHAR szTempPath[MAX_PATH];
197 TCHAR szFileName[MAX_PATH];
199 GetTempPath( SAL_N_ELEMENTS(szTempPath), szTempPath );
200 GetTempFileName( szTempPath, TEXT("DSC"), 0, szFileName );
202 FILE *fp = _tfopen( szFileName, _T("wb") );
204 if ( fp )
206 rtl::OString strUTF8(rtl::OUStringToOString(GetUsing(),
207 RTL_TEXTENCODING_UTF8));
209 fwrite( strUTF8.getStr(), 1, strUTF8.getLength(), fp );
210 fclose( fp );
213 SetEnvironmentVariable( TEXT("ERRORREPORT_SUBJECT"), reinterpret_cast<LPCTSTR>(GetDocType().GetBuffer()) );
214 SetEnvironmentVariable( TEXT("ERRORREPORT_BODYFILE"), szFileName );
216 _TCHAR szBuffer[1024];
217 TCHAR szPath[MAX_PATH];
218 LPTSTR lpFilePart;
219 PROCESS_INFORMATION ProcessInfo;
220 STARTUPINFO StartupInfo;
222 if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_PATH, szPath, &lpFilePart ) )
224 ZeroMemory( &StartupInfo, sizeof(StartupInfo) );
225 StartupInfo.cb = sizeof(StartupInfo.cb);
227 sntprintf( szBuffer, SAL_N_ELEMENTS(szBuffer),
228 _T("%s -noui -load -send"),
229 szPath );
231 if (
232 CreateProcess(
233 NULL,
234 szBuffer,
235 NULL,
236 NULL,
237 sal_False,
239 NULL, NULL, &StartupInfo, &ProcessInfo )
242 DWORD dwExitCode;
244 WaitForSingleObject( ProcessInfo.hProcess, INFINITE );
245 if ( GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) && 0 == dwExitCode )
246 return true;
251 DeleteFile( szFileName );
254 return false;
258 } // namespace DocRecovery
259 } // namespace svx
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */