Example #1
0
        private void MainWindow_OnLoaded(object sender, RoutedEventArgs e)
        {
            EnableBlur();
            string url     = "https://api.github.com/repos/WolvenKit/CP77Tools/releases";
            string getJson = HttpUitls.Get(url);
            JArray ret     = (JArray)JsonConvert.DeserializeObject(getJson);

            for (int git = 0; git < ret.Count; git++)
            {
                JObject githubInfo = (JObject)ret[git];

                if (githubInfo["name"].ToString().Contains("UI"))
                {
                    continue;
                }

                string versionInfo = githubInfo["tag_name"].ToString();

                try
                {
                    if (File.Exists("ToolsVersion"))
                    {
                        if (File.ReadAllText("ToolsVersion") != versionInfo)
                        {
                            HandyControl.Controls.Growl.Warning(Application.Current.FindResource("c_发现工具更新").ToString(), "InfoMessage");
                        }
                    }
                }
                catch (Exception ex)
                {
                    consoleBox.Inlines.Add(new Run(ex.Message + "\r\n"));
                }
                break;
            }

            if (File.Exists("config.json"))
            {
                JObject config = (JObject)JsonConvert.DeserializeObject(File.ReadAllText("config.json"));
                CreateDirectory.IsChecked = (bool?)config["CreateDirectory"];
                ParametersOnly.IsChecked  = (bool?)config["ParametersOnly"];
                ShowCMD.IsChecked         = (bool?)config["ShowCMD"];
                StreamingUpdate.IsChecked = (bool?)config["StreamingUpdate"];
            }
            else
            {
                string config = "{\"CreateDirectory\": " + CreateDirectory.IsChecked.ToString().ToLower() + ",\"ParametersOnly\": " + ParametersOnly.IsChecked.ToString().ToLower() + ",\"ShowCMD\": " + ShowCMD.IsChecked.ToString().ToLower() + ",\"StreamingUpdate\": " + StreamingUpdate.IsChecked.ToString().ToLower() + " }";
                File.WriteAllText("config.json", config);
            }

            AutoUpdater.Start("http://kit.alcedo.top/AutoUpdater.xml");
        }
Example #2
0
        //更新工具
        private void UpdateToolsClick(object sender, RoutedEventArgs e)
        {
            executionLoading.Visibility    = Visibility.Visible;
            DoRun_Button.IsEnabled         = false;
            DoArchive_Button.IsEnabled     = false;
            DoUpdateTools_Button.IsEnabled = false;
            DoDump_Button.IsEnabled        = false;
            DoPack_Button.IsEnabled        = false;
            DoRebuild_Button.IsEnabled     = false;
            consoleBox.Inlines.Add(new Run(Application.Current.FindResource("c_获取更新").ToString() + " \r\n"));
            string url = "https://api.github.com/repos/WolvenKit/CP77Tools/releases";

            if (StreamingUpdate.IsChecked == true)
            {
                url = "https://kit.alcedo.top/UpdateTools.json";
            }
            string getJson = HttpUitls.Get(url);
            JArray ret     = (JArray)JsonConvert.DeserializeObject(getJson);

            for (int git = 0; git < ret.Count; git++)
            {
                JObject githubInfo = (JObject)ret[git];

                if (githubInfo["name"].ToString().Contains("UI"))
                {
                    continue;
                }

                string versionInfo = githubInfo["tag_name"].ToString();
                string downloadUrl = githubInfo["assets"][0]["browser_download_url"].ToString();

                //文件路径
                string ToolsVersionPath = "ToolsVersion";

                try
                {
                    if (File.Exists(ToolsVersionPath))
                    {
                        if (File.ReadAllText(ToolsVersionPath) == versionInfo)
                        {
                            consoleBox.Inlines.Add(new Run()
                            {
                                Text = Application.Current.FindResource("c_无更新上").ToString() + versionInfo + Application.Current.FindResource("c_无更新下").ToString() + " \r\n", Foreground = new SolidColorBrush(Colors.Blue)
                            });
                            executionLoading.Visibility    = Visibility.Hidden;
                            DoRun_Button.IsEnabled         = true;
                            DoArchive_Button.IsEnabled     = true;
                            DoUpdateTools_Button.IsEnabled = true;
                            DoDump_Button.IsEnabled        = true;
                            DoPack_Button.IsEnabled        = true;
                            DoRebuild_Button.IsEnabled     = true;
                        }
                        else
                        {
                            consoleBox.Inlines.Add(new Run(downloadUrl + Application.Current.FindResource("c_下载中").ToString() + " \r\n"));
                            using (WebClient client = new WebClient())
                            {
                                client.DownloadFileAsync(new Uri(downloadUrl.Trim()), "CP77Tools.zip");
                                client.DownloadProgressChanged += client_DownloadProgressChanged;
                                client.DownloadFileCompleted   += client_DownloadFileCompleted;
                            }
                            File.WriteAllText(ToolsVersionPath, versionInfo);
                        }
                    }
                    else
                    {
                        consoleBox.Inlines.Add(new Run(downloadUrl + Application.Current.FindResource("c_下载中").ToString() + " \r\n"));
                        using (WebClient client = new WebClient())
                        {
                            client.DownloadFileAsync(new Uri(downloadUrl.Trim()), "CP77Tools.zip");
                            client.DownloadProgressChanged += client_DownloadProgressChanged;
                            client.DownloadFileCompleted   += client_DownloadFileCompleted;
                        }
                        File.WriteAllText(ToolsVersionPath, versionInfo);
                    }
                }
                catch (Exception ex)
                {
                    consoleBox.Inlines.Add(new Run(ex.Message + "\r\n"));
                    executionLoading.Visibility    = Visibility.Hidden;
                    DoRun_Button.IsEnabled         = true;
                    DoArchive_Button.IsEnabled     = true;
                    DoUpdateTools_Button.IsEnabled = true;
                    DoDump_Button.IsEnabled        = true;
                    DoPack_Button.IsEnabled        = true;
                    DoRebuild_Button.IsEnabled     = true;
                }
                break;
            }
        }