예제 #1
0
        void AutoUpdater_NewUpdate(Services.NewUpdateInfo info)
        {
            if (notify_later_clicked)
            {
                return;
            }
            Dispatcher.Invoke(() =>
            {
                UI.NewUpdateWindow nuw = new UI.NewUpdateWindow()
                {
                    DataContext = info,
                    Icon        = this.Icon,
                    Owner       = this
                };

                bool?res = nuw.ShowDialog();

                if (res == true)
                {
                    string byteflood_location = System.Reflection.Assembly.GetExecutingAssembly().Location;
                    System.IO.FileInfo fi     = new IO.FileInfo(byteflood_location);
                    string updater            = System.IO.Path.Combine(fi.DirectoryName, "ByteFloodUpdater.exe");
                    if (System.IO.File.Exists(updater))
                    {
                        ProcessStartInfo psi = new ProcessStartInfo(updater);
                        psi.Arguments        = string.Format("\"{0}\" \"{1}\"", info.DownloadUrl, fi.DirectoryName);

                        Process.Start(psi);

                        state.Shutdown();
                        Environment.Exit(0);
                    }
                    else
                    {
                        MessageBox.Show("Updater executable does not exist!", "Cannot update");
                    }
                }

                notify_later_clicked = res == false;
            });
        }
예제 #2
0
        public static async Task <NewUpdateInfo> CheckforUpdatesAsync(CancellationToken token, bool fire_events = true)
        {
            try
            {
                using (WebClient nc = new WebClient())
                {
                    nc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; rv:31.0) Firefox/31.0");
                    nc.Headers.Add(HttpRequestHeader.IfNoneMatch, App.Settings.UpdateSourceEtag);

                    var task = nc.DownloadStringTaskAsync(UpdateURL);
                    token.Register(nc.CancelAsync);
                    var data = await task;

                    App.Settings.UpdateSourceEtag = nc.ResponseHeaders[HttpResponseHeader.ETag];

                    JsonArray releases_list = JsonConvert.Import <JsonArray>(data);

                    JsonObject latest_release = (JsonObject)releases_list[0];

                    bool prerelease = Convert.ToBoolean(latest_release["prerelease"]);
                    if (prerelease)
                    {
                        return(null);
                    }

                    string tag = Convert.ToString(latest_release["tag_name"]);

                    int    version = 0;
                    string a       = tag.Remove(0, 1).Replace(".", "");

                    Int32.TryParse(a, out version);

                    if (version > Utility.ByteFloodVersion)
                    {
                        NewUpdateInfo ifo = new NewUpdateInfo();
                        ifo.Tag     = tag;
                        ifo.Version = version;

                        ifo.Link  = Convert.ToString(latest_release["html_url"]);
                        ifo.Title = Convert.ToString(latest_release["name"]);

                        JsonArray downloads = (JsonArray)latest_release["assets"];

                        foreach (JsonObject release in downloads)
                        {
                            string u = Convert.ToString(release["browser_download_url"]);
                            if (u.EndsWith(".zip"))
                            {
                                ifo.DownloadUrl = u;
                                break;
                            }
                        }

                        ifo.ChangeLog = Convert.ToString(latest_release["body"]);

                        if (NewUpdate != null && fire_events)
                        {
                            NewUpdate(ifo);
                        }
                        return(ifo);
                    }
                }
            }
            catch (WebException)
            {
                //{"The remote server returned an error: (304) Not Modified."}
                return(null);
            }
            catch (Exception)
            {
                return(null);
            }
            return(null);
        }
예제 #3
0
        public static async Task<NewUpdateInfo> CheckforUpdatesAsync(CancellationToken token, bool fire_events = true)
        {
            try
            {
                using (WebClient nc = new WebClient())
                {
                    nc.Headers.Add(HttpRequestHeader.UserAgent, "Mozilla/5.0 (Windows NT 6.1; rv:31.0) Firefox/31.0");
                    nc.Headers.Add(HttpRequestHeader.IfNoneMatch, App.Settings.UpdateSourceEtag);

                    var task = nc.DownloadStringTaskAsync(UpdateURL);
					token.Register(nc.CancelAsync);
	                var data = await task;

                    App.Settings.UpdateSourceEtag = nc.ResponseHeaders[HttpResponseHeader.ETag];

                    JsonArray releases_list = JsonConvert.Import<JsonArray>(data);

                    JsonObject latest_release = (JsonObject)releases_list[0];

                    bool prerelease = Convert.ToBoolean(latest_release["prerelease"]);
                    if (prerelease) { return null; }

                    string tag = Convert.ToString(latest_release["tag_name"]);

                    int version = 0;
                    string a = tag.Remove(0, 1).Replace(".", "");

                    Int32.TryParse(a, out version);

                    if (version > Utility.ByteFloodVersion)
                    {
                        NewUpdateInfo ifo = new NewUpdateInfo();
                        ifo.Tag = tag;
                        ifo.Version = version;

                        ifo.Link = Convert.ToString(latest_release["html_url"]);
                        ifo.Title = Convert.ToString(latest_release["name"]);

                        JsonArray downloads = (JsonArray)latest_release["assets"];

                        foreach (JsonObject release in downloads)
                        {
                            string u = Convert.ToString(release["browser_download_url"]);
                            if (u.EndsWith(".zip"))
                            {
                                ifo.DownloadUrl = u;
                                break;
                            }
                        }

                        ifo.ChangeLog = Convert.ToString(latest_release["body"]);

                        if (NewUpdate != null && fire_events) { NewUpdate(ifo); }
                        return ifo;
                    }
                }
            }
            catch (WebException) 
            {
                //{"The remote server returned an error: (304) Not Modified."}
                return null;
            }
            catch (Exception)
            {
                return null;
            }
            return null;
        }