What happened to the Messenger Plus! forums on msghelp.net?
Shoutbox » MsgHelp Archive » Messenger Plus! for Live Messenger » Scripting » help me debugging this script

Pages: (2): « First « 1 [ 2 ] Last »
help me debugging this script
Author: Message:
Matti
Elite Member
*****

Avatar
Script Developer and Helper

Posts: 1646
Reputation: 39
31 / Male / Flag
Joined: Apr 2004
RE: help me debugging this script
It would be a terrible idea to do that every 5 seconds. You could better listen for a file modification every 30 seconds and if it changed, change your variables.

Take a look at the code snippet here, and you can make something like:
code:
var ListenInterval = 30000; //30 seconds

//This has been token from the code snippet, all credits go to OcuS
var FileModificationDates = [];
function ListenForFileModification(FilePath, Callback) {
   var DateLastModified = GetFileModificationDate(FilePath);
   if (DateLastModified === false) return false;

   Callback = Callback || function(FilePath) {};
   FileModificationDates[FilePath] = {
      file : FilePath,
      date : DateLastModified,
      callback : Callback
   }
   MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
   return true;
}

function GetFileModificationDate(FilePath) {
   var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
   if (!FileSystem.FileExists(FilePath)) return false;
   var File = FileSystem.GetFile(FilePath);
   return '' + File.DateLastModified + '';
}

function OnEvent_Timer(TimerId) {
   var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
   if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
      var FilePath = TimerMatchLSTN[1];
      var DateLastModified = GetFileModificationDate(FilePath);
      if (DateLastModified === false) return false;

      if (DateLastModified != FileModificationDates[FilePath].date){
         FileModificationDates[FilePath].callback(FilePath);
         FileModificationDates[FilePath] = undefined;
         return true;
      }
      MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
      return true;
   }
}

function OnEvent_Initialize(MessengerStart) {
//Here comes your original stuff...
//And here are our listening function calls!
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', SetDef);
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', SetDef);

}

function SetDef(FilePath) {
   //I'll use a regular expression for this one, it checks if the file's right and captures the welcome or

goodbye
   if(FilePath.test(/\\def(welcome|goodbye)msg\.txt$/i) {
      //We'll open our file
      var File = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(FilePath, 1);
      //Here we'll see what it has captured and save it in the right variable
      switch(RegExp.$1) {
         case "welcome":
            DefWelcomeMsg = File.ReadAll();
            break;
         case "goodbye":
            DefGoodbyeMsg = File.ReadAll();
            break;
      }
      //At the end, we'll close the file
      File.Close();
      //That's all folks!
   }
}



I'm too nice for these guys... :sad:

This post was edited on 02-01-2007 at 06:25 PM by Matti.
Plus! Script Developer | Plus! Beta Tester | Creator of Countdown Live | Co-developer of Screenshot Sender 5

Found my post useful? Rate me!
02-01-2007 06:24 PM
Profile E-Mail PM Web Find Quote Report
Wakaki
Junior Member
**

Avatar

Posts: 30
30 / Male / –
Joined: Jan 2007
O.P. RE: RE: help me debugging this script
quote:
Originally posted by Mattike
It would be a terrible idea to do that every 5 seconds. You could better listen for a file modification every 30 seconds and if it changed, change your variables.

Take a look at the code snippet here, and you can make something like:
code:
var ListenInterval = 30000; //30 seconds

//This has been token from the code snippet, all credits go to OcuS
var FileModificationDates = [];
function ListenForFileModification(FilePath, Callback) {
   var DateLastModified = GetFileModificationDate(FilePath);
   if (DateLastModified === false) return false;

   Callback = Callback || function(FilePath) {};
   FileModificationDates[FilePath] = {
      file : FilePath,
      date : DateLastModified,
      callback : Callback
   }
   MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
   return true;
}

function GetFileModificationDate(FilePath) {
   var FileSystem = new ActiveXObject('Scripting.FileSystemObject');
   if (!FileSystem.FileExists(FilePath)) return false;
   var File = FileSystem.GetFile(FilePath);
   return '' + File.DateLastModified + '';
}

function OnEvent_Timer(TimerId) {
   var TimerMatchLSTN = TimerId.match(/^LSTN_FileModification_(.+)$/);
   if (TimerMatchLSTN.length && FileModificationDates[TimerMatchLSTN[1]]) {
      var FilePath = TimerMatchLSTN[1];
      var DateLastModified = GetFileModificationDate(FilePath);
      if (DateLastModified === false) return false;

      if (DateLastModified != FileModificationDates[FilePath].date){
         FileModificationDates[FilePath].callback(FilePath);
         FileModificationDates[FilePath] = undefined;
         return true;
      }
      MsgPlus.AddTimer('LSTN_FileModification_' + FilePath, ListenInterval);
      return true;
   }
}

function OnEvent_Initialize(MessengerStart) {
//Here comes your original stuff...
//And here are our listening function calls!
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defwelcomemsg.txt', SetDef);
ListenForFileModification(MsgPlus.ScriptFilesPath + '\\defgoodbyemsg.txt', SetDef);

}

function SetDef(FilePath) {
   //I'll use a regular expression for this one, it checks if the file's right and captures the welcome or

goodbye
   if(FilePath.test(/\\def(welcome|goodbye)msg\.txt$/i) {
      //We'll open our file
      var File = new ActiveXObject("Scripting.FileSystemObject").OpenTextFile(FilePath, 1);
      //Here we'll see what it has captured and save it in the right variable
      switch(RegExp.$1) {
         case "welcome":
            DefWelcomeMsg = File.ReadAll();
            break;
         case "goodbye":
            DefGoodbyeMsg = File.ReadAll();
            break;
      }
      //At the end, we'll close the file
      File.Close();
      //That's all folks!
   }
}



I'm too nice for these guys... :sad:


thank you thank you thank you

i will test it in the morning tommorow

p.s. youre right youre too nice:D:wicked:
[Image: wakakipt2.png]
02-01-2007 09:23 PM
Profile 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