diff --git a/calendar/resources/content/jslib/io/dir.js b/calendar/resources/content/jslib/io/dir.js index 242d7626611..d8d30ecae08 100644 --- a/calendar/resources/content/jslib/io/dir.js +++ b/calendar/resources/content/jslib/io/dir.js @@ -40,17 +40,15 @@ Instructions: */ -if(typeof(JS_LIB_LOADED)=='boolean') -{ +if (typeof(JS_LIB_LOADED)=='boolean') { /************* INCLUDE FILESYSTEM *****************/ if(typeof(JS_FILESYSTEM_LOADED)!='boolean') - include(JS_LIB_PATH+'io/filesystem.js'); + include(jslib_filesystem); /************* INCLUDE FILESYSTEM *****************/ /****************** Globals **********************/ - const JS_DIR_FILE = "dir.js"; const JS_DIR_LOADED = true; @@ -68,70 +66,62 @@ const JS_DIR_OK = true; const JS_DIR_DEFAULT_PERMS = 0755; -const JS_DIR_FilePath = new Components.Constructor( JS_DIR_LOCAL_CID, JS_DIR_I_LOCAL_FILE, JS_DIR_INIT_W_PATH); - +const JS_DIR_FilePath = new C.Constructor(JS_DIR_LOCAL_CID, + JS_DIR_I_LOCAL_FILE, + JS_DIR_INIT_W_PATH); +/****************** Globals **********************/ /****************** Dir Object Class *********************/ +// constructor function Dir(aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "Please enter a local file path to initialize", "NS_ERROR_XPC_NOT_ENOUGH_ARGS", JS_DIR_FILE); - throw Components.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; + throw C.results.NS_ERROR_XPC_NOT_ENOUGH_ARGS; } - return this.initPath(arguments); - -} // constructor + return this.initPath(arguments); +} // end constructor Dir.prototype = new FileSystem; - Dir.prototype.fileInst = null; /********************* CREATE ****************************/ Dir.prototype.create = function(aPermissions) { - if(!this.mPath) - { + if(!this.mPath) { jslibError(null, "create (no file path defined)", "NS_ERROR_NOT_INITIALIZED"); - return Components.results.NS_ERROR_NOT_INITIALIZED; + return C.results.NS_ERROR_NOT_INITIALIZED; } - if(this.exists()) - { + if(this.exists()) { jslibError(null, "(Dir already exists", "NS_ERROR_FAILURE", JS_DIR_FILE+":create"); return null; } - if(aPermissions){ + if(aPermissions) { var checkPerms = this.validatePermissions(aPermissions); - if(!checkPerms) - { - jslibError(null, "create (invalid permissions)", "NS_ERROR_INVALID_ARG", JS_DIR_FILE+":create"); - return Components.results.NS_ERROR_INVALID_ARG; + if(!checkPerms) { + jslibError(null, "create (invalid permissions)", + "NS_ERROR_INVALID_ARG", JS_DIR_FILE+":create"); + return C.results.NS_ERROR_INVALID_ARG; } //var baseTen = permissions.toString(10); - //if(baseTen.substring(0,1) != 0) //aPermissions = 0+baseTen; - } - else - { + } else { checkPerms = JS_DIR_DEFAULT_PERMS; } var rv = null; - try - { + try { rv=this.mFileInst.create(JS_DIR_DIRECTORY, parseInt(aPermissions) ); - } - catch (e) - { + } catch (e) { jslibError(e, "(unable to create)", "NS_ERROR_FAILURE", JS_DIR_FILE+":create"); rv=null; } @@ -143,18 +133,15 @@ Dir.prototype.create = function(aPermissions) Dir.prototype.readDir = function () { - if(!this.exists()) - { + if(!this.exists()) { jslibError(null, "(Dir already exists", "NS_ERROR_FAILURE", JS_DIR_FILE+":readDir"); return null; } var rv=null; - try - { - if(!this.isDir()) - { + try { + if(!this.isDir()) { jslibError(null, "(file is not a directory)", "NS_ERROR_FAILURE", JS_DIR_FILE+":readDir"); return null; } @@ -166,9 +153,8 @@ Dir.prototype.readDir = function () if(typeof(JS_FILE_LOADED)!='boolean') include(JS_LIB_PATH+'io/file.js'); - while(files.hasMoreElements()) - { - file = files.getNext().QueryInterface(Components.interfaces.nsILocalFile); + while(files.hasMoreElements()) { + file = files.getNext().QueryInterface(C.interfaces.nsILocalFile); if(file.isFile()) listings.push(new File(file.path)); @@ -177,10 +163,7 @@ Dir.prototype.readDir = function () } rv=listings; - } - - catch(e) - { + } catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILE_FILE+":readDir"); rv=null; } @@ -196,34 +179,30 @@ Dir.prototype.remove = function (aRecursive) aRecursive=false; if(!this.checkInst()) - throw Components.results.NS_ERROR_NOT_INITIALIZED; + throw C.results.NS_ERROR_NOT_INITIALIZED; if(!this.mPath) { - jslibError(null, "remove (no path defined)", "NS_ERROR_INVALID_ARG", JS_DIR_FILE+":remove"); + jslibError(null, "remove (no path defined)", + "NS_ERROR_INVALID_ARG", JS_DIR_FILE+":remove"); return null; } var rv=null - try - { - if(!this.exists()) - { + try { + if(!this.exists()) { jslibError(null, "(directory doesn't exist)", "NS_ERROR_FAILURE", JS_DIR_FILE+":remove"); return null; } - if(!this.isDir()) - { + if(!this.isDir()) { jslibError(null, "(file is not a directory)", "NS_ERROR_FAILURE", JS_DIR_FILE+":remove"); return null; } rv=this.mFileInst.remove(aRecursive); - } - catch (e) - { + } catch (e) { jslibError(e, "(dir not empty, use 'remove(true)' for recursion)", "NS_ERROR_UNEXPECTED", JS_DIR_FILE+":remove"); rv=null; @@ -236,8 +215,7 @@ Dir.prototype.remove = function (aRecursive) Dir.prototype.super_help = FileSystem.prototype.help; Dir.prototype.__defineGetter__('help', -function() -{ +function() { var help = this.super_help() + " create(aPermissions);\n" + @@ -247,14 +225,11 @@ function() return help; }); -jslib_debug('*** load: '+JS_DIR_FILE+' OK'); +jslibDebug('*** load: '+JS_DIR_FILE+' OK'); -} - -else -{ +} else { dump("JSLIB library not loaded:\n" + " \tTo load use: chrome://jslib/content/jslib.js\n" + - " \tThen: include('chrome://jslib/content/io/dir.js');\n\n"); + " \tThen: include(jslib_dir);\n\n"); } diff --git a/calendar/resources/content/jslib/io/dirUtils.js b/calendar/resources/content/jslib/io/dirUtils.js index 5aedc69436c..081e35a0e6c 100644 --- a/calendar/resources/content/jslib/io/dirUtils.js +++ b/calendar/resources/content/jslib/io/dirUtils.js @@ -32,134 +32,103 @@ Instructions: */ -if(typeof(JS_LIB_LOADED)=='boolean') -{ +if(typeof(JS_LIB_LOADED)=='boolean') { -const JS_DIRUTILS_FILE = "dirUtils.js"; -const JS_DIRUTILS_LOADED = true; +const JS_DIRUTILS_FILE = "dirUtils.js"; +const JS_DIRUTILS_LOADED = true; -const JS_DIRUTILS_FILE_LOCAL_CID = "@mozilla.org/file/local;1"; -const JS_DIRUTILS_FILE_DIR_CID = "@mozilla.org/file/directory_service;1"; +const JS_DIRUTILS_FILE_LOCAL_CID = "@mozilla.org/file/local;1"; +const JS_DIRUTILS_FILE_DIR_CID = "@mozilla.org/file/directory_service;1"; -const JS_DIRUTILS_FILE_I_LOCAL_FILE = "nsILocalFile"; -const JS_DIRUTILS_INIT_W_PATH = "initWithPath"; -const JS_DIRUTILS_I_PROPS = "nsIProperties"; +const JS_DIRUTILS_FILE_I_LOCAL_FILE = "nsILocalFile"; +const JS_DIRUTILS_INIT_W_PATH = "initWithPath"; +const JS_DIRUTILS_I_PROPS = "nsIProperties"; +const JS_DIRUTILS_NSIFILE = C.interfaces.nsIFile; -const JS_DIRUTILS_NSIFILE = Components.interfaces.nsIFile; +const NS_APP_PREFS_50_DIR = "PrefD"; // /root/.mozilla/Default User/k1m30xaf.slt +const NS_APP_CHROME_DIR = "AChrom"; // /usr/src/mozilla/dist/bin/chrome +const NS_APP_USER_PROFILES_ROOT_DIR = "DefProfRt"; // /root/.mozilla +const NS_APP_USER_PROFILE_50_DIR = "ProfD"; // /root/.mozilla/Default User/k1m30xaf.slt -const NS_APP_PREFS_50_DIR = "PrefD"; // /root/.mozilla/Default User/k1m30xaf.slt -const NS_APP_CHROME_DIR = "AChrom"; // /usr/src/mozilla/dist/bin/chrome -const NS_APP_USER_PROFILES_ROOT_DIR = "DefProfRt"; // /root/.mozilla -const NS_APP_USER_PROFILE_50_DIR = "ProfD"; // /root/.mozilla/Default User/k1m30xaf.slt -const NS_APP_APPLICATION_REGISTRY_DIR = "AppRegD"; // /root/.mozilla -const NS_APP_APPLICATION_REGISTRY_FILE = "AppRegF"; // /root/.mozilla/appreg -const NS_APP_DEFAULTS_50_DIR = "DefRt"; // /usr/src/mozilla/dist/bin/defaults -const NS_APP_PREF_DEFAULTS_50_DIR = "PrfDef"; // /usr/src/mozilla/dist/bin/defaults/pref -const NS_APP_PROFILE_DEFAULTS_50_DIR = "profDef"; // /usr/src/mozilla/dist/bin/defaults/profile/US -const NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR = "ProfDefNoLoc";// /usr/src/mozilla/dist/bin/defaults/profile -const NS_APP_RES_DIR = "ARes"; // /usr/src/mozilla/dist/bin/res -const NS_APP_PLUGINS_DIR = "APlugns"; // /usr/src/mozilla/dist/bin/plugins -const NS_APP_SEARCH_DIR = "SrchPlugns"; // /usr/src/mozilla/dist/bin/searchplugins -const NS_APP_PREFS_50_FILE = "PrefF"; // /root/.mozilla/Default User/k1m30xaf.slt/prefs.js -const NS_APP_USER_CHROME_DIR = "UChrm"; // /root/.mozilla/Default User/k1m30xaf.slt/chrome -const NS_APP_LOCALSTORE_50_FILE = "LclSt"; // /root/.mozilla/Default User/k1m30xaf.slt/localstore.rdf -const NS_APP_HISTORY_50_FILE = "UHist"; // /root/.mozilla/Default User/k1m30xaf.slt/history.dat -const NS_APP_USER_PANELS_50_FILE = "UPnls"; // /root/.mozilla/Default User/k1m30xaf.slt/panels.rdf -const NS_APP_USER_MIMETYPES_50_FILE = "UMimTyp"; // /root/.mozilla/Default User/k1m30xaf.slt/mimeTypes.rdf -const NS_APP_BOOKMARKS_50_FILE = "BMarks"; // /root/.mozilla/Default User/k1m30xaf.slt/bookmarks.html -const NS_APP_SEARCH_50_FILE = "SrchF"; // /root/.mozilla/Default User/k1m30xaf.slt/search.rdf -const NS_APP_MAIL_50_DIR = "MailD"; // /root/.mozilla/Default User/k1m30xaf.slt/Mail -const NS_APP_IMAP_MAIL_50_DIR = "IMapMD"; // /root/.mozilla/Default User/k1m30xaf.slt/ImapMail -const NS_APP_NEWS_50_DIR = "NewsD"; // /root/.mozilla/Default User/k1m30xaf.slt/News -const NS_APP_MESSENGER_FOLDER_CACHE_50_DIR = "MFCaD"; // /root/.mozilla/Default User/k1m30xaf.slt/panacea.dat +const NS_APP_APPLICATION_REGISTRY_DIR = "AppRegD"; // /root/.mozilla +const NS_APP_APPLICATION_REGISTRY_FILE = "AppRegF"; // /root/.mozilla/appreg +const NS_APP_DEFAULTS_50_DIR = "DefRt"; // /usr/src/mozilla/dist/bin/defaults +const NS_APP_PREF_DEFAULTS_50_DIR = "PrfDef"; // /usr/src/mozilla/dist/bin/defaults/pref +const NS_APP_PROFILE_DEFAULTS_50_DIR = "profDef"; // /usr/src/mozilla/dist/bin/defaults/profile/US +const NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR = "ProfDefNoLoc"; // /usr/src/mozilla/dist/bin/defaults/profile +const NS_APP_RES_DIR = "ARes"; // /usr/src/mozilla/dist/bin/res +const NS_APP_PLUGINS_DIR = "APlugns"; // /usr/src/mozilla/dist/bin/plugins +const NS_APP_SEARCH_DIR = "SrchPlugns"; // /usr/src/mozilla/dist/bin/searchplugins +const NS_APP_PREFS_50_FILE = "PrefF"; // /root/.mozilla/Default User/k1m30xaf.slt/prefs.js +const NS_APP_USER_CHROME_DIR = "UChrm"; // /root/.mozilla/Default User/k1m30xaf.slt/chrome +const NS_APP_LOCALSTORE_50_FILE = "LclSt"; // /root/.mozilla/Default User/k1m30xaf.slt/localstore.rdf +const NS_APP_HISTORY_50_FILE = "UHist"; // /root/.mozilla/Default User/k1m30xaf.slt/history.dat +const NS_APP_USER_PANELS_50_FILE = "UPnls"; // /root/.mozilla/Default User/k1m30xaf.slt/panels.rdf +const NS_APP_USER_MIMETYPES_50_FILE = "UMimTyp"; // /root/.mozilla/Default User/k1m30xaf.slt/mimeTypes.rdf +const NS_APP_BOOKMARKS_50_FILE = "BMarks"; // /root/.mozilla/Default User/k1m30xaf.slt/bookmarks.html +const NS_APP_SEARCH_50_FILE = "SrchF"; // /root/.mozilla/Default User/k1m30xaf.slt/search.rdf +const NS_APP_MAIL_50_DIR = "MailD"; // /root/.mozilla/Default User/k1m30xaf.slt/Mail +const NS_APP_IMAP_MAIL_50_DIR = "IMapMD"; // /root/.mozilla/Default User/k1m30xaf.slt/ImapMail +const NS_APP_NEWS_50_DIR = "NewsD"; // /root/.mozilla/Default User/k1m30xaf.slt/News +const NS_APP_MESSENGER_FOLDER_CACHE_50_DIR = "MFCaD"; // /root/.mozilla/Default User/k1m30xaf.slt/panacea.dat -const JS_DIRUTILS_FilePath = new Components.Constructor( - JS_DIRUTILS_FILE_LOCAL_CID, +const JS_DIRUTILS_FilePath = new C.Constructor(JS_DIRUTILS_FILE_LOCAL_CID, JS_DIRUTILS_FILE_I_LOCAL_FILE, JS_DIRUTILS_INIT_W_PATH); -const JS_DIRUTILS_DIR = new Components.Constructor( - JS_DIRUTILS_FILE_DIR_CID, +const JS_DIRUTILS_DIR = new C.Constructor(JS_DIRUTILS_FILE_DIR_CID, JS_DIRUTILS_I_PROPS); // constructor function DirUtils(){} -DirUtils.prototype = -{ +DirUtils.prototype = { getPath : function (aAppID) { - if(!aAppID) - { + if(!aAppID) { jslibError(null, "(no arg defined)", "NS_ERROR_INVALID_ARG", JS_FILE_FILE+":getPath"); return null; } var rv; - try { rv=(new JS_DIRUTILS_DIR()).get(aAppID, JS_DIRUTILS_NSIFILE).path; } - - catch (e) - { + try { + rv=(new JS_DIRUTILS_DIR()).get(aAppID, JS_DIRUTILS_NSIFILE).path; + } catch (e) { jslibError(e, "(unexpected error)", "NS_ERROR_FAILURE", JS_DIRUTILS_FILE+":getPath"); rv=null; } return rv; - }, getPrefsDir : function () { return this.getPath(NS_APP_PREFS_50_DIR); }, - getChromeDir : function () { return this.getPath(NS_APP_CHROME_DIR); }, - getMozHomeDir : function () { return this.getPath(NS_APP_USER_PROFILES_ROOT_DIR); }, - getMozUserHomeDir : function () { return this.getPath(NS_APP_USER_PROFILE_50_DIR); }, - getAppRegDir : function () { return this.getPath(NS_APP_APPLICATION_REGISTRY_FILE); }, - getAppDefaultDir : function () { return this.getPath(NS_APP_DEFAULTS_50_DIR); }, - getAppDefaultPrefDir : function () { return this.getPath(NS_APP_PREF_DEFAULTS_50_DIR); }, - getProfileDefaultsLocDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_50_DIR); }, - getProfileDefaultsDir : function () { return this.getPath(NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR); }, - getAppResDir : function () { return this.getPath(NS_APP_RES_DIR); }, - getAppPluginsDir : function () { return this.getPath(NS_APP_PLUGINS_DIR); }, - getSearchPluginsDir : function () { return this.getPath(NS_APP_SEARCH_DIR); }, - getPrefsFile : function () { return this.getPath(NS_APP_PREFS_50_FILE); }, - getUserChromeDir : function () { return this.getPath(NS_APP_USER_CHROME_DIR); }, - getLocalStore : function () { return this.getPath(NS_APP_LOCALSTORE_50_FILE); }, - getHistoryFile : function () { return this.getPath(NS_APP_HISTORY_50_FILE); }, - getPanelsFile : function () { return this.getPath(NS_APP_USER_PANELS_50_FILE); }, - getMimeTypes : function () { return this.getPath(NS_APP_USER_MIMETYPES_50_FILE); }, - getBookmarks : function () { return this.getPath(NS_APP_BOOKMARKS_50_FILE); }, - getSearchFile : function () { return this.getPath(NS_APP_SEARCH_50_FILE); }, - getUserMailDir : function () { return this.getPath(NS_APP_MAIL_50_DIR); }, - getUserImapDir : function () { return this.getPath(NS_APP_IMAP_MAIL_50_DIR); }, - getUserNewsDir : function () { return this.getPath(NS_APP_NEWS_50_DIR); }, - getMessengerFolderCache : function () { return this.getPath(NS_APP_MESSENGER_FOLDER_CACHE_50_DIR); }, -get help(){ - +get help() { const help = "\n\nFunction and Attribute List:\n" + @@ -190,18 +159,17 @@ get help(){ " getMessengerFolderCache()\n\n"; return help; - } + }; //END CLASS -jslib_debug('*** load: '+JS_DIRUTILS_FILE+' OK'); +jslibDebug('*** load: '+JS_DIRUTILS_FILE+' OK'); } // END BLOCK JS_LIB_LOADED CHECK -else -{ +else { dump("JSLIB library not loaded:\n" + " \tTo load use: chrome://jslib/content/jslib.js\n" + - " \tThen: include('chrome://jslib/content/io/dirUtils.js');\n\n"); + " \tThen: include(jslib_dirutils);\n\n"); } diff --git a/calendar/resources/content/jslib/io/file.js b/calendar/resources/content/jslib/io/file.js index 5b6e5ac5ad6..d095757c480 100644 --- a/calendar/resources/content/jslib/io/file.js +++ b/calendar/resources/content/jslib/io/file.js @@ -152,10 +152,9 @@ const JS_FILE_DEFAULT_PERMS = 0644; const JS_FILE_OK = true; try { - /* const JS_FILE_FileChannel = new C.Constructor (JS_FILE_F_CHANNEL_CID, JS_FILE_I_FILE_CHANNEL); - */ + const JS_FILE_InputStream = new C.Constructor (JS_FILE_I_STREAM_CID, JS_FILE_I_SCRIPTABLE_IN_STREAM); @@ -166,12 +165,10 @@ try { * The File Transport Service provides nsITransport objects * which can supply nsIOutputStream objects for writing to files. */ - - /* const JS_FILE_FileTransportService = C.classes[JS_FILE_F_TRANSPORT_SERVICE_CID]. getService(C.interfaces.nsIFileTransportService); - */ + } catch (e) { jslibError (e, "open("+this.mMode+") (unable to get nsIFileChannel)", "NS_ERROR_FAILURE", @@ -384,6 +381,7 @@ File.prototype.open = function(aMode, aPerms) this.mLineBuffer = new Array(); this.mFileChannel.init(this.mFileInst, JS_FILE_READ, this.permissions); this.mInputStream.init(this.mFileChannel.open()); + this.mLineBuffer = new Array(); rv=true; } catch (e) { jslibError(e, "open(r) (error setting permissions)", diff --git a/calendar/resources/content/jslib/io/fileUtils.js b/calendar/resources/content/jslib/io/fileUtils.js index 26d9ef31fde..ac9fabda071 100644 --- a/calendar/resources/content/jslib/io/fileUtils.js +++ b/calendar/resources/content/jslib/io/fileUtils.js @@ -119,13 +119,12 @@ FileUtils.prototype = { mFileInst : null, /********************* CHROME_TO_PATH ***************************/ -// this is here for backward compatability but is depreciated --pete +// this is here for backward compatability but is deprecated --pete chrome_to_path : function (aPath) { return this.chromeToPath(aPath); }, chromeToPath : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":chromeToPath"); return null; } @@ -133,46 +132,32 @@ chromeToPath : function (aPath) var uri = C.classes[JS_FILEUTILS_SIMPLEURI_PROGID].createInstance(JS_FILEUTILS_I_URI); var path; - if(aPath.search(/^chrome:/) == 0) - { - try - { + if(aPath.search(/^chrome:/) == 0) { + try { var cr = C.classes[JS_FILEUTILS_CHROME_REG_PROGID].getService(); - if (cr) - { + if (cr) { cr = cr.QueryInterface(C.interfaces.nsIChromeRegistry); uri.spec = aPath; uri.spec = cr.convertChromeURL(uri); path = uri.path; } - } - - catch(e) {} + } catch(e) {} var rv; - try - { + try { var dir = new C.Constructor(JS_FILEUTILS_DR_PROGID, JS_FILEUTILS_I_PROPS); rv = (new dir()).get(JS_FILEUTILS_CHROME_DIR, C.interfaces.nsIFile).path; rv = path.replace(/\/chrome/, rv); - } - - catch (e) - { + } catch (e) { jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":chromeToPath"); rv = null; } - } - else - if(aPath.search(/^file:/) == 0) - { + else if(aPath.search(/^file:/) == 0) { rv=this.urlToPath(aPath); - } - - else + } else rv=null; return rv; @@ -183,24 +168,18 @@ URL_to_path : function (aPath){ return this.urlToPath(aPath); }, urlToPath : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":urlToPath"); return null; } var rv; - if(aPath.search(/^file:/) == 0) - { - try - { + if(aPath.search(/^file:/) == 0) { + try { var uri = C.classes[JS_FILEUTILS_NETWORK_STD_CID].createInstance(JS_FILEUTILS_I_FILEURL); uri.spec = aPath; rv = uri.file.path; - } - - catch (e) - { + } catch (e) { jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":urlToPath"); rv=null; } @@ -212,20 +191,16 @@ urlToPath : function (aPath) /********************* EXISTS ***************************/ exists : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":exists"); return null; } var rv; - try - { + try { var file = new JS_FILEUTILS_FilePath(aPath); rv=file.exists(); - } - catch(e) - { + } catch(e) { jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":exists"); rv=null; } @@ -238,34 +213,28 @@ rm : function (aPath) { return this.remove(aPath); }, remove : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":remove"); return null; } var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aPath); - if(fileInst.isDirectory()) - { + if(fileInst.isDirectory()) { jslibError(null, "path is a dir. use rmdir()", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":remove"); return null; } fileInst.remove(false); rv = C.results.NS_OK; - } - catch (e) - { + } catch (e) { jslibError(e, "(unexpected)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":urlToPath"); rv=null; } @@ -276,63 +245,51 @@ remove : function (aPath) /********************* COPY *****************************/ copy : function (aSource, aDest) { - if(!aSource || !aDest) - { + if(!aSource || !aDest) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":copy"); return null; } - if(!this.exists(aSource)) - { + if(!this.exists(aSource)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":copy"); return null; } var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aSource); var dir = new JS_FILEUTILS_FilePath(aDest); var copyName = fileInst.leafName; - if(fileInst.isDirectory()) - { + if(fileInst.isDirectory()) { jslibError(null, "(cannot copy directory)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy"); return null; } - if(!this.exists(aDest) || !dir.isDirectory()) - { + if(!this.exists(aDest) || !dir.isDirectory()) { copyName = dir.leafName; dir = new JS_FILEUTILS_FilePath(dir.path.replace(copyName,'')); - if(!this.exists(dir.path)) - { + if(!this.exists(dir.path)) { jslibError(null, "(dest "+dir.path+" doesn't exist)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy"); return null; } - if(!dir.isDirectory()) - { + if(!dir.isDirectory()) { jslibError(null, "(dest "+dir.path+" is not a valid path)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy"); return null; } } - if(this.exists(this.append(dir.path, copyName))) - { + if(this.exists(this.append(dir.path, copyName))) { jslibError(null, "(dest "+this.append(dir.path, copyName)+" already exists)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":copy"); return null; } rv=fileInst.copyTo(dir, copyName); - rv = C.results.NS_OK; - } - - catch (e) - { + } catch (e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":copy"); rv=null; } @@ -343,28 +300,24 @@ copy : function (aSource, aDest) /********************* LEAF *****************************/ leaf : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":leaf"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":leaf"); return null; } var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aPath); rv=fileInst.leafName; } - catch(e) - { + catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":leaf"); rv=null; } @@ -375,25 +328,21 @@ leaf : function (aPath) /********************* APPEND ***************************/ append : function (aDirPath, aFileName) { - if(!aDirPath || !aFileName) - { + if(!aDirPath || !aFileName) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append"); return null; } - if(!this.exists(aDirPath)) - { + if(!this.exists(aDirPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":append"); return null; } var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aDirPath); - if(fileInst.exists() && !fileInst.isDirectory()) - { + if(fileInst.exists() && !fileInst.isDirectory()) { jslibError(null, aDirPath+" is not a dir", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":append"); return null; } @@ -401,10 +350,7 @@ append : function (aDirPath, aFileName) fileInst.append(aFileName); rv=fileInst.path; delete fileInst; - } - - catch(e) - { + } catch(e) { jslibError(e?e:null, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":append"); rv=null; } @@ -424,27 +370,21 @@ validatePermissions : function(aNum) /********************* PERMISSIONS **********************/ permissions : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":permissions"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":permissions"); return null; } var rv; - try - { + try { rv=(new JS_FILEUTILS_FilePath(aPath)).permissions.toString(8); - } - - catch(e) - { + } catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":permissions"); rv=null; } @@ -455,28 +395,22 @@ permissions : function (aPath) /********************* MODIFIED *************************/ dateModified : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":dateModified"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":dateModified"); return null; } var rv; - try - { + try { var date = new Date((new JS_FILEUTILS_FilePath(aPath)).lastModificationDate).toLocaleString(); rv=date; - } - - catch(e) - { + } catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":dateModified"); rv=null; } @@ -487,27 +421,21 @@ dateModified : function (aPath) /********************* SIZE *****************************/ size : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":size"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":size"); return null; } var rv; - try - { + try { rv = (new JS_FILEUTILS_FilePath(aPath)).fileSize; - } - - catch(e) - { + } catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":size"); rv=0; } @@ -520,29 +448,23 @@ extension : function (aPath){ return this.ext(aPath); }, ext : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":ext"); return null; } - if(!this.exists(aPath)) - { + if(!this.exists(aPath)) { jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":ext"); return null; } var rv; - try - { + try { var leafName = (new JS_FILEUTILS_FilePath(aPath)).leafName; var dotIndex = leafName.lastIndexOf('.'); rv=(dotIndex >= 0) ? leafName.substring(dotIndex+1) : ""; - } - - catch(e) - { + } catch(e) { jslibError(e, "(unexpected error)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":ext"); rv=null; } @@ -555,20 +477,17 @@ dirPath : function (aPath){ return this.parent(aPath); }, parent : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":parent"); return null; } var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aPath); - if(!fileInst.exists()) - { + if(!fileInst.exists()) { jslibError(null, "(file doesn't exist)", "NS_ERROR_FAILURE", JS_FILEUTILS_FILE+":parent"); return null; } @@ -576,16 +495,14 @@ parent : function (aPath) if(fileInst.isFile()) rv=fileInst.parent.path; - else - if(fileInst.isDirectory()) - rv=fileInst.path; + else if(fileInst.isDirectory()) + rv=fileInst.path; - else - rv=null; + else + rv=null; } - catch (e) - { + catch (e) { jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":parent"); rv=null; } @@ -594,6 +511,7 @@ parent : function (aPath) }, /********************* SPAWN ****************************/ +run : function (aPath, aArgs) { this.spawn(aPath, aArgs); }, spawn : function (aPath, aArgs) /* * Trys to execute the requested file as a separate *non-blocking* process. @@ -603,15 +521,15 @@ spawn : function (aPath, aArgs) * */ { - if(!aPath) - { - jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":spawn"); + if(!aPath) { + jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", + JS_FILEUTILS_FILE+":spawn"); return null; } - if(!this.exists(aPath)) - { - jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":spawn"); + if(!this.exists(aPath)) { + jslibError(null, "(file doesn't exist)", "NS_ERROR_UNEXPECTED", + JS_FILEUTILS_FILE+":spawn"); return null; } @@ -619,30 +537,25 @@ spawn : function (aPath, aArgs) if(aArgs) len = aArgs.length; - else aArgs=null; var rv; - try - { + try { var fileInst = new JS_FILEUTILS_FilePath(aPath); - if(!fileInst.isExecutable()) - { - jslibError(null, "(File is not executable)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":spawn"); + if(!fileInst.isExecutable()) { + jslibError(null, "(File is not executable)", "NS_ERROR_INVALID_ARG", + JS_FILEUTILS_FILE+":spawn"); return null; } - if(fileInst.isDirectory()) - { - jslibError(null, "(File is not a program)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":spawn"); + if(fileInst.isDirectory()) { + jslibError(null, "(File is not a program)", "NS_ERROR_UNEXPECTED", + JS_FILEUTILS_FILE+":spawn"); return null; - } - - else - { + } else { // Create and execute the process... /* * NOTE: The first argument of the process instance's 'run' method @@ -651,25 +564,23 @@ spawn : function (aPath, aArgs) * on return if a variable is supplied--not sure how to implement * this with JavaScript though. */ - try - { - var theProcess = C.classes[JS_FILEUTILS_PROCESS_CID].createInstance(JS_FILEUTILS_I_PROCESS); + try { + var theProcess = C.classes[JS_FILEUTILS_PROCESS_CID]. + createInstance(JS_FILEUTILS_I_PROCESS); theProcess.init(fileInst); - return theProcess.run(false, aArgs, len, {}); - } - catch (e) - { - jslibError(e, "(problem spawing process)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":spawn"); + rv = theProcess.run(false, aArgs, len); + jslib_debug("rv="+rv); + } catch (e) { + jslibError(e, "(problem spawing process)", "NS_ERROR_UNEXPECTED", + JS_FILEUTILS_FILE+":spawn"); rv=null; } } - } - - catch (e) - { - jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":spawn"); + } catch (e) { + jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", + JS_FILEUTILS_FILE+":spawn"); rv=null; } @@ -679,23 +590,18 @@ spawn : function (aPath, aArgs) /********************* nsIFILE **************************/ nsIFile : function (aPath) { - if(!aPath) - { + if(!aPath) { jslibError(null, "(no path defined)", "NS_ERROR_INVALID_ARG", JS_FILEUTILS_FILE+":nsIFile"); return null; } var rv; - try - { + try { rv = new JS_FILEUTILS_FilePath(aPath); - } - - catch (e) - { + } catch (e) { jslibError(e, "(problem getting file instance)", "NS_ERROR_UNEXPECTED", JS_FILEUTILS_FILE+":nsIFile"); - rv=null; + rv = null; } return rv; @@ -720,12 +626,11 @@ get help() " size(aPath);\n" + " ext(aPath);\n" + " parent(aPath);\n" + - " spawn(aPath, aArgs);\n" + + " run(aPath, aArgs);\n" + " nsIFile(aPath);\n" + " help;\n"; return help; - } }; diff --git a/calendar/resources/content/jslib/io/filesystem.js b/calendar/resources/content/jslib/io/filesystem.js index fe5d947ae0a..dbfb78a9b79 100644 --- a/calendar/resources/content/jslib/io/filesystem.js +++ b/calendar/resources/content/jslib/io/filesystem.js @@ -78,15 +78,13 @@ FileSystem.prototype = { ***************************/ initPath : function(args) { - var fileURL; - var i; // check if the argument is a file:// url if(typeof(args)=='object') { - for (i=0; i\n" + "\tMartin.T.Kutschker \n"; const JS_LIB_BUILD = "0.9.5"; @@ -68,6 +68,23 @@ const JS_LIB_HELP = "\n\nWelcome to jslib version "+JS_LIB_VERSION+"\n\n" + "Global Variables:\n\n" + " JS_LIB_DEBUG\n JS_LIB_ERROR\n\n"; +// help identifier +const jslib_help = "need to write some global help docs here\n"; + +// Library Identifiers + +// io library modules +const jslib_io = JS_LIB_PATH+'io/io.js'; +const jslib_filesystem = JS_LIB_PATH+'io/filesystem.js' +const jslib_file = JS_LIB_PATH+'io/file.js'; +const jslib_fileutils = JS_LIB_PATH+'io/fileUtils.js'; +const jslib_dir = JS_LIB_PATH+'io/dir.js'; +const jslib_dirutils = JS_LIB_PATH+'io/dirUtils.js'; + +// sound library modules +const jslib_sound = JS_LIB_PATH+'sound/sound.js'; + + /*************************** GLOBALS ***************************/ /**************************************************************** @@ -122,7 +139,7 @@ function include(aScriptPath) { } /**************************************************************** -* void jslibDdebug(aOutString) * +* void jslibDebug(aOutString) * * aOutString is an argument of string debug message * * returns void * * Ex: * @@ -184,6 +201,7 @@ function jslibError(e, aType, aResults, aCaller) { return (dump("JS_LIB_ERROR=ON\n")); var errMsg="ERROR: "+(aCaller?"in "+aCaller:"")+" "+aType+"\n"; + var e = null; if (e) { var m = (e.message?e.message:e); var r = (typeof(e.result)!='undefined'?'0x'+e.result.toString(16):'');