示例#1
0
        private void CheckForOldModList()
        {
            var oldModListFileDirectory = new DirectoryInfo($"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}/TexTools/TexTools.modlist");

            if (File.Exists(oldModListFileDirectory.FullName))
            {
                var modListContent = File.ReadAllLines(oldModListFileDirectory.FullName);

                if (modListContent.Length > 0)
                {
                    var warningMessage =
                        "Older TexTools ModList Found.\n\nThe Older ModList is incompatible with this version.\n\nIn order to use this version, all previous mods will be disabled, and the previous ModList erased.\n\n" +
                        "If you would like to retain your mods, it is recommended that you create a backup ModPack in the older TexTools Version, then import it into this one.\n\nWould you like to continue?";

                    if (FlexibleMessageBox.Show(
                            $"{warningMessage}",
                            "Older ModList Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) ==
                        DialogResult.Yes)
                    {
                        var modding = new Modding(_gameDirectory);
                        var index   = new Index(_gameDirectory);
                        var dat     = new Dat(_gameDirectory);
                        var error   = false;

                        if (index.IsIndexLocked(XivDataFile._0A_Exd))
                        {
                            FlexibleMessageBox.Show("Unable to continue while game is running.\n\nPlease exit the game and try again.", $"ModList Disable Failed", MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            error = true;
                        }
                        else
                        {
                            try
                            {
                                modding.DisableOldModList(oldModListFileDirectory);
                            }
                            catch (Exception ex)
                            {
                                error = true;
                                var message =
                                    $"There was an error attempting to disable a mod from previous version.\n\nError Message:\n{ex.Message}\n\nIt is recommended to do a Start Over from the previous version first.";
                                FlexibleMessageBox.Show(message, $"Previous Version Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }

                        if (!error)
                        {
                            File.Delete(oldModListFileDirectory.FullName);

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

                                foreach (var datFile in datFiles)
                                {
                                    File.Delete(datFile);
                                }
                            }
                        }
                        else
                        {
                            System.Windows.Application.Current.Shutdown();
                        }
                    }
                    else
                    {
                        System.Windows.Application.Current.Shutdown();
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Checks for older modlist
        /// </summary>
        private async void CheckForOldModList()
        {
            var oldModListFileDirectory =
                new DirectoryInfo(
                    $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}/TexTools/TexTools.modlist");

            if (File.Exists(oldModListFileDirectory.FullName))
            {
                var modListContent = File.ReadAllLines(oldModListFileDirectory.FullName);

                if (modListContent.Length > 0)
                {
                    if (FlexibleMessageBox.Show(_win32Window,
                                                UIMessages.OldTexToolsFoundMessage, UIMessages.OldModListFoundTitle,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        var modding = new Modding(_gameDirectory);

                        var dat   = new Dat(_gameDirectory);
                        var error = false;

                        if (_index.IsIndexLocked(XivDataFile._0A_Exd))
                        {
                            FlexibleMessageBox.Show(_win32Window, UIMessages.ModListIndexLockedErrorMessage,
                                                    UIMessages.ModListDisableFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            error = true;
                        }
                        else
                        {
                            try
                            {
                                await modding.DisableOldModList(oldModListFileDirectory);
                            }
                            catch (Exception ex)
                            {
                                error = true;
                                FlexibleMessageBox.Show(_win32Window,
                                                        string.Format(UIMessages.OldModListDisableFailedMessage, ex.Message),
                                                        UIMessages.PreviousVersionErrorTitle, MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                            }
                        }

                        if (!error)
                        {
                            File.Delete(oldModListFileDirectory.FullName);

                            // 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);
                                }
                            }
                        }
                        else
                        {
                            System.Windows.Application.Current.Shutdown();
                        }
                    }
                    else
                    {
                        System.Windows.Application.Current.Shutdown();
                    }
                }
            }
        }
示例#3
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();
                    });
                }
            }));
        }
        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();
                    });
                }
            }));
        }
        /// <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);
            }
        }
        /// <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);

            if (index.IsIndexLocked(XivDataFile._0A_Exd))
            {
                FlexibleMessageBox.Show("Error Accessing Index File\n\n" +
                                        "Please exit the game before proceeding.\n" +
                                        "-----------------------------------------------------\n\n",
                                        "Index Access Error", MessageBoxButtons.OK, MessageBoxIcon.Error);

                return;
            }

            var result = FlexibleMessageBox.Show("Starting over will:\n\n" +
                                                 "Restore index files to their original state.\n" +
                                                 "Delete all mod dat files from game folder.\n" +
                                                 "Delete all mod list file entries.\n\n" +
                                                 "Do you want to start over?", "Start Over", MessageBoxButtons.YesNo, MessageBoxIcon.Information);

            if (result == System.Windows.Forms.DialogResult.Yes)
            {
                var task = Task.Run((() =>
                {
                    var modding = new Modding(gameDirectory);
                    var dat = new Dat(gameDirectory);

                    var indexBackupsDirectory = new DirectoryInfo(Settings.Default.Backup_Directory);
                    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($"No backup files found in the following directory:\n{indexBackupsDirectory.FullName}\n\n" +
                                                $"Index entries will be put back to original offsets instead.\n" +
                                                "-----------------------------------------------------\n\n",
                                                "Backup Files Missing", MessageBoxButtons.OK, MessageBoxIcon.Warning);

                        // Toggle off all mods
                        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 = dat.GetModdedDatList(xivDataFile);

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

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

                    modding.CreateModlist();
                }));

                task.Wait();

                await this.ShowMessageAsync("Start Over Complete", "The start over process has been completed.");
            }
        }
示例#7
0
        /// <summary>
        /// Checks for older modlist
        /// </summary>
        private async Task <bool> CheckForOldModList()
        {
            // This code probably needs to go soon.
            // Textools sub 2.0 hasn't worked since before Shadowbringers, and this code was always super buggy
            // to start with.

            var oldModListFileDirectory =
                new DirectoryInfo(
                    $"{Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)}/TexTools/TexTools.modlist");

            if (File.Exists(oldModListFileDirectory.FullName))
            {
                var modListContent = File.ReadAllLines(oldModListFileDirectory.FullName);

                if (modListContent.Length > 0)
                {
                    if (FlexibleMessageBox.Show(_win32Window,
                                                UIMessages.OldTexToolsFoundMessage, UIMessages.OldModListFoundTitle,
                                                MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                    {
                        var modding = new Modding(_gameDirectory);

                        var dat   = new Dat(_gameDirectory);
                        var error = false;

                        if (_index.IsIndexLocked(XivDataFile._0A_Exd))
                        {
                            FlexibleMessageBox.Show(_win32Window, UIMessages.ModListIndexLockedErrorMessage,
                                                    UIMessages.ModListDisableFailedTitle, MessageBoxButtons.OK, MessageBoxIcon.Warning);
                            error = true;
                        }
                        else
                        {
                            try
                            {
                                await modding.DisableOldModList(oldModListFileDirectory);
                            }
                            catch (Exception ex)
                            {
                                error = true;
                                FlexibleMessageBox.Show(_win32Window,
                                                        string.Format(UIMessages.OldModListDisableFailedMessage, ex.Message),
                                                        UIMessages.PreviousVersionErrorTitle, MessageBoxButtons.OK,
                                                        MessageBoxIcon.Error);
                            }
                        }

                        if (!error)
                        {
                            File.Delete(oldModListFileDirectory.FullName);

                            // 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);
                                }
                            }
                        }
                        else
                        {
                            return(false);
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }