| 1 |
use crate::errors::{ErrorKind, Result}; |
| 2 |
use crate::fsshttpb::data::exguid::ExGuid; |
| 3 |
use crate::one::property::object_reference::ObjectReference; |
| 4 |
use crate::one::property::{simple, PropertyType}; |
| 5 |
use crate::one::property_set::PropertySetId; |
| 6 |
use crate::onestore::object::Object; |
| 7 |
|
| 8 |
/// A section's table of contents. |
| 9 |
/// |
| 10 |
/// See [\[MS-ONE\] 2.2.15]. |
| 11 |
/// |
| 12 |
/// [\[MS-ONE\] 2.2.15]: https://docs.microsoft.com/en-us/openspecs/office_file_formats/ms-one/6c1dd264-850b-4e46-af62-50b4dba49b62 |
| 13 |
#[derive(Debug)] |
| 14 |
pub(crate) struct Data { |
| 15 |
pub(crate) children: Vec<ExGuid>, |
| 16 |
pub(crate) filename: Option<String>, |
| 17 |
pub(crate) ordering_id: Option<u32>, |
| 18 |
// FIXME: Color!? |
| 19 |
} |
| 20 |
|
| 21 |
pub(crate) fn parse(object: &Object) -> Result<Data> { |
| 22 |
if object.id() != PropertySetId::TocContainer.as_jcid() { |
| 23 |
return Err(ErrorKind::MalformedOneNoteFileData( |
| 24 |
format!("unexpected object type: 0x{:X}", object.id().0).into(), |
| 25 |
) |
| 26 |
.into()); |
| 27 |
} |
| 28 |
|
| 29 |
let children = |
| 30 |
ObjectReference::parse_vec(PropertyType::TocChildren, object)?.unwrap_or_default(); |
| 31 |
let filename = simple::parse_string(PropertyType::FolderChildFilename, object)? |
| 32 |
.map(|s| s.replace("^M", "+")) |
| 33 |
.map(|s| s.replace("^J", ",")); |
| 34 |
let ordering_id = simple::parse_u32(PropertyType::NotebookElementOrderingId, object)?; |
| 35 |
|
| 36 |
Ok(Data { |
| 37 |
children, |
| 38 |
filename, |
| 39 |
ordering_id, |
| 40 |
}) |
| 41 |
} |