public static bool?OpenTool(Stream stream, Bar.EntryType type) { string name; switch (type) { case Bar.EntryType.Bar: name = "OpenKh.Tools.BarEditor"; break; case Bar.EntryType.Imgd: name = "OpenKh.Tools.ImgdViewer"; break; case Bar.EntryType.Imgz: name = "OpenKh.Tools.ImgzViewer"; break; default: throw new NotImplementedException($"Unable to find a tool for \"{type}\" files."); } var toolModule = Plugins .GetModules <IToolModule>(null, x => x.Contains(name) && Path.GetExtension(x) == ".exe") .FirstOrDefault(); var tool = Activator.CreateInstance(toolModule.Item2) as IToolModule; stream.Position = 0; return(tool?.ShowDialog(stream)); }
public static void ForAllBarEntries(string gamePath, Bar.EntryType entryType, Action <Bar.Entry> action) => Directory .GetFiles(gamePath, "*", SearchOption.AllDirectories) .Where(fileName => File.OpenRead(fileName).Using(stream => Bar.IsValid(stream))) .SelectMany(fileName => File.OpenRead(fileName).Using(stream => Bar.Read(stream))) .Where(x => x.Type == entryType && x.Index == 0) .AsParallel() .ForAll(action);
public ResourceSelectionDialog( IEnumerable <Bar.Entry> entries, Bar.EntryType animationType, Bar.EntryType textureType) { _animations = entries .Where(x => x.Type == animationType && x.Index == 0) .ToArray(); _textures = entries .Where(x => x.Type == textureType && x.Index == 0) .ToArray(); }
public static IEnumerable <Bar.Entry> ForEntry(this IEnumerable <Bar.Entry> entries, Bar.EntryType type, string name, int index, Action <Bar.Entry> funcEntry) { var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name && x.Index == index); if (entry == null) { entry = new Bar.Entry { Type = type, Name = name, Index = index, Stream = new MemoryStream() }; entries = entries.Concat(new Bar.Entry[] { entry }); } funcEntry(entry); return(entries); }
public static T ForEntry <T>(this IEnumerable <Bar.Entry> entries, string name, Bar.EntryType type, Func <Stream, T> action) => entries.ForEntry(x => x.Type == type && x.Name == name, action);
public static bool ForEntry(this IEnumerable <Bar.Entry> entries, string name, Bar.EntryType type, Action <Stream> action) { var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name); if (entry == null) { return(false); } entry.Stream.Seek(0, SeekOrigin.Begin); action(entry.Stream); return(true); }
public static string GetSuggestedExtension(Bar.EntryType type) => SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension;
public static void AssertAllBarEntries(string gamePath, Bar.EntryType entryType, Func <Stream, Stream> assertion) => ForAllBarEntries(gamePath, entryType, entry => AssertStream(entry.Stream, assertion));
public static T ForEntry <T>(this IEnumerable <Bar.Entry> entries, string name, Bar.EntryType type, Func <Stream, T> action) { var entry = entries.FirstOrDefault(x => x.Type == type && x.Name == name); if (entry == null) { return(default);