private void MapEntryToFomodOption(List <Tuple <FomodFile, ModOption> > map, Entry entry, ModOption archiveModOption)
        {
            string entryPath     = entry.GetPath();
            string fomodBasePath = archiveModOption.BaseInstallerPath;

            if (fomodBasePath.Length > 0)
            {
                entryPath = entryPath.Replace(fomodBasePath, "");
            }
            foreach (Tuple <FomodFile, ModOption> mapping in map)
            {
                FomodFile fileNode = mapping.Item1;
                ModOption option   = mapping.Item2;

                if (fileNode.MatchesPath(entryPath))
                {
                    string mappedPath = fileNode.MappedPath(entryPath);
                    if (mappedPath == "")
                    {
                        continue;
                    }
                    if (option.Assets.IndexOf(mappedPath) > -1)
                    {
                        continue;
                    }
                    option.Assets.Add(mappedPath);
                    option.Size += (long)entry.Size;

                    // enqueue jobs for analyzing archives and plugins
                    MapEntryToOption(entry, option, archiveModOption);
                }
            }
        }
Example #2
0
        public DownloadFilesViewModel(IEventAggregator eventAggregator, string downloadURL, string downloadPath, ModOption option)
        {
            _eventAggregator   = eventAggregator;
            _dialogCoordinator = DialogCoordinator.Instance;
            _downloadURL       = downloadURL;
            _downloadPath      = downloadPath;
            _option            = option;
            Title      = "Скачивание " + _option.Name;
            _webClient = new MyWebClient {
                CachePolicy = new HttpRequestCachePolicy(HttpRequestCacheLevel.NoCacheNoStore)
            };

            if (AutoUpdater.Proxy != null)
            {
                _webClient.Proxy = AutoUpdater.Proxy;
            }

            var uri = new Uri(_downloadURL);

            _tempFile = string.IsNullOrEmpty(_downloadPath) ? Path.GetTempFileName() : Path.Combine(_downloadPath, $"{Guid.NewGuid().ToString()}.tmp");

            _webClient.DownloadProgressChanged += OnDownloadProgressChanged;

            _webClient.DownloadFileCompleted += WebClientOnDownloadFileCompleted;

            _webClient.DownloadFileAsync(uri, _tempFile);
        }
Example #3
0
        public List <ModOption> BuildModOptions(string fomodBasePath)
        {
            List <ModOption> options = new List <ModOption>();

            if (BaseFiles != null)
            {
                ModOption baseOption = new ModOption("Base FOMOD Files", true, true);
                AddFileMappings(baseOption, BaseFiles);
                options.Add(baseOption);
            }
            foreach (FomodPlugin plugin in Plugins)
            {
                ModOption option = new ModOption(plugin);
                if (plugin.Files != null)
                {
                    AddFileMappings(option, plugin.Files);
                }
                if (!options.Exists(o => o.Matches(option)))
                {
                    options.Add(option);
                }
            }
            foreach (ModOption option in options)
            {
                List <ModOption> matchingOpts = options.FindAll(o => o.Name.Equals(option.Name));
                if (matchingOpts.Count > 1)
                {
                    SpecifyModOptionNames(matchingOpts);
                }
            }
            return(options);
        }
        /// <summary>
        /// The event handler for the remove options button clicked
        /// </summary>
        private void RemoveOptionButton_Click(object sender, RoutedEventArgs e)
        {
            _selectedModOption =
                (from option in _modOptions
                 where option.Name.Equals(OptionList.SelectedItem.ToString())
                 select option).FirstOrDefault();

            _modOptions.Remove(_selectedModOption);

            foreach (var item in OptionList.Items)
            {
                if (item.ToString().Equals(_selectedModOption.Name))
                {
                    if (OptionList.Items.Count > 0)
                    {
                        OptionList.SelectedIndex = 0;
                    }
                    else
                    {
                        OptionList.SelectedIndex = -1;
                    }
                    OptionList.Items.Remove(item);
                    break;
                }
            }
        }
        /// <summary>
        /// Adds the option to the group
        /// </summary>
        /// <param name="optionText">The option name</param>
        /// <param name="optionNum">The option number</param>
        private void AddOption(string optionText, int optionNum = 0)
        {
            if (OptionNameTextBox.Text.Equals(string.Empty))
            {
                return;
            }

            var optionListItems = OptionList.Items.Cast <string>().ToList();

            if (optionListItems.IndexOf(optionText) != -1)
            {
                AddOption($"{OptionNameTextBox.Text} {optionNum + 1}", optionNum + 1);
            }
            else
            {
                var modOption = new ModOption
                {
                    Name = optionText
                };

                _modOptions.Add(modOption);

                OptionList.Items.Add(optionText);
                OptionList.SelectedIndex = OptionList.Items.Count - 1;
            }

            OptionNameTextBox.Text = string.Empty;
        }
            // create mod option based on underlying type and attributes of cfgField
            public static ModOption create(Config.Field cfgField)
            {
                ModOption option = null;

#if DEBUG
                // trying to use all creators to check for ambiguity
                foreach (var c in creators)
                {
                    var optionTmp = c.create(cfgField);

                    Debug.assert(option == null || optionTmp == null,
                                 $"Options.Factory: ambiguity for field '{cfgField.path}' (both {option?.GetType().Name} and {optionTmp?.GetType().Name})");

                    option ??= optionTmp;
                }
#else
                foreach (var c in creators)
                {
                    if ((option = c.create(cfgField)) != null)
                    {
                        break;
                    }
                }
#endif
                if (option != null)
                {
                    modifiers.ForEach(m => m.process(option));
                }

                return(option);
            }
Example #7
0
 public void process(ModOption option)
 {
     if (option.cfgField.getAttr <CustomOrderAttribute>(true) is CustomOrderAttribute customOrder)
     {
         option.addHandler(new CustomOrderHandler(customOrder.modIDBefore));
     }
 }
Example #8
0
        private bool ArchiveModOptionExists(string filePath)
        {
            ModOption existingArchiveOption = ArchiveModOptions.Where(
                x => x.SourceFilePath == filePath
                ).FirstOrDefault();

            return(existingArchiveOption != null);
        }
Example #9
0
 private void Awake()
 {
     foreach (AbilityMods n in mods)
     {
         ModOption temp = Instantiate(modPrefab, options.transform).GetComponent <ModOption>();
         temp.mod     = n;
         temp.modSlot = this;
     }
 }
        /// <summary>
        /// The event handler for the option list selection changed
        /// </summary>
        private void OptionList_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            IncludedModsList.Items.Clear();

            if (OptionList.SelectedIndex != -1)
            {
                _selectedModOption =
                    (from option in _modOptions
                     where option.Name.Equals(OptionList.SelectedItem.ToString())
                     select option).FirstOrDefault();

                if (_selectedModOption.Description != null)
                {
                    OptionDescription.Text = _selectedModOption.Description;
                }
                else
                {
                    OptionDescription.Text = string.Empty;
                }

                if (_selectedModOption.Image != null)
                {
                    OptionImage.Source = _selectedModOption.Image.ToBitmapSource();
                }
                else
                {
                    OptionImage.Source = null;
                }

                if (_selectedModOption.Mods != null && _selectedModOption.Mods.Count > 0)
                {
                    foreach (var mod in _selectedModOption.Mods)
                    {
                        var includedMods = new IncludedMods
                        {
                            Name     = $"{Path.GetFileNameWithoutExtension(mod.Key)} ({mod.Value.Name})",
                            FullPath = mod.Value.FullPath
                        };

                        IncludedModsList.Items.Add(includedMods);
                    }
                }

                ModListGrid.IsEnabled        = true;
                OptionDescription.IsEnabled  = true;
                OptionImageButton.IsEnabled  = true;
                RemoveOptionButton.IsEnabled = true;
            }
            else
            {
                ModListGrid.IsEnabled        = false;
                OptionDescription.IsEnabled  = false;
                OptionImageButton.IsEnabled  = false;
                RemoveOptionButton.IsEnabled = false;
            }
        }
Example #11
0
        private string GetOutputFilename(List <ModOption> archiveModOptions)
        {
            ModOption baseOption = archiveModOptions.Find(modOption => modOption.Default);

            if (baseOption == null)
            {
                baseOption = archiveModOptions.First();
            }
            return(baseOption.Name);
        }
Example #12
0
 public void process(ModOption option)
 {
     if (option.cfgField.getAttr <FieldAttribute>() is FieldAttribute fieldAttr)
     {
         if (fieldAttr.tooltipType != null || fieldAttr.tooltip != null)
         {
             option.addHandler(new Components.Tooltip.Add(fieldAttr.tooltipType, fieldAttr.tooltip));
         }
     }
 }
        public static void add(ModOption option)
        {
            if (instance == null)
            {
                registerLabel("Name", ref optionsName);
                OptionsPanelHandler.RegisterModOptions(instance = new Options());
            }

            instance.modOptions.Add(option);
        }
Example #14
0
 private string GetDestinationPath(ModOption archiveModOption, Entry entry)
 {
     if (ArchiveHelpers.ShouldExtract(entry))
     {
         return(archiveModOption.GetExtractedEntryPath(entry));
     }
     else
     {
         return(null);
     }
 }
Example #15
0
 public static async Task CreateModConfigWorker(ModOption mod)
 {
     if (ConfigWorkers.ContainsKey(mod.Id))
     {
         var workerCollection = ConfigWorkers[mod.Id];
         var worker           = Activator.CreateInstance(workerCollection.configWorker) as ModConfigWorkerBase;
         worker.id     = workerCollection.workerAttribute.id;
         worker.mod    = mod;
         worker.helper = new ModConfigHelper(mod);
         await worker.Work();
     }
 }
Example #16
0
 private void AddFileMappings(ModOption option, List <FomodFile> files)
 {
     option.FomodFiles.AddRange(files);
     foreach (FomodFile file in files)
     {
         Tuple <FomodFile, ModOption> mapping = new Tuple <FomodFile, ModOption>(file, option);
         if (FileMap.IndexOf(mapping) == -1)
         {
             FileMap.Add(mapping);
         }
     }
 }
Example #17
0
                public void process(ModOption option)
                {
                    if (option.cfgField.getAttr <HideableAttribute>(true) is HideableAttribute hideableAttr)
                    {
                        string groupID = hideableAttr.groupID;

                        if (groupID == null)
                        {
                            option.cfgField.getAttrs <HideableAttribute>(true).forEach(attr => groupID ??= attr.groupID);
                        }

                        option.addHandler(new Components.Hider.Add(hideableAttr.visChecker, groupID));
                    }
                }
Example #18
0
 private void ReportFomodOption(ModOption option)
 {
     _backgroundWorker.ReportMessage(option.Name, true);
     foreach (FomodFile fomodFile in option.FomodFiles)
     {
         if (string.IsNullOrEmpty(fomodFile.Destination))
         {
             _backgroundWorker.ReportMessage("  " + fomodFile.Source, false);
         }
         else
         {
             _backgroundWorker.ReportMessage(string.Format("  {0} -> {1}",
                                                           fomodFile.Source, fomodFile.Destination), false);
         }
     }
 }
Example #19
0
                public void process(ModOption option)
                {
                    if (processed || !(processed = true))                     // process only the first added option
                    {
                        return;
                    }

                    Debug.assert(instance == null);                     // if this the first option, ModOptions shouldn't be created yet

                    if (option.cfgField.getAttr <NameAttribute>(true) is NameAttribute nameAttr)
                    {
                        if (nameAttr.tooltipType != null || nameAttr.tooltip != null)
                        {
                            option.addHandler(new Components.Tooltip.AddToHeading(nameAttr.tooltipType, nameAttr.tooltip));
                        }
                    }
                }
Example #20
0
        private void AnalyzeNormalArchive(ModOption archiveModOption)
        {
            ArchiveFile archive = archiveModOption.Archive;

            foreach (Entry modArchiveEntry in archive.FileEntries())
            {
                // append entry path to option assets
                string entryPath = modArchiveEntry.GetPath();
                archiveModOption.Assets.Add(entryPath);
                _backgroundWorker.ReportMessage(entryPath, false);

                // enqueue jobs for analyzing archives and plugins
                MapEntryToOption(modArchiveEntry, archiveModOption, archiveModOption);
            }

            _modAnalysis.ModOptions.Add(archiveModOption);
        }
Example #21
0
        private List <ModOption> AnalyzeFomodArchive(ModOption archiveModOption)
        {
            ArchiveFile archive = archiveModOption.Archive;

            _backgroundWorker.ReportMessage("Parsing FOMOD Options", true);
            List <ModOption> fomodOptions = new List <ModOption>();

            // STEP 1: Find the fomod/ModuleConfig.xml file and extract it
            Entry configEntry = archive.FindArchiveEntry(@"fomod\ModuleConfig.xml");

            _backgroundWorker.ReportMessage("Found FOMOD Config at " + configEntry.GetPath(), false);

            Directory.CreateDirectory(@".\fomod");
            configEntry.ExtractToDirectory(@".\fomod");
            _backgroundWorker.ReportMessage("FOMOD Config Extracted", false);

            // STEP 2: Parse ModuleConfig.xml and determine what the mod options are
            FomodConfig fomodConfig = new FomodConfig(@".\fomod\ModuleConfig.xml");

            _backgroundWorker.ReportMessage("Detecting FOMOD options" + Environment.NewLine, true);
            fomodOptions = fomodConfig.BuildModOptions(archiveModOption.BaseInstallerPath);
            foreach (ModOption option in fomodOptions)
            {
                ReportFomodOption(option);
            }

            // STEP 4: Loop through the archive's assets appending them to mod options per mapping
            IList <Entry> fileEntries = archive.FileEntries();

            _backgroundWorker.ReportMessage(string.Format("{0}Mapping {1} assets to {2} FOMOD Options",
                                                          Environment.NewLine, fileEntries.Count, fomodOptions.Count), true);
            foreach (Entry entry in fileEntries)
            {
                MapEntryToFomodOption(fomodConfig.FileMap, entry, archiveModOption);
            }

            // STEP 5: Delete any options that have no assets or plugins in them
            _backgroundWorker.ReportMessage(Environment.NewLine + "Cleaning up...", true);
            fomodOptions.RemoveAll(ModOption.IsEmpty);

            // Return the mod options we built
            _backgroundWorker.ReportMessage(Environment.NewLine + "Done.  " + fomodOptions.Count + " FOMOD Options found.", true);
            return(fomodOptions);
        }
Example #22
0
            // create mod option based on underlying type and attributes of cfgField
            public static ModOption create(Config.Field cfgField)
            {
                ModOption option = null;

                foreach (var c in creators)
                {
                    if ((option = c.create(cfgField)) != null)
                    {
                        break;
                    }
                }

                if (option != null)
                {
                    modifiers.ForEach(m => m.process(option));
                }

                return(option);
            }
Example #23
0
 // performs the enqueued entry analysis jobs
 // TODO: Raise exception if job fails
 private void AnalyzeEntries(ModOption archiveModOption)
 {
     foreach (string pluginPath in archiveModOption.PluginPaths)
     {
         PluginDump dump = _pluginAnalyzer.GetPluginDump(pluginPath);
         if (dump != null)
         {
             MapPluginDump(pluginPath, dump);
         }
     }
     foreach (string archivePath in archiveModOption.ArchivePaths)
     {
         List <string> assets = _assetArchiveAnalyzer.GetAssetPaths(archivePath);
         if (assets == null)
         {
             continue;
         }
         MapArchiveAssetPaths(archivePath, assets);
     }
 }
Example #24
0
                    public void init(ModOption option)
                    {
                        parentOption = option;

                        if (tooltip == null)
                        {
                            return;
                        }

                        // adjust text size for default tooltip (before we registering string with LanguageHelper)
                        if (tooltipCmpType == null)
                        {
                            tooltip = $"<size={defaultTextSize}>" + tooltip + "</size>";
                        }

                        string stringID = option.id + ".tooltip";

                        uniqueIDs.ensureUniqueID(ref stringID);                         // in case we add more than one tooltip to the option (e.g. for heading)

                        registerLabel(stringID, ref tooltip, false);
                    }
Example #25
0
        private List <ModOption> AnalyzeBainArchive(ModOption archiveModOption)
        {
            ArchiveFile archive = archiveModOption.Archive;
            bool        flex    = archiveModOption.IsFlexArchive;

            if (flex)
            {
                archiveModOption.BaseInstallerPath = archiveModOption.Archive.GetBaseDirectory();
            }
            string bainType = flex ? "FLEX" : "BAIN";

            _backgroundWorker.ReportMessage("Parsing " + bainType + " Options", true);
            List <ModOption> bainOptions = new List <ModOption>();
            List <Tuple <string, ModOption> > bainMap = new List <Tuple <string, ModOption> >();

            // STEP 1. Find BAIN directories and build mod options for them
            foreach (string bainDirectory in archiveModOption.GetInstallerDirectories(!flex))
            {
                string bainOptionName = Path.GetFileName(bainDirectory);
                _backgroundWorker.ReportMessage("Found " + bainType + " Option " + bainOptionName, false);
                ModOption bainOption = new ModOption(bainOptionName, false, true);
                bainMap.Add(new Tuple <string, ModOption>(bainDirectory, bainOption));
                bainOptions.Add(bainOption);
            }

            // STEP 2: Map entries to bain options
            IList <Entry> fileEntries = archive.FileEntries();

            _backgroundWorker.ReportMessage(string.Format("{0}Mapping {1} assets to {2} {3} Options",
                                                          Environment.NewLine, fileEntries.Count, bainOptions.Count, bainType), true);
            foreach (Entry entry in fileEntries)
            {
                MapEntryToBainOption(bainMap, entry, archiveModOption);
            }

            // Return the mod options we built
            _backgroundWorker.ReportMessage("Done.  " + bainOptions.Count + " " + bainType + " Options found.", true);
            return(bainOptions.OrderBy(x => x.Name).ToList());
        }
Example #26
0
        private void MapEntryToBainOption(List <Tuple <string, ModOption> > map, Entry entry, ModOption archiveModOption)
        {
            string entryPath = entry.GetPath();

            foreach (Tuple <string, ModOption> mapping in map)
            {
                string    bainPath = mapping.Item1 + @"\";
                ModOption option   = mapping.Item2;

                if (entryPath.StartsWith(bainPath))
                {
                    string mappedPath = entryPath.Replace(bainPath, "");
                    if (mappedPath == "")
                    {
                        continue;
                    }
                    option.Assets.Add(mappedPath);
                    option.Size += (long)entry.Size;

                    // enqueue jobs for analyzing archives and plugins
                    MapEntryToOption(entry, option, archiveModOption);
                }
            }
        }
Example #27
0
 private void AnalyzeArchive(ModOption modOption)
 {
     if (modOption.IsFomodArchive)
     {
         List <ModOption> fomodOptions = AnalyzeFomodArchive(modOption);
         fomodOptions.ForEach(mo => {
             mo.MD5Hash = modOption.MD5Hash;
             mo.Default = mo.Default && modOption.Default;
         });
         _modAnalysis.ModOptions.Add(modOption);
         _modAnalysis.ModOptions.AddRange(fomodOptions);
     }
     else if (modOption.IsBainArchive || modOption.IsFlexArchive)
     {
         List <ModOption> bainOptions = AnalyzeBainArchive(modOption);
         bainOptions.ForEach(mo => { mo.MD5Hash = modOption.MD5Hash; });
         _modAnalysis.ModOptions.Add(modOption);
         _modAnalysis.ModOptions.AddRange(bainOptions);
     }
     else
     {
         AnalyzeNormalArchive(modOption);
     }
 }
Example #28
0
 public static PersistenceMod CreateData(ModOption option) => new PersistenceMod(option);
Example #29
0
 public void init(ModOption option) => id = option.id;
        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);
            }
        }