|
阅读:3440回复:2
关于插件对文件存储的问题-怎样直接保存文件到桌面
我想问的是,火狐捷径的网页截屏功能,截取的图片地址能否修改为保存到桌面?
这个插件中原始的保存路径是TmpD,也就是用户的temp文件夹。 我根据mozilla官方的file I/O介绍进行修改(https://developer.mozilla.org/index.php?title=File_I%2F%2FO), 如果改成Home,那么确实将保存在用户文件夹内(Documents and settings\username), 但改成Desk时,虽然截屏图片temp.png将保存在桌面,但画图程序会出现错误,mspaint无法加载已保存在桌面的temp.png图片。我猜这是因为中文版WindowsXP的桌面路径名是中文,而不是“\Documents and Settings\username\Desktop”的缘故。要真是如此,那我该如何改动呢? var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
限于水平问题,我也搞不定“Components.interfaces.nsIFile”方法中直接调用本地路径的方法(比如“C:\documents and settings\username\桌面”) 恳请大家指教。 |
|
|
1楼#
发布于:2008-11-27 19:11
不是很明白你的问题。你说“如果改成Home,那么确实将保存在用户文件夹内”,那就是说文件保存成功了咯?那标题为什么是问“怎样直接保存文件到桌面”?
|
|
|
2楼#
发布于:2008-11-27 19:11
marffin:不是很明白你的问题。你说“如果改成Home,那么确实将保存在用户文件夹内”,那就是说文件保存成功了咯?那标题为什么是问“怎样直接保存文件到桌面”?回到原帖 是的,是保持成功了,对不起,我表述有些问题。 这个功能实现的是“截取当前网页图片,存为temp.png,并保存到TmpD文件夹(也就是/username/temp),同时用mspaint.exe打开这个保存的图片” 我的问题应该是:图片保存成功后,mspaint.exe打开这个图片时有报错。并且我猜是因为图片保存的路径中有中文造成的(因为中文版XP的桌面文件夹的名字就是桌面而不是英文WINXP中的Desktop) 我想问: var arguments = args; process.run(false,arguments,arguments.length); process.run在执行时,arguments中含有中文,会不会出错? 相关的代码段如下,完整的插件包在附件。 function quicklaunch_runProcInWinD(relPath,args){
try{
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var winDir = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties).get("WinD", Components.interfaces.nsILocalFile);
var file = Components.classes["@mozilla.org/file/local;1"].createInstance(Components.interfaces.nsILocalFile);
file.initWithPath(winDir.path + "\" +relPath);
var process=Components.classes['@mozilla.org/process/util;1'].createInstance(Components.interfaces.nsIProcess);
process.init(file);
var arguments = args;
// alert(args);
process.run(false,arguments,arguments.length);
}catch(e){alert(e);}
}
function quicklaunch_openPageWithMspaint(){
var data = quicklaunch_printScreen();
//create Temp File
var file = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("TmpD", Components.interfaces.nsIFile);
file.append("temp.png");
file.createUnique(Components.interfaces.nsIFile.NORMAL_FILE_TYPE, 0666);
// do whatever you need to the created file
//alert(file.path);
var io = Components.classes["@mozilla.org/network/io-service;1"]
.getService(Components.interfaces.nsIIOService);
var source = io.newURI(data, "UTF8", null);
var target = io.newFileURI(file)
// alert(1);
// prepare to save the canvas data
var persist = Components.classes["@mozilla.org/embedding/browser/nsWebBrowserPersist;1"]
.createInstance(Components.interfaces.nsIWebBrowserPersist);
persist.persistFlags = Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_REPLACE_EXISTING_FILES;
persist.persistFlags |= Components.interfaces.nsIWebBrowserPersist.PERSIST_FLAGS_AUTODETECT_APPLY_CONVERSION;
// alert(1);
// displays a download dialog (remove these 3 lines for silent download)
// var xfer = Components.classes["@mozilla.org/transfer;1"]
// .createInstance(Components.interfaces.nsITransfer);
// xfer.init(source, target, "", null, null, null, persist);
// persist.progressListener = xfer;
// save the canvas data to the file
persist.saveURI(source, null, null, null, null, file);
// alert(1);
quicklaunch_runProcInWinD('system32\\mspaint.exe',[file.path]);
// alert(1);
} |
|
|