Exemplo n.º 1
0
        /// <summary>
        /// Display the Update Screen
        /// </summary>
        /// <param name="show">true, if it should be visible even if no updates were found</param>
        public static void ShowUpdate(bool show)
        {
            if (!show)
            {
                TimeSpan ts = DateTime.Now - Helper.WindowsRegistry.LastUpdateCheck;
                //only check for new releases once a Day
                if (!Helper.QARelease && !Helper.WindowsRegistry.WasQAUser)
                {
                    if (ts < new TimeSpan(7, 0, 0, 0))
                    {
                        return;
                    }
                }
                else if (Helper.WindowsRegistry.WasQAUser)
                {
                    if (ts < new TimeSpan(3, 12, 0, 0))
                    {
                        return;
                    }
                }
                else if (ts < new TimeSpan(1, 12, 0, 0))
                {
                    return;
                }
            }

            //scan for an Update
            Wait.SubStart();
            About f = new About(true);

            f.Text = SimPe.Localization.GetString("Updates");
            long   version   = 0;
            long   qaversion = 0;
            string text      = "";

            SimPe.Updates.UpdateState.SetUpdatablePluginList(SimPe.FileTable.WrapperRegistry.UpdatablePlugins);
            SimPe.Updates.UpdateState res = WebUpdate.CheckUpdate(ref version, ref qaversion);


            if (!show && res.UpdatesAvailable)
            {
                DialogResult dr = Message.Show(SimPe.Localization.GetString("UpdatesAvailable"), SimPe.Localization.GetString("Updates"), MessageBoxButtons.YesNo);
                if (dr == DialogResult.No)
                {
                    res.Discard();
                }
            }
            string html = GetHtmlBase();

            text += "<h2><span class=\"highlight\">" + SimPe.Localization.GetString("Current Version") + ":</span> " + Helper.SimPeVersionString;
            if (Helper.DebugMode)
            {
                text += " (" + Helper.SimPeVersionLong.ToString() + ")";
            }
            text += "</h2>";
            if (Helper.QARelease)
            {
                text += "<h2><span class=\"highlight\">" + SimPe.Localization.GetString("Available QA-Version") + ":</span> " + Helper.LongVersionToString(qaversion) + "</h2>";
            }
            text += "<h2><span class=\"highlight\">" + SimPe.Localization.GetString("Available Version") + ":</span> " + Helper.LongVersionToString(version);
            if ((res.SimPeState & SimPe.Updates.UpdateStates.NewRelease) != 0)
            {
                text += " (" + SimPe.Localization.GetString("download") + ": <b>http://sims.ambertation.de/download.shtml</b>)";
            }
            text += "</h2>";
            text += "<br /><br />";

            if (res.Count > 0)
            {
                text += "<h2><i>" + SimPe.Localization.GetString("Updateable Plugins") + "</i></h2><ul>";
                foreach (SimPe.Updates.UpdateInfo ui in res)
                {
                    text += "<li>";
                    text += "&nbsp;&nbsp;&nbsp;&nbsp;<span class=\"highlight\">";
                    if (ui.HasUpdate)
                    {
                        text += "<i>";
                    }
                    text += ui.DisplayName;
                    if (ui.HasUpdate)
                    {
                        text += "</i>";
                    }
                    text += ":</span><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + SimPe.Localization.GetString("installed") + "=" + ui.CurrentVersion.ToString() + ", " + SimPe.Localization.GetString("available") + "=" + ui.AvailableVersion.ToString() + "<br />";
                    if (ui.HasUpdate)
                    {
                        text += "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + SimPe.Localization.GetString("Download from") + ": " + ui.DownloadUrl + "<br />";
                    }
                    text += "</li>";
                }

                text += "</ul><br /><br />";
            }
            if ((res.SimPeState & SimPe.Updates.UpdateStates.NewQARelease) != 0)
            {
                text += SimPe.Localization.GetString("get_qa_release");
            }
            else if ((res.SimPeState & SimPe.Updates.UpdateStates.NewRelease) != 0)
            {
                text += WebUpdate.GetChangeLog();
            }
            else
            {
                text += SimPe.Localization.GetString("no_new_version");
            }

            f.wb.DocumentText = html.Replace("{CONTENT}", text);
            f.rtb.Rtf         = Ambertation.Html2Rtf.Convert(text);
            Wait.SubStop();
            if (show || res.UpdatesAvailable)
            {
                SimPe.Splash.Screen.Stop();
                f.ShowDialog();
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Check for SimPE Updates
        /// </summary>
        /// <returns>true if success</returns>
        public static UpdateState CheckUpdate(ref long version, ref long qaversion)
        {
            if (!IsConnectedToInternet())
            {
                return(new UpdateState(UpdateStates.Nothing));
            }
            Helper.WindowsRegistry.LastUpdateCheck = DateTime.Now;

            WebClient Client = new WebClient();
            bool      run    = true;

            if (Helper.StartedGui == Executable.Classic)
            {
                run = WaitingScreen.Running;
                WaitingScreen.Wait();
            }
            else
            {
                Wait.SubStart();
            }
            try
            {
                WaitingScreen.UpdateMessage("Check for new Updates");
                Wait.Message = "Check for new Updates";

                string content = DownloadContent("http://sims.ambertation.de/downloadnfo.txt?&browser=simpe");

                //extract the Version String
                WaitingScreen.UpdateMessage("read latest Version");
                Wait.Message = "Reciving latest Version";
                UpdateState res = new UpdateState(UpdateStates.Nothing);
                try
                {
                    version   = GetVersion(content, "lversion");
                    qaversion = GetVersion(content, "qaversion");

                    if (version > Helper.SimPeVersionLong)
                    {
                        res.AddSimPeState(UpdateStates.NewRelease);
                    }

                    if (Helper.QARelease || Helper.WindowsRegistry.WasQAUser)
                    {
                        if (qaversion > Helper.SimPeVersionLong)
                        {
                            res.AddSimPeState(UpdateStates.NewQARelease);
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop(); run = false;
                    }
                    Helper.ExceptionMessage("", ex);
                }

                try
                {
                    bool first = true;
                    System.Collections.Generic.List <string> urls = new System.Collections.Generic.List <string>();
                    foreach (IUpdatablePlugin pl in UpdateState.UpdateablePluginList)
                    {
                        string url = pl.GetUpdateInformation().VersionCheckUrl;
                        if (urls.Contains(url.ToLower()))
                        {
                            continue;
                        }
                        urls.Add(url.ToLower());

                        content = DownloadContent(url);
                        res.CheckPluginUpdates(content, first);

                        first = false;
                    }
                }
                catch (Exception ex)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop(); run = false;
                    }
                    Helper.ExceptionMessage("", ex);
                }

                if (Helper.StartedGui == Executable.Classic)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop();
                    }
                }
                else
                {
                    Wait.SubStop();
                }


                return(res);
            }
            catch (Exception ex)
            {
                Helper.ExceptionMessage(new Warning("SimPE was unable to connect to the Internet. It cannot lookup the latest Version.", "You can deactivate the Version Check in Extras->Preferences... .", ex));
            }
            finally
            {
                if (Helper.StartedGui == Executable.Classic)
                {
                    if (!run)
                    {
                        WaitingScreen.Stop();
                    }
                }
                else
                {
                    Wait.SubStop();
                }
            }

            return(new UpdateState(UpdateStates.Nothing));
        }