Пример #1
0
        public void UpdateApp(Object sender, EventArgs args)
        {
            currentVersion = UpdateVersion.Version;

            Uri updateJson = new Uri(Program.urlBase + string.Format("update?v2={0}", UpdateVersion.Version.ToString()));

            Console.WriteLine("Updatejson: " + updateJson.ToString());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateJson);

            IAsyncResult res = request.BeginGetResponse(null, null);

            while (!res.IsCompleted)
            {
                if (worker.CancellationPending)
                {
                    return;
                }
            }
            HttpWebResponse response = request.EndGetResponse(res) as HttpWebResponse;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                    version = JsonSerializer.DeserializeFromReader <UpdateVersion>(reader);
                }
                if (version == null)
                {
                    return;
                }

                this.DialogResult = (version.updateVersion > UpdateVersion.Version) ? DialogResult.Yes : DialogResult.No;
                if (UpdateVersion.Version > version.updateVersion)
                {
                    this.DialogResult = DialogResult.Ignore;
                }
            }
        }
Пример #2
0
        public void UpdateApp(Object sender, EventArgs args)
        {
            currentVersion = UpdateVersion.Version;

            Uri updateJson = new Uri(Program.urlBase + string.Format("update?v={0}", UpdateVersion.Version.ToString()));

            Console.WriteLine("Updatejson: " + updateJson.ToString());
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(updateJson);

            IAsyncResult res = request.BeginGetResponse(null, null);

            while (!res.IsCompleted)
            {
                if (worker.CancellationPending)
                {
                    return;
                }
            }
            HttpWebResponse response = request.EndGetResponse(res) as HttpWebResponse;

            if (response.StatusCode == HttpStatusCode.OK)
            {
                using (StreamReader reader = new StreamReader(response.GetResponseStream())) {
                    version = JsonConvert.DeserializeObject <UpdateVersion>(reader.ReadToEnd());
                }
                if (version == null)
                {
                    return;
                }

                this.DialogResult = (version.updateVersion > UpdateVersion.Version) ? DialogResult.Yes : DialogResult.No;
                if (UpdateVersion.Version > version.updateVersion)
                {
                    this.DialogResult = DialogResult.Ignore;
                }


                // If not ignoring updates
                if (!Properties.Settings.Default.SigIgnore)
                {
                    // If new version is above current sig version
                    // Or if they don't exist

                    bool sigExist = File.Exists(Path.Combine(Program.appBase, "signatures.json"));
                    bool strExist = File.Exists(Path.Combine(Program.appBase, "structures.json"));
                    if ((version.sigVersion > Properties.Settings.Default.SigVersion) || version.sigVersion == -1 || !(sigExist && strExist))
                    {
                        Console.WriteLine("Downloading signatures");
                        string sigUrl = string.Format("update?f=signatures&v={0}", UpdateVersion.Version.ToString());
                        if (DownloadToProgramFile(sigUrl, "signatures.json"))
                        {
                            Console.WriteLine("Downloaded signatures");
                        }
                        Console.WriteLine("Downloading structures");
                        string strUrl = string.Format("update?f=structures&v={0}", UpdateVersion.Version.ToString());
                        if (DownloadToProgramFile(strUrl, "structures.json"))
                        {
                            Console.WriteLine("Downloaded structures");
                        }

                        Properties.Settings.Default.SigVersion = version.sigVersion;
                        Console.WriteLine(string.Format("ver1: {0} ver2: {1}", version.sigVersion, Properties.Settings.Default.SigVersion));
                        Properties.Settings.Default.Save();

                        // New signature update
                        // Reset forced stuff so people don't get stuck on that junk
                        if (version.sigVersion > 0)
                        {
                            Properties.Settings.Default.ForcedOpen = false;
                        }
                    }
                }
            }
        }