bump product version to 4.1.6.2
[LibreOffice.git] / svx / source / dialog / sendreportw32.cxx
blob0a02388a3c86261afa6eb21feabc07614acc47d5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #define UNICODE
21 #define _UNICODE
23 #include "docrecovery.hxx"
25 #undef WB_LEFT
26 #undef WB_RIGHT
28 #include <prewin.h>
29 #include <postwin.h>
30 #include <tchar.h>
31 #include <stdio.h>
32 #include <systools/win32/uwinapi.h>
33 #include <sal/macros.h>
35 // need to undef min and max macros from MS headers here to make
36 // the std::min and std::max from stl visible again
37 #ifdef min
38 #undef min
39 #endif
40 #ifdef max
41 #undef max
42 #endif
44 //***************************************************************************
46 static LONG RegReadValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, LPVOID lpData, DWORD cbData )
48 HKEY hKey = NULL;
49 LONG lResult;
51 lResult = RegOpenKeyEx( hBaseKey, lpSubKey, 0, KEY_QUERY_VALUE, &hKey );
53 if ( ERROR_SUCCESS == lResult )
55 lResult = RegQueryValueEx( hKey, lpValueName, NULL, NULL, (LPBYTE)lpData, &cbData );
56 RegCloseKey( hKey );
59 return lResult;
62 //***************************************************************************
64 static LONG RegWriteValue( HKEY hBaseKey, LPCTSTR lpSubKey, LPCTSTR lpValueName, DWORD dwType, LPCVOID lpData, DWORD cbData )
66 HKEY hKey = NULL;
67 LONG lResult;
69 lResult = RegCreateKeyEx( hBaseKey, lpSubKey, 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, &hKey, NULL );
71 if ( ERROR_SUCCESS == lResult )
73 lResult = RegSetValueEx( hKey, lpValueName, 0, dwType, (CONST sal_uInt8 *)lpData, cbData );
74 RegCloseKey( hKey );
77 return lResult;
80 //***************************************************************************
82 namespace svx{
83 namespace DocRecovery{
85 bool ErrorRepSendDialog::ReadParams()
87 _TCHAR szBuffer[2048];
89 if ( ERROR_SUCCESS == RegReadValue(
90 HKEY_CURRENT_USER,
91 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
92 TEXT("HTTPProxyServer"),
93 szBuffer,
94 sizeof(szBuffer) ) )
95 maParams.maHTTPProxyServer = (sal_Unicode *)szBuffer;
97 DWORD dwProxyPort;
98 if ( ERROR_SUCCESS == RegReadValue(
99 HKEY_CURRENT_USER,
100 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
101 TEXT("HTTPProxyPort"),
102 &dwProxyPort,
103 sizeof(dwProxyPort) ) )
105 _stprintf( szBuffer, _T("%d"), dwProxyPort );
106 maParams.maHTTPProxyPort = (sal_Unicode *)szBuffer;
109 if ( ERROR_SUCCESS == RegReadValue(
110 HKEY_CURRENT_USER,
111 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
112 TEXT("ReturnAddress"),
113 szBuffer,
114 sizeof(szBuffer) ) )
115 maEMailAddrED.SetText(OUString((sal_Unicode *)szBuffer));
117 DWORD fAllowContact = sal_False;
118 RegReadValue(
119 HKEY_CURRENT_USER,
120 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
121 TEXT("AllowContact"),
122 &fAllowContact,
123 sizeof(fAllowContact) );
124 maContactCB.Check( (sal_Bool)fAllowContact );
126 DWORD uInternetConnection = 0;
127 RegReadValue(
128 HKEY_CURRENT_USER,
129 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
130 TEXT("HTTPConnection"),
131 &uInternetConnection,
132 sizeof(uInternetConnection) );
133 maParams.miHTTPConnectionType = uInternetConnection;
135 return true;
138 bool ErrorRepSendDialog::SaveParams()
140 const _TCHAR *lpHTTPProxyServer = reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyServer.GetBuffer());
141 RegWriteValue(
142 HKEY_CURRENT_USER,
143 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
144 TEXT("HTTPProxyServer"), REG_SZ,
145 lpHTTPProxyServer,
146 sizeof(TCHAR) * (_tcslen(lpHTTPProxyServer) + 1) );
148 _TCHAR* endptr = NULL;
149 DWORD dwProxyPort = _tcstoul( reinterpret_cast<LPCTSTR>(maParams.maHTTPProxyPort.GetBuffer()), &endptr, 10 );
151 RegWriteValue(
152 HKEY_CURRENT_USER,
153 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
154 TEXT("HTTPProxyPort"), REG_DWORD,
155 &dwProxyPort,
156 sizeof(DWORD) );
158 DWORD fAllowContact = IsContactAllowed();
159 RegWriteValue(
160 HKEY_CURRENT_USER,
161 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
162 TEXT("AllowContact"), REG_DWORD,
163 &fAllowContact,
164 sizeof(DWORD) );
167 DWORD uInternetConnection = maParams.miHTTPConnectionType;
169 RegWriteValue(
170 HKEY_CURRENT_USER,
171 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
172 TEXT("HTTPConnection"), REG_DWORD,
173 &uInternetConnection,
174 sizeof(DWORD) );
176 const _TCHAR *lpEmail = reinterpret_cast<LPCTSTR>(GetEMailAddress().GetBuffer());
177 RegWriteValue(
178 HKEY_CURRENT_USER,
179 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
180 TEXT("ReturnAddress"), REG_SZ,
181 lpEmail,
182 sizeof(TCHAR) * (_tcslen(lpEmail) + 1) );
184 return true;
187 bool ErrorRepSendDialog::SendReport()
189 TCHAR szTempPath[MAX_PATH];
190 TCHAR szFileName[MAX_PATH];
192 GetTempPath( SAL_N_ELEMENTS(szTempPath), szTempPath );
193 GetTempFileName( szTempPath, TEXT("DSC"), 0, szFileName );
195 FILE *fp = _tfopen( szFileName, _T("wb") );
197 if ( fp )
199 OString strUTF8(OUStringToOString(GetUsing(),
200 RTL_TEXTENCODING_UTF8));
202 fwrite( strUTF8.getStr(), 1, strUTF8.getLength(), fp );
203 fclose( fp );
206 SetEnvironmentVariable( TEXT("ERRORREPORT_SUBJECT"), reinterpret_cast<LPCTSTR>(GetDocType().GetBuffer()) );
207 SetEnvironmentVariable( TEXT("ERRORREPORT_BODYFILE"), szFileName );
209 _TCHAR szBuffer[1024];
210 TCHAR szPath[MAX_PATH];
211 LPTSTR lpFilePart;
212 PROCESS_INFORMATION ProcessInfo;
213 STARTUPINFO StartupInfo;
215 if ( SearchPath( NULL, TEXT("crashrep.exe"), NULL, MAX_PATH, szPath, &lpFilePart ) )
217 ZeroMemory( &StartupInfo, sizeof(StartupInfo) );
218 StartupInfo.cb = sizeof(StartupInfo.cb);
220 sntprintf( szBuffer, SAL_N_ELEMENTS(szBuffer),
221 _T("%s -noui -load -send"),
222 szPath );
224 if (
225 CreateProcess(
226 NULL,
227 szBuffer,
228 NULL,
229 NULL,
230 sal_False,
232 NULL, NULL, &StartupInfo, &ProcessInfo )
235 DWORD dwExitCode;
237 WaitForSingleObject( ProcessInfo.hProcess, INFINITE );
238 if ( GetExitCodeProcess( ProcessInfo.hProcess, &dwExitCode ) && 0 == dwExitCode )
239 return true;
244 DeleteFile( szFileName );
247 return false;
251 } // namespace DocRecovery
252 } // namespace svx
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */