public void SaveToPcc(PCCPackage pcc)
        {
            var index = pcc.FindClass("BioCodexMap");

            if (index == 0)
            {
                return;
            }

            var exportIndex = pcc.Exports.FindIndex(entry => entry.idxClass == index);

            if (exportIndex < 0)
            {
                return;
            }

            var codexMapData       = pcc.Exports[exportIndex].Data;
            var codexMapProperties = PropertyReader.getPropList(pcc, codexMapData);

            if (codexMapProperties.Count <= 0)
            {
                return;
            }

            var codexMapProperty   = codexMapProperties.Find(property => property.TypeVal == PropertyReader.Type.None);
            var codexMapDataOffset = codexMapProperty.offend;

            byte[] bytes;
            var    codexMap = new BioCodexMap(CodexSections.ToDictionary(pair => pair.Key, pair => pair.Value),
                                              CodexPages.ToDictionary(pair => pair.Key, pair => pair.Value));

            // CodexMap
            using (var stream = new MemoryStream())
            {
                ((BinaryBioCodexMap)codexMap).Save(stream);

                bytes = stream.ToArray();
            }

            Array.Resize(ref codexMapData, codexMapDataOffset + bytes.Length);
            bytes.CopyTo(codexMapData, codexMapDataOffset);

            var temp = pcc.Exports[exportIndex];

            Array.Resize(ref temp.Data, codexMapData.Length);
            codexMapData.CopyTo(temp.Data, 0);
            pcc.Exports[exportIndex] = temp;
        }
        public void AddCodexPage(int id, BioCodexPage codexPage = null)
        {
            if (CodexPages == null)
            {
                CodexPages = InitCollection <KeyValuePair <int, BioCodexPage> >();
            }

            if (id < 0)
            {
                return;
            }

            var codexPagePair = new KeyValuePair <int, BioCodexPage>(id, codexPage ?? new BioCodexPage());

            CodexPages.Add(codexPagePair);

            SelectedCodexPage = codexPagePair;
        }
        public void SaveToPcc(IMEPackage pcc)
        {
            IExportEntry export;

            try
            {
                export = pcc.Exports.First(exp => exp.ClassName == "BioCodexMap");
            }
            catch
            {
                return;
            }

            var codexMapData       = export.Data;
            var codexMapProperties = PropertyReader.getPropList(export);

            if (codexMapProperties.Count <= 0)
            {
                return;
            }

            var codexMapProperty   = codexMapProperties.Find(property => property.TypeVal == PropertyType.None);
            var codexMapDataOffset = codexMapProperty.offend;

            byte[] bytes;
            var    codexMap = new BioCodexMap(CodexSections.ToDictionary(pair => pair.Key, pair => pair.Value),
                                              CodexPages.ToDictionary(pair => pair.Key, pair => pair.Value));

            // CodexMap
            using (var stream = new MemoryStream())
            {
                ((BinaryBioCodexMap)codexMap).Save(stream);

                bytes = stream.ToArray();
            }

            Array.Resize(ref codexMapData, codexMapDataOffset + bytes.Length);
            bytes.CopyTo(codexMapData, codexMapDataOffset);

            export.Data = codexMapData;
        }
        public void RemoveCodexPage()
        {
            if (CodexPages == null || SelectedCodexPage.Value == null)
            {
                return;
            }

            var index = CodexPages.IndexOf(SelectedCodexPage);

            if (!CodexPages.Remove(SelectedCodexPage))
            {
                return;
            }

            if (CodexPages.Any())
            {
                SelectedCodexPage = ((index - 1) >= 0)
                                        ? CodexPages[index - 1]
                                        : CodexPages.First();
            }
        }
        public void ChangeCodexPageId()
        {
            if (SelectedCodexPage.Value == null)
            {
                return;
            }

            var dlg = new ChangeObjectIdDialog
            {
                ContentText = string.Format("Change id of codex page #{0}", SelectedCodexPage.Key),
                ObjectId    = SelectedCodexPage.Key
            };

            if (dlg.ShowDialog() == false || dlg.ObjectId < 0 || dlg.ObjectId == SelectedCodexPage.Key)
            {
                return;
            }

            var codexSection = SelectedCodexPage.Value;

            CodexPages.Remove(SelectedCodexPage);

            AddCodexPage(dlg.ObjectId, codexSection);
        }
 private int GetMaxCodexPageId()
 {
     return(CodexPages.Any() ? CodexPages.Max(pair => pair.Key) : -1);
 }