public static void RemoveUnpacker(ResourceTypeUnpacker unpacker) { Unpacker.Remove(unpacker); }
public static void Activate(string name, IProgressIndicator ProgressInfo, string targetDir = null) { if (targetDir == null) { targetDir = ResourceDirectory; } if (LoadedPacks.ContainsKey(name)) { ProgressInfo?.SetProgress("Loading Package...", 1, 3); Stream archStream = IOManager.GetStream(LoadedPacks[name].ResourceData); ZipArchive arch = new ZipArchive(archStream); ProgressInfo?.SetProgress("Preparing Unpackers...", 2, 3); Dictionary <string, string[]> unpackers = new Dictionary <string, string[]>( LoadedPacks[name] .UnpackerConfig .Split( new[] { ';' }, StringSplitOptions .RemoveEmptyEntries ).Select( x => { KeyValuePair <string , string [] > ret = new KeyValuePair <string , string [] >( x.Split( '+' )[0], x.Split( '+' ) ); List < string > temp = ret .Value .Select(y => y == "" ? y : "." + y) .ToList(); temp .RemoveAt( 0 ); ret = new KeyValuePair <string , string [] >( ret .Key, temp .ToArray() ); return (ret); } ).ToDictionary( x => x.Key, y => y.Value ) ); ProgressInfo?.SetProgress("Unpacking...", 3, 3); IProgressIndicator perFileProgress = ProgressInfo?.CreateSubTask(); int fileCount = 0; for (int i = 0; i < arch.Entries.Count; i++) { if (arch.Entries[i].Name == "Info.xml") { continue; } bool unpacked = false; foreach (KeyValuePair <string, string[]> keyValuePair in unpackers) { if (keyValuePair.Value.Contains(Path.GetExtension(arch.Entries[i].Name))) { ResourceTypeUnpacker u = Unpacker.FirstOrDefault(x => x.UnpackerName == keyValuePair.Key); if (u == null) { continue; } perFileProgress?.SetProgress( "Unpacking:" + arch.Entries[i].FullName, fileCount, arch.Entries.Count - 1 ); fileCount++; u.Unpack( targetDir, arch.Entries[i].FullName, arch.Entries[i].Open(), perFileProgress?.CreateSubTask() ); unpacked = true; break; } } if (!unpacked) { perFileProgress?.SetProgress( "Unpacking:" + arch.Entries[i].FullName, fileCount, arch.Entries.Count - 1 ); fileCount++; string key = unpackers.Where(x => x.Value.Length == 0).Select(x => x.Key).FirstOrDefault(); if (key == null) { continue; } ResourceTypeUnpacker u = Unpacker.FirstOrDefault(x => x.UnpackerName == key); if (u == null) { continue; } u.Unpack( targetDir, arch.Entries[i].FullName, arch.Entries[i].Open(), perFileProgress?.CreateSubTask() ); } } perFileProgress?.Dispose(); ProgressInfo?.Dispose(); } }
public static void AddUnpacker(ResourceTypeUnpacker unpacker) { Unpacker.Add(unpacker); }