2007-07-24 18:05:54 -07:00
|
|
|
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
|
|
* Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
* 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
* the License. You may obtain a copy of the License at
|
|
|
|
* http://www.mozilla.org/MPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* License.
|
|
|
|
*
|
|
|
|
* The Original Code is Mozilla Toolkit Crash Reporter
|
|
|
|
*
|
|
|
|
* The Initial Developer of the Original Code is
|
|
|
|
* Ted Mielczarek <ted.mielczarek@gmail.com>
|
|
|
|
* Portions created by the Initial Developer are Copyright (C) 2006
|
|
|
|
* the Initial Developer. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Contributor(s):
|
2007-07-24 18:06:05 -07:00
|
|
|
* Ted Mielczarek <ted.mielczarek@gmail.com>
|
|
|
|
* Dave Camp <dcamp@mozilla.com>
|
2007-07-24 18:05:54 -07:00
|
|
|
*
|
|
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
* use your version of this file under the terms of the MPL, indicate your
|
|
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
|
|
* the provisions above, a recipient may use your version of this file under
|
|
|
|
* the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
*
|
|
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
|
|
|
|
#ifdef WIN32_LEAN_AND_MEAN
|
|
|
|
#undef WIN32_LEAN_AND_MEAN
|
|
|
|
#endif
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
#include "crashreporter.h"
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
#include <windows.h>
|
|
|
|
#include <commctrl.h>
|
|
|
|
#include <richedit.h>
|
|
|
|
#include <shellapi.h>
|
2007-07-24 18:06:08 -07:00
|
|
|
#include <shlobj.h>
|
|
|
|
#include <shlwapi.h>
|
2007-07-24 18:06:05 -07:00
|
|
|
#include <set>
|
2007-07-24 18:05:54 -07:00
|
|
|
#include "resource.h"
|
|
|
|
#include "client/windows/sender/crash_report_sender.h"
|
2007-07-24 18:06:08 -07:00
|
|
|
#include "common/windows/string_utils-inl.h"
|
2007-07-24 18:05:54 -07:00
|
|
|
|
|
|
|
#define CRASH_REPORTER_VALUE L"Enabled"
|
2007-07-24 18:06:05 -07:00
|
|
|
#define SUBMIT_REPORT_VALUE L"SubmitReport"
|
|
|
|
#define EMAIL_ME_VALUE L"EmailMe"
|
|
|
|
#define EMAIL_VALUE L"Email"
|
|
|
|
#define MAX_EMAIL_LENGTH 1024
|
2007-07-24 18:05:54 -07:00
|
|
|
|
|
|
|
#define WM_UPLOADCOMPLETE WM_APP
|
|
|
|
|
2007-07-24 18:05:55 -07:00
|
|
|
using std::string;
|
2007-07-24 18:05:54 -07:00
|
|
|
using std::wstring;
|
|
|
|
using std::map;
|
2007-07-24 18:06:05 -07:00
|
|
|
using std::vector;
|
|
|
|
using std::set;
|
2007-07-24 18:06:10 -07:00
|
|
|
using std::ios;
|
|
|
|
using std::ifstream;
|
|
|
|
using std::ofstream;
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:08 -07:00
|
|
|
using namespace CrashReporter;
|
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
typedef struct {
|
|
|
|
HWND hDlg;
|
2007-07-24 18:05:55 -07:00
|
|
|
wstring dumpFile;
|
2007-07-24 18:06:05 -07:00
|
|
|
map<wstring,wstring> queryParameters;
|
|
|
|
wstring sendURL;
|
|
|
|
|
|
|
|
wstring serverResponse;
|
|
|
|
} SendThreadData;
|
|
|
|
|
|
|
|
static HANDLE gThreadHandle;
|
|
|
|
static SendThreadData gSendData = { 0, };
|
|
|
|
static vector<string> gRestartArgs;
|
|
|
|
static map<wstring,wstring> gQueryParameters;
|
|
|
|
static wstring gCrashReporterKey(L"Software\\Mozilla\\Crash Reporter");
|
|
|
|
|
|
|
|
// When vertically resizing the dialog, these items should move down
|
|
|
|
static set<UINT> gAttachedBottom;
|
|
|
|
|
|
|
|
// Default set of items for gAttachedBottom
|
|
|
|
static const UINT kDefaultAttachedBottom[] = {
|
|
|
|
IDC_VIEWREPORTCHECK,
|
|
|
|
IDC_VIEWREPORTTEXT,
|
|
|
|
IDC_SUBMITCRASHCHECK,
|
|
|
|
IDC_EMAILMECHECK,
|
|
|
|
IDC_EMAILTEXT,
|
|
|
|
IDC_CLOSEBUTTON,
|
|
|
|
IDC_RESTARTBUTTON,
|
|
|
|
};
|
|
|
|
|
|
|
|
static wstring UTF8ToWide(const string& utf8, bool *success = 0);
|
|
|
|
static DWORD WINAPI SendThreadProc(LPVOID param);
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
static wstring Str(const char* key)
|
|
|
|
{
|
|
|
|
return UTF8ToWide(gStrings[key]);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
/* === win32 helper functions === */
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
static void DoInitCommonControls()
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
INITCOMMONCONTROLSEX ic;
|
|
|
|
ic.dwSize = sizeof(INITCOMMONCONTROLSEX);
|
|
|
|
ic.dwICC = ICC_PROGRESS_CLASS;
|
|
|
|
InitCommonControlsEx(&ic);
|
2007-07-24 18:05:54 -07:00
|
|
|
// also get the rich edit control
|
|
|
|
LoadLibrary(L"riched20.dll");
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static bool GetBoolValue(HKEY hRegKey, LPCTSTR valueName, DWORD* value)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
DWORD type, dataSize;
|
|
|
|
dataSize = sizeof(DWORD);
|
|
|
|
if (RegQueryValueEx(hRegKey, valueName, NULL, &type, (LPBYTE)value, &dataSize) == ERROR_SUCCESS
|
|
|
|
&& type == REG_DWORD)
|
|
|
|
return true;
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
return false;
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static bool CheckBoolKey(const wchar_t* key,
|
|
|
|
const wchar_t* valueName,
|
|
|
|
bool* enabled)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
|
|
|
*enabled = false;
|
|
|
|
bool found = false;
|
|
|
|
HKEY hRegKey;
|
|
|
|
DWORD val;
|
|
|
|
// see if our reg key is set globally
|
2007-07-24 18:06:05 -07:00
|
|
|
if (RegOpenKey(HKEY_LOCAL_MACHINE, key, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
if (GetBoolValue(hRegKey, valueName, &val)) {
|
|
|
|
*enabled = (val == 1);
|
|
|
|
found = true;
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
RegCloseKey(hRegKey);
|
|
|
|
} else {
|
|
|
|
// look for it in user settings
|
|
|
|
if (RegOpenKey(HKEY_CURRENT_USER, key, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
if (GetBoolValue(hRegKey, valueName, &val)) {
|
|
|
|
*enabled = (val == 1);
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
RegCloseKey(hRegKey);
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
|
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static void SetBoolKey(const wchar_t* key, const wchar_t* value, bool enabled)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
|
|
|
HKEY hRegKey;
|
2007-07-24 18:06:05 -07:00
|
|
|
if (RegCreateKey(HKEY_CURRENT_USER, key, &hRegKey) == ERROR_SUCCESS) {
|
2007-07-24 18:05:54 -07:00
|
|
|
DWORD data = (enabled ? 1 : 0);
|
2007-07-24 18:06:05 -07:00
|
|
|
RegSetValueEx(hRegKey, value, 0, REG_DWORD, (LPBYTE)&data, sizeof(data));
|
2007-07-24 18:05:54 -07:00
|
|
|
RegCloseKey(hRegKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static bool GetStringValue(HKEY hRegKey, LPCTSTR valueName, wstring& value)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
DWORD type, dataSize;
|
|
|
|
wchar_t buf[2048];
|
|
|
|
dataSize = sizeof(buf);
|
|
|
|
if (RegQueryValueEx(hRegKey, valueName, NULL, &type, (LPBYTE)buf, &dataSize) == ERROR_SUCCESS
|
|
|
|
&& type == REG_SZ) {
|
|
|
|
value = buf;
|
|
|
|
return true;
|
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
return false;
|
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static bool GetStringKey(const wchar_t* key,
|
|
|
|
const wchar_t* valueName,
|
|
|
|
wstring& value)
|
|
|
|
{
|
|
|
|
value = L"";
|
|
|
|
bool found = false;
|
|
|
|
HKEY hRegKey;
|
|
|
|
// see if our reg key is set globally
|
|
|
|
if (RegOpenKey(HKEY_LOCAL_MACHINE, key, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
if (GetStringValue(hRegKey, valueName, value)) {
|
|
|
|
found = true;
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
RegCloseKey(hRegKey);
|
|
|
|
} else {
|
|
|
|
// look for it in user settings
|
|
|
|
if (RegOpenKey(HKEY_CURRENT_USER, key, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
if (GetStringValue(hRegKey, valueName, value)) {
|
|
|
|
found = true;
|
|
|
|
}
|
|
|
|
RegCloseKey(hRegKey);
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
return found;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetStringKey(const wchar_t* key,
|
|
|
|
const wchar_t* valueName,
|
|
|
|
const wstring& value)
|
|
|
|
{
|
|
|
|
HKEY hRegKey;
|
|
|
|
if (RegCreateKey(HKEY_CURRENT_USER, key, &hRegKey) == ERROR_SUCCESS) {
|
|
|
|
RegSetValueEx(hRegKey, valueName, 0, REG_SZ,
|
|
|
|
(LPBYTE)value.c_str(),
|
|
|
|
(value.length() + 1) * sizeof(wchar_t));
|
|
|
|
RegCloseKey(hRegKey);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Gets the position of a window relative to another window's client area
|
|
|
|
static void GetRelativeRect(HWND hwnd, HWND hwndParent, RECT* r)
|
|
|
|
{
|
|
|
|
GetWindowRect(hwnd, r);
|
|
|
|
ScreenToClient(hwndParent, (POINT*)&(r->left));
|
|
|
|
ScreenToClient(hwndParent, (POINT*)&(r->right));
|
|
|
|
}
|
|
|
|
|
|
|
|
static void SetDlgItemVisible(HWND hwndDlg, UINT item, bool visible)
|
|
|
|
{
|
|
|
|
HWND hwnd = GetDlgItem(hwndDlg, item);
|
|
|
|
LONG style = GetWindowLong(hwnd, GWL_STYLE);
|
|
|
|
if (visible)
|
|
|
|
style |= WS_VISIBLE;
|
|
|
|
else
|
|
|
|
style &= ~WS_VISIBLE;
|
2007-07-24 18:05:54 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
SetWindowLong(hwnd, GWL_STYLE, style);
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static void SetDlgItemDisabled(HWND hwndDlg, UINT item, bool disabled)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
HWND hwnd = GetDlgItem(hwndDlg, item);
|
|
|
|
LONG style = GetWindowLong(hwnd, GWL_STYLE);
|
|
|
|
if (!disabled)
|
|
|
|
style |= WS_DISABLED;
|
|
|
|
else
|
|
|
|
style &= ~WS_DISABLED;
|
|
|
|
|
|
|
|
SetWindowLong(hwnd, GWL_STYLE, style);
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
/* === Crash Reporting Dialog === */
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static void StretchDialog(HWND hwndDlg, int ydiff)
|
|
|
|
{
|
|
|
|
RECT r;
|
|
|
|
GetWindowRect(hwndDlg, &r);
|
|
|
|
r.bottom += ydiff;
|
|
|
|
MoveWindow(hwndDlg, r.left, r.top,
|
|
|
|
r.right - r.left, r.bottom - r.top, TRUE);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ReflowDialog(HWND hwndDlg, int ydiff)
|
|
|
|
{
|
|
|
|
// Move items attached to the bottom down/up by as much as
|
|
|
|
// the window resize
|
|
|
|
for (set<UINT>::const_iterator item = gAttachedBottom.begin();
|
|
|
|
item != gAttachedBottom.end();
|
|
|
|
item++) {
|
|
|
|
RECT r;
|
|
|
|
HWND hwnd = GetDlgItem(hwndDlg, *item);
|
|
|
|
GetRelativeRect(hwnd, hwndDlg, &r);
|
|
|
|
r.top += ydiff;
|
|
|
|
r.bottom += ydiff;
|
|
|
|
MoveWindow(hwnd, r.left, r.top,
|
|
|
|
r.right - r.left, r.bottom - r.top, TRUE);
|
|
|
|
}
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
static DWORD WINAPI SendThreadProc(LPVOID param)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:04 -07:00
|
|
|
bool finishedOk;
|
2007-07-24 18:06:05 -07:00
|
|
|
SendThreadData* td = (SendThreadData*)param;
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
if (td->sendURL.empty()) {
|
2007-07-24 18:06:04 -07:00
|
|
|
finishedOk = false;
|
2007-07-24 18:06:05 -07:00
|
|
|
} else {
|
2007-07-24 18:06:10 -07:00
|
|
|
google_breakpad::CrashReportSender sender(L"");
|
2007-07-24 18:06:05 -07:00
|
|
|
finishedOk = (sender.SendCrashReport(td->sendURL,
|
|
|
|
td->queryParameters,
|
2007-07-24 18:06:10 -07:00
|
|
|
td->dumpFile,
|
2007-07-24 18:06:05 -07:00
|
|
|
&td->serverResponse)
|
2007-07-24 18:05:56 -07:00
|
|
|
== google_breakpad::RESULT_SUCCEEDED);
|
2007-07-24 18:06:04 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
PostMessage(td->hDlg, WM_UPLOADCOMPLETE, finishedOk ? 1 : 0, 0);
|
2007-07-24 18:05:56 -07:00
|
|
|
|
2007-07-24 18:05:54 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
static void EndCrashReporterDialog(HWND hwndDlg, int code)
|
|
|
|
{
|
|
|
|
// Save the current values to the registry
|
|
|
|
wchar_t email[MAX_EMAIL_LENGTH];
|
|
|
|
GetDlgItemText(hwndDlg, IDC_EMAILTEXT, email, sizeof(email));
|
|
|
|
SetStringKey(gCrashReporterKey.c_str(), EMAIL_VALUE, email);
|
|
|
|
|
|
|
|
SetBoolKey(gCrashReporterKey.c_str(), EMAIL_ME_VALUE,
|
|
|
|
IsDlgButtonChecked(hwndDlg, IDC_EMAILMECHECK) != 0);
|
|
|
|
SetBoolKey(gCrashReporterKey.c_str(), SUBMIT_REPORT_VALUE,
|
|
|
|
IsDlgButtonChecked(hwndDlg, IDC_SUBMITREPORTCHECK) != 0);
|
|
|
|
|
|
|
|
EndDialog(hwndDlg, code);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void MaybeSendReport(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
if (!IsDlgButtonChecked(hwndDlg, IDC_SUBMITREPORTCHECK)) {
|
|
|
|
EndCrashReporterDialog(hwndDlg, 0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
gThreadHandle = NULL;
|
|
|
|
gSendData.hDlg = hwndDlg;
|
|
|
|
gSendData.queryParameters = gQueryParameters;
|
|
|
|
|
|
|
|
gThreadHandle = CreateThread(NULL, 0, SendThreadProc, &gSendData, 0, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void RestartApplication()
|
|
|
|
{
|
|
|
|
wstring cmdLine;
|
|
|
|
|
|
|
|
for (unsigned int i = 0; i < gRestartArgs.size(); i++) {
|
|
|
|
cmdLine += L"\"" + UTF8ToWide(gRestartArgs[i]) + L"\" ";
|
|
|
|
}
|
|
|
|
|
|
|
|
STARTUPINFO si;
|
|
|
|
PROCESS_INFORMATION pi;
|
|
|
|
|
|
|
|
ZeroMemory(&si, sizeof(si));
|
|
|
|
si.cb = sizeof(si);
|
|
|
|
si.dwFlags = STARTF_USESHOWWINDOW;
|
|
|
|
si.wShowWindow = SW_SHOWNORMAL;
|
|
|
|
ZeroMemory(&pi, sizeof(pi));
|
|
|
|
|
|
|
|
if (CreateProcess(NULL, (LPWSTR)cmdLine.c_str(), NULL, NULL, FALSE, 0,
|
|
|
|
NULL, NULL, &si, &pi)) {
|
|
|
|
CloseHandle(pi.hProcess);
|
|
|
|
CloseHandle(pi.hThread);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ShowReportInfo(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
wstring description;
|
|
|
|
|
|
|
|
for (map<wstring,wstring>::const_iterator i = gQueryParameters.begin();
|
|
|
|
i != gQueryParameters.end();
|
|
|
|
i++) {
|
|
|
|
description += i->first;
|
|
|
|
description += L": ";
|
|
|
|
description += i->second;
|
|
|
|
description += L"\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
description += L"\n";
|
|
|
|
description += Str(ST_EXTRAREPORTINFO);
|
|
|
|
|
|
|
|
SetDlgItemText(hwndDlg, IDC_VIEWREPORTTEXT, description.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
static void ShowHideReport(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
// When resizing the dialog to show the report, these items should
|
|
|
|
// stay put
|
|
|
|
gAttachedBottom.erase(IDC_VIEWREPORTCHECK);
|
|
|
|
gAttachedBottom.erase(IDC_VIEWREPORTTEXT);
|
|
|
|
|
|
|
|
RECT r;
|
|
|
|
HWND hwnd = GetDlgItem(hwndDlg, IDC_VIEWREPORTTEXT);
|
|
|
|
|
|
|
|
GetWindowRect(hwnd, &r);
|
|
|
|
int diff = (r.bottom - r.top) + 10;
|
|
|
|
if (IsDlgButtonChecked(hwndDlg, IDC_VIEWREPORTCHECK)) {
|
|
|
|
SetDlgItemVisible(hwndDlg, IDC_VIEWREPORTTEXT, true);
|
|
|
|
} else {
|
|
|
|
SetDlgItemVisible(hwndDlg, IDC_VIEWREPORTTEXT, false);
|
|
|
|
diff = -diff;
|
|
|
|
}
|
|
|
|
|
|
|
|
StretchDialog(hwndDlg, diff);
|
|
|
|
|
|
|
|
// set these back to normal
|
|
|
|
gAttachedBottom.insert(IDC_VIEWREPORTCHECK);
|
|
|
|
gAttachedBottom.insert(IDC_VIEWREPORTTEXT);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void UpdateEmail(HWND hwndDlg)
|
|
|
|
{
|
|
|
|
if (IsDlgButtonChecked(hwndDlg, IDC_EMAILMECHECK)) {
|
|
|
|
wchar_t email[MAX_EMAIL_LENGTH];
|
|
|
|
GetDlgItemText(hwndDlg, IDC_EMAILTEXT, email, sizeof(email));
|
|
|
|
gQueryParameters[L"Email"] = email;
|
|
|
|
} else {
|
|
|
|
gQueryParameters.erase(L"Email");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static BOOL CALLBACK CrashReporterDialogProc(HWND hwndDlg, UINT message,
|
|
|
|
WPARAM wParam, LPARAM lParam)
|
|
|
|
{
|
|
|
|
static int sHeight = 0;
|
|
|
|
|
|
|
|
bool success;
|
|
|
|
bool enabled;
|
|
|
|
|
|
|
|
switch (message) {
|
|
|
|
case WM_INITDIALOG: {
|
|
|
|
RECT r;
|
|
|
|
GetClientRect(hwndDlg, &r);
|
|
|
|
sHeight = r.bottom - r.top;
|
|
|
|
|
|
|
|
SetWindowText(hwndDlg, Str(ST_CRASHREPORTERTITLE).c_str());
|
|
|
|
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_DESCRIPTIONTEXT,
|
|
|
|
EM_SETEVENTMASK, (WPARAM)NULL,
|
|
|
|
ENM_REQUESTRESIZE);
|
|
|
|
wstring description = Str(ST_CRASHREPORTERHEADER);
|
|
|
|
description += L"\n\n";
|
|
|
|
description += Str(ST_CRASHREPORTERDESCRIPTION);
|
|
|
|
SetDlgItemText(hwndDlg, IDC_DESCRIPTIONTEXT, description.c_str());
|
|
|
|
|
|
|
|
// Make the title bold.
|
|
|
|
CHARFORMAT fmt = { 0, };
|
|
|
|
fmt.cbSize = sizeof(fmt);
|
|
|
|
fmt.dwMask = CFM_BOLD;
|
|
|
|
fmt.dwEffects = CFE_BOLD;
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_DESCRIPTIONTEXT, EM_SETSEL,
|
|
|
|
0, Str(ST_CRASHREPORTERHEADER).length());
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_DESCRIPTIONTEXT, EM_SETCHARFORMAT,
|
|
|
|
SCF_SELECTION, (LPARAM)&fmt);
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_DESCRIPTIONTEXT, EM_SETSEL, 0, 0);
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_DESCRIPTIONTEXT,
|
|
|
|
EM_SETTARGETDEVICE, (WPARAM)NULL, 0);
|
|
|
|
|
|
|
|
SetDlgItemText(hwndDlg, IDC_VIEWREPORTCHECK, Str(ST_VIEWREPORT).c_str());
|
|
|
|
SendDlgItemMessage(hwndDlg, IDC_VIEWREPORTTEXT,
|
|
|
|
EM_SETTARGETDEVICE, (WPARAM)NULL, 0);
|
|
|
|
|
|
|
|
|
|
|
|
SetDlgItemText(hwndDlg, IDC_SUBMITREPORTCHECK,
|
|
|
|
Str(ST_CHECKSUBMIT).c_str());
|
|
|
|
if (CheckBoolKey(gCrashReporterKey.c_str(),
|
|
|
|
SUBMIT_REPORT_VALUE, &enabled) &&
|
|
|
|
!enabled) {
|
|
|
|
CheckDlgButton(hwndDlg, IDC_SUBMITREPORTCHECK, BST_UNCHECKED);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_EMAILMECHECK), enabled);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_EMAILTEXT), enabled);
|
|
|
|
} else {
|
|
|
|
CheckDlgButton(hwndDlg, IDC_SUBMITREPORTCHECK, BST_CHECKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDlgItemText(hwndDlg, IDC_EMAILMECHECK, Str(ST_CHECKEMAIL).c_str());
|
|
|
|
if (CheckBoolKey(gCrashReporterKey.c_str(), EMAIL_ME_VALUE, &enabled) &&
|
|
|
|
enabled) {
|
|
|
|
CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_CHECKED);
|
|
|
|
} else {
|
|
|
|
CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_UNCHECKED);
|
|
|
|
}
|
|
|
|
|
|
|
|
wstring email;
|
|
|
|
if (GetStringKey(gCrashReporterKey.c_str(), EMAIL_VALUE, email)) {
|
|
|
|
SetDlgItemText(hwndDlg, IDC_EMAILTEXT, email.c_str());
|
|
|
|
}
|
|
|
|
|
|
|
|
SetDlgItemText(hwndDlg, IDC_CLOSEBUTTON, Str(ST_CLOSE).c_str());
|
|
|
|
|
|
|
|
if (gRestartArgs.size() > 0) {
|
|
|
|
SetDlgItemText(hwndDlg, IDC_RESTARTBUTTON, Str(ST_RESTART).c_str());
|
|
|
|
} else {
|
|
|
|
// No restart arguments, move the close button over to the side
|
|
|
|
// and hide the restart button
|
|
|
|
SetDlgItemVisible(hwndDlg, IDC_RESTARTBUTTON, false);
|
|
|
|
|
|
|
|
RECT closeRect;
|
|
|
|
HWND hwndClose = GetDlgItem(hwndDlg, IDC_CLOSEBUTTON);
|
|
|
|
GetRelativeRect(hwndClose, hwndDlg, &closeRect);
|
|
|
|
|
|
|
|
RECT restartRect;
|
|
|
|
HWND hwndRestart = GetDlgItem(hwndDlg, IDC_RESTARTBUTTON);
|
|
|
|
GetRelativeRect(hwndRestart, hwndDlg, &restartRect);
|
|
|
|
|
|
|
|
int size = closeRect.right - closeRect.left;
|
|
|
|
closeRect.right = restartRect.right;
|
|
|
|
closeRect.left = closeRect.right - size;
|
|
|
|
|
|
|
|
MoveWindow(hwndClose, closeRect.left, closeRect.top,
|
|
|
|
closeRect.right - closeRect.left,
|
|
|
|
closeRect.bottom - closeRect.top,
|
|
|
|
TRUE);
|
|
|
|
}
|
|
|
|
UpdateEmail(hwndDlg);
|
|
|
|
ShowReportInfo(hwndDlg);
|
|
|
|
|
|
|
|
SetFocus(GetDlgItem(hwndDlg, IDC_EMAILTEXT));
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
case WM_SIZE: {
|
|
|
|
ReflowDialog(hwndDlg, HIWORD(lParam) - sHeight);
|
|
|
|
sHeight = HIWORD(lParam);
|
|
|
|
InvalidateRect(hwndDlg, NULL, TRUE);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
case WM_NOTIFY: {
|
|
|
|
NMHDR* notification = reinterpret_cast<NMHDR*>(lParam);
|
|
|
|
if (notification->code == EN_REQUESTRESIZE) {
|
|
|
|
// Resizing the rich edit control to fit the description text.
|
|
|
|
REQRESIZE* reqresize = reinterpret_cast<REQRESIZE*>(lParam);
|
|
|
|
RECT newSize = reqresize->rc;
|
|
|
|
RECT oldSize;
|
|
|
|
GetRelativeRect(notification->hwndFrom, hwndDlg, &oldSize);
|
|
|
|
|
|
|
|
// resize the text box as requested
|
|
|
|
MoveWindow(notification->hwndFrom, newSize.left, newSize.top,
|
|
|
|
newSize.right - newSize.left, newSize.bottom - newSize.top,
|
|
|
|
TRUE);
|
|
|
|
|
|
|
|
// Resize the dialog to fit (the WM_SIZE handler will move the controls)
|
|
|
|
StretchDialog(hwndDlg, newSize.bottom - oldSize.bottom);
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
case WM_COMMAND: {
|
|
|
|
if (HIWORD(wParam) == BN_CLICKED) {
|
|
|
|
switch(LOWORD(wParam)) {
|
|
|
|
case IDC_VIEWREPORTCHECK:
|
|
|
|
ShowHideReport(hwndDlg);
|
|
|
|
break;
|
|
|
|
case IDC_SUBMITREPORTCHECK:
|
|
|
|
enabled = (IsDlgButtonChecked(hwndDlg, IDC_SUBMITREPORTCHECK) != 0);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_EMAILMECHECK), enabled);
|
|
|
|
EnableWindow(GetDlgItem(hwndDlg, IDC_EMAILTEXT), enabled);
|
|
|
|
break;
|
|
|
|
case IDC_EMAILMECHECK:
|
|
|
|
UpdateEmail(hwndDlg);
|
|
|
|
ShowReportInfo(hwndDlg);
|
|
|
|
break;
|
|
|
|
case IDC_CLOSEBUTTON:
|
|
|
|
// Hide the dialog after "closing", but leave it around to coordinate
|
|
|
|
// with the upload thread
|
|
|
|
ShowWindow(hwndDlg, SW_HIDE);
|
|
|
|
MaybeSendReport(hwndDlg);
|
|
|
|
break;
|
|
|
|
case IDC_RESTARTBUTTON:
|
|
|
|
// Hide the dialog after "closing", but leave it around to coordinate
|
|
|
|
// with the upload thread
|
|
|
|
ShowWindow(hwndDlg, SW_HIDE);
|
|
|
|
RestartApplication();
|
|
|
|
MaybeSendReport(hwndDlg);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else if (HIWORD(wParam) == EN_CHANGE) {
|
|
|
|
switch(LOWORD(wParam)) {
|
|
|
|
case IDC_EMAILTEXT:
|
|
|
|
wchar_t email[MAX_EMAIL_LENGTH];
|
|
|
|
if (GetDlgItemText(hwndDlg, IDC_EMAILTEXT, email, sizeof(email)) > 0)
|
|
|
|
CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_CHECKED);
|
|
|
|
else
|
|
|
|
CheckDlgButton(hwndDlg, IDC_EMAILMECHECK, BST_UNCHECKED);
|
|
|
|
UpdateEmail(hwndDlg);
|
|
|
|
ShowReportInfo(hwndDlg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
case WM_UPLOADCOMPLETE: {
|
|
|
|
WaitForSingleObject(gThreadHandle, INFINITE);
|
|
|
|
success = (wParam == 1);
|
2007-07-24 18:06:08 -07:00
|
|
|
SendCompleted(success, WideToUTF8(gSendData.serverResponse));
|
2007-07-24 18:06:05 -07:00
|
|
|
if (!success) {
|
|
|
|
MessageBox(hwndDlg,
|
|
|
|
Str(ST_SUBMITFAILED).c_str(),
|
|
|
|
Str(ST_CRASHREPORTERTITLE).c_str(),
|
|
|
|
MB_OK | MB_ICONERROR);
|
|
|
|
}
|
|
|
|
EndCrashReporterDialog(hwndDlg, success ? 1 : 0);
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
static wstring UTF8ToWide(const string& utf8, bool *success)
|
2007-07-24 18:05:54 -07:00
|
|
|
{
|
2007-07-24 18:06:08 -07:00
|
|
|
wchar_t* buffer = NULL;
|
2007-07-24 18:06:03 -07:00
|
|
|
int buffer_size = MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(),
|
2007-07-24 18:05:55 -07:00
|
|
|
-1, NULL, 0);
|
2007-07-24 18:06:03 -07:00
|
|
|
if(buffer_size == 0) {
|
|
|
|
if (success)
|
|
|
|
*success = false;
|
|
|
|
return L"";
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
|
|
|
buffer = new wchar_t[buffer_size];
|
2007-07-24 18:06:03 -07:00
|
|
|
if(buffer == NULL) {
|
|
|
|
if (success)
|
|
|
|
*success = false;
|
|
|
|
return L"";
|
|
|
|
}
|
|
|
|
|
|
|
|
MultiByteToWideChar(CP_UTF8, 0, utf8.c_str(),
|
2007-07-24 18:05:55 -07:00
|
|
|
-1, buffer, buffer_size);
|
2007-07-24 18:06:03 -07:00
|
|
|
wstring str = buffer;
|
2007-07-24 18:05:55 -07:00
|
|
|
delete [] buffer;
|
2007-07-24 18:06:03 -07:00
|
|
|
|
|
|
|
if (success)
|
|
|
|
*success = true;
|
|
|
|
|
|
|
|
return str;
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:10 -07:00
|
|
|
string WideToUTF8(const wstring& wide, bool* success)
|
2007-07-24 18:06:08 -07:00
|
|
|
{
|
|
|
|
char* buffer = NULL;
|
2007-07-24 18:06:03 -07:00
|
|
|
int buffer_size = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
|
2007-07-24 18:06:08 -07:00
|
|
|
-1, NULL, 0, NULL, NULL);
|
2007-07-24 18:06:03 -07:00
|
|
|
if(buffer_size == 0) {
|
|
|
|
if (success)
|
|
|
|
*success = false;
|
|
|
|
return "";
|
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
|
|
|
buffer = new char[buffer_size];
|
2007-07-24 18:06:03 -07:00
|
|
|
if(buffer == NULL) {
|
|
|
|
if (success)
|
|
|
|
*success = false;
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
|
2007-07-24 18:06:08 -07:00
|
|
|
-1, buffer, buffer_size, NULL, NULL);
|
2007-07-24 18:06:03 -07:00
|
|
|
string utf8 = buffer;
|
2007-07-24 18:06:08 -07:00
|
|
|
delete [] buffer;
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
if (success)
|
|
|
|
*success = true;
|
|
|
|
|
|
|
|
return utf8;
|
2007-07-24 18:06:08 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
/* === Crashreporter UI Functions === */
|
|
|
|
|
|
|
|
bool UIInit()
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
for (int i = 0; i < sizeof(kDefaultAttachedBottom) / sizeof(UINT); i++) {
|
|
|
|
gAttachedBottom.insert(kDefaultAttachedBottom[i]);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
DoInitCommonControls();
|
2007-07-24 18:06:08 -07:00
|
|
|
return true;
|
2007-07-24 18:05:54 -07:00
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
void UIShutdown()
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
void UIShowDefaultUI()
|
2007-07-24 18:06:08 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
MessageBox(NULL, Str(ST_CRASHREPORTERDEFAULT).c_str(),
|
|
|
|
L"Crash Reporter",
|
|
|
|
MB_OK | MB_ICONSTOP);
|
2007-07-24 18:06:08 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:05 -07:00
|
|
|
void UIShowCrashUI(const string& dumpFile,
|
|
|
|
const StringTable& queryParameters,
|
|
|
|
const string& sendURL,
|
|
|
|
const vector<string>& restartArgs)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
gSendData.hDlg = NULL;
|
|
|
|
gSendData.dumpFile = UTF8ToWide(dumpFile);
|
|
|
|
gSendData.sendURL = UTF8ToWide(sendURL);
|
|
|
|
|
|
|
|
for (StringTable::const_iterator i = queryParameters.begin();
|
|
|
|
i != queryParameters.end();
|
|
|
|
i++) {
|
|
|
|
gQueryParameters[UTF8ToWide(i->first)] = UTF8ToWide(i->second);
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
|
|
|
|
if (gQueryParameters.find(L"Vendor") != gQueryParameters.end()) {
|
2007-09-26 11:35:21 -07:00
|
|
|
gCrashReporterKey = L"Software\\";
|
|
|
|
if (!gQueryParameters[L"Vendor"].empty()) {
|
|
|
|
gCrashReporterKey += gQueryParameters[L"Vendor"] + L"\\";
|
|
|
|
}
|
|
|
|
gCrashReporterKey += gQueryParameters[L"Name"] + L"\\Crash Reporter";
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
2007-07-24 18:06:05 -07:00
|
|
|
|
|
|
|
gRestartArgs = restartArgs;
|
|
|
|
|
|
|
|
DialogBoxParam(NULL, MAKEINTRESOURCE(IDD_SENDDIALOG), NULL,
|
|
|
|
(DLGPROC)CrashReporterDialogProc, 0);
|
2007-07-24 18:06:03 -07:00
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
void UIError_impl(const string& message)
|
2007-07-24 18:06:03 -07:00
|
|
|
{
|
|
|
|
wstring title = Str(ST_CRASHREPORTERTITLE);
|
|
|
|
if (title.empty())
|
|
|
|
title = L"Crash Reporter Error";
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
MessageBox(NULL, UTF8ToWide(message).c_str(), title.c_str(),
|
|
|
|
MB_OK | MB_ICONSTOP);
|
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
bool UIGetIniPath(string& path)
|
|
|
|
{
|
|
|
|
wchar_t fileName[MAX_PATH];
|
|
|
|
if (GetModuleFileName(NULL, fileName, MAX_PATH)) {
|
|
|
|
// get crashreporter ini
|
|
|
|
wchar_t* s = wcsrchr(fileName, '.');
|
|
|
|
if (s) {
|
|
|
|
wcscpy(s, L".ini");
|
|
|
|
path = WideToUTF8(fileName);
|
|
|
|
return true;
|
2007-07-24 18:06:08 -07:00
|
|
|
}
|
2007-07-24 18:06:03 -07:00
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
return false;
|
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
bool UIGetSettingsPath(const string& vendor,
|
|
|
|
const string& product,
|
|
|
|
string& settings_path)
|
|
|
|
{
|
|
|
|
wchar_t path[MAX_PATH];
|
|
|
|
if(SUCCEEDED(SHGetFolderPath(NULL,
|
|
|
|
CSIDL_APPDATA,
|
|
|
|
NULL,
|
|
|
|
0,
|
|
|
|
path))) {
|
|
|
|
if (!vendor.empty()) {
|
|
|
|
PathAppend(path, UTF8ToWide(vendor).c_str());
|
2007-07-24 18:06:08 -07:00
|
|
|
}
|
2007-07-24 18:06:03 -07:00
|
|
|
PathAppend(path, UTF8ToWide(product).c_str());
|
|
|
|
PathAppend(path, L"Crash Reports");
|
|
|
|
settings_path = WideToUTF8(path);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
bool UIEnsurePathExists(const string& path)
|
|
|
|
{
|
|
|
|
if (CreateDirectory(UTF8ToWide(path).c_str(), NULL) == 0) {
|
|
|
|
if (GetLastError() != ERROR_ALREADY_EXISTS)
|
|
|
|
return false;
|
|
|
|
}
|
2007-07-24 18:06:08 -07:00
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
return true;
|
|
|
|
}
|
2007-07-24 18:05:55 -07:00
|
|
|
|
2007-07-24 18:06:09 -07:00
|
|
|
bool UIFileExists(const string& path)
|
|
|
|
{
|
|
|
|
DWORD attrs = GetFileAttributes(UTF8ToWide(path).c_str());
|
|
|
|
return (attrs != INVALID_FILE_ATTRIBUTES);
|
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
bool UIMoveFile(const string& oldfile, const string& newfile)
|
|
|
|
{
|
2007-07-24 18:06:05 -07:00
|
|
|
if (oldfile == newfile)
|
|
|
|
return true;
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
return MoveFile(UTF8ToWide(oldfile).c_str(), UTF8ToWide(newfile).c_str())
|
|
|
|
== TRUE;
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
|
|
|
|
2007-07-24 18:06:03 -07:00
|
|
|
bool UIDeleteFile(const string& oldfile)
|
2007-07-24 18:05:55 -07:00
|
|
|
{
|
2007-07-24 18:06:03 -07:00
|
|
|
return DeleteFile(UTF8ToWide(oldfile).c_str()) == TRUE;
|
2007-07-24 18:05:55 -07:00
|
|
|
}
|
2007-07-24 18:06:10 -07:00
|
|
|
|
|
|
|
ifstream* UIOpenRead(const string& filename)
|
|
|
|
{
|
|
|
|
// adapted from breakpad's src/common/windows/http_upload.cc
|
|
|
|
|
|
|
|
// The "open" method on pre-MSVC8 ifstream implementations doesn't accept a
|
|
|
|
// wchar_t* filename, so use _wfopen directly in that case. For VC8 and
|
|
|
|
// later, _wfopen has been deprecated in favor of _wfopen_s, which does
|
|
|
|
// not exist in earlier versions, so let the ifstream open the file itself.
|
|
|
|
#if _MSC_VER >= 1400 // MSVC 2005/8
|
|
|
|
ifstream* file = new ifstream();
|
|
|
|
file->open(UTF8ToWide(filename).c_str(), ios::in);
|
|
|
|
#else // _MSC_VER >= 1400
|
|
|
|
ifstream* file = new ifstream(_wfopen(UTF8ToWide(filename).c_str(), L"r"));
|
|
|
|
#endif // _MSC_VER >= 1400
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|
|
|
|
|
|
|
|
ofstream* UIOpenWrite(const string& filename)
|
|
|
|
{
|
|
|
|
// adapted from breakpad's src/common/windows/http_upload.cc
|
|
|
|
|
|
|
|
// The "open" method on pre-MSVC8 ifstream implementations doesn't accept a
|
|
|
|
// wchar_t* filename, so use _wfopen directly in that case. For VC8 and
|
|
|
|
// later, _wfopen has been deprecated in favor of _wfopen_s, which does
|
|
|
|
// not exist in earlier versions, so let the ifstream open the file itself.
|
|
|
|
#if _MSC_VER >= 1400 // MSVC 2005/8
|
|
|
|
ofstream* file = new ofstream();
|
|
|
|
file->open(UTF8ToWide(filename).c_str(), ios::out);
|
|
|
|
#else // _MSC_VER >= 1400
|
|
|
|
ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(), L"w"));
|
|
|
|
#endif // _MSC_VER >= 1400
|
|
|
|
|
|
|
|
return file;
|
|
|
|
}
|