/// <summary> /// Add <see cref="ZipArchiveEntry"/> into tree structure. /// </summary> /// <param name="root"></param> /// <param name="zipArchiveEntries"></param> /// <param name="streamProvider">stream provider for files</param> /// <returns>this</returns> static ArchiveDirectoryEntry AddArchiveEntries(ArchiveDirectoryEntry root, IEnumerable <ZipArchiveEntry> zipArchiveEntries, IStreamProvider streamProvider) { foreach (ZipArchiveEntry ze in zipArchiveEntries) { // Is entry a file if (!ze.FullName.EndsWith("/") || ze.Length > 0L) { // Split to filename and path int slashIx = ze.FullName.LastIndexOf('/'); string filename = ze.FullName.Substring(slashIx + 1); string dirPath = slashIx < 0 ? "" : ze.FullName.Substring(0, slashIx); // Create file entry ArchiveFileEntry fileEntry = new ArchiveFileEntry(streamProvider, ze.FullName, filename, ze.Length, ze.LastWriteTime); // Create dir ArchiveDirectoryEntry dir = root.GetOrCreateDirectory(dirPath); // Add to dir dir.files[filename] = fileEntry; } else { // Create dir root.GetOrCreateDirectory(ze.FullName); } } // Return the whole tree return(root); }
public static GameFont HiResFromGameData() { using (DisposableStack disposables = new DisposableStack(2)) { GameImage firstImage, secondImage; ArchiveDirectoryEntry mainDirectory = Archives.GetEntry <ArchiveDirectoryEntry>(MainPath); ArchiveDirectoryEntry menuDirectory = Archives.GetEntry <ArchiveDirectoryEntry>(MenuPath); ArchiveDirectoryEntry hiresDirectory = menuDirectory.GetChildEntry <ArchiveDirectoryEntry>(HiResDirectoryName); ArchiveFileEntry tdwEntry = mainDirectory.GetChildEntry <ArchiveFileEntry>(HiResCharactersWidthsFileName); ArchiveFileEntry image01 = hiresDirectory.GetChildEntry <ArchiveFileEntry>(HiResFontImage1FileName); ArchiveFileEntry image02 = hiresDirectory.GetChildEntry <ArchiveFileEntry>(HiResFontImage2FileName); byte[] widths; using (TdwFileReader tdwReader = new TdwFileReader(tdwEntry.OpenReadableContentStream())) widths = tdwReader.Table; using (TexFileReader texReader = new TexFileReader(image01.OpenReadableContentStream())) { firstImage = GameImageReader.FromTex(texReader); disposables.Add(firstImage.Layer); } using (TexFileReader texReader = new TexFileReader(image02.OpenReadableContentStream())) secondImage = disposables.Add(GameImageReader.FromTex(texReader)); int x = firstImage.X; int y = firstImage.Y; GLTexture palettes = firstImage.Palettes; GLTexture layer = GLTextureFactory.HorizontalJoin(firstImage.Layer, secondImage.Layer); GameImage image = new GameImage(x, y, layer, palettes); return(new GameFont(image, widths)); } }
public static void HiResToGameData(GameFont gameFont) { using (DisposableStack disposables = new DisposableStack(2)) { GLTexture leftTexture; GLTexture rightTexture; GLTextureFactory.HorizontalSplit(gameFont.CharactersImage.Layer, out leftTexture, out rightTexture); disposables.Add(leftTexture); disposables.Add(rightTexture); ArchiveDirectoryEntry mainDirectory = Archives.GetEntry <ArchiveDirectoryEntry>(GameFontReader.MainPath); ArchiveDirectoryEntry menuDirectory = Archives.GetEntry <ArchiveDirectoryEntry>(GameFontReader.MenuPath); ArchiveDirectoryEntry hiresDirectory = menuDirectory.GetChildEntry <ArchiveDirectoryEntry>(GameFontReader.HiResDirectoryName); ArchiveFileEntry tdwEntry = mainDirectory.GetChildEntry <ArchiveFileEntry>(GameFontReader.HiResCharactersWidthsFileName); ArchiveFileEntry image01 = hiresDirectory.GetChildEntry <ArchiveFileEntry>(GameFontReader.HiResFontImage1FileName); ArchiveFileEntry image02 = hiresDirectory.GetChildEntry <ArchiveFileEntry>(GameFontReader.HiResFontImage2FileName); using (Stream output = tdwEntry.OpenWritableCapacityStream()) using (TdwFileWriter tdwWriter = new TdwFileWriter(output)) { tdwWriter.WriteFontCharactersWidths(gameFont.CharactersWidths); tdwEntry.UpdateMetrics((int)output.Position, tdwEntry.ContentOffset, Compression.None); } using (Stream output = image01.OpenWritableCapacityStream()) using (TexFileWriter texWriter = new TexFileWriter(output)) { texWriter.WriteImage(leftTexture, gameFont.CharactersImage.Palettes); image01.UpdateMetrics((int)output.Position, image01.ContentOffset, Compression.None); } using (Stream output = image02.OpenWritableCapacityStream()) using (TexFileWriter texWriter = new TexFileWriter(output)) { texWriter.WriteImage(rightTexture, gameFont.CharactersImage.Palettes); image02.UpdateMetrics((int)output.Position, image02.ContentOffset, Compression.None); } Archives.GetInfo(ArchiveName.Main).Update(); Archives.GetInfo(ArchiveName.Menu).Update(); } }
public static GameFont FromGameData(ArchiveDirectoryEntry directory, string name) { ArchiveFileEntry tdwEntry = (ArchiveFileEntry)directory.Childs.TryGetValue(name + ".tdw"); if (tdwEntry == null) { return(null); } using (TdwFileReader tdwReader = new TdwFileReader(tdwEntry.OpenReadableContentStream())) using (TimFileReader timReader = tdwReader.TimReader) { if (timReader == null) { return(null); } GameImage image = GameImageReader.FromTim(timReader); return(new GameFont(image, tdwReader.Table)); } }
private static LocalizableStrings LoadAreaNames() { lock (_glossaryNode) { if (_glossaryNode.Value != null) { XmlElement node = _glossaryNode.Value.GetChildElement("AreaNames"); return(LocalizableString.FromXml(node)); } ArchiveDirectoryEntry dir = Archives.GetEntry <ArchiveDirectoryEntry>(SourcePath); ArchiveFileEntry entry1 = dir.GetChildEntry <ArchiveFileEntry>(AreaNamesFileName); LocalizableStrings result = new LocalizableStrings(256); using (DictionaryFileReader dicReader = new DictionaryFileReader(entry1.OpenReadableContentStream())) foreach (string title in dicReader.Titles) { result.Add(new LocalizableString(title, title)); } return(result); } }
public static Location FindLocation(string name) { Exceptions.CheckArgumentNullOrEmprty(name, "name"); if (name.Length < 2) { throw new ArgumentException("name"); } string transformedPath = GetTransformedPath(name); ArchiveDirectoryEntry locationDirectory = FindLocationDirectory(name); if (locationDirectory == null) { return(null); } GameLocationReader gameReader = new GameLocationReader(locationDirectory, name); GameLocationWriter gameWriter = new GameLocationWriter(locationDirectory, name); XmlLocationReader xmlReader = new XmlLocationReader(transformedPath); XmlLocationWriter xmlWriter = new XmlLocationWriter(transformedPath); return(new Location(name, gameReader, gameWriter, xmlReader, xmlWriter)); }
public GameLocationWriter(ArchiveDirectoryEntry locationDirectory, string name) { _locationDirectory = Exceptions.CheckArgumentNull(locationDirectory, "locationDirectory"); _name = Exceptions.CheckArgumentNullOrEmprty(name, "name"); }