-
Notifications
You must be signed in to change notification settings - Fork 2
/
install.js
159 lines (136 loc) · 5.24 KB
/
install.js
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
// install.js is used by SeaMonkey and older Firefox versions.
// Taken from http://users.skynet.be/fa258499/hackexttutorial.html
//
// TODO: SeaMonkey still fails on something, but isn't helpful telling us.
// Please tell us what we need to fix to make it work!
(function() {
var displayName = "CertPatrol";
var version = "2.0.14";
var name = "certpatrol"; // leafname of the JAR file
// The following three sets of variables tell this installer script how your
// extension directory structure looks.
// If your jar file contains content/packagename use the second packageDir
// variable. Same rule applies for skinDir and localeDir. I set them up
// independent of each other just in case an extension layout is wacky.
var packageDir = "/"
var skinDir = ""
var localeDir = "/"
// languages disabled for now... FIXME
var locales = new Array( ); // "en", "it", "de" );
var skins = new Array( ); // "classic"
var prefs = new Array( "CertPatrol.js" );
var components = new Array( );
var searchPlugins = new Array( );
// Mozilla Suite/Seamonkey stores all pref files in a single directory
// under the application directory. If the name of the preference file(s)
// is/are not unique enough, you may override other extension preferences.
// set this to true if you need to prevent this.
var disambiguatePrefs = true;
// Editable Items End
// This code is heavily inspired by Chris Pederick (useragentswitcher) install.js
// Contributors: Philip Chee, deathburger
//
// Philip Chee: Added installation of prefs, components, and locales.
// deathburger: Refactored to move all changable items to the top of the file.
var jarName = name + ".jar";
var jarFolder = "content" + packageDir
var error = null;
var folder = getFolder("Profile", "chrome");
var prefFolder = getFolder(getFolder("Program", "defaults"), "pref");
var compFolder = getFolder("Components");
var searchFolder = getFolder("Plugins");
var existsInApplication = File.exists(getFolder(getFolder("chrome"), jarName));
var existsInProfile = File.exists(getFolder(folder, jarName));
var contentFlag = CONTENT | PROFILE_CHROME;
var localeFlag = LOCALE | PROFILE_CHROME;
var skinFlag = SKIN | PROFILE_CHROME;
// If the extension exists in the application folder or it doesn't exist
// in the profile folder and the user doesn't want it installed to the
// profile folder
if(existsInApplication ||
(!existsInProfile &&
!confirm( "Do you want to install the " + displayName +
" extension into your profile folder?\n" +
"(Cancel will install into the application folder)")))
{
contentFlag = CONTENT | DELAYED_CHROME;
folder = getFolder("chrome");
localeFlag = LOCALE | DELAYED_CHROME;
skinFlag = SKIN | DELAYED_CHROME;
}
initInstall(displayName, name, version);
setPackageFolder(folder);
error = addFile(name, version, "chrome/" + jarName, folder, null);
// If adding the JAR file succeeded
if(error == SUCCESS)
{
folder = getFolder(folder, jarName);
registerChrome(contentFlag, folder, jarFolder);
for (var i = 0; i < locales.length; i++) {
registerChrome(localeFlag, folder, "locale/" + locales[i] + localeDir);
}
for (var i = 0; i < skins.length; i++) {
registerChrome(skinFlag, folder, "skin/" + skins[i] + skinDir);
}
for (var i = 0; i < prefs.length; i++) {
if (!disambiguatePrefs) {
addFile(name + " Defaults", version, "defaults/preferences/" + prefs[i],
prefFolder, prefs[i], true);
} else {
addFile(name + " Defaults", version, "defaults/preferences/" + prefs[i],
prefFolder, name + "-" + prefs[i], true);
}
}
for (var i = 0; i < components.length; i++) {
addFile(name + " Components", version, "components/" + components[i],
compFolder, components[i], true);
}
for (var i = 0; i < searchPlugins.length; i++) {
addFile(name + " searchPlugins", version, "searchplugins/" + searchPlugins[i],
searchFolder, searchPlugins[i], true);
}
error = performInstall();
// If the install failed
if(error != SUCCESS && error != REBOOT_NEEDED)
{
displayError(error);
cancelInstall(error);
}
else
{
alert("The installation of the " + displayName + " extension succeeded.");
}
}
else
{
displayError(error);
cancelInstall(error);
}
// Displays the error message to the user
function displayError(error)
{
// If the error code was -215
if(error == READ_ONLY)
{
alert("The installation of " + displayName +
" failed.\nOne of the files being overwritten is read-only.");
}
// If the error code was -235
else if(error == INSUFFICIENT_DISK_SPACE)
{
alert("The installation of " + displayName +
" failed.\nThere is insufficient disk space.");
}
// If the error code was -239
else if(error == CHROME_REGISTRY_ERROR)
{
alert("The installation of " + displayName +
" failed.\nChrome registration failed.");
}
else
{
alert("The installation of " + displayName +
" failed.\nThe error code is: " + error);
}
}
})();