Example #1
0
        public static void CollectAndShowReleaseNotes()
        {
            Task.Run(() =>
            {
                try
                {
                    var json = DownloadJson("https://api.github.com/repos/xupefei/QuickLook/releases");

                    var notes = string.Empty;

                    foreach (var item in json)
                    {
                        notes += $"# {item["name"]}\r\n\r\n";
                        notes += item["body"] + "\r\n\r\n";
                    }

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

                    Application.Current.Dispatcher.Invoke(() => ViewWindowManager.GetInstance()
                                                          .InvokeViewer(changeLogPath));
                }
                catch (Exception e)
                {
                    Debug.WriteLine(e.Message);
                    Application.Current.Dispatcher.Invoke(
                        () => TrayIconManager.GetInstance().ShowNotification("",
                                                                             string.Format(TranslationHelper.GetString("Update_Error"), e.Message)));
                }
            });
        }
Example #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}"));
                }
            });
        }