Ejemplo n.º 1
0
        private void GcDownloadStep1SetupArray()
        {
            string compareID = string.Empty;

            //common
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = MetaDataXml,
                Xpath               = @"//protocol/@version",
                GetRequestParamater = "metadata_protocol_version",
                IsRequired          = true
            });
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = GameInfoXml,
                Xpath               = @"//protocol/game/part_versions/version[@name='client']/@installed",
                GetRequestParamater = "client_current_version",
                IsRequired          = true
            });
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = GameInfoXml,
                Xpath               = @"//protocol/game/id",
                GetRequestParamater = "game_id",
                IsRequired          = true
            });
            GameCenterProperty idProp       = GameCenterProperties[GameCenterProperties.Count - 1];
            string             pathToGameId = Path.Combine(SelectedClient, GameInfoXml);

            //set wot as default
            idProp.Value = "wot";
            if (!File.Exists(pathToGameId))
            {
                Logging.Error("xml file {0} does not exist!");
            }
            else
            {
                idProp.Value = XmlUtils.GetXmlStringFromXPath(pathToGameId, idProp.Xpath);
                Logging.Info("id processed as {0}", idProp.Value);
            }
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = GameInfoXml,
                Xpath               = @"//protocol/game/client_type",
                GetRequestParamater = "client_type",
                IsRequired          = true
            });
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = GameInfoXml,
                Xpath               = @"//protocol/game/localization",
                GetRequestParamater = "lang",
                IsRequired          = true
            });
            GameCenterProperties.Add(new GameCenterProperty()
            {
                FileName            = GameInfoXml,
                Xpath               = @"//protocol/game/update_urls/value",
                GetRequestParamater = "BASE_URL",
                IsRequired          = true
            });

            //different
            if (idProp.Value.ToLower().Contains("wot"))
            {
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/predefined_section/chain_id",
                    GetRequestParamater = "chain_id",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/version",
                    GetRequestParamater = "metadata_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='locale']/@installed",
                    GetRequestParamater = "locale_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='sdcontent']/@installed",
                    GetRequestParamater = "sdcontent_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='hdcontent']/@installed",
                    GetRequestParamater = "hdcontent_current_version",
                    IsRequired          = false
                });
            }
            else if (idProp.Value.ToLower().Contains("wows"))
            {
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/predefined_section/chain_id",
                    GetRequestParamater = "chain_id",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/version",
                    GetRequestParamater = "metadata_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='locale']/@installed",
                    GetRequestParamater = "locale_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='sdcontent']/@installed",
                    GetRequestParamater = "sdcontent_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='udsound']/@installed",
                    GetRequestParamater = "udsound_current_version",
                    IsRequired          = false
                });
            }
            else if (idProp.Value.ToLower().Contains("wowp"))
            {
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/chain_id",
                    GetRequestParamater = "chain_id",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = MetaDataXml,
                    Xpath               = @"//protocol/metadata_version",
                    GetRequestParamater = "metadata_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='wwlocale']/@installed",
                    GetRequestParamater = "wwlocale_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='content']/@installed",
                    GetRequestParamater = "content_current_version",
                    IsRequired          = true
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='hdcontent']/@installed",
                    GetRequestParamater = "hdcontent_current_version",
                    IsRequired          = false
                });
                GameCenterProperties.Add(new GameCenterProperty()
                {
                    FileName            = GameInfoXml,
                    Xpath               = @"//protocol/game/part_versions/version[@name='tm']/@installed",
                    GetRequestParamater = "tm_current_version",
                    IsRequired          = true
                });
            }
        }
Ejemplo n.º 2
0
        private async void GcDownloadStep3Init()
        {
            GcDownloadStep3NextButton.IsEnabled = false;
            //get patch list info
            GcDownloadStep3StackPanel.Children.Clear();
            GcDownloadStep3StackPanel.Children.Add(new TextBlock()
            {
                Text = Translations.GetTranslatedString("loading") + "..."
            });

            //build the get request
            Logging.Info("Building GET request");
            StringBuilder requestBuilder = new StringBuilder();

            if ((bool)GcDownloadStep1GameCenterCheckbox.IsChecked)
            {
                requestBuilder.Append("https://wguswgc-wgcct.wargaming.net/api/v1/wgc_update/?protocol_version=1.9");
                foreach (GameCenterProperty gameCenterProperty in GameCenterProperties)
                {
                    requestBuilder.AppendFormat("&{0}={1}", gameCenterProperty.GetRequestParamater, gameCenterProperty.Value);
                }
            }
            else
            {
                List <GameCenterProperty> baseUrlPropertyList = GameCenterProperties.Where(gc => gc.GetRequestParamater.Equals("BASE_URL")).ToList();
                if (baseUrlPropertyList == null || baseUrlPropertyList.Count == 0)
                {
                    Logging.Error("Failed to get WG patch instructions (getting BASE_URL)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
                GameCenterProperty urlProperty = baseUrlPropertyList[0];
                requestBuilder.AppendFormat("{0}api/v1/patches_chain/?protocol_version=1.9", urlProperty.Value);
                foreach (GameCenterProperty gameCenterProperty in GameCenterProperties)
                {
                    if (string.IsNullOrWhiteSpace(gameCenterProperty.Value) && !gameCenterProperty.IsRequired)
                    {
                        continue;
                    }
                    else if (gameCenterProperty.GetRequestParamater.Equals("BASE_URL"))
                    {
                        continue;
                    }
                    requestBuilder.AppendFormat("&{0}={1}", gameCenterProperty.GetRequestParamater, gameCenterProperty.Value);
                }
            }

            requestBuilder.AppendFormat("&{0}={1}", "installation_id", "relhax_update_request");
            Logging.Info("Built GET request: {0}", requestBuilder.ToString());

            XmlDocument xmlDocument = null;

            //download based on request
            using (client = new WebClient())
            {
                string xmlString = string.Empty;
                try
                {
                    xmlString = await client.DownloadStringTaskAsync(requestBuilder.ToString());
                }
                catch (Exception ex)
                {
                    Logging.Exception(ex.ToString());
                    Logging.Error("Failed to get WG patch instructions (webClient)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
                if (string.IsNullOrWhiteSpace(xmlString))
                {
                    Logging.Error("Failed to get WG patch instructions (empty string)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
                xmlDocument = XmlUtils.LoadXmlDocument(xmlString, XmlLoadType.FromString);
                if (xmlDocument == null)
                {
                    Logging.Error("Failed to get WG patch instructions (XML parse error)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
            }

            //get all file notes
            XmlNodeList fileList = XmlUtils.GetXmlNodesFromXPath(xmlDocument, @"//file");

            if (fileList == null || fileList.Count == 0)
            {
                Logging.Info("0 WG patches (empty node list with xpath '//file')");
                GcDownloadStep3StackPanel.Children.Clear();
                GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                {
                    Text       = Translations.GetTranslatedString("GcDownloadStep3NoFilesUpToDate"),
                    Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                });
                GcDownloadStep3NextButton.IsEnabled = false;
                return;
            }

            //build list of files to download
            string baseURL = XmlUtils.GetXmlStringFromXPath(xmlDocument, @"//protocol/patches_chain/web_seeds/url");

            if (string.IsNullOrEmpty(baseURL))
            {
                Logging.Error("Failed to get WG patch instructions (XML parse error of web_seeds)");
                GcDownloadStep3StackPanel.Children.Clear();
                GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                {
                    Text       = Translations.GetTranslatedString("error"),
                    Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                });
                GcDownloadStep3NextButton.IsEnabled = false;
                return;
            }
            Logging.Info("BaseURL parsed as {0}", baseURL);


            if (PatchFileProperties == null)
            {
                PatchFileProperties = new List <PatchFileProperty>();
            }
            PatchFileProperties.Clear();
            foreach (XmlNode element in fileList)
            {
                PatchFileProperty prop = new PatchFileProperty
                {
                    BaseURL = baseURL
                };

                //size
                XmlNode node = element.SelectSingleNode(@"size");
                if (node == null)
                {
                    Logging.Error("Failed to get WG patch instructions (XML parse error of nodes in fileList)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
                prop.Size = ulong.Parse(node.InnerText);

                //name
                node = element.SelectSingleNode(@"name");
                if (node == null)
                {
                    Logging.Error("Failed to get WG patch instructions (XML parse error of nodes in fileList)");
                    GcDownloadStep3StackPanel.Children.Clear();
                    GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                    {
                        Text       = Translations.GetTranslatedString("error"),
                        Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                    });
                    GcDownloadStep3NextButton.IsEnabled = false;
                    return;
                }
                prop.Filename   = node.InnerText.Split('/')[1];
                prop.FolderName = node.InnerText.Split('/')[0];

                PatchFileProperties.Add(prop);
                Logging.Info("Parsed Patch File: Filename={0}, FolderName={1}, Size={2}", prop.Filename, prop.FolderName, prop.Size);
            }

            //display them to UI
            GcDownloadStep3StackPanel.Children.Clear();
            foreach (PatchFileProperty pfp in PatchFileProperties)
            {
                GcDownloadStep3StackPanel.Children.Add(new TextBlock()
                {
                    Text       = string.Format("File={0}, Size={1}", pfp.Filename, FileUtils.SizeSuffix(pfp.Size, 1, true, false)),
                    Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                });
            }
            GcDownloadStep3NextButton.IsEnabled = true;
        }
Ejemplo n.º 3
0
        private void GcDownloadStep1GetParams()
        {
            GcDownloadStep1CurrentlySelectedClient.Text = string.Format(Translations.GetTranslatedString("GcDownloadStep1CurrentlySelectedClient"),
                                                                        SelectedClient);
            GcDownloadStep1CurrentlySelectedClient.Foreground = System.Windows.Media.Brushes.DarkGreen;

            string missingFiles = (bool)GcDownloadStep1GameCenterCheckbox.IsChecked ? GcDownloadStep1CheckMissingFilesWgc() : GcDownloadStep1CheckMissingFiles();

            if (!string.IsNullOrWhiteSpace(missingFiles))
            {
                MessageBox.Show(string.Format("{0}:{1}{2}", Translations.GetTranslatedString("GcMissingFiles"), Environment.NewLine, missingFiles.ToString()));
                GcDownloadStep1ResetParams(false, false);
                return;
            }

            Logging.Info("All required files found, collecting data for GET request");
            bool gotAllValues = true;

            GcDownloadStep1KeyValueGrid.Children.Clear();

            //loop to get all the params
            for (int i = 0; i < GameCenterProperties.Count; i++)
            {
                GameCenterProperty gameCenterProperty = GameCenterProperties[i];

                gameCenterProperty.KeyBlock = new TextBlock()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch,
                    Text       = gameCenterProperty.GetRequestParamater,
                    Foreground = UISettings.CurrentTheme.TextblockColorset.ForegroundBrush.Brush
                };
                //https://stackoverflow.com/questions/18659435/programmatically-add-label-to-grid
                Grid.SetColumn(gameCenterProperty.KeyBlock, 0);
                Grid.SetRow(gameCenterProperty.KeyBlock, i);
                GcDownloadStep1KeyValueGrid.Children.Add(gameCenterProperty.KeyBlock);

                gameCenterProperty.ValueBlock = new TextBlock()
                {
                    HorizontalAlignment = HorizontalAlignment.Stretch,
                    VerticalAlignment   = VerticalAlignment.Stretch
                };
                Grid.SetColumn(gameCenterProperty.ValueBlock, 1);
                Grid.SetRow(gameCenterProperty.ValueBlock, i);
                GcDownloadStep1KeyValueGrid.Children.Add(gameCenterProperty.ValueBlock);

                string completeLocationPath = string.Empty;
                if ((bool)GcDownloadStep1GameCenterCheckbox.IsChecked)
                {
                    completeLocationPath = gameCenterProperty.FileName.Equals(WgcNotificationsXml) ? notificationsXmlPathWgc : versionXmlPathWgc;
                }
                else
                {
                    completeLocationPath = gameCenterProperty.FileName.Equals(GameInfoXml) ? gameInfoXmlPath : metaDataXmlPath;
                }

                Logging.Info("Getting property '{0}' for file {1}", gameCenterProperty.Xpath, completeLocationPath);
                gameCenterProperty.Value = XmlUtils.GetXmlStringFromXPath(completeLocationPath, gameCenterProperty.Xpath);

                if (string.IsNullOrWhiteSpace(gameCenterProperty.Value))
                {
                    if (gameCenterProperty.IsRequired)
                    {
                        Logging.Error("Failure getting property!");
                        gameCenterProperty.GaveError = true;
                        if (gameCenterProperty.ValueBlock != null)
                        {
                            gameCenterProperty.ValueBlock.Text       = Translations.GetTranslatedString("error");
                            gameCenterProperty.ValueBlock.Foreground = System.Windows.Media.Brushes.Red;
                        }
                        gotAllValues = false;
                    }
                    else
                    {
                        gameCenterProperty.GaveError = false;
                        Logging.Warning("Did not get property '{0}, but IsRequired=False", gameCenterProperty.Xpath);
                        if (gameCenterProperty.ValueBlock != null)
                        {
                            gameCenterProperty.ValueBlock.Text       = Translations.GetTranslatedString("none");
                            gameCenterProperty.ValueBlock.Foreground = System.Windows.Media.Brushes.Orange;
                        }
                    }
                }
                else
                {
                    Logging.Info("Success getting property! ({0})", gameCenterProperty.Value);
                    gameCenterProperty.GaveError = false;
                    if (gameCenterProperty.ValueBlock != null)
                    {
                        gameCenterProperty.ValueBlock.Text       = gameCenterProperty.Value;
                        gameCenterProperty.ValueBlock.Foreground = System.Windows.Media.Brushes.DarkGreen;
                    }
                }
                GameCenterProperties[i] = gameCenterProperty;
            }


            if (gotAllValues)
            {
                Logging.Info("All GET parameters found!");
                GcDownloadStep1Next.IsEnabled = true;
            }
            else
            {
                Logging.Info("Not all GET parameters found!");
                GcDownloadStep1ResetParams(false, false);
                return;
            }
        }