private void ImportV1ModPack(FileInfo modPackFile, ZipFile extractedModPack, string modRaw) { PluginLog.Log(" -> Importing V1 ModPack"); var modListRaw = modRaw.Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ); var modList = modListRaw.Select(JsonConvert.DeserializeObject <SimpleMod>); // Create a new ModMeta from the TTMP modlist info var modMeta = new ModMeta { Author = "Unknown", Name = modPackFile.Name, Description = "Mod imported from TexTools mod pack", }; // Open the mod data file from the modpack as a SqPackStream using var modData = GetMagicSqPackDeleterStream(extractedModPack, "TTMPD.mpd"); var newModFolder = CreateModFolder(Path.GetFileNameWithoutExtension(modPackFile.Name)); File.WriteAllText( Path.Combine(newModFolder.FullName, "meta.json"), JsonConvert.SerializeObject(modMeta) ); ExtractSimpleModList(newModFolder, modList, modData); }
public static void GenerateMetaFile(ModMeta meta) { Logger.InfoLog($"-Creating meta for {meta.ModName}"); string modMeta = JsonConvert.SerializeObject(meta, Formatting.Indented); File.WriteAllText(Path.Combine(PathList.ModsFolderPath, meta.ModName + ".json"), modMeta); }
private void ImportV1ModPack(FileInfo modPackFile) { PluginLog.Log(" -> Importing V1 ModPack"); using var extractedModPack = ZipFile.Read(modPackFile.OpenRead()); var modListRaw = GetStringFromZipEntry(extractedModPack["TTMPL.mpl"], Encoding.UTF8).Split( new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None ); var modList = modListRaw.Select(JsonConvert.DeserializeObject <SimpleMod>); // Create a new ModMeta from the TTMP modlist info var modMeta = new ModMeta { Author = "Unknown", Name = modPackFile.Name, Description = "Mod imported from TexTools mod pack" }; // Open the mod data file from the modpack as a SqPackStream var modData = GetSqPackStreamFromZipEntry(extractedModPack["TTMPD.mpd"]); var newModFolder = new DirectoryInfo(Path.Combine(_outDirectory.FullName, Path.GetFileNameWithoutExtension(modPackFile.Name))); newModFolder.Create(); File.WriteAllText(Path.Combine(newModFolder.FullName, "meta.json"), JsonConvert.SerializeObject(modMeta)); ExtractSimpleModList(newModFolder, modList, modData); }
private void ImportSimpleV2ModPack(ZipFile extractedModPack) { PluginLog.Log(" -> Importing Simple V2 ModPack"); var modList = JsonConvert.DeserializeObject <SimpleModPack>(GetStringFromZipEntry(extractedModPack["TTMPL.mpl"], Encoding.UTF8)); // Create a new ModMeta from the TTMP modlist info var modMeta = new ModMeta { Author = modList.Author, Name = modList.Name, Description = string.IsNullOrEmpty(modList.Description) ? "Mod imported from TexTools mod pack" : modList.Description }; // Open the mod data file from the modpack as a SqPackStream var modData = GetSqPackStreamFromZipEntry(extractedModPack["TTMPD.mpd"]); var newModFolder = new DirectoryInfo(Path.Combine(_outDirectory.FullName, Path.GetFileNameWithoutExtension(modList.Name))); newModFolder.Create(); File.WriteAllText(Path.Combine(newModFolder.FullName, "meta.json"), JsonConvert.SerializeObject(modMeta)); ExtractSimpleModList(newModFolder, modList.SimpleModsList, modData); }
private void DrawModAddButton() { if (ImGui.BeginPopupContextItem(LabelAddModPopup)) { if (_keyboardFocus) { ImGui.SetKeyboardFocusHere(); _keyboardFocus = false; } var newName = ""; if (ImGui.InputTextWithHint("##AddMod", "New Mod Name...", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue)) { try { var newDir = TexToolsImport.CreateModFolder(new DirectoryInfo(_base._plugin.Configuration !.CurrentCollection), newName); var modMeta = new ModMeta { Author = "Unknown", Name = newName, Description = string.Empty, }; var metaPath = Path.Combine(newDir.FullName, "meta.json"); File.WriteAllText(metaPath, JsonConvert.SerializeObject(modMeta, Formatting.Indented)); _base.ReloadMods(); SelectModByDir(newDir.Name); } catch (Exception e) { PluginLog.Error($"Could not create directory for new Mod {newName}:\n{e}"); } ImGui.CloseCurrentPopup(); } if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape))) { ImGui.CloseCurrentPopup(); } ImGui.EndPopup(); } ImGui.PushFont(UiBuilder.IconFont); if (ImGui.Button(FontAwesomeIcon.Plus.ToIconString(), SelectorButtonSizes)) { _keyboardFocus = true; ImGui.OpenPopup(LabelAddModPopup); } ImGui.PopFont(); if (ImGui.IsItemHovered()) { ImGui.SetTooltip(TooltipAdd); } }
private void ImportExtendedV2ModPack(ZipFile extractedModPack) { PluginLog.Log(" -> Importing Extended V2 ModPack"); var mpl = extractedModPack.GetEntry("TTMPL.mpl"); var modList = JsonConvert.DeserializeObject <ExtendedModPack>(GetStringFromZipEntry(extractedModPack, mpl, Encoding.UTF8)); // Create a new ModMeta from the TTMP modlist info var modMeta = new ModMeta { Author = modList.Author, Name = modList.Name, Description = string.IsNullOrEmpty(modList.Description) ? "Mod imported from TexTools mod pack" : modList.Description, Version = modList.Version }; // Open the mod data file from the modpack as a SqPackStream using var modData = GetMagicSqPackDeleterStream(extractedModPack, "TTMPD.mpd"); var newModFolder = new DirectoryInfo( Path.Combine(_outDirectory.FullName, Path.GetFileNameWithoutExtension(modList.Name) ) ); newModFolder.Create(); File.WriteAllText( Path.Combine(newModFolder.FullName, "meta.json"), JsonConvert.SerializeObject(modMeta) ); if (modList.SimpleModsList != null) { ExtractSimpleModList(newModFolder, modList.SimpleModsList, modData); } if (modList.ModPackPages == null) { return; } // Iterate through all pages // For now, we are just going to import the default selections // TODO: implement such a system in resrep? foreach (var option in from modPackPage in modList.ModPackPages from modGroup in modPackPage.ModGroups from option in modGroup.OptionList where option.IsChecked select option) { ExtractSimpleModList(newModFolder, option.ModsJsons, modData); } }
private void DrawModAddPopup() { if (!ImGui.BeginPopup(LabelAddModPopup)) { return; } using var raii = ImGuiRaii.DeferredEnd(ImGui.EndPopup); if (_modAddKeyboardFocus) { ImGui.SetKeyboardFocusHere(); _modAddKeyboardFocus = false; } var newName = ""; if (ImGui.InputTextWithHint("##AddMod", "New Mod Name...", ref newName, 64, ImGuiInputTextFlags.EnterReturnsTrue)) { try { var newDir = TexToolsImport.CreateModFolder(new DirectoryInfo(Penumbra.Config !.ModDirectory), newName); var modMeta = new ModMeta { Author = "Unknown", Name = newName.Replace('/', '\\'), Description = string.Empty, }; var metaFile = new FileInfo(Path.Combine(newDir.FullName, "meta.json")); modMeta.SaveToFile(metaFile); _modManager.AddMod(newDir); ModFileSystem.InvokeChange(); SelectModOnUpdate(newDir.Name); } catch (Exception e) { PluginLog.Error($"Could not create directory for new Mod {newName}:\n{e}"); } ImGui.CloseCurrentPopup(); } if (ImGui.IsKeyPressed(ImGui.GetKeyIndex(ImGuiKey.Escape))) { ImGui.CloseCurrentPopup(); } }
void AddMeta(DirectoryInfo optionFolder, DirectoryInfo baseFolder, ModMeta meta, string optionName) { var optionFolderLength = optionFolder.FullName.Length; var baseFolderLength = baseFolder.FullName.Length; foreach (var dir in optionFolder.EnumerateDirectories()) { foreach (var file in dir.EnumerateFiles("*.*", SearchOption.AllDirectories)) { meta.Groups.AddFileToOtherGroups(optionName , file.FullName.Substring(baseFolderLength).TrimStart('\\') , file.FullName.Substring(optionFolderLength).TrimStart('\\').Replace('\\', '/')); } } }
public void UpdateSetting(DirectoryInfo modPath, ModMeta meta, bool clear) { if (!Settings.TryGetValue(modPath.Name, out var settings)) { return; } if (clear) { settings.Settings.Clear(); } if (settings.FixInvalidSettings(meta)) { Save(); } }
private static Mod LoadMod(FileInfo file) { Logger.InfoLog($"-Loading {file.Name}"); string modName = Path.GetFileNameWithoutExtension(file.Name); if (file.Directory.FullName == PathList.BepMonomodPath) { modName = modName.Split('.')[1]; } string pathToMeta = Path.Combine(PathList.ModsFolderPath, $"{modName}.json"); ModMeta meta = null; if (File.Exists(pathToMeta)) { meta = MetaHandler.GetMeta(pathToMeta); } if (meta == null) { meta = new ModMeta() { ModType = ModTypeChecker.GetModType(file), ModName = modName }; MetaHandler.GenerateMetaFile(meta); } var mod = new Mod() { IsEnabled = false, CurrentlyEnabled = false, Meta = meta }; return(mod); }
private static void AddMeta(DirectoryInfo baseFolder, DirectoryInfo groupFolder, ModGroup group, ModMeta meta) { var inf = new OptionGroup { SelectionType = group.SelectionType, GroupName = group.GroupName !, Options = new List <Option>(), }; foreach (var opt in group.OptionList !) { var option = new Option { OptionName = opt.Name !, OptionDesc = string.IsNullOrEmpty(opt.Description) ? "" : opt.Description !, OptionFiles = new Dictionary <RelPath, HashSet <GamePath> >(), }; var optDir = new DirectoryInfo(Path.Combine(groupFolder.FullName, opt.Name !.ReplaceInvalidPathSymbols())); if (optDir.Exists) { foreach (var file in optDir.EnumerateFiles("*.*", SearchOption.AllDirectories)) { option.AddFile(new RelPath(file, baseFolder), new GamePath(file, optDir)); } } inf.Options.Add(option); } meta.Groups.Add(inf.GroupName, inf); }
private void ImportExtendedV2ModPack(ZipFile extractedModPack, string modRaw) { PluginLog.Log(" -> Importing Extended V2 ModPack"); var modList = JsonConvert.DeserializeObject <ExtendedModPack>(modRaw); // Create a new ModMeta from the TTMP modlist info var modMeta = new ModMeta { Author = modList.Author ?? "Unknown", Name = modList.Name ?? "New Mod", Description = string.IsNullOrEmpty(modList.Description) ? "Mod imported from TexTools mod pack" : modList.Description ?? "", Version = modList.Version ?? "", }; // Open the mod data file from the modpack as a SqPackStream using var modData = GetMagicSqPackDeleterStream(extractedModPack, "TTMPD.mpd"); var newModFolder = CreateModFolder(modList.Name ?? "New Mod"); if (modList.SimpleModsList != null) { ExtractSimpleModList(newModFolder, modList.SimpleModsList, modData); } if (modList.ModPackPages == null) { return; } // Iterate through all pages foreach (var page in modList.ModPackPages) { if (page.ModGroups == null) { continue; } foreach (var group in page.ModGroups.Where(group => group.GroupName != null && group.OptionList != null)) { var groupFolder = new DirectoryInfo(Path.Combine(newModFolder.FullName, group.GroupName !.ReplaceInvalidPathSymbols())); if (groupFolder.Exists) { groupFolder = new DirectoryInfo(groupFolder.FullName + $" ({page.PageIndex})"); group.GroupName += $" ({page.PageIndex})"; } foreach (var option in group.OptionList !.Where(option => option.Name != null && option.ModsJsons != null)) { var optionFolder = new DirectoryInfo(Path.Combine(groupFolder.FullName, option.Name !.ReplaceInvalidPathSymbols())); ExtractSimpleModList(optionFolder, option.ModsJsons !, modData); } AddMeta(newModFolder, groupFolder, group, modMeta); } } File.WriteAllText( Path.Combine(newModFolder.FullName, "meta.json"), JsonConvert.SerializeObject(modMeta, Formatting.Indented) ); }
[TestMethod()] public void ModMetaNormTest() { var dict = new Dictionary <string, string>(); dict.Add("*", "def"); var meta = new ModMeta() { Id = "", Lang = new string[0], Mods = new string[] { "" }, Name = new TextSet { Default = " " }, Description = new TextSet { Default = "a", Dict = new Dictionary <string, string>() }, Author = new TextSet { Default = " ", Dict = dict }, Requires = new AppVer[0], Disables = new AppVer[] { new AppVer("") }, Dlls = new DllMeta[] { new DllMeta { Path = "" } }, }; meta.Normalise(); Assert.IsNull(meta.Id, "Id"); Assert.IsNull(meta.Lang, "Langs"); Assert.IsNull(meta.Mods, "Mods"); Assert.IsNull(meta.Name, "Name"); Assert.IsNull(meta.Description.Dict, "Description"); Assert.AreEqual("def", meta.Author.Default, "Author.Default"); Assert.IsNull(meta.Requires, "Requires"); Assert.IsNull(meta.Disables, "Disables"); Assert.IsNull(meta.Dlls, "Dlls"); meta.Id = "Abc"; meta.Normalise(); Assert.AreEqual("Abc", meta.Id, "Id 2"); Assert.AreEqual("Abc", meta.Name.ToString(), "Name 2"); meta.Actions = new Dictionary <string, object> [0]; meta.Normalise(); Assert.IsNull(meta.Actions, "Empty actions"); meta.Actions = new Dictionary <string, object>[] { null, null }; meta.Normalise(); Assert.IsNull(meta.Actions, "null actions"); var emptyDict = new Dictionary <string, object>(); meta.Actions = new Dictionary <string, object>[] { emptyDict }; meta.Normalise(); Assert.IsNull(meta.Actions, "Empty action"); //emptyDict.Add( "a", null ); emptyDict.Add("", "b"); meta.Actions = new Dictionary <string, object>[] { emptyDict }; meta.Normalise(); Assert.IsNull(meta.Actions, "Empty action val and key"); emptyDict.Add(" A ", " b "); meta.Actions = new Dictionary <string, object>[] { emptyDict }; meta.Normalise(); Assert.IsNotNull(meta.Actions, "Non-empty action val and key"); Assert.AreEqual(" b ", meta.Actions[0]["a"], "Action keys are trimmed and lowercased"); }
public ResourceMod(ModMeta meta, DirectoryInfo dir) { Meta = meta; ModBasePath = dir; }