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 ************************************************************************/
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
49 #include "docrecovery.hxx"
51 //***************************************************************************
53 static LONG
RegReadValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPVOID lpData
, DWORD cbData
)
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
);
69 //***************************************************************************
71 static LONG
RegWriteValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, DWORD dwType
, LPCVOID lpData
, DWORD cbData
)
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
);
87 //***************************************************************************
90 namespace DocRecovery
{
92 bool ErrorRepSendDialog::ReadParams()
94 _TCHAR szBuffer
[2048];
96 if ( ERROR_SUCCESS
== RegReadValue(
98 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
99 TEXT("HTTPProxyServer"),
102 maParams
.maHTTPProxyServer
= (sal_Unicode
*)szBuffer
;
105 if ( ERROR_SUCCESS
== RegReadValue(
107 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
108 TEXT("HTTPProxyPort"),
110 sizeof(dwProxyPort
) ) )
112 _stprintf( szBuffer
, _T("%d"), dwProxyPort
);
113 maParams
.maHTTPProxyPort
= (sal_Unicode
*)szBuffer
;
116 if ( ERROR_SUCCESS
== RegReadValue(
118 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
119 TEXT("ReturnAddress"),
122 maEMailAddrED
.SetText( (sal_Unicode
*)szBuffer
);
124 DWORD fAllowContact
= sal_False
;
127 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
128 TEXT("AllowContact"),
130 sizeof(fAllowContact
) );
131 maContactCB
.Check( (sal_Bool
)fAllowContact
);
133 DWORD uInternetConnection
= 0;
136 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
137 TEXT("HTTPConnection"),
138 &uInternetConnection
,
139 sizeof(uInternetConnection
) );
140 maParams
.miHTTPConnectionType
= uInternetConnection
;
145 bool ErrorRepSendDialog::SaveParams()
147 const _TCHAR
*lpHTTPProxyServer
= reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyServer
.GetBuffer());
150 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
151 TEXT("HTTPProxyServer"), REG_SZ
,
153 sizeof(TCHAR
) * (_tcslen(lpHTTPProxyServer
) + 1) );
155 _TCHAR
* endptr
= NULL
;
156 DWORD dwProxyPort
= _tcstoul( reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyPort
.GetBuffer()), &endptr
, 10 );
160 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
161 TEXT("HTTPProxyPort"), REG_DWORD
,
165 DWORD fAllowContact
= IsContactAllowed();
168 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
169 TEXT("AllowContact"), REG_DWORD
,
174 DWORD uInternetConnection
= maParams
.miHTTPConnectionType
;
178 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
179 TEXT("HTTPConnection"), REG_DWORD
,
180 &uInternetConnection
,
183 const _TCHAR
*lpEmail
= reinterpret_cast<LPCTSTR
>(GetEMailAddress().GetBuffer());
186 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
187 TEXT("ReturnAddress"), REG_SZ
,
189 sizeof(TCHAR
) * (_tcslen(lpEmail
) + 1) );
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") );
206 rtl::OString
strUTF8(rtl::OUStringToOString(GetUsing(),
207 RTL_TEXTENCODING_UTF8
));
209 fwrite( strUTF8
.getStr(), 1, strUTF8
.getLength(), 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
];
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"),
239 NULL
, NULL
, &StartupInfo
, &ProcessInfo
)
244 WaitForSingleObject( ProcessInfo
.hProcess
, INFINITE
);
245 if ( GetExitCodeProcess( ProcessInfo
.hProcess
, &dwExitCode
) && 0 == dwExitCode
)
251 DeleteFile( szFileName
);
258 } // namespace DocRecovery
261 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */