@@ -121,5 +121,65 @@ NoteData _migrate(NoteData noteData, FileMetadata metadata) {
121
121
kInfoArchiveFile, utf8.encode (json.encode (infoData)));
122
122
}
123
123
}
124
+ if (version < 12 ) {
125
+ Map ? resolvePackAssetLocation (Map location, String kind) {
126
+ final pack = location['pack' ] as String ? ;
127
+ final name = location['name' ] as String ? ;
128
+ if ((pack? .isEmpty ?? true ) || (name? .isEmpty ?? true )) {
129
+ return null ;
130
+ }
131
+ final packData = noteData.getAsset ('$kPacksArchiveDirectory /$pack .bfly' );
132
+ if (packData == null ) return null ;
133
+ final data = NoteData .fromData (packData);
134
+ final item = data.getAsset ('$kind /$name ' );
135
+ if (item == null ) return null ;
136
+ return {
137
+ 'name' : name,
138
+ 'item' : item,
139
+ };
140
+ }
141
+
142
+ void updatePenProperty (Map property) {
143
+ if (property['fill' ] != true ) return ;
144
+ property['fill' ] = property['color' ];
145
+ property['color' ] = null ;
146
+ }
147
+
148
+ for (final page in noteData.getAssets ('$kPagesArchiveDirectory /' )) {
149
+ final data = noteData.getAsset ('$kPagesArchiveDirectory /$page ' );
150
+ if (data == null ) continue ;
151
+ final pageData = json.decode (utf8.decode (data)) as Map <String , dynamic >;
152
+ final layers = pageData['layers' ] as List ? ;
153
+ for (final layer in layers ?? []) {
154
+ final content = layer['content' ] as List ? ;
155
+ for (final item in content ?? []) {
156
+ if ((const ['text' , 'markdown' ].contains (item['type' ]))) {
157
+ item['stylesheet' ] = resolvePackAssetLocation (
158
+ item['stylesheet' ], kStylesArchiveDirectory);
159
+ } else if (item['type' ] == 'pen' ) {
160
+ updatePenProperty (item['property' ]);
161
+ }
162
+ }
163
+ }
164
+ }
165
+ final info = noteData.getAsset (kInfoArchiveFile);
166
+ if (info != null ) {
167
+ final infoData = json.decode (utf8.decode (info)) as Map <String , dynamic >;
168
+ final tools = infoData['tools' ] as List ? ;
169
+ for (final item in tools ?? []) {
170
+ if ((const ['text' , 'markdown' ].contains (item['type' ]))) {
171
+ item['stylesheet' ] = resolvePackAssetLocation (
172
+ item['stylesheet' ], kStylesArchiveDirectory);
173
+ } else if (item['type' ] == 'stamp' ) {
174
+ item['component' ] = resolvePackAssetLocation (
175
+ item['component' ], kComponentsArchiveDirectory);
176
+ } else if (item['type' ] == 'pen' ) {
177
+ updatePenProperty (item['property' ]);
178
+ }
179
+ }
180
+ noteData = noteData.setAsset (
181
+ kInfoArchiveFile, utf8.encode (json.encode (infoData)));
182
+ }
183
+ }
124
184
return noteData;
125
185
}
0 commit comments