private void 用户脚本UserScriptToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Data.SessionInfo sinfo = Data.VDB.ReadSessionInfo(
         Data.VDB.GetSessionSavePath(
             listOfContainer.SelectedItems[0].Name
             )
         );
     new ScriptManager(sinfo).ShowDialog();
 }
 private void  除会话DeleteToolStripMenuItem_Click(object sender, EventArgs e)
 {
     Data.SessionInfo sinfo = Data.VDB.ReadSessionInfo(
         Data.VDB.GetSessionSavePath(
             listOfContainer.SelectedItems[0].Name
             )
         );
     Data.VDB.DeleteSession(sinfo);
     RefreshList();
 }
Esempio n. 3
0
        public ScriptManager(Data.SessionInfo session)
        {
            this.session = session;
            InitializeComponent();
            Text           = "脚本管理器 - " + Properties.Settings.Default.Title;
            noticePad.Text = "* 正在编辑 " + session.SessionName + " 的脚本设置    关闭窗口自动保存";
            StringBuilder sb = new StringBuilder();

            if (session.UUID == "GLOBAL")
            {
                session.Userscripts = Data.VDB.GlobalUserScripts.ToArray();
            }
            foreach (string url in session.Userscripts)
            {
                try
                {
                    new Uri(url);//检测是否合法
                    sb.Append(url + "\n");
                }
                catch (UriFormatException) { }
            }
            userScriptBox.Text = sb.ToString();
        }
        private void okbutton_Click(object sender, EventArgs e)
        {
            if (coName.Text.Length < 1)
            {
                return;
            }
            string UUID   = System.Guid.NewGuid().ToString("N");
            var    ssInfo = new Data.SessionInfo()
            {
                SessionName = coName.Text,
                UUID        = UUID,
                SessionPath = Data.VDB.GetSessionSavePath(UUID),
                Url         = Data.VDB.defaultUrl,
                Userscripts = new string[0]
            };

            MessageBox.Show("[" + ssInfo.SessionName + "]\n" +
                            "UUID:" + ssInfo.UUID + "\n" +
                            "PATH:" + ssInfo.SessionPath,
                            "正在创建新会话");
            Data.VDB.PutSessionInfo(ssInfo);
            RefreshList();
        }
        public BrowserWindow(Data.SessionInfo session, bool keepDebugWindow = false)
        {
            GM = new GMApi.GM_API_Handler(session.UUID, this);
            CheckForIllegalCrossThreadCalls = false;
            InitializeComponent();
            this.Text = session.SessionName + " - " + Properties.Settings.Default.Title;
            webBro    = new ChromiumWebBrowser();

            logger.AppendText("脚本加载器任务:准备脚本数据\n\n正在预加载脚本...\n");

            webBro.RequestContext = Data.CM.GetContext(session.UUID).context;
            browserLayoutPanel.Controls.Add(webBro);
            webBro.Dock            = DockStyle.Fill;
            webBro.LifeSpanHandler = new Common.Control.CefSharpOpenPageSelf();
            webBro.AddressChanged += onAddrChange;
            webBro.JavascriptObjectRepository.Settings.LegacyBindingEnabled = true;
            webBro.JavascriptObjectRepository.Register("GM", GM, false);

            this.session = session;
            sUUID        = session.UUID;
            Task t = Task.Run(async() =>
            {
                List <string> Uscripts = Data.VDB.GetSessionRelatedScripts(session.UUID);
                scripts.Clear();
                int cnt = 0;
                foreach (string urlstr in Uscripts)
                {
                    if (urlstr.Length < 1)
                    {
                        continue;
                    }
                    try
                    {
                        logger.AppendText("加载:" + urlstr + "\n");
                        if (this.IsDisposed)
                        {
                            return;
                        }
                        UserScript script = null;
                        Uri url           = new Uri(urlstr);
                        if (url.Scheme == "localscript")
                        {
                            script = new LocalUserScriptHandler(session).GetLocalUserScript(url.Host);
                        }
                        else if (url.Scheme == "globalscript")
                        {
                            script = LocalUserScriptHandler.GetUserScript(url.Host);
                        }
                        else
                        {
                            var code = Data.ScriptFetchEngine.GetScriptContent(urlstr, session);
                            script   = new UserScript(code);
                        }
                        if (script == null ||
                            script.conf.Name == null ||
                            script.conf.Name == "")
                        {
                            continue;
                        }
                        logger.AppendText("正在准备预定义资源...\n");
                        foreach (KeyValuePair <string, string> kvp in script.conf.Resources)
                        {
                            if (this.IsDisposed)
                            {
                                return;
                            }
                            logger.AppendText("[" + kvp.Key + "]\t" + kvp.Value + " \t");
                            try
                            {
                                GM.storage.preLoadResources.Add(kvp.Key, new GMApi.StorageSystem.Resource()
                                {
                                    content = ScriptFetchEngine.GetScriptContent(kvp.Value),
                                    url     = kvp.Value
                                });
                                logger.AppendText("Done. Len=" +
                                                  GM.storage.preLoadResources[kvp.Key].content.Length
                                                  + "\n");
                            }
                            catch
                            {
                                GM.storage.preLoadResources.Add(kvp.Key, new GMApi.StorageSystem.Resource()
                                {
                                    content = "",
                                    url     = kvp.Value
                                });
                                logger.AppendText("Fail.\n");
                            }
                        }
                        scripts.Add(script);
                        logger.AppendText("当前脚本完成。\n\n");
                        cnt++;
                        this.Text = session.SessionName + "(Script*" + cnt + ") - " + Properties.Settings.Default.Title;
                    }
                    catch (Exception err)
                    {
                        logger.AppendText("脚本加载出现问题:" + err.Message + "\n调用栈:\n");
                        logger.AppendText(err.StackTrace + "\n");
                    }
                }
                if (this.IsDisposed)
                {
                    return;
                }
                logger.AppendText("预加载完成,开始载入网页。\n");
                await Task.Delay(1000);
                if (this.IsDisposed)
                {
                    return;
                }
                if (!keepDebugWindow)
                {
                    logger.Hide();
                }
                webBro.FrameLoadEnd += onFrameLoadEnd;
                webBro.Load(session.Url);
            });
        }
 public LocalUserScriptHandler(SessionInfo session)
 {
     this.session = session;
 }