Exemple #1
0
        private UpdateInfo[] LoadUpdates(string folder, AppInfo info)
        {
            string versionsFolder = Path.Combine(folder, info.downloadBaseDir);

            UpdateInfo[] updates = new UpdateInfo[info.versions.Length];
            for (int i = 0; i < info.versions.Length; i++)
            {
                double cur = info.versions[i];
                string curVersionFolder = Path.Combine(versionsFolder, VersionFormatter.ToString(cur));
                string infoFile         = Path.Combine(curVersionFolder, "info.json");
                updates[i] = UpdateInfo.FromJson(File.ReadAllText(infoFile));
            }
            return(updates);
        }
Exemple #2
0
        //void LoadBOFilesOnline()
        //{
        //    foreach (var obo in Settings.OnlineBOs)
        //    {
        //        try
        //        {
        //            WebClient webClient = new WebClient();
        //            webClient.DownloadStringCompleted += delegate (object sender, DownloadStringCompletedEventArgs e)
        //            {
        //                if (e.Cancelled || e.Error != null)
        //                {
        //                    Console.WriteLine(string.Format("Could not download Build Order at {0}.", obo));
        //                    return;
        //                }

        //                BuildOrderData boData = BuildOrderData.FromJson(e.Result);
        //                BuildOrderList.AddBuildOrders(boData);
        //            };
        //            webClient.DownloadStringAsync(new Uri(obo));
        //        }
        //        catch (ArgumentNullException e) { Console.WriteLine(e); }
        //        catch (WebException e) { Console.WriteLine(e); }
        //        catch (NotSupportedException e) { Console.WriteLine(e); }

        //    }
        //}
        public void CheckUpdates(bool notify = false)
        {
            try
            {
                WebClient webClient = new WebClient();
                webClient.DownloadStringCompleted += delegate(object sender, DownloadStringCompletedEventArgs e)
                {
                    if (e.Cancelled || e.Error != null)
                    {
                        if (notify)
                        {
                            ShowUpdate(Strings.Update_ConnectionError, "");
                        }
                        Console.WriteLine("Could not download latest Update Information. Please make sure this link is valid and you are connected to the internet.");
                        return;
                    }
                    UpdateInfo dataOnline = UpdateInfo.FromJson(e.Result);
                    //if (!ResourceExists(FolderNames.UpdateJsonPack))
                    //{
                    //    Console.WriteLine("Your" + FolderNames.UpdateJsonPack + "is missing. Please backup your builds and redownload the app.");
                    //    ShowUpdate(string.Format(Strings.Update_FileError, FolderNames.UpdateJsonPack), dataOnline.Latest.Link);
                    //}

                    using (var r = new StreamReader(GetResourceStream(new Uri(FolderNames.UpdateJsonPack)).Stream))
                    {
                        string     jsonLocal = r.ReadToEnd();
                        UpdateInfo dataLocal = UpdateInfo.FromJson(jsonLocal);
                        if (dataLocal.Latest.Id < dataOnline.Latest.Id)
                        {
                            HasLatestUpdate = false;
                            ShowUpdate(string.Format(Strings.Update_NewVersion, dataOnline.Latest.Name, dataOnline.Latest.Description), dataOnline.Latest.Link);
                        }
                        else
                        {
                            if (notify)
                            {
                                ShowUpdate(Strings.Update_UpToDate, "");
                            }
                            Console.WriteLine("You are up-to-date!");
                        }
                    }
                };
                webClient.DownloadStringAsync(new Uri(Settings.UpdateURL));
            }
            catch (ArgumentNullException e) { Console.WriteLine(e); }
            catch (WebException e) { Console.WriteLine(e); }
            catch (NotSupportedException e) { Console.WriteLine(e); }
        }