2 * (C) Copyright 2004-2007 Shawn Betts
3 * (C) Copyright 2007-2009 John J. Foerch
4 * (C) Copyright 2007-2008 Jeremy Maitin-Shepard
6 * Use, modification, and distribution are subject to the terms specified in the
11 * get_os returns a string identifying the current OS.
12 * possible values include 'Darwin', 'Linux' and 'WINNT'.
14 let (xul_runtime = Cc['@mozilla.org/xre/app-info;1']
15 .getService(Ci.nsIXULRuntime)) {
17 return xul_runtime.OS;
21 const WINDOWS = (get_os() == "WINNT");
22 const POSIX = !WINDOWS;
26 * get_xulrunner_version returns the version string of the running
29 function get_mozilla_version () {
30 return Cc['@mozilla.org/xre/app-info;1']
31 .getService(Ci.nsIXULAppInfo)
37 * getenv returns the value of a named environment variable or null if
38 * the environment variable does not exist.
40 let (env = Cc['@mozilla.org/process/environment;1']
41 .getService(Ci.nsIEnvironment)) {
42 function getenv (variable) {
43 if (env.exists(variable))
44 return env.get(variable);
51 * get_home_directory returns an nsILocalFile object of the user's
54 function get_home_directory () {
55 var dir = Cc["@mozilla.org/file/local;1"]
56 .createInstance(Ci.nsILocalFile);
57 if (get_os() == "WINNT") {
58 var home = getenv('HOME') ||
59 getenv('USERPROFILE') ||
60 getenv('HOMEDRIVE') + getenv('HOMEPATH');
61 home = home.replace("/", "\\", "g");
62 dir.initWithPath(home);
64 dir.initWithPath(getenv('HOME'));
69 /* get_current_profile returns the name of the current profile, or
70 * null if that information cannot be found. The result is cached for
71 * quick repeat lookup. This is safe because xulrunner does not
72 * support switching profiles on the fly.
74 * Profiles don't necessarily have a name--as such this information should
75 * not be depended on for anything important. It is mainly intended for
76 * decoration of the window title and mode-line.
78 let (profile_name = null) {
79 function get_current_profile () {
82 if ("@mozilla.org/profile/manager;1" in Cc) {
83 profile_name = Cc["@mozilla.org/profile/manager;1"]
84 .getService(Ci.nsIProfile)
88 var current_profile_path = Cc["@mozilla.org/file/directory_service;1"]
89 .getService(Ci.nsIProperties)
90 .get("ProfD", Ci.nsIFile).path;
91 var profile_service = Cc["@mozilla.org/toolkit/profile-service;1"]
92 .getService(Components.interfaces.nsIToolkitProfileService);
93 var profiles = profile_service.profiles;
94 while (profiles.hasMoreElements()) {
95 var p = profiles.getNext().QueryInterface(Ci.nsIToolkitProfile);
96 if (current_profile_path == p.localDir.path ||
97 current_profile_path == p.rootDir.path)
99 profile_name = p.name;
109 function get_locale () {
110 const LOCALE_PREF = "general.useragent.locale";
111 return get_localized_pref(LOCALE_PREF) || get_pref(LOCALE_PREF);
115 const PATH = getenv("PATH").split(POSIX ? ":" : ";");
116 const path_component_regexp = POSIX ? /^[^\/]+$/ : /^[^\/\\]+$/;
118 function find_file_in_path (name) {
119 if (name instanceof Ci.nsIFile) {
124 var file = Cc["@mozilla.org/file/local;1"]
125 .createInstance(Ci.nsILocalFile);
126 if (! path_component_regexp.test(name)) {
129 file.initWithPath(name);
136 for (var i = 0, plen = PATH.length; i < plen; ++i) {
138 file.initWithPath(PATH[i]);
139 file.appendRelativePath(name);