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(); } }
private void Read() { string manifestFile = Config.ManifestFile(_baseFileName); if (!File.Exists(manifestFile)) { AddLastManifest(new ManifestImmutable(this)); return; } FileStream fs = new FileStream(manifestFile, FileMode.Open, FileAccess.Read, FileShare.None, 1024, false); BinaryReader reader = new BinaryReader(fs); try { var m = new ManifestImmutable(this); // 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); m.ReadManifestContents(reader); AddLastManifest(m); } catch (Exception ex) { LogMessage("Error reading manifest file: {0} - {1}", _baseFileName, ex.Message); } finally { reader.Close(); } }