public static ISSGenericFile BuildFile(SSMod mod, SSRelativeUrl Url) { FileInfo info = new FileInfo(Url?.ToString() ?? throw new ArgumentNullException("The Url cannot be null.")); string FileName = info.Name ?? throw new ArgumentNullException("The FileName cannot be null."); string Extension = info.Extension; switch (Extension) { case ".json": return(new SSJson(mod, Url)); case ".faction": return(new SSFaction(mod, Url)); case ".variant": return(new SSVariant(mod, Url)); case ".ship": return(new SSShipHull(mod, Url)); case ".skin": return(new SSShipHullSkin(mod, Url)); case ".csv": return(new SSCsv(mod, Url)); case ".jar": case ".java": return(new SSNoMerge(mod, Url)); default: return(new SSBinary(mod, Url)); } }
public SSGeneric(ISSMod mod, SSRelativeUrl url) { SourceMod = mod; //RelativeUrl = new SSRelativeUrl(url.Relative); RelativeUrl = url; FileInfo info = new FileInfo(url.ToString()); FileName = info.Name ?? throw new ArgumentNullException("The FileName cannot be null."); }
/// <summary>From a list of file creates a maping between a jsonvalue relative path and the actual file</summary> /// <param name="files">list of all files accesible</param> /// <param name="referencedRessources">Ressources referenced</param> public static Dictionary <JsonValue, string> FindFromFiles(IEnumerable <ISSGenericFile> files, IEnumerable <JsonValue> referencedRessources) { Dictionary <JsonValue, string> result = new Dictionary <JsonValue, string>(); foreach (JsonValue reference in referencedRessources) { SSRelativeUrl url = new SSRelativeUrl(reference.ToString()); ISSGenericFile matching = FindFromFiles(files, url); SSFullUrl full = matching.SourceMod.ModUrl + url; result.Add(reference, full.ToString()); } return(result); }
static void Main() { SSBaseUrl SSUrl = new SSBaseUrl("E:\\SS\\Starsector"); SSLinkUrl CoreUrl = new SSLinkUrl("starsector-core"); //SSLinkUrl TahlanUrl = new SSLinkUrl("mods\\tahlan"); SSLinkUrl SWPUrl = new SSLinkUrl("mods\\Ship and Weapon Pack"); SSRelativeUrl shipdataUrl = new SSRelativeUrl("data\\hulls\\ship_data.csv"); SSFullUrl dataurl = SSUrl + SWPUrl + shipdataUrl; CSVContent content; using (StreamReader sr = File.OpenText(dataurl.ToString())) { content = CSVContent.ExtractFromText(sr); } dataurl = SSUrl + CoreUrl + shipdataUrl; CSVContent content2; using (StreamReader sr = File.OpenText(dataurl.ToString())) { content2 = CSVContent.ExtractFromText(sr); } CSVContent content3 = CSVContent.Merge(new[] { content, content2 }); var b = content3.GetLineByColumnValue("id", "swp_archon")["tags"]; //SSBaseUrl ModFolderPath = SSUrl + "mods"; //DirectoryInfo ModsDirectory = new DirectoryInfo(ModFolderPath.ToString()); //IEnumerable<DirectoryInfo> ModsEnumerable = ModsDirectory.EnumerateDirectories(); SSDirectory directory = new SSDirectory(); directory.InstallationUrl = SSUrl; directory.ReadMods(); directory.PopulateMergedCollections(); VariantsRessources variant = new VariantsRessources(directory); ShipHullRessources ship = new ShipHullRessources(directory, variant); BPPackageRessources BPRessource = new BPPackageRessources(directory, ship); //SSDirectory test = new SSDirectory(SSUrl); //SSModWritable target = new SSModWritable(); //target.ModUrl = SSUrl + new SSLinkUrl("mods\\lepg"); //test.ReadMods("lepg"); //test.PopulateMergedCollections(); //FactionEditor factionEditor = new FactionEditor(test); //List<SSFactionGroup> factions = factionEditor.GetFaction(); // }
public JsonArray ReadUsedMod() { SSBaseLinkUrl ModFolderPath = InstallationUrl + new SSLinkUrl("mods"); SSMod Dummy = new SSMod(ModFolderPath); SSRelativeUrl rela = new SSRelativeUrl("enabled_mods.json"); SSJson file = new SSJson(Dummy, rela); file.ExtractFile(); JsonToken trying; file.Fields.TryGetValue(".enabledMods", out trying); if (trying == null) { return(new JsonArray()); } return(trying as JsonArray); }
public SSBinary(SSMod mod, SSRelativeUrl url) : base(mod, url) { }
/// <summary>Replace whatever faction are in the receiver by those of this editor</summary> public void ReplaceFactionToWrite(SSModWritable receiver) { if (Factions == null) { throw new InvalidOperationException("no factions merged"); } IEnumerable <SSFactionGroup> OldFactions = from ISSWritable w in receiver.FileList where w is SSFactionGroup select w as SSFactionGroup; foreach (SSFactionGroup f in OldFactions.ToList()) { receiver.FileList.Remove(f); } foreach (SSFactionGroup f in Factions) { receiver.FileList.Add(f); } SSRelativeUrl settingUrl = new SSRelativeUrl("data\\config\\settings.json"); SSJson SettingFile = (from ISSWritable w in receiver.FileList where w.RelativeUrl.Equals(settingUrl) select w as SSJson).SingleOrDefault(); Portraits = new List <JsonValue>(Ressources.PortraitsRessources.GetOriginalPortraits(Factions)); var UsedPortraits = new List <JsonValue>(Ressources.PortraitsRessources.GetCurrentPortraits(Factions)); var UnusedPortrait = Portraits.Except(UsedPortraits); JsonObject finalPortraits = new JsonObject(UnusedPortrait, "portraits"); if (SettingFile == null) { SettingFile = new SSJson(receiver, settingUrl); SettingFile.JsonContent = new JsonObject(); receiver.FileList.Add(SettingFile); SettingFile.JsonContent.AddSubField(".graphics.portraits", finalPortraits); SettingFile.RefreshFields(); } else { JsonToken setted; SettingFile.Fields.TryGetValue(".graphics.portraits", out setted); if (setted == null) { SettingFile.JsonContent.AddSubField(".graphics.portraits", finalPortraits); } else { JsonObject set = (JsonObject)setted; set.Values.Clear(); foreach (KeyValuePair <JsonValue, JsonToken> kv in finalPortraits.Values) { set.Values.Add(kv.Key, kv.Value); } SettingFile.RefreshFields(); } } IEnumerable <SSFactionGroup> OverWritten = from SSFactionGroup f in Factions where f.MustOverwrite == true select f; IEnumerable <string> ModOverWritten = OverWritten.Select(f => f.MonitoredContent).SelectMany(m => m.Files).Select(f => f.SourceMod).Distinct().Select(mod => mod.ModName); IEnumerable <JsonValue> AddedPortrait = Factions.FindAll(f => f.MonitoredContent.IsModified()).SelectMany(f => { List <MonitoredArrayModification> result = new List <MonitoredArrayModification>(); result.AddRange(f.MalePortraits.GetAddedMod()); result.AddRange(f.FemalePortraits.GetAddedMod()); return(result); }).Select(m => ((JsonValue)m.Content)).Distinct(); JsonRelativeToPortraits converter = new JsonRelativeToPortraits(); IEnumerable <string> addMod = AddedPortrait.Select(j => converter.Convert(new object[] { j, PortraitsRessource }, null, null, null)).Select(p => ((Portraits)p).SourceModName).Distinct(); var together = (ModOverWritten ?? Enumerable.Empty <string>()).Concat(addMod ?? Enumerable.Empty <string>()).Distinct(); JsonValue OldDesc = receiver.ModInfo.Fields[".description"] as JsonValue; string old = OldDesc.ToString(); OldDesc.SetContent(old + " Faction were modified using mods: " + string.Join(", ", together)); }
/// <summary>From a list of file implementing the generic file interface a relative reference finds a ressource.</summary> /// <param name="files">list of all files accesible</param> /// <param name="url">Relative Url of the referenced Url</param> public static ISSGenericFile FindFromFiles(IEnumerable <ISSGenericFile> files, SSRelativeUrl url) { var match = from f in files where f.RelativeUrl == url select f; return(match.Single()); }
public SSCsv(SSMod ssmod, SSRelativeUrl url) : base(ssmod, url) { }
public SSNoMerge(SSMod mod, SSRelativeUrl url) : base(mod, url) { }
public SSShipHullSkin(ISSMod mod, SSRelativeUrl Url) : base(mod, Url) { }
public SSVariant(ISSMod mod, SSRelativeUrl Url) : base(mod, Url) { }
public SSFaction(ISSMod mod, SSRelativeUrl Url) : base(mod, Url) { }