private void LoadGameVersionAsync()
        {
            //Settings MySettings = null;

/*            bool noSave = false;
 *          if (Program.Settings == null )
 *          {
 *              //MySettings = Commons.GetSettings();
 *          } else
 *          {
 *
 *              noSave = true;
 *          }*/
            VersionInfoImport Import = WGAPI.GetVersionInfo();

            if (Import.Status.Equals("ok"))
            {
                VersionInfo Info      = Import.VersionInfo;
                long        UpdatedAt = Info.Updated;
                string      Version   = Info.GameVersion;
                this.GameDate    = Commons.ConvertToDate(UpdatedAt);
                this.GameVersion = Version;
                if (Program.Settings != null)
                {
                    Program.Settings.GameUpdated = GameDate;
                    Program.Settings.GameVersion = Version;
                }
            }
        }
Exemple #2
0
        private void HelpAbout_Load(object sender, EventArgs e)
        {
            String         jsonFile = Commons.GetCurrentDirectory() + "/randomizer.json";
            ProgramVersion versionInfo;

            if (File.Exists(jsonFile))
            {
                string jsonText = File.ReadAllText(jsonFile);
                versionInfo = JsonConvert.DeserializeObject <ProgramVersion>(jsonText);
            }
            else
            {
                versionInfo = WGAPI.GetProgramVersion();
            }

            programVersion.Text = versionInfo.Version;
            updateTime.Text     = versionInfo.Updated;

            Settings settings = Commons.GetSettings();

            gameVersion.Text = settings.GameVersion;
            string cc = Properties.Settings.Default.Locale;
            string dt = Commons.ConvertDateToLocalFormat(settings.GameUpdated, cc);

            gameDate.Text = dt;
            string cinfo = (settings.ConsumablesInfoVersion == null || settings.ConsumablesInfoVersion.Equals("")) ? "": settings.ConsumablesInfoVersion;

            lblConsumablesInfoVer.Text = cinfo;
        }
        public void loadUserShipsInPort(long UserID, bool hideMessage = false)
        {
            LOG.Debug("loadUserShipsInPort()");
            PlayerShipImport Importer = WGAPI.GetPlayerShips(UserID);

            if (Importer.Status.ToLower().Equals("ok"))
            {
                List <PlayerShip> PersonalShips = new List <PlayerShip>();
                Dictionary <string, List <PlayerShip> > ImportedShips = Importer.Ships;

                foreach (KeyValuePair <string, List <PlayerShip> > ShipID in ImportedShips)
                {
                    foreach (PlayerShip PShip in ShipID.Value)
                    {
                        PersonalShips.Add(PShip);
                    }
                }

                string FileName = Commons.GetPersonalShipsFileName();
                BinarySerialize.WriteToBinaryFile <List <PlayerShip> >(FileName, PersonalShips);

                if (hideMessage == false)
                {
                    MessageBox.Show("Your ships have been imported.", "Load Personal Data", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                LOG.Debug("User ships downloaded ok");
            }
            else
            {
                LOG.Warning("Download of users ships failed!");
                MessageBox.Show("Some error occured during gathering of data. Try again later.", "Connection error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
        private void CheckProgramVersion()
        {
            LOG.Debug("CheckProgramVersion()-RandomizerVersion: " + Application.ProductVersion);
            ProgramVersion versionInfo = WGAPI.GetProgramVersion();

            ChangeLog         = versionInfo.ChangeLog;
            RandomizerVersion = versionInfo.Version;

            DateTime updateDate = new DateTime();

            updateDate = DateTime.Parse(versionInfo.Updated);
            if (!versionInfo.Version.Equals(Application.ProductVersion))
            {
                LOG.Debug("New version available.");
                string cc        = Properties.Settings.Default.Locale;
                string msg       = "The new version " + RandomizerVersion + " is available as per " + Commons.ConvertDateToLocalFormat(updateDate, cc) + "\nDo You want to download it now?";
                var    userInput = MessageBox.Show(msg, "New version of the WoWs Randomizer available!", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (userInput == DialogResult.Yes)
                {
                    LOG.Debug("User requested download of new Randomizer version");
                    string downloadsPath = KnownFolders.GetPath(KnownFolder.Downloads);
                    string fileName      = downloadsPath + "\\" + Path.GetFileName(System.Reflection.Assembly.GetEntryAssembly().Location);
                    using (WebClient wc = new WebClient())
                    {
                        wc.DownloadFile(versionInfo.URL, fileName);
                        MessageBox.Show("The new version has been downloaded to Your download folder.\n(" + fileName + ")\nClose this program and replace the EXE-file in this folder with the downloaded one.", "New version downloaded", MessageBoxButtons.OK, MessageBoxIcon.Information);
                        LOG.Debug("Download complete.");
                    }
                }
            }
        }
        private void VersionChecker()
        {
            LOG.Debug("VersionChecker()");
            if (Program.Settings == null)
            {
                return;
            }
            if (Program.Settings.GameVersion == null)
            {
                LOG.Debug("No version stored. Getting new version.");
                LoadGameVersionAsync();
            }
            if (Program.Settings.Server == null || Program.Settings.Server.Equals(""))
            {
                return;
            }

            DateTime Today     = DateTime.Now;
            DateTime LastCheck = Program.Settings.LastChecked;

            if (LastCheck == null || DateTime.Compare(LastCheck.AddHours(23), Today) <= 0)
            {
                LOG.Debug("Last check not performed or more than 23 hours ago. Perform new check!");
                Program.Settings.LastChecked = Today;
                if (Program.Settings.UserID != 0)
                {
                    LOG.Debug("Loading users ships");
                    loadUserShipsInPort(Program.Settings.UserID, true);
                }

                VersionInfoImport Import = WGAPI.GetVersionInfo();
                if (Import.Status.Equals("ok"))
                {
                    VersionInfo Info = Import.VersionInfo;
                    GameVersion = Info.GameVersion;
                    GameDate    = Commons.ConvertToDate(Info.Updated);
                    LOG.Info("Gameversion: " + Info.GameVersion);
                    if (Program.Settings.GameVersion != null && Program.Settings.GameVersion.Equals(Info.GameVersion))
                    {
                        if (DateTime.Compare(Program.Settings.GameUpdated, GameDate) != 0)
                        {
                            LOG.Info("Game data needs to be updated. Not same game date.");
                            UpdateNeeded = true;
                        }
                    }
                    else
                    {
                        LOG.Info("Game data needs to be updated. Not same game version");
                        UpdateNeeded = true;
                    }
                }
            }
            else
            {
                Program.Settings.LastChecked = Today;
            }
        }
        private void UpdateShips()
        {
            LOG.Debug("UpdateShips()");
            List <Ship> AllShips = WGAPI.GetAllShipsFromWG();

            if (AllShips != null)
            {
                Program.AllShips = AllShips;
            }
        }
 private void UpdateModules()
 {
     LOG.Debug("UpdateModules()");
     try
     {
         Program.AllModules = WGAPI.GetAllModules();
         foreach (KeyValuePair <string, ModuleData> Mod in Program.AllModules)
         {
             ModuleTranslator.Transfer(Mod.Value);
         }
         BinarySerialize.WriteToBinaryFile(Commons.GetModulesFileName(), Program.AllModules);
     }
     catch (Exception e) { LOG.Error("Error during Module import: ", e); }
 }
 private void ShipImage_Click(object sender, EventArgs e)
 {
     LOG.Debug("ShipImage_Click: " + ShipName.Text.ToString());
     if (messageBox.Visible)
     {
         messageBox.Visible = false;
     }
     if (ShipName.Text.ToString().Equals("") || ShipName.Text.ToString().Equals(" "))
     {
         LOG.Debug("No ship selected");
         return;
     }
     WGAPI.OpenShipWikipedia(ShipName.Text.ToString());
 }
        private void UpdateFlags()
        {
            LOG.Debug("UpdateFlags()");
            ConsumablesImporter Importer = WGAPI.GetFlags();

            if (Importer.Status.ToLower().Equals("ok"))
            {
                Program.Flags = new List <Consumable>();
                foreach (KeyValuePair <string, Consumable> Flag in Importer.Data)
                {
                    Program.Flags.Add(Flag.Value);
                }
                BinarySerialize.WriteToBinaryFile(Commons.GetFlagsFileName(), Program.Flags);
            }
        }
        private void GetMessage()
        {
            messageBox.Visible = false;
            MessageImporter message = WGAPI.GetMessage();

            if (message.Status.Equals("ok"))
            {
                string dontshowId = Properties.Settings.Default.MessageBoxId;
                LOG.Debug("Dont show MessageID: " + dontshowId);
                LOG.Debug("Loaded MessageID: " + message.MessageID);

                if (dontshowId.Trim().Equals(message.MessageID.Trim(), StringComparison.OrdinalIgnoreCase))
                {
                    LOG.Debug("Ignoring MessageID: " + message.MessageID);
                    messageBox.Visible = false;
                }
                else if (!dateIsInRange(message.StartDate, message.EndDate))
                {
                    LOG.Debug("Date is not in range for MessageID: " + message.MessageID + " (" + message.StartDate + "-" + message.EndDate + ")");
                    messageBox.Visible = false;
                }
                else
                {
                    LOG.Info("Showing message " + message.MessageID);

                    messageBox.Controls["message"].Text  = message.Message;
                    messageBox.Controls["datespan"].Text = message.EndDate + " - " + message.StartDate;
                    if (message.URL.Length > 0)
                    {
                        messageBox.Controls["link"].Text = message.URL;
                    }
                    else
                    {
                        messageBox.Controls["link"].Text    = "";
                        messageBox.Controls["link"].Visible = false;
                    }
                    messageBox.Controls["id"].Text = message.MessageID;

                    LeftPanel.Click  += FormRandomizer_Click;
                    RightPanel.Click += FormRandomizer_Click;

                    messageBox.Visible = true;
                }
            }
        }
        private void UpdateUpgrades()
        {
            LOG.Debug("UpdateUpgrades()");
            ConsumablesImporter Importer = WGAPI.GetUpgrades();

            if (Importer.Status.ToLower().Equals("ok"))
            {
                Program.Upgrades = new List <Consumable>();
                foreach (KeyValuePair <string, Consumable> Data in Importer.Data)
                {
                    Program.Upgrades.Add(Data.Value);
                }
                BinarySerialize.WriteToBinaryFile(Commons.GetUpgradesFileName(), Program.Upgrades);
            }
            else
            {
                LOG.Warning("Unable to import Upgrades: " + Importer.Status.ToString());
            }
        }
 private bool UpdateUserPlayerIDAsync()
 {
     if (Program.Settings.UserID == 0 && !Program.Settings.Nickname.Equals("") && !Program.Settings.Server.Equals(""))
     {
         PlayerSearch PlayerImporter = WGAPI.SearchPlayer(Program.Settings.Nickname);
         if (PlayerImporter.Status.ToLower() == "ok")
         {
             Program.Settings.UserID = PlayerImporter.Player[0].ID;
             return(true);
         }
         else
         {
             MessageBox.Show("Unable to find a player with that nickname: " + Program.Settings.Nickname, "Error on Get User Info");
             return(false);
         }
     }
     else
     {
         return(true);
     }
 }
        public void UpdateCommanderSkills(bool ForceUpdate = false)
        {
            LOG.Debug("UpdateCommanderSkills()");
            SkillImporter Importer = WGAPI.GetCommanderSkills();

            if (Importer.Status.ToLower().Equals("ok"))
            {
                string csv = Properties.Settings.Default.CommanderSkillsVersion;

                if (ForceUpdate || (!csv.Equals("") && !csv.Equals(Importer.Version)))
                {
                    Program.CommanderSkills = new Dictionary <string, List <Skill> >();
                    Program.CommanderSkills = Importer.Data;
                    BinarySerialize.WriteToBinaryFile(Commons.GetCommanderSkillFileName(), Program.CommanderSkills);
                    Properties.Settings.Default.CommanderSkillsVersion = Importer.Version;
                    Properties.Settings.Default.Save();
                    LOG.Info("Imported commander skills: " + Program.CommanderSkills["dd"].Count + ", " + Program.CommanderSkills["ca"].Count + ", " + Program.CommanderSkills["bb"].Count + ", " + Program.CommanderSkills["cv"].Count);
                }
                else
                {
                    LOG.Info("Commander skills are up to date. No import/refresh needed.");
                }
            }
            else
            {
                LOG.Warning("Unable to import commander skills: " + Importer.Status.ToString());
            }

/*            SkillImporter Importer = WGAPI.GetCommanderSkills();
 *          if (Importer.Status.ToLower().Equals("ok"))
 *          {
 *              Program.CommanderSkills = new List<Skill>();
 *              foreach (KeyValuePair<string, Skill> SkillData in Importer.Data)
 *              {
 *                  Program.CommanderSkills.Add(SkillData.Value);
 *              }
 *              BinarySerialize.WriteToBinaryFile(Commons.GetCommanderSkillFileName(), Program.CommanderSkills);
 *          }*/
        }
Exemple #14
0
        private void Clan_Load(object sender, EventArgs e)
        {
            string cc = Properties.Settings.Default.Locale;

            this.Text = ClanID + ": ";
            ClanImport Import = WGAPI.GetClanInfo(ClanID);

            if (Import.Status.Equals("ok"))
            {
                ClanData Claninfo = Import.Data[ClanID.ToString()];
                this.Text = ClanID + ": [" + Claninfo.Tag + "] - " + Claninfo.Name;

                lblCreated.Text     = Commons.ConvertDateToLocalFormat(Commons.ConvertToDate(Claninfo.Created), cc);
                lblCreatedBy.Text   = Claninfo.CreatedBy;
                lblLeader.Text      = Claninfo.Leader;
                lblMemberCount.Text = Claninfo.Count + " members.";
                rtDescription.Text  = Claninfo.Description;

                AddHeaders();
                AddRows(Claninfo.Members);
            }
        }
        public static void AddConsumablesInfo(bool ForceUpdate = false)
        {
            if (Program.Settings == null)
            {
                return;
            }
            ConsumablesInfoImporter import = WGAPI.GetConsumablesInfo();

            if (!import.Status.Equals("ok"))
            {
                return;
            }

            if (ForceUpdate || (Program.Settings.ConsumablesInfoVersion != null && !Program.Settings.ConsumablesInfoVersion.Equals(import.Version)))
            {
                foreach (Ship ship in Program.AllShips)
                {
                    ship.Consumables = new List <ConsumableInfo>();
                    ship.Airstrike   = new ModuleAirstrike();
                }
                Program.Settings.ConsumablesInfoVersion = import.Version;

                foreach (KeyValuePair <string, List <ConsumablesInfoTypeImporter> > list in import.Consumables)
                {
                    Enum.TryParse(list.Key, out ConsumableType CType);

                    foreach (ConsumablesInfoTypeImporter con in list.Value)
                    {
                        List <Ship> ShipList = new List <Ship>();

                        if (con.GroupSelection != null && !con.GroupSelection.Equals(""))
                        {
                            ShipList = ShipFinder.FindShips(con.ID, con.GroupSelection, con.Exceptions);
                        }
                        else
                        {
                            ShipList = ShipFinder.FindShips(con.ID, con.Group, con.Exceptions);
                        }
                        foreach (Ship ship in ShipList)
                        {
                            ship.Consumables.Add(new ConsumableInfo()
                            {
                                Duration = con.Duration, Range = con.Range, Type = CType, Cooldown = con.Cooldown, Charges = con.Charges, ExtraInfo = con.ExtraInfo
                            });
                        }
                    }
                }

                foreach (KeyValuePair <string, ModuleAirstrike> airstrike in import.Airstrike)
                {
                    long shipId = Convert.ToInt64(airstrike.Key);
                    Ship ship   = Program.AllShips.Find(e => e.ID == shipId);
                    if (ship != null)
                    {
                        ship.Airstrike = airstrike.Value;
                    }
                }
                UpdateUpgradesInfo();
                BinarySerialize.WriteToBinaryFile <List <Ship> >(Commons.GetShipListFileName(), Program.AllShips);
            }
        }
        private void LoadUserData(long userId)
        {
            string cc = Properties.Settings.Default.Locale;
            PlayerClanInfoImport clanImport = WGAPI.GetPlayerClanInfo(userId);

            if (clanImport.Status.Equals("ok"))
            {
                PlayerClanInfoData data     = clanImport.Data[userId.ToString()];
                ClanBaseData       ClanInfo = data.ClanData;
                string             txt      = "";
                txt += "[" + ClanInfo.Tag + "] " + ClanInfo.Name + " (" + ClanInfo.Count + " members)\n" + data.Role + "\n(member since: " + Commons.ConvertDateToLocalFormat(Commons.ConvertToDate(data.Joined), cc) + ")";
                lblClanInfo.Text       = txt;
                btnGetClanInfo.Tag     = data.ClanID;
                btnGetClanInfo.Visible = true;
            }
            else
            {
                lblClanInfo.Text       = "(no clan info availalbe)";
                btnGetClanInfo.Visible = false;
            }
            PlayerPersonalDataImport Import = WGAPI.GetPlayerPersonalData(userId);

            if (Import.Status.Equals("ok"))
            {
                string locale = Properties.Settings.Default.Locale;
                if (locale.Length == 0)
                {
                    locale = "en-US";
                }

                PlayerPersonalData pdata = Import.Data[userId.ToString()];

                lblStatsUpdatedAt.Text = "The statistics was last updated at " + Commons.ConvertDateToLocalFormat(Commons.ConvertToDate(pdata.StatsUpdatedAt), locale);
                lblCreated.Text        = "Account created: " + Commons.ConvertDateToLocalFormat(Commons.ConvertToDate(pdata.AccountCreated), locale);
                string txt = "Profile is ";
                if (pdata.HiddenProfile)
                {
                    txt += "HIDDEN";
                }
                else
                {
                    txt += "VISIBLE";
                }

                lblHidden.Text = txt;

                PlayerStatistics        stats       = pdata.Statistics;
                PlayerBatteryStatistics mainBattery = stats.PVPStatistics.MainBattery;
                lblHits.Text     = mainBattery.Hits.ToString();
                lblFrags.Text    = mainBattery.Kills.ToString();
                lblFired.Text    = mainBattery.ShotsFired.ToString();
                lblMaxKills.Text = mainBattery.MaxKilled.ToString();

                Ship findShip = Program.AllShips.Find(x => x.ID == mainBattery.MaxKilledShipId);
                lblMaxKillsShip.Text = findShip.Name;

                PlayerBatteryStatistics secBattery = stats.PVPStatistics.SecondBattery;
                lblHits2.Text     = secBattery.Hits.ToString();
                lblFrags2.Text    = secBattery.Kills.ToString();
                lblFired2.Text    = secBattery.ShotsFired.ToString();
                lblMaxKills2.Text = secBattery.MaxKilled.ToString();

                findShip = Program.AllShips.Find(x => x.ID == secBattery.MaxKilledShipId);
                lblMaxKillsShip2.Text = findShip.Name;

                PlayerBatteryStatistics torps = stats.PVPStatistics.Torpedoes;
                lblHits3.Text     = torps.Hits.ToString();
                lblFrags3.Text    = torps.Kills.ToString();
                lblFired3.Text    = torps.ShotsFired.ToString();
                lblMaxKills3.Text = torps.MaxKilled.ToString();

                findShip = Program.AllShips.Find(x => x.ID == torps.MaxKilledShipId);
                lblMaxKillsShip3.Text = findShip.Name;

                lblWin.Text          = stats.PVPStatistics.Wins.ToString();
                lblLoss.Text         = stats.PVPStatistics.Losses.ToString();
                lblDraw.Text         = stats.PVPStatistics.Draws.ToString();
                lblTotalBattles.Text = stats.PVPStatistics.Battles.ToString();
                lblSurvived.Text     = stats.PVPStatistics.SurvivedBattles.ToString();
                lblSurvivedWins.Text = stats.PVPStatistics.SurvivedBattlesWin.ToString();

                lblXPTotal.Text   = stats.PVPStatistics.Experience.ToString();
                lblXPMax.Text     = stats.PVPStatistics.MaxXP.ToString();
                findShip          = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxXPShipId);
                lblXPMaxShip.Text = findShip.Name;

                lblDamageTotal.Text   = stats.PVPStatistics.DamageDealt.ToString();
                lblDamageMax.Text     = stats.PVPStatistics.MaxDamageDealt.ToString();
                findShip              = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxDamageDealtShipId);
                lblDamageMaxShip.Text = findShip.Name;

                lblKillsTotal.Text          = stats.PVPStatistics.ShipsKilled.ToString();
                lblKillsMax.Text            = stats.PVPStatistics.MaxShipsKilled.ToString();
                findShip                    = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxShipsKilledShipId);
                lblKillsMaxShip.Text        = findShip.Name;
                lblPlanesKilledTotal.Text   = stats.PVPStatistics.PlanesKilled.ToString();
                lblPlanesKilledMax.Text     = stats.PVPStatistics.MaxPlanesKilled.ToString();
                findShip                    = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxPlanesKilledShipId);
                lblPlanesKilledMaxShip.Text = findShip.Name;

                lblMaxShipsSpotted.Text = stats.PVPStatistics.MaxShipsSpotted.ToString();
                findShip = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxShipsSpottedShipId);
                lblMaxShipsSpottedShipId.Text = findShip.Name;
                lblShipsSpottedTotal.Text     = stats.PVPStatistics.ShipsSpotted.ToString();
                lblMaxScouting.Text           = stats.PVPStatistics.MaxScoutingDamage.ToString();
                findShip = Program.AllShips.Find(x => x.ID == stats.PVPStatistics.MaxScountingDamageShipId);
                lblMaxScoutingShip.Text = findShip.Name;
                lblScoutingTotal.Text   = stats.PVPStatistics.ScoutingDamage.ToString();

                lblCapturePoints.Text        = stats.PVPStatistics.CapturePoints.ToString();
                lblControlCapturePoints.Text = stats.PVPStatistics.ControlCapturePoints.ToString();
                lblDroppedCapturePoints.Text = stats.PVPStatistics.DroppedCapturePoints.ToString();

                PlayerAuxilliaryStatistics aux = stats.PVPStatistics.Ramming;
                lblRamming.Text  = aux.Kills.ToString();
                aux              = stats.PVPStatistics.Aircraft;
                lblAircraft.Text = aux.Kills.ToString();
            }
        }
 private void ShipImage_Click(object sender, EventArgs e)
 {
     WGAPI.OpenShipWikipedia(ShipName.Text.ToString());
 }