public bool TryInject(IUiInjectionSource source, string sourceFullPath, ArchiveEntryInjectionData data, ArchiveEntry entry) { Dictionary<string, string> sourceEntries; using (Stream input = source.TryOpen(sourceFullPath)) { if (input != null) { string entryName; ZtrTextReader reader = new ZtrTextReader(input, StringsZtrFormatter.Instance); sourceEntries = reader.Read(out entryName).ToDictionary(e => e.Key, e => e.Value); using (Stream output = data.OuputStreamFactory(entry)) Inject(data.Listing, entry, sourceEntries, output); return true; } } MemoryInjectionSource memorySource = source as MemoryInjectionSource; if (memorySource == null) return false; sourceEntries = memorySource.TryProvideStrings(); if (sourceEntries == null) return false; using (Stream output = data.OuputStreamFactory(entry)) Inject(data.Listing, entry, sourceEntries, output); return true; }
//private static void PackFonts(string root, BinaryWriter bw) //{ // const string xgrArchiveName = @"gui/resident/system.unpack"; // root = Path.Combine(root, @"Fonts"); // ImgbPatchData.WriteTo(xgrArchiveName, root, bw); //} private void PackStrings(string root, BinaryWriter bw) { if (CancelEvent.IsSet()) return; root = Path.Combine(root, @"Strings"); string[] files = Directory.GetFiles(root, "*.strings", SearchOption.AllDirectories); Position = 0; Maximum = files.Length; foreach (string file in files) { if (CancelEvent.IsSet()) return; using (FileStream input = File.OpenRead(file)) { string name; ZtrTextReader reader = new ZtrTextReader(input, StringsZtrFormatter.Instance); ZtrFileEntry[] entries = reader.Read(out name); bw.Write(entries.Length); foreach (ZtrFileEntry entry in entries) { bw.Write(entry.Key); bw.Write(entry.Value); } } OnProgress(1); } bw.Write(0); }
private Dictionary<string, string> ReadStrings(DirectoryInfo translationDir) { String[] strings = Directory.GetFiles(Path.Combine(translationDir.FullName, "Strings"), "*.strings", SearchOption.AllDirectories); Dictionary<string, string> result = new Dictionary<string, string>(16000); Maximum = strings.Length; for (int i = 0; i < strings.Length; i++) { if (CancelEvent.IsSet()) return result; using (FileStream input = File.OpenRead(strings[i])) { string name; ZtrTextReader unpacker = new ZtrTextReader(input, StringsZtrFormatter.Instance); ZtrFileEntry[] entries = unpacker.Read(out name); foreach (ZtrFileEntry entry in entries) { string key = entry.Key; string value = entry.Value; result[key] = value; } } } return result; }