What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » How to update the DP filename as personal Msg

Pages: (2): « First « 1 [ 2 ] Last »
How to update the DP filename as personal Msg
Author: Message:
Danny22
New Member
*


Posts: 11
Joined: Dec 2008
RE: How to update the DP filename as personal Msg
I tried to look into the code of Display Picture Changer script (v1.2?), and I hope this is what you are looking for.
Please open the Display Picture Changer script file and do the following changes.

1. In the function ChangeDp, after the code
code:
Messenger.MyDisplayPicture = fileName;
add the following:
code:
UpdatePsm(fileName.Path);

2. Add the following code at the bottom of the script:
code:
function UpdatePsm(NewFileName)
{
    var tempFileName = NewFileName;
    // extract the file name
    tempFileName = tempFileName.substr(tempFileName.lastIndexOf("\\") + 1);
    var extPos = tempFileName.lastIndexOf(".");
    if (extPos >= 0) // the file name has an extension
    {
        // remove the extension
        tempFileName = tempFileName.substr(0, extPos);
    }
    // update personal message
    Messenger.MyPersonalMessage = tempFileName;
}
01-19-2009 06:39 PM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
36 / Male / Flag
Joined: Jul 2005
RE: How to update the DP filename as personal Msg
quote:
Originally posted by Danny22

code:
UpdatePsm(fileName.Path);

code:
function UpdatePsm(NewFileName)
{
    var tempFileName = NewFileName;
    // extract the file name
    tempFileName = tempFileName.substr(tempFileName.lastIndexOf("\\") + 1);
    var extPos = tempFileName.lastIndexOf(".");
    if (extPos >= 0) // the file name has an extension
    {
        // remove the extension
        tempFileName = tempFileName.substr(0, extPos);
    }
    // update personal message
    Messenger.MyPersonalMessage = tempFileName;
}

...which essentially does the same as
Javascript code:
Messenger.MyPersonalMessage = fileName.Name.substring(0, fileName.Name.lastIndexOf("."))

back on windows, so it's tested this time ;)

This post was edited on 01-19-2009 at 07:05 PM by Jesus.
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
01-19-2009 07:04 PM
Profile PM Find Quote Report
Danny22
New Member
*


Posts: 11
Joined: Dec 2008
RE: RE: How to update the DP filename as personal Msg
quote:
Originally posted by Jesus

...which essentially does the same as
Javascript code:
Messenger.MyPersonalMessage = fileName.Name.substring(0, fileName.Name.lastIndexOf("."))

back on windows, so it's tested this time ;)

Sorry but that is not completely correct.
A file does not have to have an extension (.xxx).
lastIndexOf() will return -1 if there is no period in the string.
This leaves us with substring(0, -1), which will return "".

If I should further explain why I wrote the code that way, I will do so...

The reason why I used a new function, is to seperate your custom code from the original code as much as possible. It is easier for you to make changes that way.
You can of course use fileName.Name instead, because it does not really matter which one you use in this case.
However, by using fileName.Path, you can use both the full path (NewFileName) and just the name (tempFileName) in your own code without making any changes if you somehow want to do something with both.
I like clean and reliable code.
To make it extra clean, you could even put your own code in new files if there is a lot of code.

Please correct me if I am mistaken about anything.

This post was edited on 01-19-2009 at 08:39 PM by Danny22.
01-19-2009 08:31 PM
Profile PM Find Quote Report
Jesus
Scripting Contest Winner
****

Avatar
Koffie, my cat ;)

Posts: 623
Reputation: 15
36 / Male / Flag
Joined: Jul 2005
RE: How to update the DP filename as personal Msg
quote:
Originally posted by Danny22
Sorry but that is not completely correct.
A file does not have to have an extension (.xxx).
lastIndexOf() will return -1 if there is no period in the string.
This leaves us with substring(0, -1), which will return "".
In general, this is correct.
However, the populateDp() function in the script already checks that only files with a jpg, gif, bmp or png extension are added to the array. So in this case you won't encounter filenames without an extension.
quote:
If I should further explain why I wrote the code that way, I will do so...

The reason why I used a new function, is to seperate your custom code from the original code as much as possible. It is easier for you to make changes that way.
You can of course use fileName.Name instead, because it does not really matter which one you use in this case.
However, by using fileName.Path, you can use both the full path (NewFileName) and just the name (tempFileName) in your own code without making any changes if you somehow want to do something with both.
Again, correct, but only IF you want to do something with the path. If not, it's basically a waste of CPU cycles (not that you'd notice it on most modern systems). The topic starter just wanted to get rid of the full path, so why get the full path and cut the folders off if you can get the filename with another method?
Also, if you want the path afterwards for another reason, there's still the File Object (fileName) to get the full path from in the way you did.
quote:
I like clean and reliable code.
To make it extra clean, you could even put your own code in new files if there is a lot of code.
I have to say, I like clean code too.
I just don't really see how it's cleaner to add an extra function if everything that function does can be done in a single statement too.
quote:
Please correct me if I am mistaken about anything.
It's not that you're mistaken about anything, for all I know your code works ok (haven't tested though). It's just that we seem to have a different idea on code organizing and efficiency.:)
Man is least himself when he is in his own person. Give him a mask and he will tell you the truth. (Oscar Wilde)
01-20-2009 02:06 AM
Profile PM Find Quote Report
Danny22
New Member
*


Posts: 11
Joined: Dec 2008
RE: How to update the DP filename as personal Msg
quote:
Originally posted by Jesus
However, the populateDp() function in the script already checks that only files with a jpg, gif, bmp or png extension are added to the array. So in this case you won't encounter filenames without an extension.
Oh, I see. If I knew that, I would have made it in just one line like you did, and made a new function if I wanted to add more to it.
I'm not using this an excuse, but I only tried to figure out how to use the fileName variable, and worked from there.

Topic starter: I already gave you a solution which should work, but also I suggest that you use Jesus' code. I am sure you have already figured out by now the best way for you to do it though.
01-20-2009 10:31 AM
Profile PM Find Quote Report
tantiger
New Member
*


Posts: 6
Joined: Jan 2009
O.P. RE: How to update the DP filename as personal Msg
Yes, thanks a lot for the discussion from you all. Really appreciate that. Both are good. I think the original DP changer not perfect, say, when u put appear offline, it won't detect that and continue changing pictures. I am trying to have my own version, can update picture and filename at the sametime or not showing the filename when I uncheck one option. And when appear offline, it will be silent :) I have somehow finished the script, now after your comments, cleaner code, hmm, I need more time, haha.

Have a  nice day! Thank you all!
01-20-2009 01:50 PM
Profile E-Mail PM Find Quote Report
Pages: (2): « First « 1 [ 2 ] Last »
« Next Oldest Return to Top Next Newest »


Threaded Mode | Linear Mode
View a Printable Version
Send this Thread to a Friend
Subscribe | Add to Favorites
Rate This Thread:

Forum Jump:

Forum Rules:
You cannot post new threads
You cannot post replies
You cannot post attachments
You can edit your posts
HTML is Off
myCode is On
Smilies are On
[img] Code is On