Пример #1
0
        internal static AutoUpdaterConfig Parse(Uri location)
        {
            try
            {
                JObject json = new JObject();
                using (WebClient wc = new WebClient())
                {
                    Uri info = new Uri(location, "update.json");
                    json = JObject.Parse(wc.DownloadString(info.AbsoluteUri));
                }

                Version version    = Version.Parse(json["version"].ToObject <string>());
                string  filename   = json["filename"].ToObject <string>();
                Uri     uri        = new Uri(location, filename);
                string  executable = json["executable"].ToObject <string>();
                string  md5        = json["md5"].ToObject <string>();
                string  launchArgs = json["launchArgs"].ToObject <string>();

                AutoUpdaterConfig ret = new AutoUpdaterConfig(version, uri, filename, executable, md5, launchArgs);
                return(ret);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Пример #2
0
        internal static AutoUpdaterConfig Parse(Uri location)
        {
            try
            {
                JObject json = new JObject();
                using (WebClient wc = new WebClient())
                {
                    json = JObject.Parse(wc.DownloadString(location.AbsoluteUri));
                }

                Version version    = Version.Parse(json["version"].ToObject <string>());
                Uri     uri        = new Uri(String.Format("https://github.com/hoangcaominh/RealTimeDRCPointsDisplayer/releases/download/{0}/Live.DRC.Points.Calculator.{0}.zip", version.ToString()));
                string  executable = json["executable"].ToObject <string>();
                string  md5        = json["md5"].ToObject <string>();
                string  launchArgs = json["launchArgs"].ToObject <string>();

                AutoUpdaterConfig ret = new AutoUpdaterConfig(version, uri, executable, md5, launchArgs);
                return(ret);
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(null);
            }
        }
Пример #3
0
        private async Task DownLoadFiles(AutoUpdaterConfig updater_config, string base_uri)
        {
            updater_config.LastUpdateTime = DateTime.Now;
            await AutoUpdaterHelper.GetUpdateItems(new DirectoryInfo( Environment.CurrentDirectory ), base_uri, "", updater_config.UpdateList, updater_config, LogFun, s => tips.Text = $"正在下载{s}");

            updater_config.UpdateList = null;
        }
        private void BgWorker_DoWork(object sender, DoWorkEventArgs e)
        {
            IAutoUpdater application = (IAutoUpdater)e.Argument;

            if (!AutoUpdaterConfig.ExistsOnServer(application.UpdateInfoLocation))
            {
                e.Cancel = true;
            }
            else
            {
                e.Result = AutoUpdaterConfig.Parse(application.UpdateInfoLocation);
            }
        }
        private void DownloadUpdate(AutoUpdaterConfig update)
        {
            AutoUpdaterDownloadForm form   = new AutoUpdaterDownloadForm(update.Uri, update.MD5, applicationInfo.ApplicationIcon);
            DialogResult            result = form.ShowDialog(applicationInfo.Context);

            if (result == DialogResult.OK)
            {
                UpdateApplication(form.TempFilePath, Path.GetDirectoryName(applicationInfo.ApplicationAssembly.Location), update.Executable, update.LaunchArgs);

                Application.Exit();
            }
            else if (result == DialogResult.Abort)
            {
                MessageBox.Show("Download aborted. The new version is not installed.", "Download Aborted", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
            else
            {
                MessageBox.Show("Download failed. A problem was encountered while downloading, please try again later.", "Download Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
        }
Пример #6
0
        private void Button1_Click(object sender, EventArgs e)
        {
            DirectoryInfo            di     = new DirectoryInfo(Environment.CurrentDirectory);
            List <Config.UpdateItem> list   = new List <Config.UpdateItem>();
            AutoUpdaterConfig        config = new AutoUpdaterConfig();

            try
            {
                if (File.Exists(textBox1.Text))
                {
                    config = jss.Deserialize <AutoUpdaterConfig>(File.ReadAllText(textBox1.Text));
                }

                File.Delete(textBox1.Text);
            }
            catch (Exception ee)
            {
            }



            if (checkBox1.Checked)
            {
                except.Add(Application.ExecutablePath);
                AutoUpdaterHelper.GenerateUpdateItems(di, list, except.ToArray());
            }
            else
            {
                AutoUpdaterHelper.GenerateUpdateItems(di, list, except.ToArray());
            }


            config.LastUpdateTime = DateTime.Now;
            config.UpdateList     = list;

            File.WriteAllText(textBox1.Text, jss.Serialize(config));
            MessageBox.Show("生成完毕");
        }
        private void BgWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            if (e.Cancelled)
            {
                MessageBox.Show("There was a problem while connecting to the server. Please try again later.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else if (e.Result == null)
            {
                MessageBox.Show("There was a problem while locating update file. Please try again later.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }
            else
            {
                AutoUpdaterConfig update = (AutoUpdaterConfig)e.Result;

                if (update != null && update.IsNewerVersion(applicationInfo.ApplicationVersion))
                {
                    if (MessageBox.Show("A newer version is available. Would you like to download?", "Update", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        DownloadUpdate(update);
                    }
                }
            }
        }
Пример #8
0
        private async void AutoUpdate_Shown(object sender, EventArgs e)
        {
            if (Config?.AutoUpdaterConfig == null)
            {
                MessageBox.Show("配置信息丢失");
                Close();
                return;
            }

            HttpClient client     = new HttpClient();
            string     remote_uri = Config.AutoUpdaterConfig.RemoteUpdateConfig;
            string     launch_app = Config.AutoUpdaterConfig.LuanchApplication;
            string     config     = null;

            while (Config.LinkTimes != 0)
            {
                try
                {
                    config = await client.GetStringAsync(Config.AutoUpdaterConfig.RemoteUpdateConfig);

                    break;
                }
                catch (Exception eeee)
                {
                    Config.LinkTimes--;
                    await Task.Run(() => Thread.Sleep(Config.TimeSpan));
                }
            }
            AutoUpdaterConfig updater_config = null;

            try
            {
                updater_config = jss.Deserialize <AutoUpdaterConfig>(config);
            }
            catch (Exception eeee)
            {
                LogFun("远程更新列表有误");
                this.Close();
                return;
            }

            Uri uri = new Uri(remote_uri);


            await DownLoadFiles(updater_config, $"{uri.Scheme}://{uri.Authority}");

            if (string.IsNullOrWhiteSpace(updater_config.RemoteUpdateConfig))
            {
                updater_config.RemoteUpdateConfig = remote_uri;
            }

            if (string.IsNullOrWhiteSpace(updater_config.LuanchApplication))
            {
                updater_config.LuanchApplication = launch_app;
            }
            tips.Text = "下载完毕";
            SavaConfigFun(updater_config);

            if (!string.IsNullOrWhiteSpace(updater_config.LuanchApplication))
            {
                StartApplication(new FileInfo(updater_config.LuanchApplication));
            }
            this.Close();
        }
Пример #9
0
        static void Main(string[] args)
        {
            jss.RegisterConverters(new JavaScriptConverter[] { new DateTimeConvert() });
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            if (args != null && args.Length > 0)
            {
                Application.Run(new ConfigForm());
            }
            else
            {
                string            config_file   = "AutoUpdaterConfig.json";
                string            background    = "bg.png";
                int               time_span     = 3000;
                int               link_times    = 10;
                AutoUpdaterConfig updaterConfig = null;

                try
                {
                    if (ConfigurationManager.AppSettings.AllKeys.Contains("config_file"))
                    {
                        config_file = ConfigurationManager.AppSettings["config_file"];
                    }
                    updaterConfig = jss.Deserialize <AutoUpdaterConfig>(File.ReadAllText(config_file));
                }
                catch (Exception e)
                {
                    Log(e);
                    File.WriteAllText(config_file, jss.Serialize(new AutoUpdaterConfig()));
                    MessageBox.Show($"配置出错,已生成配置文件{config_file}");
                    return;
                }



                try
                {
                    time_span = int.Parse(ConfigurationManager.AppSettings["time_span"]);
                }
                catch (Exception ee)
                {
                }

                try
                {
                    link_times = int.Parse(ConfigurationManager.AppSettings["link_times"]);
                }
                catch (Exception ee)
                {
                }


                if (ConfigurationManager.AppSettings.AllKeys.Contains("config_file"))
                {
                    background = ConfigurationManager.AppSettings["background"];
                }

                Log("");
                Log("");
                Log("");
                Log("");
                Log("");
                Log("");
                Log("");
                Log("----------------------------------------本次更新开始----------------------------------------");
                Application.Run(new Updater()
                {
                    Config = new Config.SelfConfig()
                    {
                        LinkTimes         = link_times,
                        TimeSpan          = time_span,
                        AutoUpdaterConfig = updaterConfig,
                        Background        = background
                    },
                    LogFun        = Log,
                    SavaConfigFun = s => File.WriteAllText(config_file, jss.Serialize(s))
                });
                Log("----------------------------------------本次更新结束----------------------------------------");
            }
        }