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...
thank you thank you thank you
i will test it in the morning tommorow
p.s. youre right youre too nice:wicked: