public PeRecordReader GetReader(string key) { if (mIndexFile == null) { return(null); } ArchiveIndex index = mIndexFile.GetArchiveIndex(key); if (null == index) { return(null); } string fileDir; if (index.yird) { if (string.IsNullOrEmpty(mIndexFile.yirdName)) { Debug.LogError("yird name is empty or null"); return(null); } fileDir = mIndexFile.GetYirdDir(dir); } else { fileDir = dir; } return(new PeRecordReader(index, fileDir, mIndexFile.header)); }
void WriteRecord(ArchiveIndexFile indexFile, ArchiveObj serializeObj) { if (serializeObj.hasNonYird) { string filePath = GetFilePath(dir, serializeObj.recordName); using (FileStream fileStream = new FileStream(filePath, FileMode.Create, FileAccess.Write)) { using (BinaryWriter writer = new BinaryWriter(fileStream)) { indexFile.header.Write(writer); indexFile.header.BeginWriteCheckSum(writer); serializeObj.Foreach((obj) => { if (!obj.yird) { Profiler.BeginSample("save:" + obj.key); long beginPos = fileStream.Position; obj.serialize.Serialize(new PeRecordWriter(obj.key, writer)); long endPos = fileStream.Position; indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos)); Profiler.EndSample(); } }); indexFile.header.EndWriteCheckSum(writer); } } } if (serializeObj.hasYird) { string yirdDir = indexFile.GetYirdDir(dir); string yirdFilePath = GetFilePath(yirdDir, serializeObj.recordName); if (!Directory.Exists(yirdDir)) { Directory.CreateDirectory(yirdDir); } using (FileStream yirdFileStream = new FileStream(yirdFilePath, FileMode.Create, FileAccess.Write)) { using (BinaryWriter yirdWriter = new BinaryWriter(yirdFileStream)) { indexFile.header.Write(yirdWriter); indexFile.header.BeginWriteCheckSum(yirdWriter); serializeObj.Foreach((obj) => { Profiler.BeginSample("save:" + obj.key); if (obj.yird) { long beginPos = yirdFileStream.Position; obj.serialize.Serialize(new PeRecordWriter(obj.key, yirdWriter)); long endPos = yirdFileStream.Position; indexFile.Add(obj.key, new ArchiveIndex(serializeObj.recordName, obj.yird, beginPos, endPos)); } Profiler.EndSample(); }); indexFile.header.EndWriteCheckSum(yirdWriter); } } } }