@@ -5,6 +5,7 @@ import { zlib } from '@kit.BasicServicesKit';
55import { EventHub } from './EventHub' ;
66import { DownloadTaskParams } from './DownloadTaskParams' ;
77import Pushy from 'librnupdate.so' ;
8+ import { saveFileToSandbox } from './SaveFile' ;
89
910interface ZipEntry {
1011 filename : string ;
@@ -233,7 +234,8 @@ export class DownloadTask {
233234
234235 return { entries } ;
235236 } catch ( error ) {
236- console . error ( 'Failed to process unzipped files:' , error ) ;
237+ error . message = 'Failed to process unzipped files:' + error . message ;
238+ console . error ( error ) ;
237239 throw error ;
238240 }
239241 }
@@ -262,10 +264,6 @@ export class DownloadTask {
262264
263265 const copies = obj . copies as Record < string , string > ;
264266 for ( const [ to , rawPath ] of Object . entries ( copies ) ) {
265- if ( ! rawPath . startsWith ( 'resources/rawfile/' ) ) {
266- // skip other resource
267- continue ;
268- }
269267 let from = rawPath . replace ( 'resources/rawfile/' , '' ) ;
270268 if ( from === '' ) {
271269 from = to ;
@@ -311,7 +309,7 @@ export class DownloadTask {
311309 await fileIo . close ( writer ) ;
312310 continue ;
313311 } catch ( error ) {
314- console . error ( 'Failed to process bundle patch:' , error ) ;
312+ error . message = 'Failed to process bundle patch:' + error . message ;
315313 throw error ;
316314 }
317315 }
@@ -432,15 +430,27 @@ export class DownloadTask {
432430
433431 for ( const [ from , targets ] of copyList . entries ( ) ) {
434432 currentFrom = from ;
435- const fromContent = await resourceManager . getRawFileContent ( from ) ;
433+ if ( from . startsWith ( 'resources/base/media/' ) ) {
434+ const mediaName = from
435+ . replace ( 'resources/base/media/' , '' )
436+ . split ( '.' ) [ 0 ] ;
437+ const mediaBuffer = await resourceManager . getMediaByName ( mediaName ) ;
438+ for ( const target of targets ) {
439+ const fileStream = fileIo . createStreamSync ( target , 'w+' ) ;
440+ fileStream . writeSync ( mediaBuffer ) ;
441+ fileStream . close ( ) ;
442+ }
443+ continue ;
444+ }
445+ const fromContent = await resourceManager . getRawFd ( from ) ;
436446 for ( const target of targets ) {
437- const fileStream = fileIo . createStreamSync ( target , 'w+' ) ;
438- fileStream . writeSync ( fromContent . buffer ) ;
439- fileStream . close ( ) ;
447+ saveFileToSandbox ( fromContent , target ) ;
440448 }
441449 }
442450 } catch ( error ) {
443- console . error ( 'Copy from resource failed:' , currentFrom , error . message ) ;
451+ error . message =
452+ 'Copy from resource failed:' + currentFrom + ',' + error . message ;
453+ console . error ( error ) ;
444454 throw error ;
445455 }
446456 }
@@ -473,7 +483,8 @@ export class DownloadTask {
473483 }
474484 }
475485 } catch ( error ) {
476- console . error ( 'Cleanup failed:' , error ) ;
486+ error . message = 'Cleanup failed:' + error . message ;
487+ console . error ( error ) ;
477488 throw error ;
478489 }
479490 }
0 commit comments