private static int RunUnpack(UnpackOptions options) { Directory.CreateDirectory(options.TargetDir); using (var ifs = new FileStream(options.SourceFile, FileMode.Open, FileAccess.Read)) { var box = CzBox.Load(ifs); var def = box.GetContentDefinition(); if (def != null) { using (var cnBoxFs = new FileStream(Path.Combine(options.TargetDir, "contentDefinition.json"), FileMode.Create, FileAccess.Write)) AuthoringUtil.JsonSerialize(def, cnBoxFs); } foreach (var(name, srcResFs) in box.GetDataEnumerator()) { using (var resFs = new FileStream(Path.Combine(options.TargetDir, name), FileMode.Create, FileAccess.Write)) srcResFs.CopyTo(resFs); } } return(0); }
private static int RunPack(PackOptions options) { ContentDefinition def = null; if (options.ContentDefinition != null) { using (var defFs = new FileStream(options.ContentDefinition, FileMode.Open, FileAccess.Read)) def = AuthoringUtil.JsonDeserialize <ContentDefinition>(defFs); } var bList = new List <FileInfo>(); if (options.Resources != null) { foreach (var res in options.Resources) { bList.Add(new FileInfo(res)); } } var metaList = new List <MutableKeyValuePair <string, int> >(); foreach (var ent in bList) { metaList.Add(new MutableKeyValuePair <string, int>(ent.Name, (int)ent.Length)); } using (var ofs = new FileStream(options.TargetFile, FileMode.Create, FileAccess.Write)) { CzBox.WriteHead(ofs, def, metaList); foreach (var ent in bList) { using (var eStream = ent.OpenRead()) eStream.CopyTo(ofs); } } return(0); }