Skip to content

Commit 14646d8

Browse files
Updated AppleNotesEmbeddedGallery to try to make use of ordering information for Gallery children to properly show up.
1 parent a79d2ff commit 14646d8

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

lib/AppleNotesEmbeddedGallery.rb

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,40 @@ def add_gallery_children
9393
zlib_inflater = Zlib::Inflate.new(Zlib::MAX_WBITS + 16)
9494
gunzipped_data = zlib_inflater.inflate(gzipped_data)
9595

96+
tmp_order = Hash.new
97+
tmp_current_uuid = ''
98+
tmp_current_order = ''
99+
96100
# Read the protobuff
97101
mergabledata_proto = MergableDataProto.decode(gunzipped_data)
102+
103+
# Loop over the entries to pull out the UUIDs for each child, as well as their ordering information
98104
mergabledata_proto.mergable_data_object.mergeable_data_object_data.mergeable_data_object_entry.each do |mergeable_data_object_entry|
105+
106+
# This section holds an obvious UUID that matches the ZIDENTIFIER column
99107
if mergeable_data_object_entry.custom_map
100-
create_child_from_uuid(mergeable_data_object_entry.custom_map.map_entry.first.value.string_value)
108+
tmp_current_uuid = mergeable_data_object_entry.custom_map.map_entry.first.value.string_value
109+
end
110+
111+
# This section holds what appears to be ordering information
112+
if mergeable_data_object_entry.unknown_message
113+
tmp_current_order = mergeable_data_object_entry.unknown_message.unknown_entry.unknown_int2
114+
end
115+
116+
# If we ever have both the UUID and order, set them in the hash and clear them
117+
if tmp_current_order != '' and tmp_current_uuid != ''
118+
tmp_order[tmp_current_order] = tmp_current_uuid
119+
tmp_current_uuid = ''
120+
tmp_current_order = ''
101121
end
102122

103123
end
124+
125+
# Loop over the Hash to put the images into the right order
126+
tmp_order.keys.sort.each do |key|
127+
create_child_from_uuid(tmp_order[key])
128+
end
129+
104130
end
105131
nil
106132
end
@@ -113,6 +139,7 @@ def create_child_from_uuid(uuid)
113139
"ZICCLOUDSYNCINGOBJECT.ZTYPEUTI " +
114140
"FROM ZICCLOUDSYNCINGOBJECT " +
115141
"WHERE ZIDENTIFIER=?", uuid) do |row|
142+
@logger.debug("Creating gallery child from #{row["Z_PK"]}: #{uuid}")
116143
tmp_child = AppleNotesEmbeddedPublicJpeg.new(row["Z_PK"],
117144
row["ZIDENTIFIER"],
118145
row["ZTYPEUTI"],

0 commit comments

Comments
 (0)