public static IEnumerable <ManifestImmutable> ReadAllManifests(string baseFileName) { string manifestFile = Config.ManifestFile(baseFileName); if (!File.Exists(manifestFile)) { throw new FileNotFoundException("Could not find the manifest file.", manifestFile); } FileStream fs = new FileStream(manifestFile, FileMode.Open, FileAccess.Read, FileShare.None, 1024, false); BinaryReader reader = new BinaryReader(fs); try { do { var m = new ManifestImmutable(null); m.ReadManifestContents(reader); yield return(m); reader.ReadInt32(); // Consume the size encoded at the end of each manifest } while (true); } finally { reader.Close(); } }
void Read() { string manifestFile = Config.ManifestFile(_baseFileName); if (!File.Exists(manifestFile)) { _manifests.AddLast(new ManifestImmutable(this)); return; } FileStream fs = new FileStream(manifestFile, FileMode.Open, FileAccess.Read, FileShare.None, 1024, false); BinaryReader reader = new BinaryReader(fs); try { // Get the size of the last manifest block reader.BaseStream.Seek(-4, SeekOrigin.End); int size = reader.ReadInt32(); // Now seek to that position and read it reader.BaseStream.Seek(-size - 4, SeekOrigin.End); var m = new ManifestImmutable(this); m.ReadManifestContents(reader); _manifests.AddLast(m); } catch (Exception ex) { LogMessage("Error reading manifest file: {0}", _baseFileName); ex.GetBaseException(); } finally { reader.Close(); } }