Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implements candidate code for pocessing ArrayOfPropertyValues #16

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions pyOneNote/FileNode.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@
import struct
from datetime import datetime, timedelta
import locale
import math

DEBUG = False


class FileNodeListHeader:
def __init__(self, file):
self.uintMagic, self.FileNodeListID, self.nFragmentSequence = struct.unpack('<8sII', file.read(16))
assert self.uintMagic == b'\xc4\xf4\xf7\xf5\xb1zV\xa4'


class FileNodeList:
Expand Down Expand Up @@ -107,7 +109,7 @@ def __init__(self, file, document):
self.document= document
self.file_node_header = FileNodeHeader(file)
if DEBUG:
print(str(file.tell()) + ' ' + self.file_node_header.file_node_type + ' ' + str(self.file_node_header.baseType))
print(str(hex(file.tell())) + ' ' + self.file_node_header.file_node_type + ' ' + str(self.file_node_header.baseType))
self.children = []
FileNode.count += 1
if self.file_node_header.file_node_type == "ObjectGroupStartFND":
Expand Down Expand Up @@ -178,7 +180,8 @@ def __init__(self, file, document):

current_offset = file.tell()
if self.file_node_header.baseType == 2:
self.children.append(FileNodeList(file, self.document, self.data.ref))
if hasattr(self, 'data') and not (self.data.ref.stp == 0 and self.data.ref.cb == 0):
self.children.append(FileNodeList(file, self.document, self.data.ref))
file.seek(current_offset)


Expand Down Expand Up @@ -245,7 +248,7 @@ def isFcrNil(self):
return res

def __repr__(self):
return 'FileChunkReference:(stp:{}, cb:{})'.format(self.stp, self.cb)
return 'FileNodeChunkReference:(stp:{}, cb:{})'.format(self.stp, self.cb)


class FileChunkReference64x32(FileNodeChunkReference):
Expand Down Expand Up @@ -383,7 +386,12 @@ def __init__(self, file, file_node_header):
self.guidReference = uuid.UUID(bytes_le=self.guidReference)
current_offset = file.tell()
file.seek(self.ref.stp)
self.fileDataStoreObject = FileDataStoreObject(file, self.ref)
try:
self.fileDataStoreObject = FileDataStoreObject(file, self.ref)
except: # noqa
# print(f'Error for datastore at {hex(current_offset)} // {self.ref.stp}')
self.fileDataStoreObject = None
pass
file.seek(current_offset)

def __str__(self):
Expand Down Expand Up @@ -638,7 +646,11 @@ def __init__(self, file, OIDs, OSIDs, ContextIDs, document):
count, = struct.unpack('<I', file.read(4))
self.rgData.append(self.get_compact_ids(ContextIDs, count))
elif type == 0x10:
raise NotImplementedError('ArrayOfPropertyValues is not implement')
cproperties, = struct.unpack('<I', file.read(4))
prid = PropertyID(file)
assert prid.type == 0x11, "prtArrayOfPropertyValues.prid.type out of spec!"
for _ in range(cproperties):
self.rgData.append(PropertySet(file, OIDs, OSIDs, ContextIDs, document))
elif type == 0x11:
self.rgData.append(PropertySet(file))
else:
Expand Down Expand Up @@ -683,6 +695,7 @@ def get_properties(self):
'offset' in property_name_lower or \
'margin' in property_name_lower:
size, = struct.unpack('<f', self.rgData[i])

propertyVal = PropertySet.half_inch_size_to_pixels(size)
elif 'langid' in property_name_lower:
lcid, =struct.unpack('<H', self.rgData[i])
Expand Down Expand Up @@ -712,7 +725,8 @@ def half_inch_size_to_pixels(picture_width, dpi=96):

# Calculate the number of pixels
pixels = picture_width * pixels_per_half_inch

if math.isnan(pixels):
return 0
return int(pixels)

[staticmethod]
Expand Down
9 changes: 6 additions & 3 deletions pyOneNote/OneDocument.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,16 @@ def get_files(self):
if hasattr(node, "data") and node.data:
if isinstance(node.data, FileDataStoreObjectReferenceFND):
if not str(node.data.guidReference) in self._files:
self._files[str(node.data.guidReference)] = {"extension": "", "content": "", "identity": ""}
self._files[str(node.data.guidReference)]["content"] = node.data.fileDataStoreObject.FileData
self._files[str(node.data.guidReference)] = {"extension": "", "content": b"", "identity": ""}
try:
self._files[str(node.data.guidReference)]["content"] = node.data.fileDataStoreObject.FileData
except AttributeError:
continue
elif isinstance(node.data, ObjectDeclarationFileData3RefCountFND):
guid = node.data.FileDataReference.StringData.replace("<ifndf>{", "").replace("}", "")
guid = guid.lower()
if not guid in self._files:
self._files[guid] = {"extension": "", "content": "", "identity": ""}
self._files[guid] = {"extension": "", "content": b"", "identity": ""}
self._files[guid]["extension"] = node.data.Extension.StringData
self._files[guid]["identity"] = str(node.data.oid)
return self._files
Expand Down