private SystemFile(int compat, SystemFileEntry[] entries) { _compat = Enum.IsDefined(typeof(Compatibility), compat) ? (Compatibility)compat : Compatibility.Version_Unknown; _entries = entries; }
public static SystemFile Read(ChmFile f) { List <SystemFileEntry> sfelst = new List <SystemFileEntry>(); ChmUnitInfo ui = new ChmUnitInfo(); byte[] buf; uint pos = 0, remaining = 0; if (!f.ResolveObject("/#SYSTEM", ref ui)) { throw new InvalidOperationException("Could not find SYSTEM file in CHM!"); } buf = new byte[ui.length]; remaining = (uint)buf.Length; if (f.RetrieveObject(ui, ref buf, 0, (long)ui.length) == 0) { throw new InvalidOperationException("Could not read SYSTEM file in CHM!"); } Int32 version = 0; Unmarshal.ToInt32(ref buf, ref pos, ref remaining, ref version); for ( ; pos < buf.Length;) { SystemFileEntry sfe = new SystemFileEntry(); Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.code); Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.length); sfe.data = new byte[sfe.length]; Array.Copy(buf, pos, sfe.data, 0, sfe.length); pos += sfe.length; remaining -= sfe.length; sfelst.Add(sfe); } return(new SystemFile(version, sfelst.ToArray())); }
public static SystemFile Read(ChmFile f) { List<SystemFileEntry> sfelst = new List<SystemFileEntry>(); ChmUnitInfo ui = new ChmUnitInfo(); byte[] buf; uint pos = 0, remaining = 0; if (!f.ResolveObject("/#SYSTEM", ref ui)) throw new InvalidOperationException("Could not find SYSTEM file in CHM!"); buf = new byte[ui.length]; remaining = (uint)buf.Length; if (f.RetrieveObject(ui, ref buf, 0, (long)ui.length) == 0) throw new InvalidOperationException("Could not read SYSTEM file in CHM!"); Int32 version = 0; Unmarshal.ToInt32(ref buf, ref pos, ref remaining, ref version); for ( ; pos < buf.Length; ) { SystemFileEntry sfe = new SystemFileEntry(); Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.code); Unmarshal.ToUInt16(ref buf, ref pos, ref remaining, ref sfe.length); sfe.data = new byte[sfe.length]; Array.Copy(buf, pos, sfe.data, 0, sfe.length); pos += sfe.length; remaining -= sfe.length; sfelst.Add(sfe); } return new SystemFile(version, sfelst.ToArray()); }