From f8446a1f62e2e608460f386702c77b2fff9c5fc7 Mon Sep 17 00:00:00 2001 From: mitsugu oyama Date: Wed, 29 Jun 2011 12:42:51 +0900 Subject: overwrite the image file? for tinami --- tinami.js | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tinami.js b/tinami.js index 644a9f9..fbf00ff 100644 --- a/tinami.js +++ b/tinami.js @@ -1,6 +1,6 @@ // INFO // var INFO = - @@ -59,17 +59,27 @@ commands.addUserCommand( let cookie=contents.cookie; let xhrImgInfo; let xhrImg; - let savePath=directoryPicker(); - if(savePath.length<1) return; + let saveDirectory=directoryPicker(); + if(saveDirectory.length<1) return; let imgUrl; + let savePath; let trueTinamiImg=function(){ let fileName=imgUrl.substr(imgUrl.lastIndexOf('/')); - savePath=savePath+fileName; + savePath=saveDirectory+fileName; let instream=xhrImg.responseText; let aFile=Cc["@mozilla.org/file/local;1"] .createInstance(Ci.nsILocalFile); aFile.initWithPath(savePath); + if(true===aFile.exists()){ + let value=window.prompt('すでに同じ名前のファイルがあります。\nデフォルトファイル名を変更してください。',fileName.substr(1)); + if(null===value){ + return false; + } + fileName='/'+value; + savePath=saveDirectory+fileName; + aFile.initWithPath(savePath); + } let outstream=Cc["@mozilla.org/network/safe-file-output-stream;1"] .createInstance(Ci.nsIFileOutputStream); outstream.init(aFile,0x02|0x08|0x20,0664,0); -- cgit v1.2.3