Exemplo n.º 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.");
                    }
                }
            }
        }
        /// <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);
        }
Exemplo n.º 3
0
 public SimpleModpackEntry(int index, SimpleModPackImporter view)
 {
     _index        = index;
     _importerView = view;
 }
Exemplo n.º 4
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);
        }