Beispiel #1
0
        private static dynamic DownloadJson(string url)
        {
            var web = new WebClientEx(15 * 1000);

            web.Headers.Add(HttpRequestHeader.UserAgent, "Wget/1.9.1");

            var response =
                web.DownloadDataStream(url);

            var json = JsonConvert.DeserializeObject <dynamic>(new StreamReader(response).ReadToEnd());

            return(json);
        }
Beispiel #2
0
        public static void CheckForUpdates(bool silent = false)
        {
            Task.Run(() =>
            {
                try
                {
                    var web = new WebClientEx(15 * 1000);
                    web.Headers.Add(HttpRequestHeader.UserAgent, "Wget/1.9.1");

                    var response = web.DownloadDataStream("https://api.github.com/repos/xupefei/QuickLook/releases");

                    var json = JsonConvert.DeserializeObject <dynamic>(new StreamReader(response).ReadToEnd());

                    var nVersion = (string)json[0]["tag_name"];
                    //nVersion = "0.2.1";

                    if (new Version(nVersion) <= Assembly.GetExecutingAssembly().GetName().Version)
                    {
                        if (!silent)
                        {
                            Application.Current.Dispatcher.Invoke(
                                () => TrayIconManager.GetInstance().ShowNotification("",
                                                                                     "You are now on the latest version."));
                        }
                        return;
                    }

                    string notes = CollectReleaseNotes(json);

                    var changeLogPath = Path.GetTempFileName() + ".md";
                    File.WriteAllText(changeLogPath, notes);

                    Application.Current.Dispatcher.Invoke(
                        () =>
                    {
                        ViewWindowManager.GetInstance().InvokeViewer(changeLogPath);
                        TrayIconManager.GetInstance().ShowNotification("",
                                                                       $"New version {nVersion} is released. Click here to open the download page.",
                                                                       clickEvent: () => Process.Start(
                                                                           @"https://github.com/xupefei/QuickLook/releases/latest"));
                    });
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.GetInstance().ShowNotification("",
                                                                             $"Error occured when checking for updates: {e.Message}"));
                }
            });
        }
Beispiel #3
0
        internal static void CheckApplicationUpdate(Version version, bool show)
        {
            var url = $"{baseUrl}VersionInfo.xml";

            try
            {
                var client = new WebClientEx(10 * 1000);
                var stream = client.DownloadDataStream(url);

                var xmlContent = new XmlDocument();
                xmlContent.Load(stream);

                ProcessUpdate(xmlContent, version, show);
            }
            catch (Exception) { }
        }
Beispiel #4
0
        internal static void CheckApplicationUpdate(string version, NotifyIcon notifyIcon)
        {
            var url = @"http://xupefei.github.io/Locale-Emulator/VersionInfo.xml";

            try
            {
                var client = new WebClientEx(10 * 1000);
                var stream = client.DownloadDataStream(url);

                var xmlContent = new XmlDocument();
                xmlContent.Load(stream);

                ProcessUpdate(xmlContent, notifyIcon);
            }
            catch (Exception)
            {
                notifyIcon.Visible = false;
                Environment.Exit(0);
            }
        }
        internal static void CheckApplicationUpdate(string version, NotifyIcon notifyIcon)
        {
            string url = string.Format(@"http://service.watashi.me/le/check.php?ver={0}&lang={1}",
                                       version,
                                       CultureInfo.CurrentUICulture.LCID);

            try
            {
                var          client = new WebClientEx(10 * 1000);
                MemoryStream stream = client.DownloadDataStream(url);

                var xmlContent = new XmlDocument();
                xmlContent.Load(stream);

                ProcessUpdate(xmlContent, notifyIcon);
            }
            catch (Exception)
            {
                notifyIcon.Visible = false;
                Environment.Exit(0);
            }
        }