public void readEntries() { if (BinaryHelper.readString(diskData, 0, 6) != "heywow") { throw new Exception("Bad file header format " + file); } if (BinaryHelper.readU16_BE(diskData, 6) != dskid) { throw new Exception("Bad file id format " + file); } for (int i = 0; i < 191; i++) { entries[i] = new FileEntry(diskData, 8 + i * 8); } }
public LureDisk(int id, string paths) { string file2 = ""; dskid = id; string[] pts = paths.Split(';'); file = "lure.dat"; if (id > 0) { file = "disk" + id.ToString() + ".vga"; file2 = "Disk" + id.ToString() + ".vga"; } if (!File.Exists(file)) { if (File.Exists(file2)) { file = file2; } else { foreach (string p in pts) { string s = p; if (s[s.Length - 1] != '/') { s += "/"; } if (File.Exists(s + file)) { file = s + file; break; } if (File.Exists(s + file2)) { file = s + file2; break; } } } } if (!File.Exists(file)) { throw new Exception("Disk not found " + file); } string xfile = file; if (File.Exists(xfile + ".bak")) { xfile += ".bak"; } FileStream fs = new FileStream(xfile, FileMode.Open); diskData = new byte[fs.Length]; fs.Read(diskData, 0, diskData.Length); fs.Close(); if (id == 0) { if (BinaryHelper.readString(diskData, 0, 4) != "lure") { throw new Exception("bad lure.dat"); } int b = 6; while (diskData[b] != LureConfig.get().lang_id) { b += 5; if (diskData[b] == 0xff) { throw new Exception("lure.dat language " + LureConfig.get().lang_id.ToString() + " not found"); } } int dofs = (int)BinaryHelper.readU32_LE(diskData, b + 1); b = 6; int dsz = int.MaxValue; while (diskData[b] != 0xFF) { int sofs = (int)BinaryHelper.readU32_LE(diskData, b + 1); b += 5; if (sofs > dofs) { if (sofs - dofs < dsz) { dsz = sofs - dofs; } } } byte[] newdisk = new byte[dsz]; Array.Copy(diskData, dofs, newdisk, 0, dsz); diskData = newdisk; } readEntries(); }