Code Viewer

./___debug.js File Size: 8.24 KB

  1. /*
  2.         Screenshot Sender 5 - ___debug.js
  3. */
  4. var __debug = function (bEnabled) {
  5.         try { var xml = new ActiveXObject('Microsoft.XMLDOM'); xml.async = false; }
  6.                 catch (e) {
  7.         try { var xml = new ActiveXObject('MSXML2.DOMDocument'); xml.async = false; }
  8.                 catch (e) { return false; } };
  9.         xml.load(MsgPlus.ScriptFilesPath+'\\ScriptInfo.xml');
  10.         this.enabled = (parseInt(xml.selectSingleNode ('//ScriptInfo/BuildInfo/Debug').text) === 1);
  11.         if (this.enabled === true) {
  12.                 this.write2log("\n-------------------\n  Script started!  \n-------------------");
  13.                 if (!Debug.DebuggingWindowVisible) {
  14.                         Debug.DebuggingWindowVisible = true;
  15.                 }
  16.                 Debug.ClearDebuggingWindow();
  17.         }       
  18. };
  19.  
  20. __debug.prototype = {
  21.         'functiondetailsregex' : /^function ((?:[a-zA-Z_\$][\w\$]*)?)[ ]*\([ ]*((?:[a-zA-Z_\$][\w\$]*(?:[ ]*,[ ]*[a-zA-Z_\$][\w\$]*)*)?)[ ]*\)[ ]*\{/,
  22.  
  23.         'trace' : function (s, log) {
  24.                 if (this.enabled === true) Debug.Trace(s);
  25.         },
  26.        
  27.         'error' : function (e, args) {
  28.                 if (this.enabled === false) return false;
  29.                 var s, fname;
  30.                 if (typeof args === 'string') {
  31.                         fname = args;
  32.                 } else if(typeof args === TYPE_OBJECT) {
  33.                         var o = this.getfunctiondetails(arg);
  34.                         if (o) fname = o.name;
  35.                 }
  36.                 var s = 'ERROR occured' + (fname ? ' in ' + fname : '') + ': ' + e.message;
  37.                 Debug.Trace(s); this.write2log(s);
  38.         },
  39.  
  40.         'getfuncname' : function (arg) {
  41.                 if (this.enabled === false) return false;
  42.                 var o = this.getfunctiondetails(arg);
  43.                 if (!o) return false;
  44.                 this.write2log(this.getlogstr(o));
  45.                 this.trace(o.name);
  46.         },
  47.        
  48.         'sgetfuncname' : function (name, arg) {
  49.                 if (this.enabled === false) return false;
  50.                 var o = this.getfunctiondetails(arg, name);
  51.                 if (!o) return false;
  52.                 this.write2log(this.getlogstr(o));
  53.         },
  54.        
  55.         'write2log' : function (str) {
  56.                 if (this.enabled === false) return false;
  57.                 var a = new ActiveXObject('Scripting.FileSystemObject').OpenTextFile(MsgPlus.ScriptFilesPath+'\\debug.log', 8, true, -1);
  58.                 a.WriteLine('['+(new Date).toLocaleTimeString() +'] '+str);
  59.                 a.Close();
  60.         },
  61.        
  62.         'getlogstr' : function (o) {
  63.                 return (o ? 'function ' + o.name + ' (' + o.args.join (', ') + ') ' : '');
  64.         },
  65.  
  66.         'getfunctiondetails' : function (arg, fname) {
  67.                 if (typeof arg === TYPE_UNDEFINED || !('callee' in arg)) return false;
  68.                 var m, f = arg.callee.toString(), numExpectedArgs = arg.callee.length;
  69.                 if (typeof f !== 'string' || f.length === 0) return false;
  70.                 if (m = this.functiondetailsregex.exec(f)) {
  71.                         var o = {
  72.                                 name: (typeof fname === 'string' ? fname : '') ,
  73.                                 args:[]
  74.                         };
  75.                         //Store function name, if captured one
  76.                         if (m[1].length > 0) {
  77.                                 o.name = m[1];
  78.                         }
  79.                         //Store the arguments
  80.                         var am = (m[2].length > 0) ? m[2].split (/[ ]*,[ ]*/) : []; //arguments matched
  81.                         var len = am.length;
  82.                         //Loop through all captured arguments
  83.                         for (var i = 0; i < len; ++i) {
  84.                                 var type = typeof arg[i], val = null;
  85.                                 if (type === TYPE_OBJECT) {
  86.                                         if ('Handle' in arg[i]) {
  87.                                                 val = arg[i].Handle;
  88.                                                 type = ('WindowId' in arg[i]) ? 'PlusWnd' : 'ChatWnd';
  89.                                         } else if ('DataPtr' in arg[i]) {
  90.                                                 type = 'DataBloc';
  91.                                                 val = arg[i].DataPtr;
  92.                                         } else if ('length' in arg[i]) {
  93.                                                 type = 'Array/Object';
  94.                                                 val = arg[i].length;
  95.                                         } else {
  96.                                                 type = TYPE_OBJECT;
  97.                                                 val = '{...}';
  98.                                         }
  99.                                 } else val = new String(arg[i]);
  100.                                 var a = {
  101.                                         type: type,
  102.                                         name: am[i],
  103.                                         val: val,
  104.                                         toString: argToString
  105.                                 };
  106.                                 o.args.push(a);
  107.                         }
  108.                         //Return the object
  109.                         return o;
  110.                 }
  111.  
  112.                 //Custom toString function for argument objects
  113.                 function argToString () {
  114.                         if (this.type === 'string') this.val = '\''+this.val+'\'';
  115.                         if (this.type === 'Array/Object') this.name += '.length';
  116.                         return ('['+this.type+'] '+this.name+' = '+ this.val);
  117.                 }
  118.         },
  119.        
  120.         "win32_error" : function () {
  121.                 var LastError = Interop.GetLastError();
  122.                 if(LastError !== 0) {
  123.                         var MsgBuffer = Interop.Allocate(1024);
  124.                         Interop.Call("Kernel32", "FormatMessageW", 0x1000, 0,
  125.                                         LastError, 0, MsgBuffer, 1024, 0);
  126.                         this.trace(MsgBuffer.ReadString(0));
  127.                         this.write2log(MsgBuffer.ReadString(0));
  128.                         MsgBuffer.Size = 0; //Release the allocated memory now
  129.                 }
  130.         }
  131. };

Version

  • 5.0.0070_20100325_publicbeta1

Developers

Project Details

  • Folders8
  • Files122
  • Total Lines11,867
  • Repository Version70

User Count

  • 162