Bug 488936 - Store the install locale in its own file. r=bsmedberg, r=ted.mielczarek
authorRobert Strong <robert.bugzilla@gmail.com>
Thu, 21 May 2009 11:02:08 -0700
changeset 28708 7bb72121c2a710f39bea3786d41ced1cb46798f1
parent 28707 8ff39c36bd2f25bcfb2912cd885ee1ad89342b2a
child 28709 e391f455c2b8bfffc357d248391981233790f933
push idunknown
push userunknown
push dateunknown
reviewersbsmedberg, ted
bugs488936
milestone1.9.2a1pre
Bug 488936 - Store the install locale in its own file. r=bsmedberg, r=ted.mielczarek
browser/installer/unix/packages-static
browser/installer/windows/packages-static
browser/locales/Makefile.in
browser/locales/updater_append.ini
toolkit/locales/Makefile.in
toolkit/locales/update.locale
toolkit/mozapps/update/src/nsUpdateService.js.in
toolkit/mozapps/update/test/unit/test_0040_general.js.in
--- a/browser/installer/unix/packages-static
+++ b/browser/installer/unix/packages-static
@@ -21,16 +21,17 @@ bin/defaults/existing-profile-defaults.j
 bin/browserconfig.properties
 bin/old-homepage-default.properties
 bin/searchplugins/*
 bin/defaults/profile/bookmarks.html
 bin/defaults/profile/localstore.rdf
 bin/defaults/profile/prefs.js
 bin/defaults/profile/mimeTypes.rdf
 bin/defaults/profile/chrome/*
+bin/update.locale
 bin/updater.ini
 bin/dictionaries/*
 
 [xpcom]
 bin/libmozjs.so
 bin/libplc4.so
 bin/libplds4.so
 bin/libxpcom.so
--- a/browser/installer/windows/packages-static
+++ b/browser/installer/windows/packages-static
@@ -21,16 +21,17 @@ bin\browserconfig.properties
 bin\old-homepage-default.properties
 bin\searchplugins\*
 bin\defaults\profile\bookmarks.html
 bin\defaults\profile\localstore.rdf
 bin\defaults\profile\prefs.js
 bin\defaults\profile\mimeTypes.rdf
 bin\defaults\profile\chrome\*
 bin\uninstall\helper.exe
+bin\update.locale
 bin\updater.ini
 bin\dictionaries\*
 
 [xpcom]
 bin\js3250.dll
 bin\plc4.dll
 bin\plds4.dll
 bin\xpcom.dll
--- a/browser/locales/Makefile.in
+++ b/browser/locales/Makefile.in
@@ -341,25 +341,25 @@ langpack: langpack-$(AB_CD)
 # tinderbox scripts. Alter it with caution.
 
 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 | \
+	cat $< $(srcdir)/../installer/windows/nsis/updater_append.ini | \
 	  sed -e "s/^InfoText=/Info=/" -e "s/^TitleText=/Title=/" | \
-	  sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" | \
-	  sed -e "s/%AB_CD%/$(AB_CD)/" > $(FINAL_TARGET)/updater.ini
+	  sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" > \
+	  $(FINAL_TARGET)/updater.ini
 else
-	cat $< $(srcdir)/updater_append.ini | \
+	cat $< \
 	  sed -e "s/^InfoText=/Info=/" -e "s/^TitleText=/Title=/" | \
-	  sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" | \
-	  sed -e "s/%AB_CD%/$(AB_CD)/" > $(FINAL_TARGET)/updater.ini
+	  sed -e "s/%MOZ_APP_DISPLAYNAME%/$(MOZ_APP_DISPLAYNAME)/" > \
+	  $(FINAL_TARGET)/updater.ini
 endif
 endif
 
 ifdef MOZ_CRASHREPORTER
 libs:: crashreporter-override.ini
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)
 endif
 
deleted file mode 100644
--- a/browser/locales/updater_append.ini
+++ /dev/null
@@ -1,5 +0,0 @@
-
-; IMPORTANT: This file should always start with a newline in case a locale
-; provided updater.ini does not end with a newline.
-[Installation]
-Locale=%AB_CD%
--- a/toolkit/locales/Makefile.in
+++ b/toolkit/locales/Makefile.in
@@ -63,16 +63,22 @@ endif
 libs-%:
 	@$(MAKE) -C ../../netwerk/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 	@$(MAKE) -C ../../dom/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 ifdef MOZ_PSM
 	@$(MAKE) -C ../../security/manager/locales/ libs AB_CD=$* XPI_NAME=locale-$*
 endif
 	@$(MAKE) libs AB_CD=$* XPI_NAME=locale-$*
 
+
+ifdef MOZ_UPDATER
+libs:: update.locale
+	cat $< | sed -e "s/%AB_CD%/$(AB_CD)/" > $(FINAL_TARGET)/update.locale
+endif
+
 ifdef MOZ_CRASHREPORTER
 libs:: crashreporter.ini
 ifneq (,$(filter mac cocoa,$(MOZ_WIDGET_TOOLKIT)))
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)/crashreporter.app/Contents/MacOS
 else
 	$(SYSINSTALL) $(IFLAGS1) $^ $(FINAL_TARGET)
 endif
 endif
new file mode 100644
--- /dev/null
+++ b/toolkit/locales/update.locale
@@ -0,0 +1,1 @@
+%AB_CD%
--- a/toolkit/mozapps/update/src/nsUpdateService.js.in
+++ b/toolkit/mozapps/update/src/nsUpdateService.js.in
@@ -73,31 +73,32 @@ const PREF_APP_DISTRIBUTION_VERSION     
 
 const URI_UPDATE_PROMPT_DIALOG  = "chrome://mozapps/content/update/updates.xul";
 const URI_UPDATE_HISTORY_DIALOG = "chrome://mozapps/content/update/history.xul";
 const URI_BRAND_PROPERTIES      = "chrome://branding/locale/brand.properties";
 const URI_UPDATES_PROPERTIES    = "chrome://mozapps/locale/update/updates.properties";
 const URI_UPDATE_NS             = "http://www.mozilla.org/2005/app-update";
 
 const KEY_APPDIR          = "XCurProcD";
+const KEY_GRED            = "GreD";
 #ifdef XP_WIN
 const KEY_UPDROOT         = "UpdRootD";
 const KEY_UAPPDATA        = "UAppData";
 #endif
 
 const DIR_UPDATES         = "updates";
 const FILE_UPDATE_STATUS  = "update.status";
 const FILE_UPDATE_VERSION = "update.version";
 const FILE_UPDATE_ARCHIVE = "update.mar";
 const FILE_UPDATE_LOG     = "update.log"
 const FILE_UPDATES_DB     = "updates.xml";
 const FILE_UPDATE_ACTIVE  = "active-update.xml";
 const FILE_PERMS_TEST     = "update.test";
 const FILE_LAST_LOG       = "last-update.log";
-const FILE_UPDATER_INI    = "updater.ini";
+const FILE_UPDATE_LOCALE  = "update.locale";
 
 const MODE_RDONLY   = 0x01;
 const MODE_WRONLY   = 0x02;
 const MODE_CREATE   = 0x08;
 const MODE_APPEND   = 0x10;
 const MODE_TRUNCATE = 0x20;
 
 const PERMS_FILE      = 0644;
@@ -513,29 +514,36 @@ function getPref(func, preference, defau
     return gPref[func](preference);
   }
   catch (e) {
   }
   return defaultValue;
 }
 
 /**
- * Gets the locale specified by the 'Locale' key in the 'Installation' section
- * of updater.ini.
+ * Gets the locale from the update.locale file for replacing %LOCALE% in the
+ * update url. The update.locale file can be located in the application
+ * directory or the GRE directory with preference given to it being located in
+ * the application directory.
  */
 function getLocale() {
   if (gLocale)
     return gLocale;
 
-  var updaterIni = getFile(KEY_APPDIR, [FILE_UPDATER_INI]);
-  var iniParser = Cc["@mozilla.org/xpcom/ini-parser-factory;1"].
-                  getService(Ci.nsIINIParserFactory).
-                  createINIParser(updaterIni);
-  gLocale = iniParser.getString("Installation", "Locale");
-  LOG("General", "getLocale - getting locale from file: " + updaterIni.path +
+  var localeFile = getFile(KEY_APPDIR, [FILE_UPDATE_LOCALE]);
+  if (!localeFile.exists())
+    localeFile = getFile(KEY_GRED, [FILE_UPDATE_LOCALE]);
+
+  if (!localeFile.exists())
+    throw Components.Exception(FILE_UPDATE_LOCALE + " file doesn't exist in " +
+                               "either the " + KEY_APPDIR + " or " + KEY_GRED +
+                               " directories", Cr.NS_ERROR_FILE_NOT_FOUND);
+
+  gLocale = readStringFromFile(localeFile);
+  LOG("General", "getLocale - getting locale from file: " + localeFile.path +
       ", locale: " + gLocale);
   return gLocale;
 }
 
 /**
  * Read the update channel from defaults only.  We do this to ensure that
  * the channel is tightly coupled with the application and does not apply
  * to other instances of the application that may use the same profile.
--- a/toolkit/mozapps/update/test/unit/test_0040_general.js.in
+++ b/toolkit/mozapps/update/test/unit/test_0040_general.js.in
@@ -149,17 +149,17 @@ function check_test_pt4() {
     abi = "Universal-gcc3";
 #endif
 
   do_check_eq(getResult(gRequestURL), gAppInfo.OS + "_" + abi);
   run_test_pt5();
 }
 
 // url constructed with %LOCALE%
-// Bug 488936 added the locale to the updater.locale file
+// Bug 488936 added the update.locale file that stores the update locale
 function run_test_pt5() {
   gCheckFunc = check_test_pt5;
   var url = URL_PREFIX + "%LOCALE%/";
   dump("Testing: url constructed with %LOCALE% - " + url + "\n");
   getPrefBranch().setCharPref(PREF_APP_UPDATE_URL_OVERRIDE, url);
   try {
     gUpdateChecker.checkForUpdates(updateCheckListener, true);
   }