Ejemplo n.º 1
0
        private void CheckForUpdate(Form f)
        {
            Task.Run(() =>
            {
                string outputPath = Path.Combine(Path.GetTempPath(), Path.GetTempFileName());
                UpdateSetting s   =
                    JsonConvert.DeserializeObject <UpdateSetting>(Properties.Settings.Default.SoftwareUpdateSettings);
                try
                {
                    FileManager.DownloadFile(s.Version, outputPath);
                    int version = Convert.ToInt16(File.ReadAllText(outputPath).Trim());

                    if (version > Version)
                    {
                        f.Invoke(new Action(() =>
                        {
                            var r = MessageBox.Show("New Update Available\nUpdate Now?", "Update",
                                                    MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation);

                            if (r == DialogResult.Yes)
                            {
                                DownloadUpdatedSoftware(s.Software);
                            }

                            Environment.Exit(Environment.ExitCode);
                        }));
                    }
                }
                catch (Exception e)
                {
                }
            });
        }
Ejemplo n.º 2
0
        private void HandelSoftwareUpdateSettings()
        {
            string       jsonSetting = Properties.Settings.Default.SoftwareUpdateSettings;
            List <Input> inputs;

            var vf = new Input()
            {
                Hint        = "Version File",
                Index       = 0,
                Length      = 0,
                IsMandatory = false,
                Name        = "vf"
            };
            var sf = new Input()
            {
                Hint        = "Software File",
                Index       = 1,
                Length      = 0,
                IsMandatory = false,
                Name        = "sf"
            };

            if (!jsonSetting.Equals(""))
            {
                UpdateSetting s = JsonConvert.DeserializeObject <UpdateSetting>(jsonSetting);
                sf.Value = s.Software;
                vf.Value = s.Version;
            }
            inputs = new List <Input>()
            {
                vf, sf
            };

            InputDialog dialog = new InputDialog("Software Update Settings", inputs, this);

            if (dialog.ShowIt() == ResultType.OK)
            {
                var result = dialog.Output;

                UpdateSetting newSetting = new UpdateSetting();
                newSetting.Version  = result.Find(x => x.Name.Equals(vf.Name)).Value;
                newSetting.Software = result.Find(x => x.Name.Equals(sf.Name)).Value;
                Properties.Settings.Default.SoftwareUpdateSettings =
                    JsonConvert.SerializeObject(newSetting);
                Properties.Settings.Default.Save();
            }
        }