@@ -454,6 +454,65 @@ public async void ShowOpenFileDialog()
454454 }
455455 }
456456
457+ //Called from UI
458+ public async void ShowOpenFileDialogXAPK ( )
459+ {
460+ FilePickerOpenOptions options = new ( ) { AllowMultiple = false } ;
461+ IReadOnlyList < IStorageFile > fileList = await MainWindow . Instance . StorageProvider . OpenFilePickerAsync ( options ) ;
462+
463+ string [ ] result = fileList . Select ( f => f . Path . LocalPath )
464+ . Where ( s => ! string . IsNullOrEmpty ( s ) )
465+ . ToArray ( ) ;
466+
467+ if ( result . Length < 1 ) return ;
468+
469+ _ = Task . Run ( ( ) =>
470+ {
471+ string xapkExtractPath = "temp/XAPK_" + DateTime . Now . ToString ( "yyyyMMddHHmm" ) ;
472+ Directory . CreateDirectory ( xapkExtractPath ) ;
473+
474+ try
475+ {
476+ Logger . Log ( LogType . Info , LogCategory . Import , $ "Decompressing '{ result [ 0 ] } '") ;
477+
478+ if ( ! File . Exists ( result [ 0 ] ) )
479+ {
480+ Logger . Log ( LogType . Error , LogCategory . Import , $ "File '{ result [ 0 ] } ' does not exist.") ;
481+ throw new Exception ( $ "File '{ result [ 0 ] } ' does not exist. Have you tried importing multiple folders?") ;
482+ }
483+
484+ LoadingText = "Decompressing " + result [ 0 ] ;
485+
486+ ZipFile . ExtractToDirectory ( result [ 0 ] , xapkExtractPath , true ) ;
487+
488+ // Post Extract
489+ if ( ! Directory . Exists ( Path . Combine ( xapkExtractPath , "Android/obb" ) ) )
490+ throw new Exception ( "Unable to find Android/obb directory" ) ;
491+
492+ string ? packageName = Path . GetFileName ( Directory . GetDirectories ( Path . Combine ( xapkExtractPath , "Android/obb" ) ) [ 0 ] ) ;
493+
494+ if ( packageName == null ) throw new Exception ( "Package name is null" ) ;
495+ Logger . Log ( LogType . Info , LogCategory . Import , packageName ) ;
496+
497+ string obbFile = Directory . GetFiles ( Path . Combine ( xapkExtractPath , "Android/obb" , packageName ) ) [ 0 ] ;
498+
499+ string xapkPostExtractPath = "temp/XAPK_POST_" + DateTime . Now . ToString ( "yyyyMMddHHmm" ) ;
500+ Directory . CreateDirectory ( xapkPostExtractPath ) ;
501+
502+ ZipFile . ExtractToDirectory ( obbFile , xapkPostExtractPath , true ) ;
503+
504+ ZipFile . ExtractToDirectory ( Path . Combine ( xapkExtractPath , packageName + ".apk" ) , xapkPostExtractPath , true ) ;
505+
506+ DoLoad ( [ xapkPostExtractPath ] ) ;
507+ }
508+ catch ( Exception ex )
509+ {
510+ LoadingText = string . Empty ;
511+ this . ShowPopup ( $ "Exception on importing XAPK: { ex . Message } ", MainWindow . Instance . LocalizationManager [ "error" ] ) ;
512+ }
513+ } ) ;
514+ }
515+
457516 //Called from UI
458517 public async void ShowOpenFolderDialog ( )
459518 {
0 commit comments