services/sync/tps/extensions/mozmill/resource/stdlib/os.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/services/sync/tps/extensions/mozmill/resource/stdlib/os.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,57 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, you can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +var EXPORTED_SYMBOLS = ['listDirectory', 'getFileForPath', 'abspath', 'getPlatform'];
     1.9 +
    1.10 +const Cc = Components.classes;
    1.11 +const Ci = Components.interfaces;
    1.12 +const Cu = Components.utils;
    1.13 +
    1.14 +Cu.import("resource://gre/modules/Services.jsm");
    1.15 +
    1.16 +function listDirectory(file) {
    1.17 +  // file is the given directory (nsIFile)
    1.18 +  var entries = file.directoryEntries;
    1.19 +  var array = [];
    1.20 +
    1.21 +  while (entries.hasMoreElements()) {
    1.22 +    var entry = entries.getNext();
    1.23 +    entry.QueryInterface(Ci.nsIFile);
    1.24 +    array.push(entry);
    1.25 +  }
    1.26 +
    1.27 +  return array;
    1.28 +}
    1.29 +
    1.30 +function getFileForPath(path) {
    1.31 +  var file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsILocalFile);
    1.32 +  file.initWithPath(path);
    1.33 +  return file;
    1.34 +}
    1.35 +
    1.36 +function abspath(rel, file) {
    1.37 +  var relSplit = rel.split('/');
    1.38 +
    1.39 +  if (relSplit[0] == '..' && !file.isDirectory()) {
    1.40 +    file = file.parent;
    1.41 +  }
    1.42 +
    1.43 +  for each(var p in relSplit) {
    1.44 +    if (p == '..') {
    1.45 +      file = file.parent;
    1.46 +    } else if (p == '.') {
    1.47 +      if (!file.isDirectory()) {
    1.48 +        file = file.parent;
    1.49 +      }
    1.50 +    } else {
    1.51 +      file.append(p);
    1.52 +    }
    1.53 +  }
    1.54 +
    1.55 +  return file.path;
    1.56 +}
    1.57 +
    1.58 +function getPlatform() {
    1.59 +  return Services.appinfo.OS.toLowerCase();
    1.60 +}

mercurial