示例#1
0
        public void Update()
        {
            if (!CheckForUpdates())
            {
                return;
            }

            Burntime.Platform.IO.ConfigSection section = config.GetSection(curVersion);
            if (section == null)
            {
                // no update for this available, download full version
                curVersion = "full";
            }

            BackgroundWorker worker = new BackgroundWorker();

            worker.RunWorkerCompleted        += new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted);
            worker.ProgressChanged           += new ProgressChangedEventHandler(worker_ProgressChanged);
            worker.DoWork                    += new DoWorkEventHandler(worker_DoWork);
            worker.WorkerSupportsCancellation = true;
            worker.WorkerReportsProgress      = true;

            progress = new Burntime.Autoupdate.UpdateProgress();

            worker.RunWorkerAsync();

            if (progress.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                worker.CancelAsync();
            }
        }
示例#2
0
        protected override void ReplaceVariables(HtmlWindow window, Uri url)
        {
            Burntime.Platform.IO.ConfigSection[] sections = downloads.GetAllSections();
            Burntime.Platform.IO.ConfigSection[] txts     = text.GetAllSections();

            if (window.Document.Url == url)
            {
                HtmlElementCollection downloadSections = window.Document.GetElementsByTagName("download");
                if (downloadSections.Count == 1)
                {
                    HtmlElement downloadSection = downloadSections[0];
                    string      innerHtml       = downloadSection.InnerHtml;
                    downloadSection.InnerHtml = "";

                    for (int i = 1; i < sections.Length; i++)
                    {
                        downloadSection.InnerHtml += innerHtml;

                        Burntime.Platform.IO.ConfigSection section = sections[i];
                        Burntime.Platform.IO.ConfigSection txt     = txts[i];

                        PackageInfo localPackage      = Program.PackageManager.GetInfo(section.Name);
                        bool        alreadyDownloaded = localPackage != null;
                        bool        isUpdateable      = false;// localPackage != null && section.GetVersion("version") > localPackage.Version;

                        Dictionary <string, bool> flags = new Dictionary <string, bool>();
                        flags.Add("alreadydownloaded", !isUpdateable && alreadyDownloaded);
                        flags.Add("update", isUpdateable);
                        flags.Add("download", !isUpdateable && !alreadyDownloaded);

                        // strings
                        foreach (HtmlElement element in window.Document.GetElementsByTagName("txt"))
                        {
                            string name = element.GetAttribute("name").ToLower();

                            if (name != "")
                            {
                                element.OuterHtml = txt.GetString(name);
                            }
                        }

                        // vars
                        foreach (HtmlElement element in window.Document.GetElementsByTagName("var"))
                        {
                            string name = element.GetAttribute("name").ToLower();

                            if (name != "")
                            {
                                element.OuterHtml = section.GetString(name);
                            }
                        }

                        // images
                        foreach (HtmlElement element in window.Document.GetElementsByTagName("img"))
                        {
                            string name = element.GetAttribute("name").ToLower();

                            if (name != "")
                            {
                                element.OuterHtml = "<img src=\"../" + section.GetString(name) + "\"/>";
                            }
                        }

                        // if
                        foreach (HtmlElement element in window.Document.GetElementsByTagName("if"))
                        {
                            string name = element.GetAttribute("name").ToLower();

                            if (name != "")
                            {
                                if (flags.ContainsKey(name))
                                {
                                    if (flags[name])
                                    {
                                        element.OuterHtml = element.InnerHtml;
                                    }
                                    else
                                    {
                                        element.OuterHtml = "";
                                    }
                                }
                            }
                        }

                        // add pak name attribute to buttons
                        foreach (HtmlElement element in window.Document.GetElementsByTagName("button"))
                        {
                            string name = element.GetAttribute("command").ToLower();

                            if (name != "")
                            {
                                // ignore already set items
                                if (element.GetAttribute("pak") == "")
                                {
                                    // set pak name
                                    element.SetAttribute("pak", section.Name);
                                    element.SetAttribute("dep", section.GetString("dependencies"));

                                    // disable if base package not downloaded yet
                                    string bas = section.GetString("base");

                                    if (bas != "" && null == Program.PackageManager.GetInfo(bas))
                                    {
                                        element.SetAttribute("disabled", "true");
                                    }
                                }
                            }
                        }
                    }

                    // remove all loading elements
                    foreach (HtmlElement element in window.Document.GetElementsByTagName("loading"))
                    {
                        element.OuterHtml = "";
                    }

                    // finally display
                    downloadSection.Style = "visibility:visible";
                }

                // set selection
                foreach (HtmlElement element in window.Document.GetElementsByTagName("option"))
                {
                    if (CheckSettingsConditions(element.GetAttribute("value")))
                    {
                        element.SetAttribute("selected", "true");
                    }
                }
                foreach (HtmlElement element in window.Document.GetElementsByTagName("input"))
                {
                    if (element.GetAttribute("type").Equals("checkbox", StringComparison.InvariantCultureIgnoreCase))
                    {
                        // add click handler
                        element.SetAttribute("command", "save");
                        element.Click += new HtmlElementEventHandler(OnClick);

                        if (CheckSettingsConditions(element.GetAttribute("value")))
                        {
                            element.SetAttribute("checked", "true");
                        }
                    }
                }
            }

            foreach (HtmlWindow frame in window.Frames)
            {
                ReplaceVariables(frame, url);
            }
        }