Ejemplo n.º 1
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            // Testing
            // this.TabControl.IsEnabled = true;

            this.Title = string.Format("{0} v{1}", this.Title, Settings.Default.CurrentVersion);

            this.items = new List <Item>();

            this.codes = new Codes(this);

            var client = new WebClient
            {
                BaseAddress = Settings.Default.VersionUrl,
                Encoding    = Encoding.UTF8,
                CachePolicy =
                    new System.Net.Cache.RequestCachePolicy(
                        System.Net.Cache.RequestCacheLevel.BypassCache)
            };

            client.Headers.Add("Cache-Control", "no-cache");
            client.DownloadStringCompleted += this.ClientDownloadStringCompleted;

            // try to get current version
            try
            {
                client.DownloadStringAsync(new Uri(string.Format("{0}{1}", client.BaseAddress, "version.txt")));
            }
            catch (Exception ex)
            {
                this.LogError(ex, "Error loading current version.");
            }

            // try to load json data
            try
            {
                var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("BotwTrainer.items.json");
                if (file != null)
                {
                    using (var reader = new StreamReader(file))
                    {
                        var data = reader.ReadToEnd();
                        this.json = JObject.Parse(data);

                        this.JsonViewer.Load(data);

                        // Shrine data
                        var shrines = this.json.SelectToken("Shrines").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var shrine in shrines)
                        {
                            this.ShrineList.Items.Add(new ComboBoxItem {
                                Content = shrine.Value["Name"], Tag = shrine.Name
                            });
                        }

                        // Tower data
                        var towers = this.json.SelectToken("Towers").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var tower in towers)
                        {
                            this.TowerList.Items.Add(new ComboBoxItem {
                                Content = tower.Value["Name"], Tag = tower.Name
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                this.LogError(ex, "Error loading json.");
            }

            IpAddress.Text = Settings.Default.IpAddress;

            this.Save.IsEnabled = this.HasChanged;
        }
Ejemplo n.º 2
0
        private void MainWindowLoaded(object sender, RoutedEventArgs e)
        {
            // Testing
            // this.TabControl.IsEnabled = true;

            Title = string.Format("{0} v{1}", Title, Settings.Default.CurrentVersion);

            var netVersion = new GetDotNetVersion().Get45PlusFromRegistry();

            if (netVersion.Version == null)
            {
                MessageBoxResult choice = MessageBox.Show("Required .NET Version 4.6.2 not found. Please update.", "New Version", MessageBoxButton.OKCancel);

                if (choice == MessageBoxResult.OK)
                {
                    Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=53345");
                }
                else
                {
                    return;
                }
            }
            else
            {
                Title += string.Format(" | .NET Version: {0}", netVersion.Version);
            }

            items = new List <Item>();

            objects = new List <Obj>();

            codes = new Codes(this);

            var client = new WebClient
            {
                BaseAddress = Settings.Default.VersionUrl,
                Encoding    = Encoding.UTF8,
                CachePolicy =
                    new System.Net.Cache.RequestCachePolicy(
                        System.Net.Cache.RequestCacheLevel.BypassCache)
            };

            client.Headers.Add("Cache-Control", "no-cache");
            client.DownloadStringCompleted += ClientDownloadStringCompleted;

            // try to get current version
            try
            {
                client.DownloadStringAsync(new Uri(string.Format("{0}{1}", client.BaseAddress, "version.txt")));
            }
            catch (Exception ex)
            {
                LogError(ex, "Error loading current version.");
            }

            // try to load json data
            try
            {
                var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("BotwTrainer.items.json");
                if (file != null)
                {
                    using (var reader = new StreamReader(file))
                    {
                        var data = reader.ReadToEnd();
                        json = JObject.Parse(data);

                        JsonViewer.Load(data);

                        // Shrine data
                        var shrines = json.SelectToken("Shrines").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var shrine in shrines)
                        {
                            ShrineList.Items.Add(new ComboBoxItem {
                                Content = shrine.Value["Name"], Tag = shrine.Name
                            });
                        }

                        // Tower data
                        var towers = json.SelectToken("Towers").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var tower in towers)
                        {
                            TowerList.Items.Add(new ComboBoxItem {
                                Content = tower.Value["Name"], Tag = tower.Name
                            });
                        }

                        // Ranches
                        var ranches = json.SelectToken("Ranches").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var ranch in ranches)
                        {
                            RanchList.Items.Add(new ComboBoxItem {
                                Content = ranch.Value["Name"], Tag = ranch.Name
                            });
                        }

                        // Misc
                        var misc = json.SelectToken("Misc").Value <JObject>().Properties().ToList().OrderBy(x => x.Name);
                        foreach (var m in misc)
                        {
                            MiscList.Items.Add(new ComboBoxItem {
                                Content = m.Value["Name"], Tag = m.Name
                            });
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                LogError(ex, "Error loading json.");
            }

            IpAddress.Text = Settings.Default.IpAddress;

            Save.IsEnabled = HasChanged;
        }