@@ -45,6 +45,7 @@ enum _OneNoteManualXpsAction { selectPdf, exportAgain, skipFile, skipAll }
4545class ImportResult {
4646 final ImportService service;
4747 final NoteData ? document;
48+ final NoteFile ? file;
4849 final List <PadElement > elements;
4950 final Map <String , Uint8List > assets;
5051 final List <(String ?, DocumentPage )> pages;
@@ -57,6 +58,7 @@ class ImportResult {
5758 ImportResult ({
5859 required this .service,
5960 required this .document,
61+ this .file,
6062 this .elements = const [],
6163 this .assets = const {},
6264 this .pages = const [],
@@ -66,7 +68,8 @@ class ImportResult {
6668 this .choosePosition = false ,
6769 }) : documentReady = false ;
6870 ImportResult .ready ({required this .service, required NoteData this .document})
69- : elements = const [],
71+ : file = null ,
72+ elements = const [],
7073 assets = document.getAllAssets (),
7174 pages = document
7275 .getPages (true )
@@ -86,6 +89,8 @@ class ImportResult {
8689 exportPresets = const [],
8790 choosePosition = false ,
8891 documentReady = true ;
92+ ImportResult .file ({required ImportService service, required NoteFile file})
93+ : this (service: service, document: null , file: file);
8994
9095 bool _isArchiveAssetPath (String path) =>
9196 validAssetPaths.any ((e) => path.startsWith ('$e /' ));
@@ -152,6 +157,8 @@ class ImportResult {
152157 return document;
153158 }
154159
160+ Future <NoteFile > exportFile () async => file ?? (await export ()).toFile ();
161+
155162 void submit ({bool ? choosePosition}) {
156163 choosePosition ?? = this .choosePosition;
157164 final state = service._getState ();
@@ -240,6 +247,7 @@ class ImportService {
240247 String type = '' ,
241248 Object ? data,
242249 NoteData ? document,
250+ bool preserveEncrypted = false ,
243251 }) async {
244252 final location = bloc? .editorController.saveCubit.state.location;
245253 Uint8List ? bytes;
@@ -279,7 +287,13 @@ class ImportService {
279287 return null ;
280288 }
281289 if (bytes == null ) return null ;
282- return import (fileType, bytes, document: document, advanced: false );
290+ return import (
291+ fileType,
292+ bytes,
293+ document: document,
294+ advanced: false ,
295+ preserveEncrypted: preserveEncrypted,
296+ );
283297 }
284298
285299 @useResult
@@ -293,6 +307,7 @@ class ImportService {
293307 TemplateFileSystem ? templateSystem,
294308 PackFileSystem ? packSystem,
295309 String ? name,
310+ bool preserveEncrypted = false ,
296311 }) async {
297312 final realDocument =
298313 document ?? bloc? .state.data ?? DocumentDefaults .createDocument ();
@@ -305,6 +320,7 @@ class ImportService {
305320 templateSystem: templateSystem,
306321 packSystem: packSystem,
307322 name: name,
323+ preserveEncrypted: preserveEncrypted,
308324 ),
309325 AssetFileType .image => importImage (
310326 bytes,
@@ -397,10 +413,14 @@ class ImportService {
397413 TemplateFileSystem ? templateSystem,
398414 PackFileSystem ? packSystem,
399415 String ? name,
416+ bool preserveEncrypted = false ,
400417 }) async {
401418 try {
402419 final file = NoteFile (bytes);
403420 final encrypted = file.isEncrypted ();
421+ if (encrypted && preserveEncrypted) {
422+ return ImportResult .file (service: this , file: file);
423+ }
404424 var password = readConnectionEncryptionPassword (effectiveStorage);
405425 NoteData ? data;
406426 if (encrypted) {
@@ -1272,7 +1292,7 @@ class ImportService {
12721292 fileSystem.storage,
12731293 document,
12741294 );
1275- fileSystem.createFile (
1295+ await fileSystem.createFile (
12761296 p.join (path ?? '' , document.name ?? '' ),
12771297 document.toFile (),
12781298 );
@@ -1290,22 +1310,16 @@ class ImportService {
12901310 fileSystem ?? = getDocumentSystem ();
12911311 for (final file in archive) {
12921312 const fileExtension = '.bfly' ;
1293- if (! file.name.endsWith (fileExtension)) continue ;
1313+ if (! file.name.toLowerCase (). endsWith (fileExtension)) continue ;
12941314 final bytes = file.readBytes ();
12951315 if (bytes == null ) continue ;
1296- var document = await (await importBfly (
1316+ final noteFile = await (await importBfly (
12971317 bytes,
12981318 advanced: false ,
1299- ))? .export ();
1300- if (document != null ) {
1301- document = addConnectionPasswordToNoteData (
1302- fileSystem.storage,
1303- document,
1304- );
1305- fileSystem.createFile (
1306- p.join (path ?? '' , file.name),
1307- document.toFile (),
1308- );
1319+ preserveEncrypted: true ,
1320+ ))? .exportFile ();
1321+ if (noteFile != null ) {
1322+ await fileSystem.createFile (p.join (path ?? '' , file.name), noteFile);
13091323 }
13101324 }
13111325 return true ;
0 commit comments