/// <summary>
        /// The event handler for the create mod pack button
        /// </summary>
        /// <remarks>
        /// This is originally the help button, but has been repurposed
        /// </remarks>
        private async void ModPackWizard_CreateModPack(object sender, System.Windows.RoutedEventArgs e)
        {
            _progressController = await this.ShowProgressAsync(UIMessages.ModPackCreationMessage, UIMessages.PleaseStandByMessage);

            var wizPages = modPackWizard.Items;

            var modPackData = new ModPackData
            {
                Name         = ModPackName.Text,
                Author       = ModPackAuthor.Text,
                Version      = VersionNumber,
                Description  = ModPackDescription.Text,
                ModPackPages = new List <ModPackData.ModPackPage>()
            };

            var pageIndex = 0;

            foreach (var wizPageItem in wizPages)
            {
                var wizPage = wizPageItem as WizardPage;

                if (wizPage.Content is WizardModPackControl control)
                {
                    if (control.ModGroupList.Count > 0)
                    {
                        modPackData.ModPackPages.Add(new ModPackData.ModPackPage
                        {
                            PageIndex = pageIndex,
                            ModGroups = control.ModGroupList
                        });
                    }
                }
                pageIndex++;
            }

            if (modPackData.ModPackPages.Count > 0)
            {
                var progressIndicator = new Progress <double>(ReportProgress);
                var texToolsModPack   = new TTMP(new DirectoryInfo(Properties.Settings.Default.ModPack_Directory), XivStrings.TexTools);
                await texToolsModPack.CreateWizardModPack(modPackData, progressIndicator);

                ModPackFileName = $"{ModPackName.Text}";
            }
            else
            {
                ModPackFileName = "NoData";
            }

            await _progressController.CloseAsync();

            DialogResult = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Creates a mod pack that uses a wizard for installation
        /// </summary>
        /// <param name="modPackData">The data that will go into the mod pack</param>
        /// <param name="progress">The progress of the mod pack creation</param>
        /// <returns>The number of pages created for the mod pack</returns>
        public async Task <int> CreateWizardModPack(ModPackData modPackData, IProgress <double> progress, bool overwriteModpack)
        {
            var processCount = await Task.Run <int>(() =>
            {
                _tempMPD      = Path.GetTempFileName();
                _tempMPL      = Path.GetTempFileName();
                var imageList = new Dictionary <string, string>();
                var pageCount = 1;

                var modPackJson = new ModPackJson
                {
                    TTMPVersion  = _currentWizardTTMPVersion,
                    Name         = modPackData.Name,
                    Author       = modPackData.Author,
                    Version      = modPackData.Version.ToString(),
                    Description  = modPackData.Description,
                    ModPackPages = new List <ModPackPageJson>()
                };

                using (var binaryWriter = new BinaryWriter(File.Open(_tempMPD, FileMode.Open)))
                {
                    foreach (var modPackPage in modPackData.ModPackPages)
                    {
                        var modPackPageJson = new ModPackPageJson
                        {
                            PageIndex = modPackPage.PageIndex,
                            ModGroups = new List <ModGroupJson>()
                        };

                        modPackJson.ModPackPages.Add(modPackPageJson);

                        foreach (var modGroup in modPackPage.ModGroups)
                        {
                            var modGroupJson = new ModGroupJson
                            {
                                GroupName     = modGroup.GroupName,
                                SelectionType = modGroup.SelectionType,
                                OptionList    = new List <ModOptionJson>()
                            };

                            modPackPageJson.ModGroups.Add(modGroupJson);

                            foreach (var modOption in modGroup.OptionList)
                            {
                                var randomFileName = "";

                                if (modOption.Image != null)
                                {
                                    randomFileName = $"{Path.GetRandomFileName()}.png";
                                    imageList.Add(randomFileName, modOption.ImageFileName);
                                }

                                var modOptionJson = new ModOptionJson
                                {
                                    Name          = modOption.Name,
                                    Description   = modOption.Description,
                                    ImagePath     = randomFileName,
                                    GroupName     = modOption.GroupName,
                                    SelectionType = modOption.SelectionType,
                                    IsChecked     = modOption.IsChecked,
                                    ModsJsons     = new List <ModsJson>()
                                };

                                modGroupJson.OptionList.Add(modOptionJson);

                                foreach (var modOptionMod in modOption.Mods)
                                {
                                    var dataFile = GetDataFileFromPath(modOptionMod.Key);

                                    var modsJson = new ModsJson
                                    {
                                        Name      = modOptionMod.Value.Name,
                                        Category  = modOptionMod.Value.Category.GetEnDisplayName(),
                                        FullPath  = modOptionMod.Key,
                                        ModSize   = modOptionMod.Value.ModDataBytes.Length,
                                        ModOffset = binaryWriter.BaseStream.Position,
                                        DatFile   = dataFile.GetDataFileName(),
                                    };

                                    binaryWriter.Write(modOptionMod.Value.ModDataBytes);

                                    modOptionJson.ModsJsons.Add(modsJson);
                                }
                            }
                        }

                        progress?.Report((double)pageCount / modPackData.ModPackPages.Count);

                        pageCount++;
                    }
                }

                File.WriteAllText(_tempMPL, JsonConvert.SerializeObject(modPackJson));

                var modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}.ttmp2");

                if (File.Exists(modPackPath) && !overwriteModpack)
                {
                    var fileNum = 1;
                    modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}({fileNum}).ttmp2");
                    while (File.Exists(modPackPath))
                    {
                        fileNum++;
                        modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}({fileNum}).ttmp2");
                    }
                }
                else if (File.Exists(modPackPath) && overwriteModpack)
                {
                    File.Delete(modPackPath);
                }

                using (var zip = ZipFile.Open(modPackPath, ZipArchiveMode.Create))
                {
                    zip.CreateEntryFromFile(_tempMPL, "TTMPL.mpl");
                    zip.CreateEntryFromFile(_tempMPD, "TTMPD.mpd");
                    foreach (var image in imageList)
                    {
                        zip.CreateEntryFromFile(image.Value, image.Key);
                    }
                }

                File.Delete(_tempMPD);
                File.Delete(_tempMPL);

                return(pageCount);
            });

            return(processCount);
        }
        private async Task CreateAdvanced()
        {
            string modPackPath = Path.Combine(Properties.Settings.Default.ModPack_Directory, $"{ViewModel.Name}.ttmp2");

            if (File.Exists(modPackPath))
            {
                DialogResult overwriteDialogResult = FlexibleMessageBox.Show(new Wpf32Window(this), UIMessages.ModPackOverwriteMessage,
                                                                             UIMessages.OverwriteTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
                if (overwriteDialogResult != System.Windows.Forms.DialogResult.Yes)
                {
                    return;
                }
            }

            await LockUi(UIStrings.Creating_Modpack, null, null);

            try
            {
                TTMP texToolsModPack = new TTMP(new DirectoryInfo(Settings.Default.ModPack_Directory), XivStrings.TexTools);
                var  index           = new Index(XivCache.GameInfo.GameDirectory);
                var  dat             = new Dat(XivCache.GameInfo.GameDirectory);
                var  modding         = new Modding(XivCache.GameInfo.GameDirectory);
                var  ModList         = modding.GetModList();

                var wizardData = new ModPackData()
                {
                    Name         = ViewModel.Name,
                    Author       = ViewModel.Author,
                    Version      = ViewModel.Version,
                    Description  = ViewModel.Description,
                    Url          = ViewModel.Url,
                    ModPackPages = new List <ModPackData.ModPackPage>()
                };

                var page = new ModPackData.ModPackPage()
                {
                    PageIndex = 1,
                    ModGroups = new List <ModGroup>()
                };

                wizardData.ModPackPages.Add(page);


                foreach (var e in ViewModel.Entries)
                {
                    var item  = e.Item;
                    var files = e.AllFiles;

                    var group = new ModGroup()
                    {
                        GroupName     = item.Name,
                        SelectionType = "Multi",
                        OptionList    = new List <ModOption>()
                    };
                    page.ModGroups.Add(group);

                    var option = new ModOption
                    {
                        GroupName     = group.GroupName,
                        IsChecked     = true,
                        Name          = GetNiceLevelName(e.Level, true, true),
                        Description   = "Item: " + item.Name + "\nInclusion Level: " + GetNiceLevelName(e.Level) + "\nPrimary Files:" + e.MainFiles.Count + "\nTotal Files:" + e.AllFiles.Count,
                        SelectionType = "Multi",
                    };
                    group.OptionList.Add(option);

                    foreach (var file in e.AllFiles)
                    {
                        var exists = await index.FileExists(file);

                        // This is a funny case where in order to create the modpack we actually have to write a default meta entry to the dats first.
                        // If we had the right functions we could just load and serialize the data, but we don't atm.
                        if (!exists && Path.GetExtension(file) == ".meta")
                        {
                            var meta = await ItemMetadata.GetMetadata(file);

                            await ItemMetadata.SaveMetadata(meta, XivStrings.TexTools);
                        }

                        var offset = await index.GetDataOffset(file);

                        var dataFile       = IOUtil.GetDataFileFromPath(file);
                        var compressedSize = await dat.GetCompressedFileSize(offset, dataFile);

                        var modEntry = ModList.Mods.FirstOrDefault(x => x.fullPath == file);
                        var modded   = modEntry != null && modEntry.enabled == true;

                        var fData = new ModData
                        {
                            Name         = e.Item.Name,
                            Category     = e.Item.SecondaryCategory,
                            FullPath     = file,
                            IsDefault    = !modded,
                            ModDataBytes = dat.GetRawData(offset, dataFile, compressedSize)
                        };
                        option.Mods.Add(file, fData);
                    }
                }

                // Okay modpack is now created internally, just need to save it.
                var progressIndicator = new Progress <double>(ReportProgressAdv);
                await texToolsModPack.CreateWizardModPack(wizardData, progressIndicator, true);

                FlexibleMessageBox.Show(new Wpf32Window(this), "Modpack Created Successfully.",
                                        "Modpack Created", MessageBoxButtons.OK, MessageBoxIcon.Information);
                await UnlockUi(this);

                DialogResult = true;
            } catch (Exception ex)
            {
                FlexibleMessageBox.Show(new Wpf32Window(this), "An Error occured while creating the modpack.\n\n" + ex.Message,
                                        "Modpack Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                await UnlockUi(this);
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Creates a mod pack that uses a wizard for installation
        /// </summary>
        /// <param name="modPackData">The data that will go into the mod pack</param>
        /// <param name="progress">The progress of the mod pack creation</param>
        /// <returns>The number of pages created for the mod pack</returns>
        public async Task <int> CreateWizardModPack(ModPackData modPackData, IProgress <double> progress, bool overwriteModpack)
        {
            var processCount = await Task.Run <int>(() =>
            {
                var guid = Guid.NewGuid();

                var dir = Path.Combine(Path.GetTempPath(), guid.ToString());
                Directory.CreateDirectory(dir);

                _tempMPD = Path.Combine(dir, "TTMPD.mpd");
                _tempMPL = Path.Combine(dir, "TTMPL.mpl");

                var imageList = new HashSet <string>();
                var pageCount = 1;

                Version version = modPackData.Version == null ? new Version(1, 0, 0, 0) : modPackData.Version;
                var modPackJson = new ModPackJson
                {
                    TTMPVersion             = _currentWizardTTMPVersion,
                    MinimumFrameworkVersion = _minimumAssembly,
                    Name         = modPackData.Name,
                    Author       = modPackData.Author,
                    Version      = version.ToString(),
                    Description  = modPackData.Description,
                    Url          = modPackData.Url,
                    ModPackPages = new List <ModPackPageJson>()
                };

                using (var binaryWriter = new BinaryWriter(File.Open(_tempMPD, FileMode.Create)))
                {
                    foreach (var modPackPage in modPackData.ModPackPages)
                    {
                        var modPackPageJson = new ModPackPageJson
                        {
                            PageIndex = modPackPage.PageIndex,
                            ModGroups = new List <ModGroupJson>()
                        };

                        modPackJson.ModPackPages.Add(modPackPageJson);

                        foreach (var modGroup in modPackPage.ModGroups)
                        {
                            var modGroupJson = new ModGroupJson
                            {
                                GroupName     = modGroup.GroupName,
                                SelectionType = modGroup.SelectionType,
                                OptionList    = new List <ModOptionJson>()
                            };

                            modPackPageJson.ModGroups.Add(modGroupJson);

                            foreach (var modOption in modGroup.OptionList)
                            {
                                var imageFileName = "";
                                if (modOption.Image != null)
                                {
                                    var fname     = Path.GetFileName(modOption.ImageFileName);
                                    imageFileName = Path.Combine(dir, fname);
                                    File.Copy(modOption.ImageFileName, imageFileName, true);
                                    imageList.Add(imageFileName);
                                }

                                var fn            = imageFileName == "" ? "" : "images/" + Path.GetFileName(imageFileName);
                                var modOptionJson = new ModOptionJson
                                {
                                    Name          = modOption.Name,
                                    Description   = modOption.Description,
                                    ImagePath     = fn,
                                    GroupName     = modOption.GroupName,
                                    SelectionType = modOption.SelectionType,
                                    IsChecked     = modOption.IsChecked,
                                    ModsJsons     = new List <ModsJson>()
                                };

                                modGroupJson.OptionList.Add(modOptionJson);

                                foreach (var modOptionMod in modOption.Mods)
                                {
                                    var dataFile = GetDataFileFromPath(modOptionMod.Key);

                                    if (ForbiddenModTypes.Contains(Path.GetExtension(modOptionMod.Key)))
                                    {
                                        continue;
                                    }
                                    var modsJson = new ModsJson
                                    {
                                        Name      = modOptionMod.Value.Name,
                                        Category  = modOptionMod.Value.Category.GetEnDisplayName(),
                                        FullPath  = modOptionMod.Key,
                                        IsDefault = modOptionMod.Value.IsDefault,
                                        ModSize   = modOptionMod.Value.ModDataBytes.Length,
                                        ModOffset = binaryWriter.BaseStream.Position,
                                        DatFile   = dataFile.GetDataFileName(),
                                    };

                                    binaryWriter.Write(modOptionMod.Value.ModDataBytes);

                                    modOptionJson.ModsJsons.Add(modsJson);
                                }
                            }
                        }

                        progress?.Report((double)pageCount / modPackData.ModPackPages.Count);

                        pageCount++;
                    }
                }

                File.WriteAllText(_tempMPL, JsonConvert.SerializeObject(modPackJson));

                var modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}.ttmp2");

                if (File.Exists(modPackPath) && !overwriteModpack)
                {
                    var fileNum = 1;
                    modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}({fileNum}).ttmp2");
                    while (File.Exists(modPackPath))
                    {
                        fileNum++;
                        modPackPath = Path.Combine(_modPackDirectory.FullName, $"{modPackData.Name}({fileNum}).ttmp2");
                    }
                }
                else if (File.Exists(modPackPath) && overwriteModpack)
                {
                    File.Delete(modPackPath);
                }

                var zf = new ZipFile();
                zf.UseZip64WhenSaving = Zip64Option.AsNecessary;
                zf.CompressionLevel   = Ionic.Zlib.CompressionLevel.None;
                zf.AddFile(_tempMPL, "");
                zf.AddFile(_tempMPD, "");
                zf.Save(modPackPath);

                foreach (var image in imageList)
                {
                    zf.AddFile(image, "images");
                }
                zf.Save(modPackPath);


                File.Delete(_tempMPD);
                File.Delete(_tempMPL);

                return(pageCount);
            });

            return(processCount);
        }
Exemplo n.º 5
0
        /// <summary>
        /// The event handler for the create mod pack button
        /// </summary>
        /// <remarks>
        /// This is originally the help button, but has been repurposed
        /// </remarks>
        private async void ModPackWizard_CreateModPack(object sender, System.Windows.RoutedEventArgs e)
        {
            _progressController = await this.ShowProgressAsync(UIMessages.ModPackCreationMessage, UIMessages.PleaseStandByMessage);

            try
            {
                var wizPages = modPackWizard.Items;

                var modPackData = new ModPackData
                {
                    Name         = ModPackName.Text,
                    Author       = ModPackAuthor.Text,
                    Version      = VersionNumber,
                    Description  = ModPackDescription.Text,
                    Url          = ModPackUrl.Text,
                    ModPackPages = new List <ModPackData.ModPackPage>()
                };

                var pageIndex = 0;
                foreach (var wizPageItem in wizPages)
                {
                    var wizPage = wizPageItem as WizardPage;

                    if (wizPage.Content is WizardModPackControl control)
                    {
                        if (control.ModGroupList.Count > 0)
                        {
                            modPackData.ModPackPages.Add(new ModPackData.ModPackPage
                            {
                                PageIndex = pageIndex,
                                ModGroups = control.ModGroupList
                            });
                        }
                    }
                    pageIndex++;
                }

                if (modPackData.ModPackPages.Count > 0)
                {
                    var progressIndicator = new Progress <double>(ReportProgress);
                    var texToolsModPack   = new TTMP(new DirectoryInfo(Properties.Settings.Default.ModPack_Directory), XivStrings.TexTools);

                    var modPackPath      = Path.Combine(Properties.Settings.Default.ModPack_Directory, $"{modPackData.Name}.ttmp2");
                    var overwriteModpack = false;

                    if (File.Exists(modPackPath))
                    {
                        var overwriteDialogResult = FlexibleMessageBox.Show(new Wpf32Window(this), UIMessages.ModPackOverwriteMessage,
                                                                            UIMessages.OverwriteTitle, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Warning);
                        if (overwriteDialogResult == System.Windows.Forms.DialogResult.Yes)
                        {
                            overwriteModpack = true;
                        }
                        else if (overwriteDialogResult == System.Windows.Forms.DialogResult.Cancel)
                        {
                            return;
                        }
                    }

                    await texToolsModPack.CreateWizardModPack(modPackData, progressIndicator, overwriteModpack);

                    ModPackFileName = $"{ModPackName.Text}";
                }
                else
                {
                    ModPackFileName = "NoData";
                }
            }
            catch (Exception ex)
            {
                FlexibleMessageBox.Show("Failed to create modpack.\n\nError: " + ex.Message, "Modpack Creation Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            finally
            {
                await _progressController.CloseAsync();
            }

            DialogResult = true;
        }