#filter substitution // main var srDest; var err; var fProgram; var platformNode; var searchPlugins = "searchplugins"; var restrictedAccess; function registerProgramFolderKey(winreg, fFolderPath) { var subkey; var err; var szCurrentMozillaVersion; /* set the Program Folder Path in the Mozilla key in the Windows Registry */ winreg.createKey("SOFTWARE\\$CompanyName$",""); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "CurrentVersion", "$UserAgent$"); subkey = "SOFTWARE\\$CompanyName$\\Mozilla"; szCurrentMozillaVersion = winreg.getValueString(subkey, "CurrentVersion"); logComment("szCurrentMozillaVersion: " + szCurrentMozillaVersion); if((szCurrentMozillaVersion == "") || (szCurrentMozillaVersion == null)) { // A Mozilla\CurrentVersion key must be set so that Java can work. // (bug 229627) subkey = "SOFTWARE\\$CompanyName$\\Mozilla"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "CurrentVersion", "$GreVersion$"); } subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$"; winreg.createKey(subkey,""); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "Program Folder Path", fFolderPath); } function createShortcuts() { var subkey; var valname; var szStartMenuPrograms; var szStartMenu; var szFolderDesktop; var szFolderQuickLaunch; var szFolderAppData; var winreg; var fTemp; var fProgram; var fDefShortcuts; var fileExe; var scExeDesc; var scFolderName; var fFolderDesktop; var fFolderPrograms; var fFolderProgramsStr; var fFolderQuickLaunch; var is_winnt; var szCurrentVersion; var folderQuickLaunchExists; winreg = getWinRegistry(); fProgram = getFolder("Program"); fDefShortcuts = getFolder("Program","defaults/shortcuts"); fTemp = fProgram + "$MainExeFile$"; fileExe = getFolder("file:///", fTemp); scExeDesc = "$ProductName$"; scFolderName = "$ProductName$"; scSafeModeDesc = "$ProductName$ (Safe Mode)"; scSafeModeParam = "-safe-mode"; if (winreg) { // determine if the script is running under NT or not winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); subkey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; szCurrentVersion = winreg.getValueString(subkey, "CurrentVersion"); logComment("szCurrentVersion: " + szCurrentVersion); is_winnt = szCurrentVersion != ""; logComment("is_winnt value: " + is_winnt); // Locate the various folders we're about to install shortcuts into. if(!is_winnt || restrictedAccess) { winreg.setRootKey(winreg.HKEY_CURRENT_USER); subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; szStartMenuPrograms = winreg.getValueString(subkey, "Programs"); szStartMenu = winreg.getValueString(subkey, "Start Menu"); szFolderDesktop = winreg.getValueString(subkey, "Desktop"); } else { winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; szStartMenuPrograms = winreg.getValueString(subkey, "Common Programs"); szStartMenu = winreg.getValueString(subkey, "Common Start Menu"); szFolderDesktop = winreg.getValueString(subkey, "Common Desktop"); } // Locate the Start Menu Programs Folder winreg.setRootKey(winreg.HKEY_CURRENT_USER); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main"; fFolderProgramsStr = winreg.getValueString(subkey, "Program Folder Path"); fFolderPrograms = getFolder("file:///", fFolderProgramsStr || szStartMenuPrograms); // Locate the Desktop Folder winreg.setRootKey(winreg.HKEY_CURRENT_USER); fFolderDesktop = getFolder("file:///", szFolderDesktop); // Locate the Quick Launch folder winreg.setRootKey(winreg.HKEY_CURRENT_USER); subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders"; szFolderAppData = winreg.getValueString(subkey, "AppData"); szFolderQuickLaunch = szFolderAppData + "\\Microsoft\\Internet Explorer\\Quick Launch"; fFolderQuickLaunch = getFolder("file:///", szFolderQuickLaunch); folderQuickLaunchExists = File.isDirectory(fFolderQuickLaunch); if(!folderQuickLaunchExists) { subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\GrpConv\\MapGroups"; szFolderQuickLaunch = winreg.getValueString(subkey, "Quick Launch"); folderQuickLaunchExists = File.isDirectory(fFolderPrograms); if(folderQuickLaunchExists) fFolderQuickLaunch = getFolder("file:///", szFolderQuickLaunch); } logComment("folderQuickLaunchExists: " + folderQuickLaunchExists); logComment("Folder StartMenuPrograms: " + szStartMenuPrograms); logComment("Folder StartMenu : " + szStartMenu); logComment("Folder FolderDesktop : " + szFolderDesktop); logComment("Folder FolderQuickLaunch: " + szFolderQuickLaunch); logComment("fileExe : " + fileExe); logComment("fFolderPrograms : " + fFolderPrograms); logComment("scExeDesc : " + scExeDesc); logComment("fProgram : " + fProgram); winreg.setRootKey(winreg.HKEY_CURRENT_USER); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main"; // Explicitly create the fFolderPrograms even though the windowsShortcut // function creates the folder. This is so that the folder creation gets // logged for uninstall to remove it. // Only create the Start Menu folder if the user selected start menu icons if (winreg.getValueNumber(subkey, "Create Start Menu Shortcut") != 0 && !File.exists(fFolderPrograms)) File.dirCreate(fFolderPrograms); // Always create default shortcuts folder if (!File.exists(fDefShortcuts)) File.dirCreate(fDefShortcuts); // Create the Shortcuts if (winreg.getValueNumber(subkey, "Create Desktop Shortcut") != 0) File.windowsShortcut(fileExe, fFolderDesktop, scExeDesc, fProgram, "", fileExe, 0); if (winreg.getValueNumber(subkey, "Create Start Menu Shortcut") != 0) { File.windowsShortcut(fileExe, fFolderPrograms, scExeDesc, fProgram, "", fileExe, 0); File.windowsShortcut(fileExe, fFolderPrograms, scSafeModeDesc, fProgram, scSafeModeParam, fileExe, 0); } if (winreg.getValueNumber(subkey, "Create Quick Launch Shortcut") != 0 && folderQuickLaunchExists) File.windowsShortcut(fileExe, fFolderQuickLaunch, scExeDesc, fProgram, "", fileExe, 0); // Always create the default shortcuts. File.windowsShortcut(fileExe, fDefShortcuts, scExeDesc, fProgram, "", fileExe, 0); File.windowsShortcut(fileExe, fDefShortcuts, scSafeModeDesc, fProgram, scSafeModeParam, fileExe, 0); if(!restrictedAccess) { winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); registerProgramFolderKey(winreg, fFolderPrograms); // This is so that Windows Media Player works with us var subkey = "SOFTWARE\\Microsoft\\MediaPlayer\\ShimInclusionList\\$MainExeFile$"; winreg.createKey(subkey, ""); } winreg.setRootKey(winreg.HKEY_CURRENT_USER); registerProgramFolderKey(winreg, fFolderPrograms); } else logComment("winreg is null"); } function IsWinnt() { /* Determines if the script is running under NT or not. * */ var winreg = getWinRegistry(); var subkey; var szCurrentVersion; winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); subkey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion"; szCurrentVersion = winreg.getValueString(subkey, "CurrentVersion"); logComment("szCurrentVersion: " + szCurrentVersion); return szCurrentVersion != ""; } function registerMainKeys(winreg) { var subkey; //the name of the subkey you are poking around in var data; var err; winreg.createKey("SOFTWARE\\$CompanyName$",""); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "CurrentVersion", "$UserAgent$"); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$"; winreg.createKey(subkey,""); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "Install Directory", fProgram); // The following keys are required to be created to supply information // about the location of the Gecko Embedded Client to 3rd party apps. // "SOFTWARE\\Mozilla" must not be localized! subkey = "SOFTWARE\\Mozilla\\$ProductName$ $UserAgentShort$"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "GeckoVer", "$GreVersion$"); subkey = "SOFTWARE\\Mozilla\\$ProductName$ $UserAgentShort$\\Extensions"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "Components", fProgram + "Components"); err = winreg.setValueString(subkey, "Plugins", fProgram + "Plugins"); subkey = "SOFTWARE\\Mozilla\\$ProductName$ $UserAgentShort$\\bin"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "PathToExe", fProgram + "$MainExeFile$"); subkey = "SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main"; err = winreg.setValueString(subkey, "PathToExe", fProgram + "$MainExeFile$"); // Register as a windows XP internet browser if( IsWinnt() ) { subkey = "Software\\Clients\\StartMenuInternet\\$MainExeFile$"; winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); winreg.createKey(subkey, ""); winreg.createKey(subkey + "\\DefaultIcon", ""); winreg.createKey(subkey + "\\shell", ""); winreg.createKey(subkey + "\\shell\\open", ""); winreg.createKey(subkey + "\\shell\\open\\command", ""); winreg.createKey(subkey + "\\InstallInfo", ""); winreg.setValueString(subkey, "", "$ProductNameInternal$"); // path does not need to be quoted per MS doc data = fProgram + "$MainExeFile$,0"; winreg.setValueString(subkey + "\\DefaultIcon", "", data); data = "\"" + fProgram + "$MainExeFile$\""; winreg.setValueString(subkey + "\\shell\\open\\command", "", data); data = "\"" + fProgram + "uninstall\\uninstall.exe\" /ua \"$UserAgent$\" /hs browser"; winreg.setValueString(subkey + "\\InstallInfo", "HideIconsCommand", data); winreg.setValueNumber(subkey + "\\InstallInfo", "IconsVisible", 1); data = "\"" + fProgram + "$MainExeFile$\" -silent -nosplash -setDefaultBrowser "; winreg.setValueString(subkey + "\\InstallInfo", "ReinstallCommand", data); data = "\"" + fProgram + "uninstall\\uninstall.exe\" /ua \"$UserAgent$\" /ss browser"; winreg.setValueString(subkey + "\\InstallInfo", "ShowIconsCommand", data); } } function updateWinReg() { //Notes: // can't use a double backslash before subkey - Windows already puts it in. // subkeys have to exist before values can be put in. var winreg = getWinRegistry(); var subkey; //the name of the subkey you are poking around in var err; var ikwDefined; if(winreg != null) { /* This will check to see if the user has restricted access or not. * It checks to see if HKEY_LOCALMACHINE\SOFTWARE is writable. If * it is, then access is not restricted. This is only used to * determine which Desktop, Programs, and Start Menu folders * are to used: common or per user */ restrictedAccess = false; ikwDefined = typeof(winreg.isKeyWritable); logComment("winreg.isKeyWritable(): " + ikwDefined); if(ikwDefined == "function") { winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); if(!winreg.isKeyWritable("SOFTWARE")) restrictedAccess = true; } logComment("restrictedAccess value: " + restrictedAccess); if(!restrictedAccess) { winreg.setRootKey(winreg.HKEY_LOCAL_MACHINE); registerMainKeys(winreg); // set the App Paths key here subkey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\$MainExeFile$"; winreg.createKey(subkey,""); err = winreg.setValueString(subkey, "", fProgram + "$MainExeFile$"); err = winreg.setValueString(subkey, "Path", fProgram); // XPInstall content type mappings. subkey = "SOFTWARE\\Classes\\MIME\\Database\\Content Type\\application/x-xpinstall;app=firefox" winreg.createKey(subkey, ""); winreg.setValueString(subkey, "Extension", ".xpi"); } winreg.setRootKey(winreg.HKEY_CURRENT_USER); registerMainKeys(winreg); } // Now clean up Uninstall entries that may be laying around in the // registry for older versions of the software that we're overwriting/ // upgrading... var wr = getWinRegistry(); wr.setRootKey(wr.HKEY_LOCAL_MACHINE); var i = 0; const uninstallKey = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; do { var key = wr.enumKeys(uninstallKey, i++); if (!key) break; key = uninstallKey + "\\" + key; // For us to remove the entry from the ARP uninstall list, the install // folder paths must *match* and the display version strings must *NOT // MATCH* - i.e. we don't want to remove the entry we just created for // this version. var itemInstallFolder = wr.getValueString(key, "InstallLocation"); var thisInstallFolder = wr.getValueString("SOFTWARE\\$CompanyName$\\$ProductName$\\$UserAgent$\\Main", "Install Directory"); var itemInstallFolderShortName = File.windowsGetShortName(getFolder("file:///", itemInstallFolder)); var thisInstallFolderShortName = File.windowsGetShortName(getFolder("file:///", thisInstallFolder)); var itemDisplayVersion = wr.getValueString(key, "DisplayVersion"); var thisDisplayVersion = "$UserAgent$"; // It is possible that a user might have installed several products into // the same directory that have the same "DisplayVersion" (e.g. "1.0")... // in this case we don't want to trash the Uninstall info for the others // so we have to be sure to make sure Comment matches... we use Comment // instead of DisplayName since DisplayName varies from version to version // as it contains the version number, and this instance of javascript is // crippled so as not to contain any useful string parsing. var itemComment = wr.getValueString(key, "Comment"); var thisComment = "$ProductName$"; if ((itemComment == thisComment || itemComment == "The Browser, Reloaded.") && itemInstallFolderShortName == thisInstallFolderShortName && thisDisplayVersion != itemDisplayVersion && wr.isKeyWritable(key)) { wr.deleteKey(key); logComment("Removing obsolete uninstall key with upgrade: " + key); } } while (true); } logComment("initInstall: platformNode=" + platformNode); // end // end - OS type detection var chromeNode = "@AB_CD@"; var regName = "locales/mozilla/" + chromeNode; var chromeName = chromeNode + ".jar"; var localeName = "locale/" + chromeNode + "/"; srDest = $SpaceRequired$:bin; err = initInstall("@AB_CD@ Langpack", "@AB_CD@", "$Version$"); logComment("initInstall: " + err); fProgram = getFolder("Program"); logComment("fProgram: " + fProgram); if(verifyDiskSpace(fProgram, srDest)) { var chromeType = LOCALE; var fTarget; err = addDirectory("", "bin", // dir name in jar to extract fProgram, // Where to put this file (Returned from GetFolder) ""); // Force Flag logComment("addDirectory() returned: " + err); setPackageFolder(fProgram); // check return value if (err == SUCCESS) { fTarget = getFolder("Program", "defaults"); logComment("fTarget: " + fTarget); err = addDirectory("", "bin/defaults", // dir name in jar to extract fTarget, // Where to put this file (Returned from GetFolder) ""); // subdir name to create relative to fProgram logComment("addDirectory() returned: " + err); fTarget = getFolder("Program", searchPlugins); logComment("fTarget: " + fTarget); err = addDirectory("", "bin/searchplugins", // dir name in jar to extract fTarget, // Where to put this file (Returned from GetFolder) ""); // subdir name to create relative to fProgram logComment("addDirectory() returned: " + err); updateWinReg(); createShortcuts(); err = performInstall(); logComment("performInstall() returned: " + err); } else { cancelInstall(err); logComment("cancelInstall due to error: " + err); } } else cancelInstall(INSUFFICIENT_DISK_SPACE); // end main