File: install.js

package info (click to toggle)
livehttpheaders 0.14-1
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 716 kB
  • ctags: 196
  • sloc: makefile: 39; sh: 35
file content (72 lines) | stat: -rw-r--r-- 2,758 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
const X_MSG = 	   "Install Live HTTP Header";
const X_NAME =     "/livehttpheaders";
const X_NAME_COM = "/livehttpheaders_com";
const X_VER  =     "0.14";
const X_JAR_FILE = "livehttpheaders.jar";
const X_COM_FILE = "nsHeaderInfo.js";

const X_CONTENT =  "content/";
const X_SKIN = 	   "skin/";
const X_LOCALES =  ["en-US", "fr-FR", "de-AT", "es-ES", "cs-CZ", "nl-NL",
      "ru-RU", "ru-RU", "da-DK", "ja-JP", "hu-HU"];

var err = initInstall(X_MSG, X_NAME, X_VER);
logComment("initInstall: " + err);
logComment("Installation started...");
resetError();

if (confirm("Do you wish to install LiveHTTPHeaders to your profile ?\n\n"+
            "Click OK to install in your profile.\n\n"+
            "Click Cancel to install it globally.")) {
  var chromeBase = PROFILE_CHROME;
  var chromeFolder = getFolder("Profile", "chrome");
} else {
  var chromeBase = DELAYED_CHROME;
  var chromeFolder = getFolder("Chrome");
}
var componentDir = getFolder("Components");
var iconFolder = getFolder(getFolder("Chrome", "icons"), "default");

addFile(X_NAME, "chrome/" + X_JAR_FILE, chromeFolder, "");
// It's okay if this fails; the component and icons aren't critical to the
// functioning of most of the extension
err = getLastError();
if (err == SUCCESS || err == REBOOT_NEEDED) {
  addFile(X_NAME_COM, "components/" + X_COM_FILE, componentDir, "");
  addFile(X_NAME, "icons/default/LiveHTTPHeaders.xpm", iconFolder, "");
  addFile(X_NAME, "icons/default/LiveHTTPHeaders.ico", iconFolder, "");
  resetError();
}

err = getLastError();
if (err == SUCCESS || err == REBOOT_NEEDED) {
  registerChrome(chromeBase | CONTENT, getFolder(chromeFolder, X_JAR_FILE), X_CONTENT);
  registerChrome(chromeBase | SKIN, getFolder(chromeFolder, X_JAR_FILE), X_SKIN);
  for(var i = 0; i < X_LOCALES.length; i++) {
    registerChrome(chromeBase | LOCALE, getFolder(chromeFolder, X_JAR_FILE),
    "locale/" + X_LOCALES[i] + "/livehttpheaders/");
  }
}
err = getLastError();
if (err == SUCCESS || err == REBOOT_NEEDED) {
  performInstall();
  err = getLastError();
  if (err == SUCCESS || err == REBOOT_NEEDED) {
    alert("LiveHTTPHeaders version " + X_VER + " is now installed.\n\nPlease restart mozilla.");
  } else {
    // Nothing to do, Mozilla will display an error message himself
  }
} else {
  cancelInstall();
  if (err == -202) {
    alert("You need to have write permissions to the chrome directory and subfolders:\n" + 
          chromeFolder);
  } else if (err == -210) {
    alert("Installation cancelled by user");
  }else {
    alert("An unknown error occured.  Error code: " + err + "\n" + 
          "Look at the following URL for a description of the error code:\n" +
          "http://developer.mozilla.org/en/docs/XPInstall_API_Reference:Return_Codes");
  }
}