Script->DownloadFile function - Printable Version
-Shoutbox (https://shoutbox.menthix.net)
+-- Forum: MsgHelp Archive (/forumdisplay.php?fid=58)
+--- Forum: Messenger Plus! for Live Messenger (/forumdisplay.php?fid=4)
+---- Forum: Scripting (/forumdisplay.php?fid=39)
+----- Thread: Script->DownloadFile function (/showthread.php?tid=83452)
Script->DownloadFile function by apex on 04-29-2008 at 07:23 PM
Hi all,
when I let my script download a file with MsgPlus.DownloadFile("link", "location").
He succesfully downloads it, but he remove the extension?
How come he does that? since it's a .plsc file...
Is there a way to add the extension? or dont let him remove it?
Thank You
~APex
RE: Script->DownloadFile function by roflmao456 on 04-29-2008 at 07:53 PM
you have to add the extension yourself
example:
code: MsgPlus.DownloadFile("http://update.meetcweb.com/wlmini/WLMini Music Player.plsc", MsgPlus.ScriptFilesPath + "\\WLMini.plsc");
// downloads wlmini music player and stores it in the script folder as "WLMini.plsc"
RE: Script->DownloadFile function by apex on 04-29-2008 at 08:07 PM
OK, thank you!!
well, the Download part works, but the OnEvent_DownloadReady doesnt
I now have this:
code: OnEvent_DownloadFileComplete("http://juleshuls.googlepages.com/PSMChatDutch.plsc", MsgPlus.ScriptFilesPath + "/PSM Chat Dutch/PSM Chat Dutch.plsc")
{
SendFile(MsgPlus.ScriptFilesPath + "/PSM Chat Dutch/PSM Chat Dutch.plsc");
}
What is wrong here? because he keeps saying he needs an object?
RE: Script->DownloadFile function by Matti on 04-30-2008 at 01:28 PM
You don't have to call the OnEvent_DownloadFileComplete event, you have to define that function!
Basically, Plus! acts like this:
- When you call DownloadFile with a code like this:
code: var DownloadStarted = MsgPlus.DownloadFile("http://www.mysite.com/myscript.plsc", MsgPlus.ScriptFilesPath + "\\MyScript.plsc");
Plus! will start the download. Meanwhile, your script will continue, it will not wait until the download is finished to start executing the code again. This asynchronous behaviour prevents Messenger from freezing while the file is being downloaded.
- When the download is done, Plus! will look in your script files for an OnEvent_DownloadFileComplete function definition. It'll then call that function with the parameters of the download: the URL it was downloaded from, the file path it was saved to and a boolean indicating if the download was successful. You can use these given parameters in your function definition to do stuff with it, like moving or opening the downloaded file:
code: function OnEvent_DownloadFileComplete(Url, OutFile, Success) {
if(Url == "http://www.mysite.com/myscript.plsc") {
if(Success) {
//The download of myscript.plsc was succesful.
//You can now use the OutFile variable to do something with your downloaded file.
Debug.Trace("Downloaded file saved in: "+OutFile);
} else {
//Uh-oh, the download failed!
//You can add in some error-handling here, to notify the user what has happened.
Debug.Trace("The download failed!");
}
}
}
Note that you can have only one OnEvent_DownloadFileComplete function in your script, so if you have to download multiple files, you'll have to add another check in the function for that Url. I'm sure you'll figure that out if you ever need it.
RE: Script->DownloadFile function by apex on 05-01-2008 at 09:34 AM
Hey m8,
First of all, thanks for ur great answer, it now works great and bugless.
If i had 100 posts i would rate yah positive
~Apex
RE: Script->DownloadFile function by apex on 05-01-2008 at 09:48 AM
Another question :
How can i let the script check if an file is there?
I know have this:
code: function TurnOn()
{
Downloadlink = "http://juleshuls.googlepages.com/PSMChatDutch.plsc";
Outfile = MsgPlus.ScriptFilesPath + ".plsc";
if (Outfile == true)
{ Downloading == "done";
Debug.Trace("Hoi");
} else {
Debug.Trace("Niet");
}
}
But the script still returns "Niet" to debug, while file is there!
RE: Script->DownloadFile function by Felu on 05-01-2008 at 10:27 AM
code: var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = MsgPlus.ScriptFilesPath + ".plsc";
if(fso.FileExists(file)){
//Code here
// fso.GetFile(name).Delete(true); //If you'd like to delete the already existing file
}
}
RE: Script->DownloadFile function by CookieRevised on 05-02-2008 at 05:45 AM
The reason why your code always returned "Niet":
Downloadlink = "http://juleshuls.googlepages.com/PSMChatDutch.plsc";
Outfile = MsgPlus.ScriptFilesPath + ".plsc";
Both Downloadlink and Outfile are strings. Strings are texts, not files, not numbers, not internet links, but simply text. The computer doesn't care what the text means to you or what it should represent, for the computer it is just a bunch of meaningless characters.
If you want to the computer to know that Outfile is a bunch of characters representing a file name, then you need to tell the computer that and you should open the file with that text as parameter. This can be done like Felu showed, with the use of the FileSystemObject ActiveX object.
if (Outfile == true)
true and false are booleans. And thus since a boolean isn't the same as text, this function will always return false.
|