/// <summary> /// Loads an archive from a file /// </summary> /// <param name="path">Path to the file</param> /// <returns>Loaded Archive</returns> /// <exception cref="System.IO.FileNotFoundException"/> /// <exception cref="System.IO.InvalidDataException"/> public static GraphicArchive Load(string path) { if (path == null) { throw new ArgumentNullException("path"); } if (File.Exists(path)) { GraphicArchive archive = null; using (FileStream stream = File.OpenRead(path)) { archive = Load(stream); archive.FileName = path; } if (archive != null && archive.ZoomFactor == ZoomFactor.Zoom1) { string animationPath = path.Remove(path.Length - 3) + "bnm"; if (File.Exists(animationPath)) { archive.Animation = Animation.Load(animationPath); } } return(archive); } else { throw new FileNotFoundException("File not found", path); } }
private static GraphicArchive Load(FileStream path) { using (BinaryReader br = new BinaryReader(path, Encoding.Unicode)) { while (br.ReadByte() != Constants.HeaderTextTerminator) { } byte[] read = br.ReadBytes(3); if (read[0] != 85 || read[1] != 90 || read[2] != 88) // 'UZX' as ASCII characters { throw new InvalidDataException("wrong identification string"); } byte zoomFactor = (byte)(br.ReadByte() - 48); // zoomFactor number is stored as ASCII. -48 will 'convert' this to int int elementNumber; List <ArchiveElement> graphics = new List <ArchiveElement>(); while (true) { elementNumber = br.ReadInt32(); if (elementNumber == -1) { break; } br.ReadInt32(); //skipping data (bauform) br.ReadInt32(); //skipping data (fwSig) int animationPhase = br.ReadInt32(); //AnimationPhase int alternative = br.ReadInt32(); //Alternative ArchiveElement archiveElement = new ArchiveElement(elementNumber, animationPhase, alternative, null); //Graphic loaded later archiveElement.SeekPosition = ((int)(br.BaseStream.Position + 4 + br.ReadInt32())); // +4 Used for unknown reasons. Possibly because of C/C# incompatibility graphics.Add(archiveElement); } foreach (var item in graphics) { br.BaseStream.Seek(item.SeekPosition + sizeof(int) * 7, SeekOrigin.Begin); // sizeof(int) * 7 => Skip 7 integer-sized fields item.Graphic = Graphic.Load(br); } GraphicArchive archive; switch (zoomFactor) { case 1: case 2: case 4: ZoomFactor f = (ZoomFactor)zoomFactor; archive = new GraphicArchive(f); break; default: throw new InvalidDataException("Invalid ZoomFactor"); } archive.graphics = graphics; return(archive); } }