Exemplo n.º 1
0
        /// <summary>
        /// This function returns TRUE if the backups should be used, and FALSE if they should not.
        /// </summary>
        /// <param name="dataFile"></param>
        /// <param name="backupsDirectory"></param>
        /// <returns></returns>
        public Task <bool> CheckForOutdatedBackups(XivDataFile dataFile, DirectoryInfo backupsDirectory)
        {
            return(Task.Run(() =>
            {
                var backupDataFile =
                    new DirectoryInfo(Path.Combine(backupsDirectory.FullName, $"{dataFile.GetDataFileName()}.win32.index"));
                var currentDataFile =
                    new DirectoryInfo(Path.Combine(_gameDirectory.FullName, $"{dataFile.GetDataFileName()}.win32.index"));

                // Since the material addition directly adds to section 1 we can no longer check for outdated using that section header
                // so instead compare the hashes of sections 2 and 3
                byte[] currentHashSection2;
                byte[] currentHashSection3;
                byte[] backupHashSection2;
                byte[] backupHashSection3;
                try
                {
                    currentHashSection2 = _index.GetIndexSection2Hash(currentDataFile);
                    currentHashSection3 = _index.GetIndexSection3Hash(currentDataFile);
                }
                catch
                {
                    // Base files are f****d, use *any* backups.
                    return true;
                }

                try
                {
                    backupHashSection2 = _index.GetIndexSection2Hash(backupDataFile);
                    backupHashSection3 = _index.GetIndexSection3Hash(backupDataFile);
                }
                catch
                {
                    // Backups are f****d, can't use those.
                    return false;
                }


                return backupHashSection2.SequenceEqual(currentHashSection2) && backupHashSection3.SequenceEqual(currentHashSection3);
            }));
        }