修改了一下DownThemAll! 使之下载完成后自动写入descript.ion

dta/manager.js

--- manager.js.orig	2009-10-27 18:16:52.000000000 +0800
+++ manager.js	2009-11-19 15:47:08.000000000 +0800

@@ -1408,6 +1408,13 @@ QueueItem.prototype = {
 			}
 			else {
 				this.tmpFile.clone().moveTo(destination, this.destinationName);
+			        //{{{ write descript.ion
+			        try {
+				    writeDescription(this.destinationPath, this.destinationName, this.urlManager.usable);
+				} catch (x) {
+				}
+			        
 				this.complete();
 			}
 		}

dta/manager.xul

--- manager.xul.orig	2009-10-27 18:16:52.000000000 +0800
+++ manager.xul	2009-11-17 18:24:28.000000000 +0800
@@ -70,6 +70,7 @@
 	<popupset>
 		<popup id="popup" onpopupshowing="Tree.refreshTools(); return true;">
 			<menuitem id="info" class="menuitem-iconic" label="&infos.label;" oncommand="Tree.showInfo();" />
+			<menuitem id="writeInfo" class="menuitem-iconic" label="write info to descript.ion" oncommand="Tree.writeInfo();" />
 			<menuseparator />
 			<menuitem id="launch" class="menuitem-iconic" label="&launch.label;" oncommand="FileHandling.openFile();" />
 			<menuitem id="delete" class="menuitem-iconic" label="&delete.label;" oncommand="FileHandling.deleteFile();" /> 

dta/manager/tree.js

--- manager/tree.js.orig	2009-10-27 18:16:52.000000000 +0800
+++ manager/tree.js	2009-11-19 15:45:24.000000000 +0800
@@ -463,6 +463,17 @@ var Tree = {
 		}
 		this.endUpdate();
 	},
+	writeInfo: function () {
+	    this.beginUpdate();
+
+	    for (let d in Tree.selected) {
+		var dir=d.destinationPath;
+		var filename=d.destinationName;
+		var url = d.urlManager.usable;
+	        writeDescription(dir, filename, url);
+	    }
+	    this.endUpdate();
+	},
 	_hoverItem: null,
 	_ww: Serv('@mozilla.org/embedcomp/window-watcher;1', 'nsIWindowWatcher'),
 	hovering: function(event) {

common/internalFunctions.js

var writeDescription = function () {
    var UNICODE =Components.classes['@mozilla.org/intl/scriptableunicodeconverter'].getService(Components.interfaces.nsIScriptableUnicodeConverter); 
    UNICODE.charset = 'UTF-8';

    		//check downloaded file existence
		var downloadedFile = new FileFactory(dir);
		if (!downloadedFile.exists() )
			return;
		downloadedFile.append(filename);
		if (!downloadedFile.exists() )
			return;

		//open descript.ion
		var descFile = new FileFactory(dir);
		descFile.append("descript.ion");
		if (!descFile.exists()) {
			descFile.create(descFile.NORMAL_FILE_TYPE, 0666);
		}

		//write info
		var aContent = "\"" + filename + "\"\t" + url + "\n";
		aContent  = UNICODE.ConvertFromUnicode(aContent);
		var ostream = Components.classes['@mozilla.org/network/file-output-stream;1'].createInstance(Components.interfaces.nsIFileOutputStream);
		//init ( nsIFile file , PRInt32 ioFlags , PRInt32 perm , PRInt32 behaviorFlags )
		const PR_WRONLY = 2;
		const PR_APPEND = 16; 
		ostream.init(descFile, 0x02|0x08|0x10, 0x200, false);

		//const NS_SEEK_END = 2;
		//ostream.seek(NS_SEEK_END, 0);
		ostream.write(aContent, aContent.length);

		aContent = UNICODE.Finish();
		if (aContent.length > 0) ostream.write(aContent, aContent.length);
		ostream.close();
	} //end of writeDescription_impl

     return writeDescription_impl;
}();

猜你喜欢

转载自yangguilong.iteye.com/blog/551791