Add example code to use beagle as a service provider.
[beagle.git] / mozilla-extension / content / jslib / io / dirUtils.js
blobc5f533a49a064236a581ad991bf4682ee3cf207b
1 /*** -*- Mode: Javascript; tab-width: 2;
3 The contents of this file are subject to the Mozilla Public
4 License Version 1.1 (the "License"); you may not use this file
5 except in compliance with the License. You may obtain a copy of
6 the License at http://www.mozilla.org/MPL/
8 Software distributed under the License is distributed on an "AS
9 IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
10 implied. See the License for the specific language governing
11 rights and limitations under the License.
13 The Original Code is Collabnet code.
14 The Initial Developer of the Original Code is Collabnet.
16 Portions created by Collabnet are Copyright (C) 2000 Collabnet.
17 All Rights Reserved.
19 Contributor(s): Pete Collins, Doug Turner, Brendan Eich, Warren Harris,
20 Eric Plaster, Martin Kutschker
23 JS Directory Class API
25 dirUtils.js
27 Function List
30 Instructions:
35 if(typeof(JS_LIB_LOADED)=='boolean') {
37 const JS_DIRUTILS_FILE = "dirUtils.js";
38 const JS_DIRUTILS_LOADED = true;
40 const JS_DIRUTILS_FILE_LOCAL_CID = "@mozilla.org/file/local;1";
41 const JS_DIRUTILS_FILE_DIR_CID = "@mozilla.org/file/directory_service;1";
43 const JS_DIRUTILS_FILE_I_LOCAL_FILE = "nsILocalFile";
44 const JS_DIRUTILS_INIT_W_PATH = "initWithPath";
45 const JS_DIRUTILS_I_PROPS = "nsIProperties";
46 const JS_DIRUTILS_NSIFILE = C.interfaces.nsIFile;
48 const NS_APP_PREFS_50_DIR = "PrefD"; // /root/.mozilla/Default User/k1m30xaf.slt
49 const NS_APP_CHROME_DIR = "AChrom"; // /usr/src/mozilla/dist/bin/chrome
50 const NS_APP_USER_PROFILES_ROOT_DIR = "DefProfRt"; // /root/.mozilla
51 const NS_APP_USER_PROFILE_50_DIR = "ProfD"; // /root/.mozilla/Default User/k1m30xaf.slt
53 const NS_APP_APPLICATION_REGISTRY_DIR = "AppRegD"; // /root/.mozilla
54 const NS_APP_APPLICATION_REGISTRY_FILE = "AppRegF"; // /root/.mozilla/appreg
55 const NS_APP_DEFAULTS_50_DIR = "DefRt"; // /usr/src/mozilla/dist/bin/defaults
56 const NS_APP_PREF_DEFAULTS_50_DIR = "PrfDef"; // /usr/src/mozilla/dist/bin/defaults/pref
57 const NS_APP_PROFILE_DEFAULTS_50_DIR = "profDef"; // /usr/src/mozilla/dist/bin/defaults/profile/US
58 const NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR = "ProfDefNoLoc"; // /usr/src/mozilla/dist/bin/defaults/profile
59 const NS_APP_RES_DIR = "ARes"; // /usr/src/mozilla/dist/bin/res
60 const NS_APP_PLUGINS_DIR = "APlugns"; // /usr/src/mozilla/dist/bin/plugins
61 const NS_APP_SEARCH_DIR = "SrchPlugns"; // /usr/src/mozilla/dist/bin/searchplugins
62 const NS_APP_PREFS_50_FILE = "PrefF"; // /root/.mozilla/Default User/k1m30xaf.slt/prefs.js
63 const NS_APP_USER_CHROME_DIR = "UChrm"; // /root/.mozilla/Default User/k1m30xaf.slt/chrome
64 const NS_APP_LOCALSTORE_50_FILE = "LclSt"; // /root/.mozilla/Default User/k1m30xaf.slt/localstore.rdf
65 const NS_APP_HISTORY_50_FILE = "UHist"; // /root/.mozilla/Default User/k1m30xaf.slt/history.dat
66 const NS_APP_USER_PANELS_50_FILE = "UPnls"; // /root/.mozilla/Default User/k1m30xaf.slt/panels.rdf
67 const NS_APP_USER_MIMETYPES_50_FILE = "UMimTyp"; // /root/.mozilla/Default User/k1m30xaf.slt/mimeTypes.rdf
68 const NS_APP_BOOKMARKS_50_FILE = "BMarks"; // /root/.mozilla/Default User/k1m30xaf.slt/bookmarks.html
69 const NS_APP_SEARCH_50_FILE = "SrchF"; // /root/.mozilla/Default User/k1m30xaf.slt/search.rdf
70 const NS_APP_MAIL_50_DIR = "MailD"; // /root/.mozilla/Default User/k1m30xaf.slt/Mail
71 const NS_APP_IMAP_MAIL_50_DIR = "IMapMD"; // /root/.mozilla/Default User/k1m30xaf.slt/ImapMail
72 const NS_APP_NEWS_50_DIR = "NewsD"; // /root/.mozilla/Default User/k1m30xaf.slt/News
73 const NS_APP_MESSENGER_FOLDER_CACHE_50_DIR = "MFCaD"; // /root/.mozilla/Default User/k1m30xaf.slt/panacea.dat
75 // Useful OS System Dirs
76 const NS_OS_CURRENT_PROCESS_DIR = "CurProcD"; // /usr/src/mozilla/dist/bin
77 const NS_OS_HOME_DIR = "Home"; // /root
78 const NS_OS_TEMP_DIR = "TmpD"; // /tmp
79 const NS_XPCOM_COMPONENT_DIR = "ComsD"; // /usr/src/mozilla/dist/bin/components
81 const JS_DIRUTILS_FilePath = new C.Constructor(JS_DIRUTILS_FILE_LOCAL_CID,
82 JS_DIRUTILS_FILE_I_LOCAL_FILE,
83 JS_DIRUTILS_INIT_W_PATH);
85 const JS_DIRUTILS_DIR = new C.Constructor(JS_DIRUTILS_FILE_DIR_CID,
86 JS_DIRUTILS_I_PROPS);
88 // constructor
89 function DirUtils(){}
91 DirUtils.prototype = {
93 getPath : function (aAppID) {
95 if(!aAppID) {
96 jslibError(null, "(no arg defined)", "NS_ERROR_INVALID_ARG", JS_FILE_FILE+":getPath");
97 return null;
100 var rv;
102 try {
103 rv=(new JS_DIRUTILS_DIR()).get(aAppID, JS_DIRUTILS_NSIFILE).path;
104 } catch (e) {
105 jslibError(e, "(unexpected error)", "NS_ERROR_FAILURE", JS_DIRUTILS_FILE+":getPath");
106 rv=null;
109 return rv;
112 getPrefsDir : function () { return this.getPath(NS_APP_PREFS_50_DIR); },
113 getChromeDir : function () { return this.getPath(NS_APP_CHROME_DIR); },
114 getMozHomeDir : function () { return this.getPath(NS_APP_USER_PROFILES_ROOT_DIR); },
115 getMozUserHomeDir : function () { return this.getPath(NS_APP_USER_PROFILE_50_DIR); },
116 getAppRegDir : function () { return this.getPath(NS_APP_APPLICATION_REGISTRY_FILE); },
117 getAppDefaultDir : function () { return this.getPath(NS_APP_DEFAULTS_50_DIR); },
118 getAppDefaultPrefDir : function () { return this.getPath(NS_APP_PREF_DEFAULTS_50_DIR); },
119 getProfileDefaultsLocDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_50_DIR); },
120 getProfileDefaultsDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR); },
121 getAppResDir : function () { return this.getPath(NS_APP_RES_DIR); },
122 getAppPluginsDir : function () { return this.getPath(NS_APP_PLUGINS_DIR); },
123 getSearchPluginsDir : function () { return this.getPath(NS_APP_SEARCH_DIR); },
124 getPrefsFile : function () { return this.getPath(NS_APP_PREFS_50_FILE); },
125 getUserChromeDir : function () { return this.getPath(NS_APP_USER_CHROME_DIR); },
126 getLocalStore : function () { return this.getPath(NS_APP_LOCALSTORE_50_FILE); },
127 getHistoryFile : function () { return this.getPath(NS_APP_HISTORY_50_FILE); },
128 getPanelsFile : function () { return this.getPath(NS_APP_USER_PANELS_50_FILE); },
129 getMimeTypes : function () { return this.getPath(NS_APP_USER_MIMETYPES_50_FILE); },
130 getBookmarks : function () { return this.getPath(NS_APP_BOOKMARKS_50_FILE); },
131 getSearchFile : function () { return this.getPath(NS_APP_SEARCH_50_FILE); },
132 getUserMailDir : function () { return this.getPath(NS_APP_MAIL_50_DIR); },
133 getUserImapDir : function () { return this.getPath(NS_APP_IMAP_MAIL_50_DIR); },
134 getUserNewsDir : function () { return this.getPath(NS_APP_NEWS_50_DIR); },
135 getMessengerFolderCache : function () { return this.getPath(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR); },
136 getCurProcDir : function () { return this.getPath(NS_OS_CURRENT_PROCESS_DIR); },
137 getHomeDir : function () { return this.getPath(NS_OS_HOME_DIR); },
138 getTmpDir : function () { return this.getPath(NS_OS_TEMP_DIR); },
139 getComponentsDir : function () { return this.getPath(NS_XPCOM_COMPONENT_DIR); },
141 get help() {
142 const help =
144 "\n\nFunction and Attribute List:\n" +
145 "\n" +
146 " getPrefsDir()\n" +
147 " getChromeDir()\n" +
148 " getMozHomeDir()\n" +
149 " getMozUserHomeDir()\n" +
150 " getAppRegDir()\n" +
151 " getAppDefaultDir()\n" +
152 " getAppDefaultPrefDir()\n" +
153 " getProfileDefaultsLocDir()\n" +
154 " getProfileDefaultsDir()\n" +
155 " getAppResDir()\n" +
156 " getAppPluginsDir()\n" +
157 " getSearchPluginsDir()\n" +
158 " getPrefsFile()\n" +
159 " getUserChromeDir()\n" +
160 " getLocalStore()\n" +
161 " getHistoryFile()\n" +
162 " getPanelsFile()\n" +
163 " getMimeTypes()\n" +
164 " getBookmarks()\n" +
165 " getSearchFile()\n" +
166 " getUserMailDir()\n" +
167 " getUserImapDir()\n" +
168 " getUserNewsDir()\n" +
169 " getMessengerFolderCache()\n\n";
171 return help;
174 }; //END CLASS
176 jslibDebug('*** load: '+JS_DIRUTILS_FILE+' OK');
178 } // END BLOCK JS_LIB_LOADED CHECK
180 else {
181 dump("JSLIB library not loaded:\n" +
182 " \tTo load use: chrome://jslib/content/jslib.js\n" +
183 " \tThen: include(jslib_dirutils);\n\n");