@@ -2,13 +2,19 @@ namespace ServiceLib.Services;
22
33public  class  UpdateService 
44{ 
5-     private  Func < bool ,  string ,  Task > ?  _updateFunc ; 
5+     private  readonly  Config ?  _config ; 
6+     private  readonly  Func < bool ,  string ,  Task > ?  _updateFunc ; 
67    private  readonly  int  _timeout  =  30 ; 
78    private  static   readonly  string  _tag  =  "UpdateService" ; 
89
9-     public  async   Task   CheckUpdateGuiN ( Config  config ,  Func < bool ,  string ,  Task >  updateFunc ,   bool   preRelease ) 
10+     public  UpdateService ( Config  config ,  Func < bool ,  string ,  Task >  updateFunc ) 
1011    { 
12+         _config  =  config ; 
1113        _updateFunc  =  updateFunc ; 
14+     } 
15+ 
16+     public  async  Task  CheckUpdateGuiN ( bool  preRelease ) 
17+     { 
1218        var  url  =  string . Empty ; 
1319        var  fileName  =  string . Empty ; 
1420
@@ -47,9 +53,8 @@ public async Task CheckUpdateGuiN(Config config, Func<bool, string, Task> update
4753        } 
4854    } 
4955
50-     public  async  Task  CheckUpdateCore ( ECoreType  type ,  Config   config ,   Func < bool ,   string ,   Task >   updateFunc ,   bool  preRelease ) 
56+     public  async  Task  CheckUpdateCore ( ECoreType  type ,  bool  preRelease ) 
5157    { 
52-         _updateFunc  =  updateFunc ; 
5358        var  url  =  string . Empty ; 
5459        var  fileName  =  string . Empty ; 
5560
@@ -101,11 +106,11 @@ public async Task CheckUpdateCore(ECoreType type, Config config, Func<bool, stri
101106        } 
102107    } 
103108
104-     public  async  Task  UpdateGeoFileAll ( Config   config ,   Func < bool ,   string ,   Task >   updateFunc ) 
109+     public  async  Task  UpdateGeoFileAll ( ) 
105110    { 
106-         await  UpdateGeoFiles ( config ,   updateFunc ) ; 
107-         await  UpdateOtherFiles ( config ,   updateFunc ) ; 
108-         await  UpdateSrsFileAll ( config ,   updateFunc ) ; 
111+         await  UpdateGeoFiles ( ) ; 
112+         await  UpdateOtherFiles ( ) ; 
113+         await  UpdateSrsFileAll ( ) ; 
109114        await  UpdateFunc ( true ,  string . Format ( ResUI . MsgDownloadGeoFileSuccessfully ,  "geo" ) ) ; 
110115    } 
111116
@@ -330,13 +335,11 @@ private async Task<RetResult> ParseDownloadUrl(ECoreType type, SemanticVersion v
330335
331336    #region Geo private
332337
333-     private  async  Task  UpdateGeoFiles ( Config   config ,   Func < bool ,   string ,   Task >   updateFunc ) 
338+     private  async  Task  UpdateGeoFiles ( ) 
334339    { 
335-         _updateFunc  =  updateFunc ; 
336- 
337-         var  geoUrl  =  string . IsNullOrEmpty ( config ? . ConstItem . GeoSourceUrl ) 
340+         var  geoUrl  =  string . IsNullOrEmpty ( _config ? . ConstItem . GeoSourceUrl ) 
338341            ?  Global . GeoUrl 
339-             :  config . ConstItem . GeoSourceUrl ; 
342+             :  _config . ConstItem . GeoSourceUrl ; 
340343
341344        List < string >  files  =  [ "geosite" ,  "geoip" ] ; 
342345        foreach  ( var  geoName  in  files ) 
@@ -345,33 +348,29 @@ private async Task UpdateGeoFiles(Config config, Func<bool, string, Task> update
345348            var  targetPath  =  Utils . GetBinPath ( $ "{ fileName } ") ; 
346349            var  url  =  string . Format ( geoUrl ,  geoName ) ; 
347350
348-             await  DownloadGeoFile ( url ,  fileName ,  targetPath ,   updateFunc ) ; 
351+             await  DownloadGeoFile ( url ,  fileName ,  targetPath ) ; 
349352        } 
350353    } 
351354
352-     private  async  Task  UpdateOtherFiles ( Config   config ,   Func < bool ,   string ,   Task >   updateFunc ) 
355+     private  async  Task  UpdateOtherFiles ( ) 
353356    { 
354357        //If it is not in China area, no update is required 
355-         if  ( config . ConstItem . GeoSourceUrl . IsNotEmpty ( ) ) 
358+         if  ( _config . ConstItem . GeoSourceUrl . IsNotEmpty ( ) ) 
356359        { 
357360            return ; 
358361        } 
359362
360-         _updateFunc  =  updateFunc ; 
361- 
362363        foreach  ( var  url  in  Global . OtherGeoUrls ) 
363364        { 
364365            var  fileName  =  Path . GetFileName ( url ) ; 
365366            var  targetPath  =  Utils . GetBinPath ( $ "{ fileName } ") ; 
366367
367-             await  DownloadGeoFile ( url ,  fileName ,  targetPath ,   updateFunc ) ; 
368+             await  DownloadGeoFile ( url ,  fileName ,  targetPath ) ; 
368369        } 
369370    } 
370371
371-     private  async  Task  UpdateSrsFileAll ( Config   config ,   Func < bool ,   string ,   Task >   updateFunc ) 
372+     private  async  Task  UpdateSrsFileAll ( ) 
372373    { 
373-         _updateFunc  =  updateFunc ; 
374- 
375374        var  geoipFiles  =  new  List < string > ( ) ; 
376375        var  geoSiteFiles  =  new  List < string > ( ) ; 
377376
@@ -414,29 +413,29 @@ private async Task UpdateSrsFileAll(Config config, Func<bool, string, Task> upda
414413        } 
415414        foreach  ( var  item  in  geoipFiles . Distinct ( ) ) 
416415        { 
417-             await  UpdateSrsFile ( "geoip" ,  item ,   config ,   updateFunc ) ; 
416+             await  UpdateSrsFile ( "geoip" ,  item ) ; 
418417        } 
419418
420419        foreach  ( var  item  in  geoSiteFiles . Distinct ( ) ) 
421420        { 
422-             await  UpdateSrsFile ( "geosite" ,  item ,   config ,   updateFunc ) ; 
421+             await  UpdateSrsFile ( "geosite" ,  item ) ; 
423422        } 
424423    } 
425424
426-     private  async  Task  UpdateSrsFile ( string  type ,  string  srsName ,   Config   config ,   Func < bool ,   string ,   Task >   updateFunc ) 
425+     private  async  Task  UpdateSrsFile ( string  type ,  string  srsName ) 
427426    { 
428-         var  srsUrl  =  string . IsNullOrEmpty ( config . ConstItem . SrsSourceUrl ) 
427+         var  srsUrl  =  string . IsNullOrEmpty ( _config . ConstItem . SrsSourceUrl ) 
429428                        ?  Global . SingboxRulesetUrl 
430-                         :  config . ConstItem . SrsSourceUrl ; 
429+                         :  _config . ConstItem . SrsSourceUrl ; 
431430
432431        var  fileName  =  $ "{ type } -{ srsName } .srs"; 
433432        var  targetPath  =  Path . Combine ( Utils . GetBinPath ( "srss" ) ,  fileName ) ; 
434433        var  url  =  string . Format ( srsUrl ,  type ,  $ "{ type } -{ srsName } ",  srsName ) ; 
435434
436-         await  DownloadGeoFile ( url ,  fileName ,  targetPath ,   updateFunc ) ; 
435+         await  DownloadGeoFile ( url ,  fileName ,  targetPath ) ; 
437436    } 
438437
439-     private  async  Task  DownloadGeoFile ( string  url ,  string  fileName ,  string  targetPath ,   Func < bool ,   string ,   Task >   updateFunc ) 
438+     private  async  Task  DownloadGeoFile ( string  url ,  string  fileName ,  string  targetPath ) 
440439    { 
441440        var  tmpFileName  =  Utils . GetTempPath ( Utils . GetGuid ( ) ) ; 
442441
0 commit comments