Ejemplo n.º 1
0
        public Task <bool> RestoreBackups(DirectoryInfo backupsDirectory)
        {
            return(Task.Run(async() =>
            {
                var backupFiles = Directory.GetFiles(backupsDirectory.FullName);
                var filesToCheck = new XivDataFile[] { XivDataFile._0A_Exd, XivDataFile._04_Chara, XivDataFile._06_Ui, XivDataFile._01_Bgcommon };
                var outdated = false;

                foreach (var xivDataFile in filesToCheck)
                {
                    var backupFile = new DirectoryInfo($"{backupsDirectory.FullName}\\{xivDataFile.GetDataFileName()}.win32.index");

                    if (!File.Exists(backupFile.FullName))
                    {
                        continue;
                    }

                    try
                    {
                        var outdatedCheck = await CheckForOutdatedBackups(xivDataFile, backupsDirectory);

                        if (!outdatedCheck)
                        {
                            outdated = true;
                        }
                    }
                    catch {
                        // If the outdated check errored out, we likely have completely broken internal dat files.
                        // ( Either deleted or 0 byte files ), so replacing them with *anything* is an improvement.
                    }
                }

                var _index = new Index(_gameDirectory);
                // Make sure backups exist and are up to date unless called with forceRestore true
                if (backupFiles.Length != 0 && !outdated)
                {
                    // Copy backups to ffxiv folder
                    foreach (var backupFile in backupFiles)
                    {
                        if (backupFile.Contains(".win32.index"))
                        {
                            File.Copy(backupFile, $"{_gameDirectory}/{Path.GetFileName(backupFile)}", true);
                        }
                    }

                    // Update all the index counts to be safe, in case the user's index backups were generated when some mod dats existed.
                    _index.UpdateAllIndexDatCounts();
                    return true;
                }
                return false;
            }));
        }