예제 #1
0
        /// <summary>
        /// Event handler for the import mod pack menu item clicked
        /// </summary>
        private async void Menu_ImportModpack_Click(object sender, RoutedEventArgs e)
        {
            var modPackDirectory = new DirectoryInfo(Settings.Default.ModPack_Directory);

            var openFileDialog = new OpenFileDialog {
                InitialDirectory = modPackDirectory.FullName, Filter = "TexToolsModPack TTMP (*.ttmp;*.ttmp2)|*.ttmp;*.ttmp2"
            };

            if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                try
                {
                    var ttmp     = new TTMP(modPackDirectory, XivStrings.TexTools);
                    var ttmpData = ttmp.GetModPackJsonData(new DirectoryInfo(openFileDialog.FileName));

                    if (ttmpData.ModPackJson.TTMPVersion.Contains("w"))
                    {
                        var importWizard = new ImportModPackWizard(ttmpData.ModPackJson, ttmpData.ImageDictionary, new DirectoryInfo(openFileDialog.FileName))
                        {
                            Owner = this
                        };
                        var result = importWizard.ShowDialog();

                        if (result == true)
                        {
                            await this.ShowMessageAsync("Import Complete", $"{importWizard.TotalModsImported} mod(s) successfully imported.");
                        }
                    }
                    else
                    {
                        var simpleImport = new SimpleModPackImporter(new DirectoryInfo(openFileDialog.FileName), ttmpData.ModPackJson)
                        {
                            Owner = this
                        };
                        var result = simpleImport.ShowDialog();

                        if (result == true)
                        {
                            await this.ShowMessageAsync("Import Complete", $"{simpleImport.TotalModsImported} mod(s) successfully imported.");
                        }
                    }
                }
                catch (Exception ex)
                {
                    var simpleImport = new SimpleModPackImporter(new DirectoryInfo(openFileDialog.FileName), null)
                    {
                        Owner = this
                    };
                    var result = simpleImport.ShowDialog();

                    if (result == true)
                    {
                        await this.ShowMessageAsync("Import Complete", $"{simpleImport.TotalModsImported} mod(s) successfully imported.");
                    }
                }
            }
        }
예제 #2
0
        private async void Menu_ModConverter_Click(object sender, RoutedEventArgs e)
        {
            var modPackDirectory = new DirectoryInfo(Settings.Default.ModPack_Directory);
            var openFileDialog   = new OpenFileDialog {
                InitialDirectory = modPackDirectory.FullName, Filter = "TexToolsModPack TTMP (*.ttmp;*.ttmp2)|*.ttmp;*.ttmp2"
            };

            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            var ttmpFileName = openFileDialog.FileName;
            var ttmp         = new TTMP(modPackDirectory, XivStrings.TexTools);

            (ModPackJson ModPackJson, Dictionary <string, Image> ImageDictionary)ttmpData;
            var progressController = await this.ShowProgressAsync(UIStrings.Mod_Converter, UIMessages.PleaseStandByMessage);

            var modsJsonList = await ttmp.GetOriginalModPackJsonData(new DirectoryInfo(ttmpFileName));

            if (modsJsonList == null)
            {
                ttmpData = await ttmp.GetModPackJsonData(new DirectoryInfo(ttmpFileName));
            }
            else
            {
                ttmpData = (ModPackJson : new ModPackJson(), ImageDictionary : new Dictionary <string, Image>());
                ttmpData.ModPackJson.Author         = "Mod Converter";
                ttmpData.ModPackJson.Version        = "1.0.0";
                ttmpData.ModPackJson.Name           = Path.GetFileNameWithoutExtension(ttmpFileName);
                ttmpData.ModPackJson.TTMPVersion    = "s";
                ttmpData.ModPackJson.SimpleModsList = new List <ModsJson>();
                foreach (var mod in modsJsonList)
                {
                    var modsJson = new ModsJson();
                    modsJson.Category     = mod.Category;
                    modsJson.DatFile      = mod.DatFile;
                    modsJson.FullPath     = mod.FullPath;
                    modsJson.ModOffset    = mod.ModOffset;
                    modsJson.ModPackEntry = null;
                    modsJson.ModSize      = mod.ModSize;
                    modsJson.Name         = mod.Name;
                    ttmpData.ModPackJson.SimpleModsList.Add(modsJson);
                }
            }
            var gameDir  = new DirectoryInfo(Settings.Default.FFXIV_Directory);
            var lang     = XivLanguages.GetXivLanguage(Settings.Default.Application_Language);
            var gear     = new Gear(gameDir, lang);
            var gearList = await gear.GetGearList();

            var modConverterView = new ModConverterView(gearList, ttmpFileName, ttmpData)
            {
                Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner
            };
            await progressController.CloseAsync();

            modConverterView.ShowDialog();
        }
        private async void Menu_ModConverter_Click(object sender, RoutedEventArgs e)
        {
            var modPackDirectory = new DirectoryInfo(Settings.Default.ModPack_Directory);
            var openFileDialog   = new OpenFileDialog {
                InitialDirectory = modPackDirectory.FullName, Filter = "TexToolsModPack TTMP (*.ttmp;*.ttmp2)|*.ttmp;*.ttmp2"
            };

            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            var ttmpFileName = openFileDialog.FileName;
            var ttmp         = new TTMP(modPackDirectory, XivStrings.TexTools);

            (ModPackJson ModPackJson, Dictionary <string, Image> ImageDictionary)ttmpData;
            var progressController = await this.ShowProgressAsync(UIStrings.Mod_Converter, UIMessages.PleaseStandByMessage);

            var modsJsonList = await ttmp.GetOriginalModPackJsonData(new DirectoryInfo(ttmpFileName));

            if (modsJsonList == null)
            {
                ttmpData = await ttmp.GetModPackJsonData(new DirectoryInfo(ttmpFileName));
            }
            else
            {
                ttmpData = (ModPackJson : new ModPackJson(), ImageDictionary : new Dictionary <string, Image>());
                ttmpData.ModPackJson.Author         = "Mod Converter";
                ttmpData.ModPackJson.Version        = "1.0.0";
                ttmpData.ModPackJson.Name           = Path.GetFileNameWithoutExtension(ttmpFileName);
                ttmpData.ModPackJson.TTMPVersion    = "s";
                ttmpData.ModPackJson.SimpleModsList = new List <ModsJson>();
                foreach (var mod in modsJsonList)
                {
                    var modsJson = new ModsJson();
                    modsJson.Category     = mod.Category;
                    modsJson.DatFile      = mod.DatFile;
                    modsJson.FullPath     = mod.FullPath;
                    modsJson.ModOffset    = mod.ModOffset;
                    modsJson.ModPackEntry = null;
                    modsJson.ModSize      = mod.ModSize;
                    modsJson.Name         = mod.Name;
                    ttmpData.ModPackJson.SimpleModsList.Add(modsJson);
                }
            }
            var categorys = ItemTreeView.ItemsSource as ObservableCollection <Category>;
            var list      = new List <xivModdingFramework.Items.Interfaces.IItem>();
            var ctgs1     = categorys[0];

            foreach (var ctgs2 in ctgs1.Categories)
            {
                if (ctgs2.Item != null)
                {
                    list.Add(ctgs2.Item);
                    continue;
                }
                foreach (var ctgs3 in ctgs2.Categories)
                {
                    if (ctgs3.Item != null)
                    {
                        list.Add(ctgs3.Item);
                    }
                }
            }
            var modConverterView = new ModConverterView(list, ttmpFileName, ttmpData)
            {
                Owner = this, WindowStartupLocation = WindowStartupLocation.CenterOwner
            };
            await progressController.CloseAsync();

            modConverterView.ShowDialog();
        }
        /// <summary>
        /// This method opens the modpack import wizard or imports a modpack silently
        /// </summary>
        /// <param name="path">The path to the modpack</param>
        /// <param name="silent">If the modpack wizard should be shown or the modpack should just be imported without any user interaction</param>
        /// <returns></returns>
        private async Task <int> ImportModpack(DirectoryInfo path, DirectoryInfo modPackDirectory, bool silent = false, bool messageInImport = false)
        {
            var              importError      = false;
            TextureView      textureView      = null;
            TextureViewModel textureViewModel = null;
            ModelView        modelView        = null;
            ModelViewModel   modelViewModel   = null;

            if (TextureTabItem != null && ModelTabItem != null)
            {
                textureView      = TextureTabItem.Content as TextureView;
                textureViewModel = textureView.DataContext as TextureViewModel;
                modelView        = ModelTabItem.Content as ModelView;
                modelViewModel   = modelView.DataContext as ModelViewModel;
            }

            if (!path.Extension.Contains("ttmp"))
            {
                FlexibleMessageBox.Show(string.Format(UIMessages.UnsupportedFileExtensionErrorMessage, path.Extension),
                                        UIMessages.UnsupportedFileExtensionErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);

                return(0);
            }

            try
            {
                var ttmp     = new TTMP(modPackDirectory, XivStrings.TexTools);
                var ttmpData = await ttmp.GetModPackJsonData(path);

                if (ttmpData.ModPackJson.TTMPVersion.Contains("w"))
                {
                    var gameDirectory = new DirectoryInfo(Settings.Default.FFXIV_Directory);
                    var index         = new Index(gameDirectory);

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

                        return(0);
                    }

                    try
                    {
                        var importWizard = new ImportModPackWizard(ttmpData.ModPackJson, ttmpData.ImageDictionary,
                                                                   path, textureViewModel, modelViewModel, messageInImport);

                        if (messageInImport)
                        {
                            importWizard.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        }
                        else
                        {
                            importWizard.Owner = this;
                        }

                        var result = importWizard.ShowDialog();

                        if (result == true)
                        {
                            return(importWizard.TotalModsImported);
                        }
                    }
                    catch
                    {
                        importError = true;
                    }
                }
                else if (ttmpData.ModPackJson.TTMPVersion.Contains("s"))
                {
                    try
                    {
                        var simpleImport = new SimpleModPackImporter(path,
                                                                     ttmpData.ModPackJson, textureViewModel, modelViewModel, silent, messageInImport);

                        if (messageInImport)
                        {
                            simpleImport.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                        }
                        else
                        {
                            simpleImport.Owner = this;
                        }

                        var result = simpleImport.ShowDialog();

                        if (result == true)
                        {
                            return(simpleImport.TotalModsImported);
                        }
                    }
                    catch
                    {
                        importError = true;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!importError)
                {
                    var simpleImport = new SimpleModPackImporter(path, null, textureViewModel, modelViewModel, silent, messageInImport);

                    if (messageInImport)
                    {
                        simpleImport.WindowStartupLocation = WindowStartupLocation.CenterScreen;
                    }
                    else
                    {
                        simpleImport.Owner = this;
                    }

                    var result = simpleImport.ShowDialog();

                    if (result == true)
                    {
                        return(simpleImport.TotalModsImported);
                    }
                }
                else
                {
                    FlexibleMessageBox.Show(string.Format(UIMessages.ModPackImportErrorMessage, path.FullName, ex.Message), UIMessages.ModPackImportErrorTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(0);
                }
            }

            return(0);
        }
        private async void LoadFromButton_Click(object sender, System.Windows.RoutedEventArgs e)
        {
            var openFileDialog = new OpenFileDialog {
                Filter = "Texture Files(*.ttmp2)|*.ttmp2", InitialDirectory = Settings.Default.ModPack_Directory
            };

            if (openFileDialog.ShowDialog() != System.Windows.Forms.DialogResult.OK)
            {
                return;
            }
            var ttmp     = new TTMP(new DirectoryInfo(Settings.Default.ModPack_Directory), XivStrings.TexTools);
            var ttmpData = await ttmp.GetModPackJsonData(new DirectoryInfo(openFileDialog.FileName));

            if (!ttmpData.ModPackJson.TTMPVersion.Contains("w"))
            {
                FlexibleMessageBox.Show(new Wpf32Window(this),
                                        UIMessages.NotWizardModPack,
                                        UIMessages.ModPackLoadingTitle, MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            var tempMPD = Path.GetTempFileName();

            using (var archive = ZipFile.OpenRead(openFileDialog.FileName))
            {
                using (var zipStream = archive.GetEntry("TTMPD.mpd").Open())
                {
                    using (var fileStream = new FileStream(tempMPD, FileMode.OpenOrCreate))
                    {
                        await zipStream.CopyToAsync(fileStream);
                    }
                }
            }
            this.ModPackAuthor.Text      = ttmpData.ModPackJson.Author;
            this.ModPackName.Text        = ttmpData.ModPackJson.Name;
            this.ModPackVersion.Text     = ttmpData.ModPackJson.Version;
            this.ModPackDescription.Text = ttmpData.ModPackJson.Description;
            for (var i = modPackWizard.Items.Count - 1; i > 0; i--)
            {
                modPackWizard.Items.RemoveAt(i);
            }
            //var previousPage = modPackWizard.CurrentPage;
            foreach (var wizPageItemJson in ttmpData.ModPackJson.ModPackPages)
            {
                var wizPage = new WizardPage();
                wizPage.Background       = null;
                wizPage.HeaderBackground = null;
                var wizModPackControl = new WizardModPackControl();
                wizPage.Content  = wizModPackControl;
                wizPage.PageType = WizardPageType.Blank;
                foreach (var groupJson in wizPageItemJson.ModGroups)
                {
                    var modGroup = new ModGroup();
                    modGroup.OptionList    = new List <ModOption>();
                    modGroup.GroupName     = groupJson.GroupName;
                    modGroup.SelectionType = groupJson.SelectionType;
                    wizModPackControl.ModGroupList.Add(modGroup);
                    wizModPackControl.ModGroupNames.Add(modGroup.GroupName);
                    foreach (var optionJson in groupJson.OptionList)
                    {
                        var modOption = new ModOption();
                        modGroup.OptionList.Add(modOption);
                        modOption.Name          = optionJson.Name;
                        modOption.GroupName     = optionJson.GroupName;
                        modOption.IsChecked     = optionJson.IsChecked;
                        modOption.SelectionType = optionJson.SelectionType;
                        modOption.Description   = optionJson.Description;
                        if (optionJson.ImagePath.Length > 0)
                        {
                            using (var zipFile = ZipFile.OpenRead(openFileDialog.FileName))
                            {
                                using (var stream = zipFile.GetEntry(optionJson.ImagePath).Open())
                                {
                                    var tmpImage = Path.GetTempFileName();
                                    using (var imageStream = File.Open(tmpImage, FileMode.OpenOrCreate))
                                    {
                                        await stream.CopyToAsync(imageStream);

                                        imageStream.Position = 0;
                                    }
                                    var fileNameBak = openFileDialog.FileName;
                                    openFileDialog.FileName = tmpImage;
                                    modOption.Image         = Image.Load(openFileDialog.FileName);
                                    modOption.ImageFileName = openFileDialog.FileName;
                                    openFileDialog.FileName = fileNameBak;
                                }
                            }
                        }
                        foreach (var modJson in optionJson.ModsJsons)
                        {
                            var modData = new ModData();
                            modData.Category = modJson.Category;
                            modData.FullPath = modJson.FullPath;
                            modData.Name     = modJson.Name;
                            using (var br = new BinaryReader(File.OpenRead(tempMPD)))
                            {
                                br.BaseStream.Seek(modJson.ModOffset, SeekOrigin.Begin);
                                modData.ModDataBytes = br.ReadBytes(modJson.ModSize);
                            }
                            modOption.Mods.Add(modData.FullPath, modData);
                        }
                        ((List <ModOption>)wizModPackControl.OptionsList.ItemsSource).Add(modOption);
                        var view             = (CollectionView)CollectionViewSource.GetDefaultView(wizModPackControl.OptionsList.ItemsSource);
                        var groupDescription = new PropertyGroupDescription("GroupName");
                        view.GroupDescriptions.Clear();
                        view.GroupDescriptions.Add(groupDescription);
                    }
                    if (modGroup.OptionList.Count > 0 && modGroup.OptionList.Count(it => it.IsChecked) == 0)
                    {
                        modGroup.OptionList[0].IsChecked = true;
                    }
                }

                modPackWizard.Items.Add(wizPage);
                modPackWizard.CanHelp = true;
            }
            modPackWizard.Items.Add(new WizardPage()
            {
                Content          = new WizardModPackControl(),
                PageType         = WizardPageType.Blank,
                Background       = null,
                HeaderBackground = null
            });
        }
예제 #6
0
        /// <summary>
        /// This method opens the modpack import wizard or imports a modpack silently
        /// </summary>
        /// <param name="path">The path to the modpack</param>
        /// <param name="silent">If the modpack wizard should be shown or the modpack should just be imported without any user interaction</param>
        /// <returns></returns>
        private async Task <int> ImportModpack(DirectoryInfo path, DirectoryInfo modPackDirectory, bool silent = false)
        {
            var importError = false;

            try
            {
                var ttmp     = new TTMP(modPackDirectory, XivStrings.TexTools);
                var ttmpData = ttmp.GetModPackJsonData(path);

                if (ttmpData.ModPackJson.TTMPVersion.Contains("w"))
                {
                    try
                    {
                        var importWizard = new ImportModPackWizard(ttmpData.ModPackJson, ttmpData.ImageDictionary,
                                                                   path)
                        {
                            Owner = this
                        };
                        var result = importWizard.ShowDialog();

                        if (result == true)
                        {
                            return(importWizard.TotalModsImported);
                        }
                    }
                    catch
                    {
                        importError = true;
                    }
                }
                else if (ttmpData.ModPackJson.TTMPVersion.Contains("s"))
                {
                    try
                    {
                        var simpleImport = new SimpleModPackImporter(path,
                                                                     ttmpData.ModPackJson, silent)
                        {
                            Owner = this
                        };
                        var result = simpleImport.ShowDialog();

                        if (result == true)
                        {
                            return(simpleImport.TotalModsImported);
                        }
                    }
                    catch
                    {
                        importError = true;
                    }
                }
            }
            catch (Exception ex)
            {
                if (!importError)
                {
                    var simpleImport = new SimpleModPackImporter(path, null, silent)
                    {
                        Owner = this
                    };
                    var result = simpleImport.ShowDialog();

                    if (result == true)
                    {
                        return(simpleImport.TotalModsImported);
                    }
                }
                else
                {
                    FlexibleMessageBox.Show($"There was an error importing the mod pack at {path.FullName}\n\nMessage: {ex.Message}", $"ModPack Import Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return(0);
                }
            }

            return(0);
        }