michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, you can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: var EXPORTED_SYMBOLS = ['listDirectory', 'getFileForPath', 'abspath', 'getPlatform']; michael@0: michael@0: const Cc = Components.classes; michael@0: const Ci = Components.interfaces; michael@0: const Cu = Components.utils; michael@0: michael@0: Cu.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function listDirectory(file) { michael@0: // file is the given directory (nsIFile) michael@0: var entries = file.directoryEntries; michael@0: var array = []; michael@0: michael@0: while (entries.hasMoreElements()) { michael@0: var entry = entries.getNext(); michael@0: entry.QueryInterface(Ci.nsIFile); michael@0: array.push(entry); michael@0: } michael@0: michael@0: return array; michael@0: } michael@0: michael@0: function getFileForPath(path) { michael@0: var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile); michael@0: file.initWithPath(path); michael@0: return file; michael@0: } michael@0: michael@0: function abspath(rel, file) { michael@0: var relSplit = rel.split('/'); michael@0: michael@0: if (relSplit[0] == '..' && !file.isDirectory()) { michael@0: file = file.parent; michael@0: } michael@0: michael@0: for each(var p in relSplit) { michael@0: if (p == '..') { michael@0: file = file.parent; michael@0: } else if (p == '.') { michael@0: if (!file.isDirectory()) { michael@0: file = file.parent; michael@0: } michael@0: } else { michael@0: file.append(p); michael@0: } michael@0: } michael@0: michael@0: return file.path; michael@0: } michael@0: michael@0: function getPlatform() { michael@0: return Services.appinfo.OS.toLowerCase(); michael@0: }