コード例 #1
0
        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));
        }
コード例 #2
0
ファイル: Helpers.cs プロジェクト: cualquiercosa327/OpenKh
 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);
コード例 #3
0
 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();
 }
コード例 #4
0
        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);
        }
コード例 #5
0
 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);
コード例 #6
0
        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);
        }
コード例 #7
0
ファイル: Helpers.cs プロジェクト: tadanokojin/OpenKh
 public static string GetSuggestedExtension(Bar.EntryType type) =>
 SuggestedExtensions.TryGetValue(type, out var ext) ? ext : DefaultExtension;
コード例 #8
0
ファイル: Helpers.cs プロジェクト: cualquiercosa327/OpenKh
 public static void AssertAllBarEntries(string gamePath, Bar.EntryType entryType, Func <Stream, Stream> assertion) =>
 ForAllBarEntries(gamePath, entryType, entry => AssertStream(entry.Stream, assertion));
コード例 #9
0
ファイル: BarExtensions.cs プロジェクト: xorllc/OpenKh
        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);