--- a/toolkit/crashreporter/client/crashreporter_win.cpp
+++ b/toolkit/crashreporter/client/crashreporter_win.cpp
@@ -2,16 +2,18 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#ifdef WIN32_LEAN_AND_MEAN
#undef WIN32_LEAN_AND_MEAN
#endif
+#define NOMINMAX
+
#include "crashreporter.h"
#include <windows.h>
#include <commctrl.h>
#include <richedit.h>
#include <shellapi.h>
#include <shlobj.h>
#include <shlwapi.h>
@@ -888,17 +890,17 @@ static BOOL CALLBACK CrashReporterDialog
RECT rect;
HWND hwnd = GetDlgItem(hwndDlg, IDC_VIEWREPORTBUTTON);
GetRelativeRect(hwnd, hwndDlg, &rect);
ResizeControl(hwnd, rect, Str(ST_VIEWREPORT), false, 0);
SetDlgItemText(hwndDlg, IDC_VIEWREPORTBUTTON, Str(ST_VIEWREPORT).c_str());
hwnd = GetDlgItem(hwndDlg, IDC_SUBMITREPORTCHECK);
GetRelativeRect(hwnd, hwndDlg, &rect);
- int maxdiff = ResizeControl(hwnd, rect, Str(ST_CHECKSUBMIT), false,
+ long maxdiff = ResizeControl(hwnd, rect, Str(ST_CHECKSUBMIT), false,
gCheckboxPadding);
SetDlgItemText(hwndDlg, IDC_SUBMITREPORTCHECK,
Str(ST_CHECKSUBMIT).c_str());
if (!CheckBoolKey(gCrashReporterKey.c_str(),
SUBMIT_REPORT_VALUE, &enabled))
enabled = ShouldEnableSending();
@@ -915,34 +917,34 @@ static BOOL CALLBACK CrashReporterDialog
SetWindowLongPtr(hwndComment, GWLP_USERDATA, (LONG_PTR)OldWndProc);
wstring commentGrayText = Str(ST_COMMENTGRAYTEXT);
wchar_t* hMem = (wchar_t*)GlobalAlloc(GPTR, (commentGrayText.length() + 1)*sizeof(wchar_t));
wcscpy(hMem, commentGrayText.c_str());
SetProp(hwndComment, L"PROP_GRAYTEXT", hMem);
hwnd = GetDlgItem(hwndDlg, IDC_INCLUDEURLCHECK);
GetRelativeRect(hwnd, hwndDlg, &rect);
- int diff = ResizeControl(hwnd, rect, Str(ST_CHECKURL), false,
+ long diff = ResizeControl(hwnd, rect, Str(ST_CHECKURL), false,
gCheckboxPadding);
- maxdiff = max(diff, maxdiff);
+ maxdiff = std::max(diff, maxdiff);
SetDlgItemText(hwndDlg, IDC_INCLUDEURLCHECK, Str(ST_CHECKURL).c_str());
// want this on by default
if (CheckBoolKey(gCrashReporterKey.c_str(), INCLUDE_URL_VALUE, &enabled) &&
!enabled) {
CheckDlgButton(hwndDlg, IDC_INCLUDEURLCHECK, BST_UNCHECKED);
} else {
CheckDlgButton(hwndDlg, IDC_INCLUDEURLCHECK, BST_CHECKED);
}
hwnd = GetDlgItem(hwndDlg, IDC_EMAILMECHECK);
GetRelativeRect(hwnd, hwndDlg, &rect);
diff = ResizeControl(hwnd, rect, Str(ST_CHECKEMAIL), false,
gCheckboxPadding);
- maxdiff = max(diff, maxdiff);
+ maxdiff = std::max(diff, maxdiff);
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);
}
@@ -990,17 +992,17 @@ static BOOL CALLBACK CrashReporterDialog
SetDlgItemVisible(hwndDlg, IDC_RESTARTBUTTON, false);
}
// See if we need to widen the window
// Leave 6 pixels on either side + 6 pixels between the buttons
int neededSize = closeRect.right - closeRect.left +
restartRect.right - restartRect.left + 6 * 3;
GetClientRect(hwndDlg, &r);
// We may already have resized one of the checkboxes above
- maxdiff = max(maxdiff, neededSize - (r.right - r.left));
+ maxdiff = std::max(maxdiff, neededSize - (r.right - r.left));
if (maxdiff > 0) {
// widen window
GetWindowRect(hwndDlg, &r);
r.right += maxdiff;
MoveWindow(hwndDlg, r.left, r.top,
r.right - r.left, r.bottom - r.top, TRUE);
// shift both buttons right
@@ -1217,43 +1219,48 @@ static wstring UTF8ToWide(const string&
delete [] buffer;
if (success)
*success = true;
return str;
}
-string WideToUTF8(const wstring& wide, bool* success)
+static string WideToMBCP(const wstring& wide, unsigned int cp, bool* success = nullptr)
{
char* buffer = NULL;
- int buffer_size = WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
+ int buffer_size = WideCharToMultiByte(cp, 0, wide.c_str(),
-1, NULL, 0, NULL, NULL);
if(buffer_size == 0) {
if (success)
*success = false;
return "";
}
buffer = new char[buffer_size];
if(buffer == NULL) {
if (success)
*success = false;
return "";
}
- WideCharToMultiByte(CP_UTF8, 0, wide.c_str(),
+ WideCharToMultiByte(cp, 0, wide.c_str(),
-1, buffer, buffer_size, NULL, NULL);
- string utf8 = buffer;
+ string mb = buffer;
delete [] buffer;
if (success)
*success = true;
- return utf8;
+ return mb;
+}
+
+string WideToUTF8(const wstring& wide, bool* success)
+{
+ return WideToMBCP(wide, CP_UTF8, success);
}
/* === Crashreporter UI Functions === */
bool UIInit()
{
for (int i = 0; i < sizeof(kDefaultAttachedBottom) / sizeof(UINT); i++) {
gAttachedBottom.insert(kDefaultAttachedBottom[i]);
@@ -1419,18 +1426,21 @@ ifstream* UIOpenRead(const string& filen
// 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
+#elif defined(_MSC_VER)
ifstream* file = new ifstream(_wfopen(UTF8ToWide(filename).c_str(), L"r"));
+#else // GCC
+ ifstream* file = new ifstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
+ ios::in);
#endif // _MSC_VER >= 1400
return file;
}
ofstream* UIOpenWrite(const string& filename, bool append) // append=false
{
// adapted from breakpad's src/common/windows/http_upload.cc
@@ -1438,19 +1448,22 @@ ofstream* UIOpenWrite(const string& file
// 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(), append ? ios::out | ios::app
: ios::out);
-#else // _MSC_VER >= 1400
+#elif defined(_MSC_VER)
ofstream* file = new ofstream(_wfopen(UTF8ToWide(filename).c_str(),
append ? L"a" : L"w"));
+#else // GCC
+ ofstream* file = new ofstream(WideToMBCP(UTF8ToWide(filename), CP_ACP).c_str(),
+ append ? ios::out | ios::app : ios::out);
#endif // _MSC_VER >= 1400
return file;
}
struct FileData
{
FILETIME timestamp;