1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 .
23 #include "docrecovery.hxx"
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
44 //***************************************************************************
46 static LONG
RegReadValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPVOID lpData
, DWORD cbData
)
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
);
62 //***************************************************************************
64 static LONG
RegWriteValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, DWORD dwType
, LPCVOID lpData
, DWORD cbData
)
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
);
80 //***************************************************************************
83 namespace DocRecovery
{
85 bool ErrorRepSendDialog::ReadParams()
87 _TCHAR szBuffer
[2048];
89 if ( ERROR_SUCCESS
== RegReadValue(
91 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
92 TEXT("HTTPProxyServer"),
95 maParams
.maHTTPProxyServer
= (sal_Unicode
*)szBuffer
;
98 if ( ERROR_SUCCESS
== RegReadValue(
100 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
101 TEXT("HTTPProxyPort"),
103 sizeof(dwProxyPort
) ) )
105 _stprintf( szBuffer
, _T("%d"), dwProxyPort
);
106 maParams
.maHTTPProxyPort
= (sal_Unicode
*)szBuffer
;
109 if ( ERROR_SUCCESS
== RegReadValue(
111 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
112 TEXT("ReturnAddress"),
115 maEMailAddrED
.SetText(OUString((sal_Unicode
*)szBuffer
));
117 DWORD fAllowContact
= sal_False
;
120 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
121 TEXT("AllowContact"),
123 sizeof(fAllowContact
) );
124 maContactCB
.Check( (sal_Bool
)fAllowContact
);
126 DWORD uInternetConnection
= 0;
129 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
130 TEXT("HTTPConnection"),
131 &uInternetConnection
,
132 sizeof(uInternetConnection
) );
133 maParams
.miHTTPConnectionType
= uInternetConnection
;
138 bool ErrorRepSendDialog::SaveParams()
140 const _TCHAR
*lpHTTPProxyServer
= reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyServer
.GetBuffer());
143 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
144 TEXT("HTTPProxyServer"), REG_SZ
,
146 sizeof(TCHAR
) * (_tcslen(lpHTTPProxyServer
) + 1) );
148 _TCHAR
* endptr
= NULL
;
149 DWORD dwProxyPort
= _tcstoul( reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyPort
.GetBuffer()), &endptr
, 10 );
153 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
154 TEXT("HTTPProxyPort"), REG_DWORD
,
158 DWORD fAllowContact
= IsContactAllowed();
161 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
162 TEXT("AllowContact"), REG_DWORD
,
167 DWORD uInternetConnection
= maParams
.miHTTPConnectionType
;
171 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
172 TEXT("HTTPConnection"), REG_DWORD
,
173 &uInternetConnection
,
176 const _TCHAR
*lpEmail
= reinterpret_cast<LPCTSTR
>(GetEMailAddress().GetBuffer());
179 TEXT("SOFTWARE\\LibreOffice\\CrashReport"),
180 TEXT("ReturnAddress"), REG_SZ
,
182 sizeof(TCHAR
) * (_tcslen(lpEmail
) + 1) );
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") );
199 OString
strUTF8(OUStringToOString(GetUsing(),
200 RTL_TEXTENCODING_UTF8
));
202 fwrite( strUTF8
.getStr(), 1, strUTF8
.getLength(), 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
];
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"),
232 NULL
, NULL
, &StartupInfo
, &ProcessInfo
)
237 WaitForSingleObject( ProcessInfo
.hProcess
, INFINITE
);
238 if ( GetExitCodeProcess( ProcessInfo
.hProcess
, &dwExitCode
) && 0 == dwExitCode
)
244 DeleteFile( szFileName
);
251 } // namespace DocRecovery
254 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */