1
/* You may find the license in the LICENSE file */
3
const EXPORTED_SYMBOLS = ['loadWindow'];
5
const Cc = Components.classes;
6
const Ci = Components.interfaces;
7
const Cr = Components.results;
8
const Cu = Components.utils;
9
const Ctor = Components.Constructor;
10
const Exception = Components.Exception;
12
function loadWindow() {};
16
Cu.import("resource://gre/modules/AddonManager.jsm");
18
const ZipReader = Ctor("@mozilla.org/libjar/zip-reader;1", "nsIZipReader", "open");
20
Cu.import("resource://dta/version.jsm");
21
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
23
const DirectoryService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
24
if (!(DirectoryService instanceof Ci.nsIDirectoryService)) {
25
throw new Exception("eek");
27
let profileDir = DirectoryService.get("ProfD", Ci.nsILocalFile);
28
let iconDir = profileDir.clone();
29
iconDir.append('icons');
30
iconDir.append('default');
33
function extract(file) {
34
let jar = new ZipReader(file);
35
let entries = jar.findEntries("chrome/icons/default/*.(ico|png|xpm)$");
36
while (entries.hasMore()) {
37
let entry = entries.getNext();
39
let name = entry.split(/[/\\]/).pop();
40
let dst = iconDir.clone();
42
jar.extract(entry, dst);
50
// flat-package version
51
function copy(directory) {
52
let srcDirectory = directory.clone();
53
srcDirectory.append('chrome');
54
srcDirectory.append('icons');
55
srcDirectory.append('default');
56
let icons = srcDirectory.directoryEntries;
57
while (icons.hasMoreElements()) {
58
let icon = icons.getNext();
59
if ((icon instanceof Ci.nsIFile) && icon.isFile()) {
61
icon.copyTo(iconDir, icon.leafName);
70
// Directory Provider we use to check the system :p
71
function CheatDirProvider() {}
72
CheatDirProvider.prototype = {
74
QueryInterface: XPCOMUtils.generateQI([Ci.nsIDirectoryServiceProvider, Ci.nsIDirectoryServiceProvider2, Ci.nsISimpleEnumerator]),
75
getFile: function(prop, persist) {
76
throw Cr.NS_ERROR_FAILURE;
78
getFiles: function(prop, persist) {
79
if (prop == "AChromDL") {
83
throw Cr.NS_ERROR_FAILURE;
85
hasMoreElements: function() this.hasMore,
88
throw Cr.NS_ERROR_FAILURE;
91
return profileDir.clone();
95
// Create icons if not there yet, or if we got a major version update
96
if (!iconDir.exists() || Version.showAbout) {
97
if (!iconDir.exists()) {
98
iconDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0755);
100
AddonManager.getAddonByID(Version.ID, function(addon) {
101
let uri = addon.getResourceURI('icon.png');
102
if (uri instanceof Ci.nsIJARURI) {
104
if (uri instanceof Ci.nsIFileURL) {
108
else if (uri instanceof Ci.nsIFileURL) {
109
copy(uri.file.parent);
115
loadWindow = function(window) {
116
let _p = new CheatDirProvider();
117
DirectoryService.registerProvider(_p);
118
window.addEventListener('load', function() {
119
window.removeEventListener('load', arguments.callee, true);
120
window.setTimeout(function() {
121
DirectoryService.unregisterProvider(_p);
129
// no need to do anything;
b'\\ No newline at end of file'