Bug 399153 - Software update should support unicode strings for the UI. r=bsmedberg, r=ehsan
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 08 Jan 2009 22:25:49 -0800
changeset 23498 177e11abd9d946ff9528c5b056cdd29b656eccd2
parent 23497 1a4e256b6894377cba435aa1296e694bb2d13493
child 23499 6128896b6f98a3dd04ba0a4a82d3f0d98464fc27
push id1
push userroot
push dateTue, 26 Apr 2011 22:38:44 +0000
treeherdermozilla-beta@bfdb6e623a36 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbsmedberg, ehsan
bugs399153
milestone1.9.2a1pre
Bug 399153 - Software update should support unicode strings for the UI. r=bsmedberg, r=ehsan
browser/locales/Makefile.in
toolkit/mozapps/update/src/updater/Makefile.in
toolkit/mozapps/update/src/updater/progressui_win.cpp
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -204,17 +204,16 @@ ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_
 MOZ_PKG_MAC_DSSTORE=$(_ABS_DIST)/branding/dsstore
 MOZ_PKG_MAC_BACKGROUND=$(_ABS_DIST)/branding/background.png
 MOZ_PKG_MAC_ICON=$(_ABS_DIST)/branding/disk.icns
 MOZ_PKG_MAC_EXTRA=--symlink "/Applications:/ "
 endif
 
 PACKAGER_NO_LIBS = 1
 include $(topsrcdir)/toolkit/mozapps/installer/packager.mk
-include $(call EXPAND_LOCALE_SRCDIR,toolkit/locales)/installer/windows/charset.mk
 
 repackage-win32-installer: WIN32_INSTALLER_OUT="$(_ABS_DIST)/$(PKG_INST_PATH)$(PKG_INST_BASENAME).exe"
 repackage-win32-installer: $(WIN32_INSTALLER_IN) $(SUBMAKEFILES)
 	@echo "Repackaging $(WIN32_INSTALLER_IN) into $(WIN32_INSTALLER_OUT)."
 ifdef MOZ_BRANDING_DIRECTORY
 	$(MAKE) -C $(DEPTH)/$(MOZ_BRANDING_DIRECTORY) export
 else
 	$(MAKE) -C ../installer/windows export
@@ -337,18 +336,17 @@ langpack-%: libs-%
 
 installers-%: clobber-% langpack-% repackage-win32-installer-% repackage-zip-%
 	@echo "repackaging done"
 
 ifdef MOZ_UPDATER
 libs:: $(addprefix $(LOCALE_SRCDIR)/,updater/updater.ini)
 ifeq ($(OS_ARCH),WINNT)
 	cat $< $(srcdir)/updater_append.ini $(srcdir)/../installer/windows/nsis/updater_append.ini | \
-	  sed -e "s/%AB_CD%/$(AB_CD)/" | \
-	  iconv -f UTF-8 -t $(WIN_INSTALLER_CHARSET) > $(FINAL_TARGET)/updater.ini
+	  sed -e "s/%AB_CD%/$(AB_CD)/" > $(FINAL_TARGET)/updater.ini
 else
 	cat $< $(srcdir)/updater_append.ini | \
 	  sed -e "s/%AB_CD%/$(AB_CD)/" > $(FINAL_TARGET)/updater.ini
 endif
 endif
 
 ifdef MOZ_CRASHREPORTER
 libs:: crashreporter-override.ini
--- a/toolkit/mozapps/update/src/updater/Makefile.in
+++ b/toolkit/mozapps/update/src/updater/Makefile.in
@@ -61,17 +61,20 @@ LIBS += \
 	$(DEPTH)/modules/libmar/src/$(LIB_PREFIX)mar.$(LIB_SUFFIX) \
 	$(BZ2_LIBS) \
 	$(NULL)
 
 ifeq ($(OS_ARCH),WINNT)
 USE_STATIC_LIBS = 1
 HAVE_PROGRESSUI = 1
 RCINCLUDE = updater.rc
-CPPSRCS += progressui_win.cpp
+CPPSRCS += \
+	progressui_win.cpp \
+	readstrings.cpp \
+	$(NULL)
 OS_LIBS += $(call EXPAND_LIBNAME,comctl32 ws2_32 shell32)
 DEFINES += -DUNICODE -D_UNICODE
 ifndef GNU_CC
 RCFLAGS += -I$(srcdir)
 else
 RCFLAGS += --include-dir $(srcdir)
 endif
 endif
--- a/toolkit/mozapps/update/src/updater/progressui_win.cpp
+++ b/toolkit/mozapps/update/src/updater/progressui_win.cpp
@@ -39,22 +39,22 @@
 
 #include <stdio.h>
 #include <windows.h>
 #include <commctrl.h>
 #include <process.h>
 #include <io.h>
 #include "resource.h"
 #include "progressui.h"
+#include "readstrings.h"
+#include "errors.h"
 
 #define TIMER_ID 1
 #define TIMER_INTERVAL 100
 
-#define MAX_INFO_LENGTH 512
-
 #define RESIZE_WINDOW(hwnd, extrax, extray) \
   { \
     RECT windowSize; \
     GetWindowRect(hwnd, &windowSize); \
     SetWindowPos(hwnd, 0, 0, 0, windowSize.right - windowSize.left + extrax, \
                  windowSize.bottom - windowSize.top + extray, \
                  SWP_NOMOVE | SWP_NOZORDER); \
   }
@@ -65,17 +65,16 @@
     windowPos.length = sizeof(windowPos); \
     GetWindowPlacement(hwnd, &windowPos); \
     SetWindowPos(hwnd, 0, windowPos.rcNormalPosition.left + dx, windowPos.rcNormalPosition.top + dy, 0, 0, \
                  SWP_NOSIZE | SWP_NOZORDER); \
   }
 
 static float sProgress;  // between 0 and 100
 static BOOL  sQuit = FALSE;
-static HFONT sSystemFont = 0;
 
 static BOOL
 GetStringsFile(WCHAR filename[MAX_PATH])
 {
   if (!GetModuleFileNameW(NULL, filename, MAX_PATH))
     return FALSE;
  
   WCHAR *dot = wcsrchr(filename, '.');
@@ -91,17 +90,17 @@ UpdateDialog(HWND hDlg)
 {
   int pos = int(sProgress + 0.5f);
   SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETPOS, pos, 0L);
 }
 
 static void
 ResizeDialogToFit(HWND hDlg)
 {
-  WCHAR text[MAX_INFO_LENGTH];
+  WCHAR text[MAX_TEXT_LEN];
   RECT infoSize, textSize;
   HFONT hInfoFont, hOldFont;
 
   HWND hWndInfo = GetDlgItem(hDlg, IDC_INFO);
   HWND hWndPro  = GetDlgItem(hDlg, IDC_PROGRESS);
 
   // Get the text that is displayed - this is what we're going to make fit.
   if (!GetWindowText(hWndInfo, text, sizeof(text)))
@@ -169,48 +168,39 @@ CenterDialog(HWND hDlg)
                HWND_TOP, 
                rcOwner.left + (rc.right / 2), 
                rcOwner.top + (rc.bottom / 2), 
                0, 0,          // ignores size arguments 
                SWP_NOSIZE); 
 }
 
 static void
-SetItemText(HWND hwnd, const WCHAR *key, const WCHAR *ini)
-{
-  WCHAR text[MAX_INFO_LENGTH];
-  if (!GetPrivateProfileStringW(L"Strings", key, NULL, text, sizeof(text), ini))
-    return;
-  SetWindowTextW(hwnd, text);
-}
-
-static void
 InitDialog(HWND hDlg)
 {
   WCHAR filename[MAX_PATH];
   if (!GetStringsFile(filename))
     return;
 
-  SetItemText(hDlg, L"Title", filename);
-  SetItemText(GetDlgItem(hDlg, IDC_INFO), L"Info", filename);
+  char path[MAX_PATH];
+  WideCharToMultiByte(CP_UTF8, 0, filename, -1, path,
+                      sizeof(path)/sizeof(path[0]), NULL, NULL );
+  StringTable uiStrings;
+  if (ReadStrings(path, &uiStrings) != OK)
+    return;
 
-  // On Win9x, we need to send WM_SETFONT for l10n builds.  Yes, we shouldn't
-  // use the system font.  For example, if the text has Japanese characters on
-  // Win98-en, then the text may not be displayed correctly.  We should perhaps
-  // support loading a font named in updater.ini; however, even then there are
-  // cases where it might not work properly.
-  if (!sSystemFont) {
-    NONCLIENTMETRICS ncm;
-    memset(&ncm, 0, sizeof(ncm));
-    ncm.cbSize = sizeof(ncm);
-    SystemParametersInfo(SPI_GETNONCLIENTMETRICS, 0, &ncm, 0);
-    sSystemFont = CreateFontIndirect(&ncm.lfMessageFont);
-  }
-  if (sSystemFont)
-    SendDlgItemMessage(hDlg, IDC_INFO, WM_SETFONT, (WPARAM)sSystemFont, 0L);
+  WCHAR szwTitle[MAX_TEXT_LEN];
+  WCHAR szwInfo[MAX_TEXT_LEN];
+
+  MultiByteToWideChar(CP_UTF8, 0, uiStrings.title, strlen(uiStrings.title) + 1,
+                      szwTitle, sizeof(szwTitle)/sizeof(szwTitle[0]));
+  MultiByteToWideChar(CP_UTF8, 0, uiStrings.info, strlen(uiStrings.info) + 1,
+                      szwInfo, sizeof(szwInfo)/sizeof(szwInfo[0]));
+
+  SetWindowTextW(hDlg, szwTitle);
+  SetWindowTextW(GetDlgItem(hDlg, IDC_INFO), szwInfo);
 
   // Set dialog icon
   HICON hIcon = LoadIcon(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_DIALOG));
   if (hIcon)
     SendMessage(hDlg, WM_SETICON, ICON_BIG, (LPARAM) hIcon);
 
   SendDlgItemMessage(hDlg, IDC_PROGRESS, PBM_SETRANGE, 0, MAKELPARAM(0, 100));
 
@@ -230,20 +220,16 @@ DialogProc(HWND hDlg, UINT message, WPAR
   {
   case WM_INITDIALOG:
     InitDialog(hDlg);
     return TRUE;
 
   case WM_TIMER:
     if (sQuit) {
       EndDialog(hDlg, 0);
-      if (sSystemFont) {
-        DeleteObject(sSystemFont);
-        sSystemFont = 0;
-      }
     } else {
       UpdateDialog(hDlg);
     }
     return TRUE;
 
   case WM_COMMAND:
     return TRUE;
   }