/*
Screenshot Sender 5 - ___debug.js
*/
var __debug = function (bEnabled) {
try { var xml = new ActiveXObject('Microsoft.XMLDOM'); xml.async = false; }
catch (e) {
try { var xml = new ActiveXObject('MSXML2.DOMDocument'); xml.async = false; }
catch (e) { return false; } };
xml.load(MsgPlus.ScriptFilesPath+'\\ScriptInfo.xml');
this.enabled = (parseInt(xml.selectSingleNode ('//ScriptInfo/BuildInfo/Debug').text) === 1);
if (this.enabled === true) {
this.write2log("\n-------------------\n Script started! \n-------------------");
if (!Debug.DebuggingWindowVisible) {
Debug.DebuggingWindowVisible = true;
}
Debug.ClearDebuggingWindow();
}
};
__debug.prototype = {
'functiondetailsregex' : /^function ((?:[a-zA-Z_\$][\w\$]*)?)[ ]*\([ ]*((?:[a-zA-Z_\$][\w\$]*(?:[ ]*,[ ]*[a-zA-Z_\$][\w\$]*)*)?)[ ]*\)[ ]*\{/,
'trace' : function (s, log) {
if (this.enabled === true) Debug.Trace(s);
},
'error' : function (e, args) {
if (this.enabled === false) return false;
var s, fname;
if (typeof args === 'string') {
fname = args;
} else if(typeof args === TYPE_OBJECT) {
var o = this.getfunctiondetails(arg);
if (o) fname = o.name;
}
var s = 'ERROR occured' + (fname ? ' in ' + fname : '') + ': ' + e.message;
Debug.Trace(s); this.write2log(s);
},
'getfuncname' : function (arg) {
if (this.enabled === false) return false;
var o = this.getfunctiondetails(arg);
if (!o) return false;
this.write2log(this.getlogstr(o));
this.trace(o.name);
},
'sgetfuncname' : function (name, arg) {
if (this.enabled === false) return false;
var o = this.getfunctiondetails(arg, name);
if (!o) return false;
this.write2log(this.getlogstr(o));
},
'write2log' : function (str) {
if (this.enabled === false) return false;
var a = new ActiveXObject('Scripting.FileSystemObject').OpenTextFile(MsgPlus.ScriptFilesPath+'\\debug.log', 8, true, -1);
a.WriteLine('['+(new Date).toLocaleTimeString() +'] '+str);
a.Close();
},
'getlogstr' : function (o) {
return (o ? 'function ' + o.name + ' (' + o.args.join (', ') + ') ' : '');
},
'getfunctiondetails' : function (arg, fname) {
if (typeof arg === TYPE_UNDEFINED || !('callee' in arg)) return false;
var m, f = arg.callee.toString(), numExpectedArgs = arg.callee.length;
if (typeof f !== 'string' || f.length === 0) return false;
if (m = this.functiondetailsregex.exec(f)) {
var o = {
name: (typeof fname === 'string' ? fname : '') ,
args:[]
};
//Store function name, if captured one
if (m[1].length > 0) {
o.name = m[1];
}
//Store the arguments
var am = (m[2].length > 0) ? m[2].split (/[ ]*,[ ]*/) : []; //arguments matched
var len = am.length;
//Loop through all captured arguments
for (var i = 0; i < len; ++i) {
var type = typeof arg[i], val = null;
if (type === TYPE_OBJECT) {
if ('Handle' in arg[i]) {
val = arg[i].Handle;
type = ('WindowId' in arg[i]) ? 'PlusWnd' : 'ChatWnd';
} else if ('DataPtr' in arg[i]) {
type = 'DataBloc';
val = arg[i].DataPtr;
} else if ('length' in arg[i]) {
type = 'Array/Object';
val = arg[i].length;
} else {
type = TYPE_OBJECT;
val = '{...}';
}
} else val = new String(arg[i]);
var a = {
type: type,
name: am[i],
val: val,
toString: argToString
};
o.args.push(a);
}
//Return the object
return o;
}
//Custom toString function for argument objects
function argToString () {
if (this.type === 'string') this.val = '\''+this.val+'\'';
if (this.type === 'Array/Object') this.name += '.length';
return ('['+this.type+'] '+this.name+' = '+ this.val);
}
},
"win32_error" : function () {
var LastError = Interop.GetLastError();
if(LastError !== 0) {
var MsgBuffer = Interop.Allocate(1024);
Interop.Call("Kernel32", "FormatMessageW", 0x1000, 0,
LastError, 0, MsgBuffer, 1024, 0);
this.trace(MsgBuffer.ReadString(0));
this.write2log(MsgBuffer.ReadString(0));
MsgBuffer.Size = 0; //Release the allocated memory now
}
}
};