Exemplo n.º 1
0
        private void LoadScripts()
        {
            //load all the scripts into the Script Object
            scriptObject.Reset();

            ScriptClass sc = new ScriptClass();

            sc.ParseCommand           += new SendCommandDelegate(Script_ParseCommand);
            sc.ParseCommandCurrent    += new SendCommandCurrentDelegate(Script_ParseCommandCurrent);
            sc.ParseIdentifier        += new ParseIdentifierDelegate(Script_ParseIdentifier);
            sc.ParseIdentifierCurrent += new ParseIdentifierCurrentDelegate(Script_ParseIdentifierCurrent);
            sc.GetIni       += new GetIniDelegate(Script_GetIni);
            sc.WriteIni     += new WriteIniDelegate(Script_WriteIni);
            sc.CheckIsOp    += new IsOpDelegate(Script_CheckIsOp);
            sc.CheckIsVoice += new IsVoiceDelegate(Script_CheckIsVoice);

            sc.RunScript     += new RunScriptDelegate(Script_RunScript);
            sc.GetDataFolder += new GetDataFolderDelegate(Script_GetDataFolder);

            scriptObject.AddObject("irc", (object)sc, true);
            scriptObject.AllowUI = true;
            scriptObject.State   = ScriptControlStates.Connected;

            //read in all the loaded script files
            if (File.Exists(scriptSettingsFile))
            {
                XmlSerializer deserializer = new XmlSerializer(typeof(IceChatVBScripts));
                TextReader    textReader   = new StreamReader(scriptSettingsFile);
                icechatVBScripts = (IceChatVBScripts)deserializer.Deserialize(textReader);
                textReader.Close();
                textReader.Dispose();
            }
            else
            {
                icechatVBScripts = new IceChatVBScripts();
            }



            foreach (String file in icechatVBScripts.listScripts)
            {
                if (File.Exists(this.CurrentFolder + Path.DirectorySeparatorChar + "Scripts" + Path.DirectorySeparatorChar + file))
                {
                    //System.Diagnostics.Debug.WriteLine("loading script file into engine: " + file);

                    StreamReader sr = new StreamReader(this.CurrentFolder + Path.DirectorySeparatorChar + "Scripts" + Path.DirectorySeparatorChar + file);
                    //add the script file into its own module
                    object o = new object();
                    Module m = scriptObject.Modules.Add(file, ref o);
                    m.AddCode(sr.ReadToEnd());

                    sr.Close();
                }
            }
        }
Exemplo n.º 2
0
 public bool Compile(WScript wscript, Script script = null)
 {
     _wscript = wscript;
     if (_script != null)
     {
         _compiler.Reset();
     }
     _script = script;
     _compiler.AddObject("WScript", wscript, true);
     _compiler.AddCode("Function IIf(Expression, TruePart, FalsePart)\r\nIf Expression Then IIf = truepart Else IIf = falsepart\r\nEnd Function\r\n");
     if (script != null)
     {
         return(AddCode(script.GetCode()));
     }
     return(true);
 }
Exemplo n.º 3
0
        ///需要添加引用COM:Microsoft Script Control 1.0
        /// <summary>
        /// 执行JS代码并返回结果
        /// </summary>
        /// <param name="sScript">JS代码</param>
        /// <param name="sName">JS函数名</param>
        /// <returns>结果</returns>
        private static string ExecJS(string sScript, string sName)
        {
            //string sInitUrl = "http://ipangu.baidu.com/ipangu-hint/hint/hintCustAdd_init.action";
            ScriptControlClass js     = new ScriptControlClass();//使用ScriptControlClass
            object             result = null;

            try
            {
                js.Language = "javascript";
                js.Reset();
                js.Eval(sScript);                //指向js脚本
                object[] obj = new object[] { };
                result = js.Run(sName, ref obj); //传入参数执行
            }
            catch (Exception ex)
            {
                result = ex.Message;
            }
            return(result.ToString());
        }
Exemplo n.º 4
0
 public string Hash(string qq, string ptwebqq)
 {
     const string url = "http://0.web.qstatic.com/webqqpic/pubapps/0/50/eqq.all.js";
     //获取hash 函数代码所在JS文件
     var jsContent = HttpHelper.Get(url);
     var index = jsContent.IndexOf("P=function(", StringComparison.Ordinal);
     var end = jsContent.IndexOf(",b=function(b){c.out", StringComparison.Ordinal) - 1;
     var hashJs = jsContent.Substring(index, end - index + 1);
     var js = new ScriptControlClass { Language = "javascript" };//使用ScriptControlClass  
     js.Reset();
     js.Eval(hashJs);
     return js.Run("P", new object[] { qq, ptwebqq }).ToString();
 }