Ejemplo n.º 1
0
        /// <summary>
        /// Imports a first generation mod pack
        /// </summary>
        /// <param name="modPackDirectory">The mod pack directory</param>
        private async Task ImportOldModPack()
        {
            Dispatcher.Invoke(() =>
            {
                var progress = new Progress <(int count, int total)>(prog =>
                {
                    LockedStatusLabel.Content = $"{UIStrings.Loading} ({prog.count}, {prog.total})";

                    if (prog.count == prog.total)
                    {
                        LockedStatusLabel.Content = UIStrings.Finalizing;
                    }
                });
            });

            var originalModPackData = await _texToolsModPack.GetOriginalModPackJsonData(_modPackDirectory);

            Dispatcher.Invoke(() =>
            {
                // There is nearly no point to doing this on another thread if it's going to be constantly
                // re-invoking the main thread with literally every line.
                foreach (var modsJson in originalModPackData)
                {
                    var jsonEntry = new ModsJson
                    {
                        Name         = modsJson.Name,
                        Category     = modsJson.Category.GetDisplayName(),
                        FullPath     = modsJson.FullPath,
                        DatFile      = modsJson.DatFile,
                        ModOffset    = modsJson.ModOffset,
                        ModSize      = modsJson.ModSize,
                        ModPackEntry = new ModPack
                        {
                            name    = Path.GetFileNameWithoutExtension(_modPackDirectory.FullName),
                            author  = "N/A",
                            version = "1.0.0"
                        }
                    };
                    JsonEntries.Add(jsonEntry);
                    Entries.Add(new SimpleModpackEntry(JsonEntries.Count - 1, this));
                }

                ModPackName.Content    = Path.GetFileNameWithoutExtension(_modPackDirectory.FullName);
                ModPackAuthor.Content  = "N/A";
                ModPackVersion.Content = "1.0.0";

                var cv = (CollectionView)CollectionViewSource.GetDefaultView(ModListView.ItemsSource);
                cv.SortDescriptions.Clear();
                cv.SortDescriptions.Add(new SortDescription(nameof(SimpleModpackEntry.ItemName), _lastDirection));

                long size = 0;
                for (int i = 0; i < JsonEntries.Count; i++)
                {
                    SelectedEntries.Add(i);
                    size += JsonEntries[i].ModSize;
                }
                ModListView.SelectAll();
                ModSize = size;
            });
        }
Ejemplo n.º 2
0
 private Affix ModJsonToAffix(
     ModsJson modsJson,
     HashSet <string> itemTags,
     Dictionary <string, int> modTiers)
 {
     return(ModJsonToAffix(modsJson,
                           modTiers[modsJson.FullName],
                           TierType.Default));
 }
Ejemplo n.º 3
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();
        }
Ejemplo n.º 4
0
        private double GetAffixSpawnWeight(ModsJson modsJsons, HashSet <string> tags)
        {
            foreach (var spawnWeight in modsJsons.SpawnWeights)
            {
                if (tags.Contains(spawnWeight.Tag))
                {
                    return(spawnWeight.Weight);
                }
            }

            return(0);
        }
Ejemplo n.º 5
0
        private Affix ModJsonToAffix(
            ModsJson modsJson,
            int modTier,
            TierType tierType)
        {
            Affix affix = new Affix();

            affix.GenerationType    = modsJson.GenerationType;
            affix.Group             = modsJson.Group;
            affix.Name              = modsJson.Name;
            affix.FullName          = modsJson.FullName;
            affix.RequiredLevel     = (int)modsJson.RequiredLevel;
            affix.Type              = modsJson.Type;
            affix.Tier              = modTier;
            affix.TierType          = tierType;
            affix.Tags              = _modTypeToTags[modsJson.Type];
            affix.AddsTags          = modsJson.AddsTags;
            affix.SpawnWeights      = modsJson.SpawnWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);
            affix.GenerationWeights = modsJson.GenerationWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);


            if (modsJson.Stats.Count > 0)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[0].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[0].Max);

                affix.StatMin1  = sMin <= sMax ? sMin : sMax;
                affix.StatMax1  = sMax >= sMin ? sMax : sMin;
                affix.StatName1 = modsJson.Stats[0].Id;
            }
            if (modsJson.Stats.Count > 1)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[1].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[1].Max);

                affix.StatMin2  = sMin <= sMax ? sMin : sMax;
                affix.StatMax2  = sMax >= sMin ? sMax : sMin;
                affix.StatName2 = modsJson.Stats[1].Id;
            }
            if (modsJson.Stats.Count > 2)
            {
                int sMin = (int)Math.Abs(modsJson.Stats[2].Min);
                int sMax = (int)Math.Abs(modsJson.Stats[2].Max);

                affix.StatMin3  = sMin <= sMax ? sMin : sMax;
                affix.StatMax3  = sMax >= sMin ? sMax : sMin;
                affix.StatName3 = modsJson.Stats[2].Id;
            }
            return(affix);
        }
Ejemplo n.º 6
0
        private Affix ModJsonToAffix(
            ModsJson modsJson,
            int modTier,
            TierType tierType,
            Faction faction = Faction.None)
        {
            Affix affix = new Affix();

            affix.GenerationType    = modsJson.GenerationType;
            affix.Group             = modsJson.Group;
            affix.Name              = modsJson.Name;
            affix.FullName          = modsJson.FullName;
            affix.RequiredLevel     = (int)modsJson.RequiredLevel;
            affix.Type              = modsJson.Type;
            affix.Tier              = modTier;
            affix.TierType          = tierType;
            affix.Faction           = faction;
            affix.Tags              = _modTypeToTags[modsJson.Type];
            affix.AddsTags          = modsJson.AddsTags;
            affix.SpawnWeights      = modsJson.SpawnWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);
            affix.GenerationWeights = modsJson.GenerationWeights.ToDictionary(x => x.Tag, x => (int)x.Weight);

            if (modsJson.Stats.Count > 0)
            {
                affix.StatMax1  = (int)modsJson.Stats[0].Max;
                affix.StatMax1  = (int)modsJson.Stats[0].Min;
                affix.StatName1 = modsJson.Stats[0].Id;
            }
            if (modsJson.Stats.Count > 1)
            {
                affix.StatMax2  = (int)modsJson.Stats[1].Max;
                affix.StatMax2  = (int)modsJson.Stats[1].Min;
                affix.StatName2 = modsJson.Stats[1].Id;
            }
            if (modsJson.Stats.Count > 2)
            {
                affix.StatMax3  = (int)modsJson.Stats[2].Max;
                affix.StatMax3  = (int)modsJson.Stats[2].Min;
                affix.StatName3 = modsJson.Stats[2].Id;
            }
            return(affix);
        }
Ejemplo n.º 7
0
        private List <FileInfo> Extract(ModsJson mods, SqPackStream pack, DirectoryInfo outputDirectory)
        {
            Console.WriteLine(" > " + mods.FullPath);
            FileResource dat = pack.ReadFile <FileResource>(mods.ModOffset);

            FileInfo fileInfo = new FileInfo(outputDirectory.FullName + "/" + mods.FullPath);

            if (!fileInfo.Directory.Exists)
            {
                fileInfo.Directory.Create();
            }

            dat.SaveFile(fileInfo.FullName);

            if (fileInfo.Extension == ".meta")
            {
                return(Metadata.Expand(fileInfo));
            }

            return(new List <FileInfo>()
            {
                fileInfo
            });
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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 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();
        }
Ejemplo n.º 10
0
 private bool ItemCanHaveAffix(ModsJson modsJsons, HashSet <string> tags)
 {
     return(GetAffixSpawnWeight(modsJsons, tags) > 0);
 }
Ejemplo n.º 11
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);
        }
Ejemplo n.º 12
0
        /// <summary>
        /// Adds the given mod entry to the simple mod pack data list
        /// </summary>
        /// <param name="modsJson">The JSON describing the mod to be added to the list</param>
        /// <param name="modding"></param>
        /// <param name="modPackJson">The JSON describing the entire modpack</param>
        /// <returns>Task</returns>
        private async Task AddToList(ModsJson modsJson, Modding modding, ModPackJson modPackJson)
        {
            var raceTask = GetRace(modsJson.FullPath);

            var numberTask = GetNumber(modsJson.FullPath);

            var typeTask = GetType(modsJson.FullPath);

            var partTask = GetPart(modsJson.FullPath);

            var mapTask = GetMap(modsJson.FullPath);

            var active       = false;
            var isActiveTask = modding.IsModEnabled(modsJson.FullPath, false);

            var taskList = new List <Task> {
                raceTask, numberTask, typeTask, partTask, mapTask, isActiveTask
            };

            var    race = XivRace.All_Races;
            string number = string.Empty, type = string.Empty, part = string.Empty, map = string.Empty;
            var    isActive = XivModStatus.Disabled;

            while (taskList.Any())
            {
                var finished = await Task.WhenAny(taskList);

                if (finished == raceTask)
                {
                    taskList.Remove(raceTask);
                    race = await raceTask;
                }
                else if (finished == numberTask)
                {
                    taskList.Remove(numberTask);
                    number = await numberTask;
                }
                else if (finished == typeTask)
                {
                    taskList.Remove(typeTask);
                    type = await typeTask;
                }
                else if (finished == partTask)
                {
                    taskList.Remove(partTask);
                    part = await partTask;
                }
                else if (finished == mapTask)
                {
                    taskList.Remove(mapTask);
                    map = await mapTask;
                }
                else if (finished == isActiveTask)
                {
                    taskList.Remove(isActiveTask);
                    isActive = await isActiveTask;
                }
            }

            if (isActive == XivModStatus.Enabled || isActive == XivModStatus.MatAdd)
            {
                active = true;
            }

            modsJson.ModPackEntry = new ModPack
            {
                name = modPackJson.Name, author = modPackJson.Author, version = modPackJson.Version
            };

            System.Windows.Application.Current.Dispatcher.Invoke(() => _simpleDataList.Add(new SimpleModPackEntries
            {
                Name      = modsJson.Name,
                Category  = modsJson.Category,
                Race      = race.ToString(),
                Type      = type,
                Part      = part,
                Num       = number,
                Map       = map,
                Active    = active,
                JsonEntry = modsJson,
            }));
        }
Ejemplo n.º 13
0
        /// <summary>
        /// Creates a mod pack that uses simple installation
        /// </summary>
        /// <param name="modPackData">The data that will go into the mod pack</param>
        /// <param name="gameDirectory">The game directory</param>
        /// <param name="progress">The progress of the mod pack creation</param>
        /// <returns>The number of mods processed for the mod pack</returns>
        public async Task <int> CreateSimpleModPack(SimpleModPackData modPackData, DirectoryInfo gameDirectory, IProgress <double> progress)
        {
            var processCount = await Task.Run <int>(() =>
            {
                var dat      = new Dat(gameDirectory);
                _tempMPD     = Path.GetTempFileName();
                _tempMPL     = Path.GetTempFileName();
                var modCount = 1;

                var modPackJson = new ModPackJson
                {
                    TTMPVersion    = _currentSimpleTTMPVersion,
                    Name           = modPackData.Name,
                    Author         = modPackData.Author,
                    Version        = modPackData.Version.ToString(),
                    Description    = modPackData.Description,
                    SimpleModsList = new List <ModsJson>()
                };

                using (var binaryWriter = new BinaryWriter(File.Open(_tempMPD, FileMode.Open)))
                {
                    foreach (var simpleModData in modPackData.SimpleModDataList)
                    {
                        var modsJson = new ModsJson
                        {
                            Name      = simpleModData.Name,
                            Category  = simpleModData.Category,
                            FullPath  = simpleModData.FullPath,
                            ModSize   = simpleModData.ModSize,
                            DatFile   = simpleModData.DatFile,
                            ModOffset = binaryWriter.BaseStream.Position
                        };

                        var rawData = dat.GetRawData((int)simpleModData.ModOffset, XivDataFiles.GetXivDataFile(simpleModData.DatFile),
                                                     simpleModData.ModSize);

                        binaryWriter.Write(rawData);

                        modPackJson.SimpleModsList.Add(modsJson);

                        progress?.Report((double)modCount / modPackData.SimpleModDataList.Count);

                        modCount++;
                    }
                }

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

                var modPackPath = $"{_modPackDirectory}\\{modPackData.Name}.ttmp";

                if (File.Exists(modPackPath))
                {
                    var fileNum = 1;
                    modPackPath = $"{_modPackDirectory}\\{modPackData.Name}({fileNum}).ttmp";
                    while (File.Exists(modPackPath))
                    {
                        fileNum++;
                        modPackPath = $"{_modPackDirectory}\\{modPackData.Name}({fileNum}).ttmp";
                    }
                }

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

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

                return(modCount);
            });

            return(processCount);
        }