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 $
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"
38 #include <tools/svwin.h>
40 #define WIN32_LEAN_AND_MEAN
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
54 #include "docrecovery.hxx"
56 //***************************************************************************
58 static LONG
RegReadValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, LPVOID lpData
, DWORD cbData
)
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
);
74 //***************************************************************************
76 static LONG
RegWriteValue( HKEY hBaseKey
, LPCTSTR lpSubKey
, LPCTSTR lpValueName
, DWORD dwType
, LPCVOID lpData
, DWORD cbData
)
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
);
92 //***************************************************************************
95 namespace DocRecovery
{
97 bool ErrorRepSendDialog::ReadParams()
99 _TCHAR szBuffer
[2048];
101 if ( ERROR_SUCCESS
== RegReadValue(
103 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
104 TEXT("HTTPProxyServer"),
107 maParams
.maHTTPProxyServer
= (sal_Unicode
*)szBuffer
;
110 if ( ERROR_SUCCESS
== RegReadValue(
112 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
113 TEXT("HTTPProxyPort"),
115 sizeof(dwProxyPort
) ) )
117 _stprintf( szBuffer
, _T("%d"), dwProxyPort
);
118 maParams
.maHTTPProxyPort
= (sal_Unicode
*)szBuffer
;
121 if ( ERROR_SUCCESS
== RegReadValue(
123 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
124 TEXT("ReturnAddress"),
127 maEMailAddrED
.SetText( (sal_Unicode
*)szBuffer
);
129 DWORD fAllowContact
= FALSE
;
132 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
133 TEXT("AllowContact"),
135 sizeof(fAllowContact
) );
136 maContactCB
.Check( (BOOL
)fAllowContact
);
138 DWORD uInternetConnection
= 0;
141 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
142 TEXT("HTTPConnection"),
143 &uInternetConnection
,
144 sizeof(uInternetConnection
) );
145 maParams
.miHTTPConnectionType
= uInternetConnection
;
150 bool ErrorRepSendDialog::SaveParams()
152 const _TCHAR
*lpHTTPProxyServer
= reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyServer
.GetBuffer());
155 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
156 TEXT("HTTPProxyServer"), REG_SZ
,
158 sizeof(TCHAR
) * (_tcslen(lpHTTPProxyServer
) + 1) );
160 _TCHAR
* endptr
= NULL
;
161 DWORD dwProxyPort
= _tcstoul( reinterpret_cast<LPCTSTR
>(maParams
.maHTTPProxyPort
.GetBuffer()), &endptr
, 10 );
165 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
166 TEXT("HTTPProxyPort"), REG_DWORD
,
170 DWORD fAllowContact
= IsContactAllowed();
173 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
174 TEXT("AllowContact"), REG_DWORD
,
179 DWORD uInternetConnection
= maParams
.miHTTPConnectionType
;
183 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
184 TEXT("HTTPConnection"), REG_DWORD
,
185 &uInternetConnection
,
188 const _TCHAR
*lpEmail
= reinterpret_cast<LPCTSTR
>(GetEMailAddress().GetBuffer());
191 TEXT("SOFTWARE\\OpenOffice.org\\CrashReport"),
192 TEXT("ReturnAddress"), REG_SZ
,
194 sizeof(TCHAR
) * (_tcslen(lpEmail
) + 1) );
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") );
211 ByteString
strUTF8( GetUsing(), RTL_TEXTENCODING_UTF8
);
213 fwrite( strUTF8
.GetBuffer(), 1, strUTF8
.Len(), 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
];
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"),
243 NULL
, NULL
, &StartupInfo
, &ProcessInfo
)
248 WaitForSingleObject( ProcessInfo
.hProcess
, INFINITE
);
249 if ( GetExitCodeProcess( ProcessInfo
.hProcess
, &dwExitCode
) && 0 == dwExitCode
)
255 DeleteFile( szFileName
);
262 } // namespace DocRecovery