public void Load(Stream stream, ProjectFileReader.OnInputPassword inputPassword = null) { ESystemInfo = null; ProjectConfigInfo = null; Resource = null; Code = null; EPackageInfo = null; InitEcSectionInfo = null; LosableSection = null; FolderSection = null; EcSection = EcSection2 = AuxiliarySection2 = AuxiliarySection3 = EditInfoSection2 = AuxiliarySection1 = null; OtherSections = new List <SectionInfo>(); using (var reader = new ProjectFileReader(stream, inputPassword)) { var processor = new Dictionary <int, Action <SectionInfo> > { { ESystemInfo.SectionKey, x => ESystemInfo = ESystemInfo.Parse(x.Data) }, { ProjectConfigInfo.SectionKey, x => ProjectConfigInfo = ProjectConfigInfo.Parse(x.Data, Encoding) }, { ResourceSectionInfo.SectionKey, x => Resource = ResourceSectionInfo.Parse(x.Data, Encoding) }, { CodeSectionInfo.SectionKey, x => Code = CodeSectionInfo.Parse(x.Data, Encoding, reader.CryptEc) }, { EPackageInfo.SectionKey, x => EPackageInfo = EPackageInfo.Parse(x.Data, Encoding) }, { InitEcSectionInfo.SectionKey, x => InitEcSectionInfo = InitEcSectionInfo.Parse(x.Data, Encoding) }, { 0x0C007319, x => EcSection = x.Data }, { 0x0F007319, x => EcSection2 = x.Data }, { 0x0B007319, x => AuxiliarySection2 = x.Data }, { LosableSectionInfo.SectionKey, x => LosableSection = LosableSectionInfo.Parse(x.Data, Encoding) }, { 0x10007319, x => AuxiliarySection3 = x.Data }, { 0x09007319, x => EditInfoSection2 = x.Data }, { 0x0A007319, x => AuxiliarySection1 = x.Data }, { FolderSectionInfo.SectionKey, x => FolderSection = FolderSectionInfo.Parse(x.Data, Encoding) } }; while (!reader.IsFinish) { var section = reader.ReadSection(); switch (section.Key) { case int key when processor.ContainsKey(key): processor[key](section); break; default: OtherSections.Add(section); break; } } } }
public static EPackageInfo Parse(byte[] data) { var packageInfo = new EPackageInfo(); using (var reader = new BinaryReader(new MemoryStream(data, false))) { var nameList = new List <string>(); while (!(reader.BaseStream.Position == reader.BaseStream.Length)) { var name = reader.ReadStringWithLengthPrefix(); if ("".Equals(name)) { name = null; } nameList.Add(name); } packageInfo.FileNames = nameList.ToArray(); } return(packageInfo); }
public void Save(Stream stream) { using (var writer = new ProjectFileWriter(stream)) { if (ESystemInfo != null) { writer.WriteSection(new SectionInfo(ESystemInfo.SectionKey, ESystemInfo.SectionName, false, ESystemInfo.ToBytes())); } if (ProjectConfigInfo != null) { writer.WriteSection(new SectionInfo(ProjectConfigInfo.SectionKey, ProjectConfigInfo.SectionName, true, ProjectConfigInfo.ToBytes(Encoding))); } if (Resource != null) { writer.WriteSection(new SectionInfo(ResourceSectionInfo.SectionKey, ResourceSectionInfo.SectionName, false, Resource.ToBytes(Encoding))); } if (Code != null) { writer.WriteSection(new SectionInfo(CodeSectionInfo.SectionKey, CodeSectionInfo.SectionName, false, Code.ToBytes(Encoding))); } if (EPackageInfo != null) { writer.WriteSection(new SectionInfo(EPackageInfo.SectionKey, EPackageInfo.SectionName, true, EPackageInfo.ToBytes(Encoding))); } if (InitEcSectionInfo != null) { writer.WriteSection(new SectionInfo(InitEcSectionInfo.SectionKey, InitEcSectionInfo.SectionName, false, InitEcSectionInfo.ToBytes(Encoding))); } if (EcSection != null) { writer.WriteSection(new SectionInfo(0x0C007319, "易模块记录段", false, EcSection)); } if (EcSection2 != null) { writer.WriteSection(new SectionInfo(0x0F007319, "易模块记录段2", true, EcSection2)); } if (AuxiliarySection2 != null) { writer.WriteSection(new SectionInfo(0x0B007319, "辅助信息段2", true, AuxiliarySection2)); } if (LosableSection != null) { writer.WriteSection(new SectionInfo(LosableSectionInfo.SectionKey, LosableSectionInfo.SectionName, true, LosableSection.ToBytes(Encoding))); } if (AuxiliarySection3 != null) { writer.WriteSection(new SectionInfo(0x10007319, "辅助信息段3", true, AuxiliarySection3)); } if (EditInfoSection2 != null) { writer.WriteSection(new SectionInfo(0x09007319, "编辑信息段2", true, EditInfoSection2)); } if (AuxiliarySection1 != null) { writer.WriteSection(new SectionInfo(0x0A007319, "辅助信息段1", true, AuxiliarySection1)); } if (FolderSection != null) { writer.WriteSection(new SectionInfo(FolderSectionInfo.SectionKey, FolderSectionInfo.SectionName, true, FolderSection.ToBytes(Encoding))); } OtherSections?.ForEach(x => writer.WriteSection(x)); } }