summaryrefslogtreecommitdiff
path: root/services/sync/tps/extensions/mozmill/resource/stdlib/os.js
blob: f515b9a01f13f3ecbb518128e5577c21e7517e3f (plain)
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
/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

var EXPORTED_SYMBOLS = ['listDirectory', 'getFileForPath', 'abspath', 'getPlatform'];

function listDirectory (file) {
  // file is the given directory (nsIFile)
  var entries = file.directoryEntries;
  var array = [];
  while (entries.hasMoreElements())
  {
    var entry = entries.getNext();
    entry.QueryInterface(Components.interfaces.nsIFile);
    array.push(entry);
  }
  return array;
}

function getFileForPath (path) {
  var file = Components.classes["@mozilla.org/file/local;1"]
                       .createInstance(Components.interfaces.nsILocalFile);
  file.initWithPath(path);
  return file;
}

function abspath (rel, file) {
  var relSplit = rel.split('/');
  if (relSplit[0] == '..' && !file.isDirectory()) {
    file = file.parent;
  }
  for each(p in relSplit) {
    if (p == '..') {
      file = file.parent;
    } else if (p == '.'){
      if (!file.isDirectory()) {
        file = file.parent;
      }
    } else {
      file.append(p);
    }
  }
  return file.path;
}

function getPlatform () {
  var xulRuntime = Components.classes["@mozilla.org/xre/app-info;1"]
                   .getService(Components.interfaces.nsIXULRuntime);
  mPlatform = xulRuntime.OS.toLowerCase();
  return mPlatform;
}