コード例 #1
0
 protected void SetDefaultConfig()
 {
     CharacterDataFolderPath        = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\My Games\\FINAL FANTASY XIV - A Realm Reborn";
     DefaultCharacterID             = "";
     UpdateRequestTimeout_Sec       = 20;
     UpdateCheckFrequency_Days      = 1.0;
     LastUpdateCheck                = DateTimeOffset.FromUnixTimeSeconds(0);
     LastConfigUpdateCheck          = DateTimeOffset.FromUnixTimeSeconds(0);
     ShowInitialWarning             = true;
     LastProgramUpdateVersionSeen   = VersionInfoHelper.Parse("0.9.0.0");                           //	First released version.
     EarliestPresetTimestampAllowed = new DateTimeOffset(2020, 2, 18, 10, 00, 00, new TimeSpan(0)); //	Time of servers up for patch 5.2.
 }
コード例 #2
0
 protected void ReadSavedConfig()
 {
     //	Read the config if we have it.
     if (File.Exists(ConfigFilePath))
     {
         List <string> lines = File.ReadLines(ConfigFilePath).ToList();
         foreach (string line in lines)
         {
             if (line.Split('=').First().Trim().Equals("CharacterDataFolderPath"))
             {
                 CharacterDataFolderPath = line.Split('=').Last().Trim();
             }
             if (line.Split('=').First().Trim().Equals("DefaultCharacterID"))
             {
                 DefaultCharacterID = line.Split('=').Last().Trim();
             }
             if (line.Split('=').First().Trim().Equals("UpdateRequestTimeout_Sec"))
             {
                 UpdateRequestTimeout_Sec = int.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("UpdateCheckFrequency_Days"))
             {
                 UpdateCheckFrequency_Days = double.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("LastUpdateCheck"))
             {
                 LastUpdateCheck = DateTimeOffset.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("LastConfigUpdateCheck"))
             {
                 LastConfigUpdateCheck = DateTimeOffset.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("ShowInitialWarning"))
             {
                 ShowInitialWarning = bool.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("LastProgramUpdateVersionSeen"))
             {
                 LastProgramUpdateVersionSeen = VersionInfoHelper.Parse(line.Split('=').Last().Trim());
             }
             if (line.Split('=').First().Trim().Equals("EarliestPresetTimestampAllowed"))
             {
                 EarliestPresetTimestampAllowed = DateTimeOffset.Parse(line.Split('=').Last().Trim());
             }
         }
     }
 }
コード例 #3
0
        protected void CheckForUpdates()
        {
            //	Set up a simple splash screen so the user knows what's going on.
            Form waitForm = new Form();

            waitForm.ControlBox    = false;
            waitForm.MaximizeBox   = false;
            waitForm.MinimizeBox   = false;
            waitForm.ShowIcon      = false;
            waitForm.StartPosition = FormStartPosition.CenterScreen;
            waitForm.MinimumSize   = waitForm.Size;
            waitForm.MaximumSize   = waitForm.Size;
            Label statusLabel = new Label();

            statusLabel.Size      = waitForm.Size;
            statusLabel.TextAlign = System.Drawing.ContentAlignment.MiddleCenter;
            statusLabel.Text      = "Checking for updates.";
            waitForm.Controls.Add(statusLabel);
            waitForm.Show();

            //	Make a backup directory to hold previous config in the case of bad updates.
            string backupFolderPath = ConfigFolderPath + "\\ConfigUpdatesBackup";

            if (!Directory.Exists(backupFolderPath))
            {
                Directory.CreateDirectory(backupFolderPath);
            }

            //	Do the actual online checks.
            using (HttpClient httpClient = new HttpClient())
            {
                //	Set the request timeout.  The default is unreasonable for how little data we are dealing with (under 10 KiB total).
                httpClient.Timeout = TimeSpan.FromSeconds(ProgramSettings.UpdateRequestTimeout_Sec);

                //	Empty version strings until we can fill them.
                string programVer           = "";
                string gameDataCfgVer       = "";
                string zoneDictionaryDatVer = "";
                bool   versionInfoValid     = false;

                //	Try to grab the current versions of things.
                try
                {
                    //	Perform the http request.
                    string currentVersionsRawData = httpClient.GetStringAsync("https://punishedpineapple.github.io/WaymarkLibrarian/Support/CurrentVersions.dat").Result;

                    //	Process what we got back.
                    string[] currentVersionsLines = currentVersionsRawData.Split(new char[] { '\r', '\n' });
                    foreach (string line in currentVersionsLines)
                    {
                        if (line.Split('=').First().Trim().Equals("Program"))
                        {
                            programVer = line.Split('=').Last().Trim();
                        }
                        if (line.Split('=').First().Trim().Equals("GameData.cfg"))
                        {
                            gameDataCfgVer = line.Split('=').Last().Trim();
                        }
                        if (line.Split('=').First().Trim().Equals("ZoneDictionary.dat"))
                        {
                            zoneDictionaryDatVer = line.Split('=').Last().Trim();
                        }
                    }

                    //	Verify that we got the bits that we need.  This isn't the best validity check, but it's probably good enough.
                    versionInfoValid = programVer.Length > 0 && gameDataCfgVer.Length > 0 && zoneDictionaryDatVer.Length > 0;

                    //	Mark that we checked for *program* updates.
                    ProgramSettings.LastUpdateCheck = DateTimeOffset.UtcNow;
                }
                catch (Exception exception)
                {
                    //	If we couldn't get valid version info, mark that we tried.
                    MessageBox.Show("Unable to retrieve current version information.  This is likely due to lack of internet access or DNS lookup failure.  Full error is as follows:\r\n\r\n\r\n" + exception.ToString(), "Failure!");
                    ProgramSettings.LastUpdateCheck       = DateTimeOffset.UtcNow;
                    ProgramSettings.LastConfigUpdateCheck = DateTimeOffset.UtcNow;
                }

                //	If we have valid version info, proceed with the rest of it.
                if (versionInfoValid)
                {
                    //	See if a newer version of the program is available than what we've seen.
                    ProgramSettings.LastProgramUpdateVersionSeen = VersionInfoHelper.Parse(programVer);
                    if (VersionInfoHelper.Parse(programVer) > ProgramSettings.LastProgramUpdateVersionSeen)
                    {
                        MessageBox.Show("A new version of this program is available.  Click on the update link in the main window or go to https://github.com/PunishedPineapple/WaymarkLibrarian/releases to download the latest version.", "New Version");
                    }

                    //	Only handle configuration updates if the program itself is up to date (since file formats could conceivably change).
                    if (VersionInfoHelper.Parse(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)) == ProgramSettings.LastProgramUpdateVersionSeen)
                    {
                        //	Update game data config.
                        if (gameDataCfgVer != GameDataSettings.GameVersion &&
                            MessageBox.Show("A new version of the game data configuration file was found.  Update now?", "Update?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            try
                            {
                                if (File.Exists(GameDataSettings.ConfigFilePath) && Directory.Exists(backupFolderPath))
                                {
                                    File.Copy(GameDataSettings.ConfigFilePath, backupFolderPath + "\\GameData.cfg." + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".bak", true);
                                }
                                byte[] rawData = httpClient.GetByteArrayAsync("https://punishedpineapple.github.io/WaymarkLibrarian/Support/GameData.cfg").Result;
                                File.WriteAllBytes(GameDataSettings.ConfigFilePath, rawData);
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show("Offsets update failed: " + exception.ToString(), "Failure!");
                            }
                        }

                        //	Update zone dictionary.
                        if (zoneDictionaryDatVer != ZoneInfoSettings.GameVersion &&
                            MessageBox.Show("A new version of the zone dictionary file was found.  Update now?", "Update?", MessageBoxButtons.YesNo) == DialogResult.Yes)
                        {
                            try
                            {
                                if (File.Exists(ZoneInfoSettings.ConfigFilePath) && Directory.Exists(backupFolderPath))
                                {
                                    File.Copy(ZoneInfoSettings.ConfigFilePath, backupFolderPath + "\\ZoneDictionary.dat." + DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss") + ".bak", true);
                                }
                                byte[] rawData = httpClient.GetByteArrayAsync("https://punishedpineapple.github.io/WaymarkLibrarian/Support/ZoneDictionary.dat").Result;
                                File.WriteAllBytes(ZoneInfoSettings.ConfigFilePath, rawData);
                            }
                            catch (Exception exception)
                            {
                                MessageBox.Show("Zone info update failed: " + exception.ToString(), "Failure!");
                            }
                        }

                        //	Mark that we checked for configuration updates.
                        ProgramSettings.LastConfigUpdateCheck = DateTimeOffset.UtcNow;
                    }
                }
            }

            //	Close the splash screen now that we're done.
            waitForm.Close();
        }
コード例 #4
0
        public Config()
        {
            //	Get the path to the settings folder.
            ConfigFolderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\PunishedPineapple\\WaymarkLibrarian\\";

            //	Create the children.
            ProgramSettings  = new ProgramConfig(ConfigFolderPath + "Options.cfg");
            GameDataSettings = new GameDataConfig(ConfigFolderPath + "GameData.cfg");
            ZoneInfoSettings = new ZoneInfo(ConfigFolderPath + "ZoneDictionary.dat");

            //	Check for updates if it is time to do so.
            if ((DateTimeOffset.UtcNow - ProgramSettings.LastUpdateCheck > TimeSpan.FromDays(ProgramSettings.UpdateCheckFrequency_Days)) ||
                (DateTimeOffset.UtcNow - ProgramSettings.LastConfigUpdateCheck > TimeSpan.FromDays(ProgramSettings.UpdateCheckFrequency_Days) && VersionInfoHelper.Parse(FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)) == ProgramSettings.LastProgramUpdateVersionSeen))
            {
                CheckForUpdates();
                GameDataSettings.Reload();
                ZoneInfoSettings.Reload();
            }

            //	The alias file lives one directory up since we may want to share it with other programs.
            CharacterAliasSettings = new CharacterAliasConfig(Directory.GetParent(ConfigFolderPath).Parent.FullName + "\\CharacterAliases.cfg");
        }