Version 0.7
[QuoteCollapse.git] / src / install.js
blobbeb92887794509a6b4f9ee23777491ca91ebf28d
1 // XpiInstaller\r
2 // By Pike (Heavily inspired by code from Henrik Gemal and Stephen Clavering)\r
3 \r
4 var XpiInstaller = {\r
5 \r
6         // --- Editable items begin ---\r
7         extFullName: 'QuoteCollapse', // The name displayed to the user (don't include the version)\r
8         extShortName: 'quotecollapse', // The leafname of the JAR file (without the .jar part)\r
9         extVersion: '0.7',\r
10         extAuthor: 'Michael J Gruber',\r
11         extLocaleNames: null, // e.g. ['en-US', 'en-GB']\r
12         extSkinNames: ['classic','mcrystal'], // e.g. ['classic', 'modern']\r
13         extPostInstallMessage: 'Success! Please restart your browser to finish the installation.', // Set to null for no post-install message\r
14         // --- Editable items end ---\r
16         profileInstall: true,\r
17         silentInstall: false,\r
19         install: function()\r
20         {\r
21                 var jarName = this.extShortName + '.jar';\r
22                 var profileDir = Install.getFolder('Profile', 'chrome');\r
24                 // Parse HTTP arguments\r
25                 this.parseArguments();\r
27                 // Check if extension is already installed in profile\r
28                 if (File.exists(Install.getFolder(profileDir, jarName)))\r
29                 {\r
30                         if (!this.silentInstall)\r
31                         {\r
32                                 Install.alert('Updating existing Profile install of ' + this.extFullName + ' to version ' + this.extVersion + '.');\r
33                         }\r
34                         this.profileInstall = true;\r
35                 }\r
36                 else if (!this.silentInstall)\r
37                 {\r
38                         // Ask user for install location, profile or browser dir?\r
39                         this.profileInstall = Install.confirm('Install ' + this.extFullName + ' ' + this.extVersion + ' to your Profile directory (OK) or your Browser directory (Cancel)?');\r
40                 }\r
42                 // Init install\r
43                 var dispName = this.extFullName + ' ' + this.extVersion;\r
44                 var regName = '/' + this.extAuthor + '/' + this.extShortName;\r
45                 Install.initInstall(dispName, regName, this.extVersion);\r
47                 // Find directory to install into\r
48                 var installPath;\r
49                 if (this.profileInstall) installPath = profileDir;\r
50                 else installPath = Install.getFolder('chrome');\r
52                 // Add JAR file\r
53                 Install.addFile(null, 'chrome/' + jarName, installPath, null);\r
55                 // Register chrome\r
56                 var jarPath = Install.getFolder(installPath, jarName);\r
57                 var installType = this.profileInstall ? Install.PROFILE_CHROME : Install.DELAYED_CHROME;\r
59                 // Register content\r
60                 Install.registerChrome(Install.CONTENT | installType, jarPath, 'content/' + this.extShortName + '/');\r
62                 // Register locales\r
63                 for (var locale in this.extLocaleNames)\r
64                 {\r
65                         var regPath = 'locale/' + this.extLocaleNames[locale] + '/' + this.extShortName + '/';\r
66                         Install.registerChrome(Install.LOCALE | installType, jarPath, regPath);\r
67                 }\r
69                 // Register skins\r
70                 for (var skin in this.extSkinNames)\r
71                 {\r
72                         var regPath = 'skin/' + this.extSkinNames[skin] + '/' + this.extShortName + '/';\r
73                         Install.registerChrome(Install.SKIN | installType, jarPath, regPath);\r
74                 }\r
76                 // Perform install\r
77                 var err = Install.performInstall();\r
78                 if (err == Install.SUCCESS || err == Install.REBOOT_NEEDED)\r
79                 {\r
80                         if (!this.silentInstall && this.extPostInstallMessage)\r
81                         {\r
82                                 Install.alert(this.extPostInstallMessage);\r
83                         }\r
84                 }\r
85                 else\r
86                 {\r
87                         this.handleError(err);\r
88                         return;\r
89                 }\r
90         },\r
92         parseArguments: function()\r
93         {\r
94                 // Can't use string handling in install, so use if statement instead\r
95                 var args = Install.arguments;\r
96                 if (args == 'p=0')\r
97                 {\r
98                         this.profileInstall = false;\r
99                         this.silentInstall = true;\r
100                 }\r
101                 else if (args == 'p=1')\r
102                 {\r
103                         this.profileInstall = true;\r
104                         this.silentInstall = true;\r
105                 }\r
106         },\r
108         handleError: function(err)\r
109         {\r
110                 if (!this.silentInstall)\r
111                 {\r
112                         Install.alert('Error: Could not install ' + this.extFullName + ' ' + this.extVersion + ' (Error code: ' + err + ')');\r
113                 }\r
114                 Install.cancelInstall(err);\r
115         }\r
116 };\r
118 XpiInstaller.install();\r