public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress <string> progress = null, XivLanguage language = XivLanguage.None)
        {
            return(Task.Run(async() =>
            {
                progress?.Report("Deleting mods...");

                var modding = new Modding(_gameDirectory);
                var backupsRestored = false;

                try
                {
                    // Try to restore the index entries to their original values by deleting any files added by TexTools
                    // and setting mods to disabled
                    await modding.DeleteAllFilesAddedByTexTools();
                    await modding.ToggleAllMods(false);
                    progress?.Report("Restoring index file backups...");
                }
                catch
                {
                    // If an exception occurred due to a corrupted modlist which couldn't be deserealized restore the backup index
                    // files by force
                    backupsRestored = await RestoreBackups(backupsDirectory);

                    if (!backupsRestored)
                    {
                        throw new Exception("Start Over Failed: Index backups missing/outdated.");
                    }
                }
                finally
                {
                    // If no exception occured, restore the backups anyway just to be safe but don't throw an exception if it fails
                    // due to outdated or missing backups since setting back the original index values should be enough hopefully
                    if (!backupsRestored)
                    {
                        backupsRestored = await RestoreBackups(backupsDirectory);

                        // If backups were not restored that means they were missing/outdated so try to make new backups now
                        if (!backupsRestored)
                        {
                            try
                            {
                                await BackupIndexFiles(backupsDirectory);
                            }
                            catch (Exception ex)
                            {
                                throw new Exception("Start Over Failed: Failed to update outdated backups.\n\n" + ex.Message);
                            }
                        }
                    }

                    progress?.Report("Deleting modded dat files...");

                    var dat = new Dat(_gameDirectory);

                    // Delete modded dat files
                    foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
                    {
                        var datFiles = await dat.GetModdedDatList(xivDataFile);

                        foreach (var datFile in datFiles)
                        {
                            File.Delete(datFile);
                        }

                        if (datFiles.Count > 0)
                        {
                            await RepairIndexDatCounts(xivDataFile);
                        }
                    }

                    progress?.Report("Cleaning up mod list...");

                    var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));

                    // Delete mod list
                    File.Delete(modListDirectory.FullName);

                    modding.CreateModlist();

                    progress?.Report("Rebuilding Cache...");

                    await Task.Run(async() =>
                    {
                        var _cache = new XivCache(_gameDirectory, language);
                        _cache.RebuildCache();
                    });
                }
            }));
        }
示例#2
0
        public Task PerformStartOver(DirectoryInfo backupsDirectory, IProgress <string> progress = null, XivLanguage language = XivLanguage.None)
        {
            return(Task.Run(async() =>
            {
                var modding = new Modding(_gameDirectory);
                var backupsRestored = false;

                // Stop the cache worker since we're blowing up the entire index file and db anyways.
                // The cache rebuild will start it up again after the cache is rebuilt.
                XivCache.CacheWorkerEnabled = false;

                try
                {
                    // Try restoring the indexes FIRST.
                    backupsRestored = await RestoreBackups(backupsDirectory);
                    progress?.Report("Restoring index file backups...");

                    if (!backupsRestored)
                    {
                        throw new Exception("Start Over Failed: Index backups missing/outdated.");
                    }
                }
                catch (Exception ex)
                {
                    try
                    {
                        // If the index restore failed, try just disabling.
                        await modding.DeleteAllFilesAddedByTexTools();
                        await modding.ToggleAllMods(false);
                        progress?.Report("Index restore failed, attempting to delete all mods instead...");
                    } catch
                    {
                        throw new Exception("Start Over Failed: Index Backups Invalid and Unable to Disable all mods.");
                    }
                }
                finally
                {
                    progress?.Report("Deleting modded dat files...");

                    var dat = new Dat(_gameDirectory);

                    // Delete modded dat files
                    foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
                    {
                        var datFiles = await dat.GetModdedDatList(xivDataFile);

                        foreach (var datFile in datFiles)
                        {
                            File.Delete(datFile);
                        }

                        if (datFiles.Count > 0)
                        {
                            await RepairIndexDatCounts(xivDataFile);
                        }
                    }

                    progress?.Report("Cleaning up mod list...");

                    var modListDirectory = new DirectoryInfo(Path.Combine(_gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));

                    // Delete mod list
                    File.Delete(modListDirectory.FullName);

                    modding.CreateModlist();

                    progress?.Report("Rebuilding Cache...");

                    await Task.Run(async() =>
                    {
                        XivCache.RebuildCache();
                    });
                }
            }));
        }
        /// <summary>
        /// Event handler for the start over menu item clicked
        /// </summary>
        private async void Menu_StartOver_Click(object sender, RoutedEventArgs e)
        {
            var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);

            var index    = new Index(gameDirectory);
            var outdated = false;

            if (index.IsIndexLocked(XivDataFile._0A_Exd))
            {
                FlexibleMessageBox.Show(UIMessages.IndexLockedErrorMessage, UIMessages.IndexLockedErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            var result = FlexibleMessageBox.Show(UIMessages.StartOverMessage, UIMessages.StartOverTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory);

                if (!Directory.Exists(indexBackupsDirectory.FullName))
                {
                    FlexibleMessageBox.Show(UIMessages.BackupFolderAccessErrorMessage,
                                            UIMessages.IndexBackupsErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }

                var filesToCheck = new XivDataFile[] { XivDataFile._01_Bgcommon, XivDataFile._04_Chara, XivDataFile._06_Ui };

                var problemChecker = new ProblemChecker(gameDirectory);

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

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

                    var outdatedCheck = await problemChecker.CheckForOutdatedBackups(xivDataFile, indexBackupsDirectory);

                    if (!outdatedCheck)
                    {
                        FlexibleMessageBox.Show(UIMessages.OutdatedBackupsErrorMessage, UIMessages.IndexBackupsErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                        outdated = true;
                    }
                }

                await Task.Run(async() =>
                {
                    var modding = new Modding(gameDirectory);
                    await modding.DeleteAllFilesAddedByTexTools();

                    var dat = new Dat(gameDirectory);

                    var modListDirectory = new DirectoryInfo(Path.Combine(gameDirectory.Parent.Parent.FullName, XivStrings.ModlistFilePath));

                    var backupFiles = Directory.GetFiles(indexBackupsDirectory.FullName);

                    // Make sure backups exist
                    if (backupFiles.Length == 0)
                    {
                        FlexibleMessageBox.Show(string.Format(UIMessages.NoBackupsFoundErrorMessage, indexBackupsDirectory.FullName),
                                                UIMessages.BackupFilesMissingTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        // Toggle off all mods
                        await modding.ToggleAllMods(false);
                    }
                    else if (outdated)
                    {
                        // Toggle off all mods
                        await modding.ToggleAllMods(false);
                    }
                    else
                    {
                        // Copy backups to ffxiv folder
                        foreach (var backupFile in backupFiles)
                        {
                            if (backupFile.Contains(".win32.index"))
                            {
                                File.Copy(backupFile, $"{gameDirectory}/{Path.GetFileName(backupFile)}", true);
                            }
                        }
                    }

                    // Delete modded dat files
                    foreach (var xivDataFile in (XivDataFile[])Enum.GetValues(typeof(XivDataFile)))
                    {
                        var datFiles = await dat.GetModdedDatList(xivDataFile);

                        foreach (var datFile in datFiles)
                        {
                            File.Delete(datFile);
                        }

                        if (datFiles.Count > 0)
                        {
                            await problemChecker.RepairIndexDatCounts(xivDataFile);
                        }
                    }

                    // Delete mod list
                    File.Delete(modListDirectory.FullName);

                    modding.CreateModlist();
                });

                UpdateViews(ItemTreeView.SelectedItem as Category);

                await this.ShowMessageAsync(UIMessages.StartOverCompleteTitle, UIMessages.StartOverCompleteMessage);
            }
        }