@@ -6,7 +6,7 @@ namespace ServiceLib.Services;
66public class UpdateService
77{
88 private Action < bool , string > ? _updateFunc ;
9- private int _timeout = 30 ;
9+ private readonly int _timeout = 30 ;
1010 private static readonly string _tag = "UpdateService" ;
1111
1212 public async Task CheckUpdateGuiN ( Config config , Action < bool , string > updateFunc , bool preRelease )
@@ -104,137 +104,6 @@ public async Task CheckUpdateCore(ECoreType type, Config config, Action<bool, st
104104 }
105105 }
106106
107- public async Task UpdateSubscriptionProcess ( Config config , string subId , bool blProxy , Action < bool , string > updateFunc )
108- {
109- _updateFunc = updateFunc ;
110-
111- _updateFunc ? . Invoke ( false , ResUI . MsgUpdateSubscriptionStart ) ;
112- var subItem = await AppHandler . Instance . SubItems ( ) ;
113-
114- if ( subItem is not { Count : > 0 } )
115- {
116- _updateFunc ? . Invoke ( false , ResUI . MsgNoValidSubscription ) ;
117- return ;
118- }
119-
120- foreach ( var item in subItem )
121- {
122- var id = item . Id . TrimEx ( ) ;
123- var url = item . Url . TrimEx ( ) ;
124- var userAgent = item . UserAgent . TrimEx ( ) ;
125- var hashCode = $ "{ item . Remarks } ->";
126- if ( id . IsNullOrEmpty ( ) || url . IsNullOrEmpty ( ) || ( subId . IsNotEmpty ( ) && item . Id != subId ) )
127- {
128- //_updateFunc?.Invoke(false, $"{hashCode}{ResUI.MsgNoValidSubscription}");
129- continue ;
130- }
131- if ( ! url . StartsWith ( Global . HttpsProtocol ) && ! url . StartsWith ( Global . HttpProtocol ) )
132- {
133- continue ;
134- }
135- if ( item . Enabled == false )
136- {
137- _updateFunc ? . Invoke ( false , $ "{ hashCode } { ResUI . MsgSkipSubscriptionUpdate } ") ;
138- continue ;
139- }
140-
141- var downloadHandle = new DownloadService ( ) ;
142- downloadHandle . Error += ( sender2 , args ) =>
143- {
144- _updateFunc ? . Invoke ( false , $ "{ hashCode } { args . GetException ( ) . Message } ") ;
145- } ;
146-
147- _updateFunc ? . Invoke ( false , $ "{ hashCode } { ResUI . MsgStartGettingSubscriptions } ") ;
148-
149- //one url
150- url = Utils . GetPunycode ( url ) ;
151- //convert
152- if ( item . ConvertTarget . IsNotEmpty ( ) )
153- {
154- var subConvertUrl = config . ConstItem . SubConvertUrl . IsNullOrEmpty ( ) ? Global . SubConvertUrls . FirstOrDefault ( ) : config . ConstItem . SubConvertUrl ;
155- url = string . Format ( subConvertUrl ! , Utils . UrlEncode ( url ) ) ;
156- if ( ! url . Contains ( "target=" ) )
157- {
158- url += string . Format ( "&target={0}" , item . ConvertTarget ) ;
159- }
160- if ( ! url . Contains ( "config=" ) )
161- {
162- url += string . Format ( "&config={0}" , Global . SubConvertConfig . FirstOrDefault ( ) ) ;
163- }
164- }
165- var result = await downloadHandle . TryDownloadString ( url , blProxy , userAgent ) ;
166- if ( blProxy && result . IsNullOrEmpty ( ) )
167- {
168- result = await downloadHandle . TryDownloadString ( url , false , userAgent ) ;
169- }
170-
171- //more url
172- if ( item . ConvertTarget . IsNullOrEmpty ( ) && item . MoreUrl . TrimEx ( ) . IsNotEmpty ( ) )
173- {
174- if ( result . IsNotEmpty ( ) && Utils . IsBase64String ( result ) )
175- {
176- result = Utils . Base64Decode ( result ) ;
177- }
178-
179- var lstUrl = item . MoreUrl . TrimEx ( ) . Split ( "," ) ?? [ ] ;
180- foreach ( var it in lstUrl )
181- {
182- var url2 = Utils . GetPunycode ( it ) ;
183- if ( url2 . IsNullOrEmpty ( ) )
184- {
185- continue ;
186- }
187-
188- var result2 = await downloadHandle . TryDownloadString ( url2 , blProxy , userAgent ) ;
189- if ( blProxy && result2 . IsNullOrEmpty ( ) )
190- {
191- result2 = await downloadHandle . TryDownloadString ( url2 , false , userAgent ) ;
192- }
193- if ( result2 . IsNotEmpty ( ) )
194- {
195- if ( Utils . IsBase64String ( result2 ) )
196- {
197- result += Environment . NewLine + Utils . Base64Decode ( result2 ) ;
198- }
199- else
200- {
201- result += Environment . NewLine + result2 ;
202- }
203- }
204- }
205- }
206-
207- if ( result . IsNullOrEmpty ( ) )
208- {
209- _updateFunc ? . Invoke ( false , $ "{ hashCode } { ResUI . MsgSubscriptionDecodingFailed } ") ;
210- }
211- else
212- {
213- _updateFunc ? . Invoke ( false , $ "{ hashCode } { ResUI . MsgGetSubscriptionSuccessfully } ") ;
214- if ( result ? . Length < 99 )
215- {
216- _updateFunc ? . Invoke ( false , $ "{ hashCode } { result } ") ;
217- }
218-
219- var ret = await ConfigHandler . AddBatchServers ( config , result , id , true ) ;
220- if ( ret <= 0 )
221- {
222- Logging . SaveLog ( "FailedImportSubscription" ) ;
223- Logging . SaveLog ( result ) ;
224- }
225- _updateFunc ? . Invoke ( false ,
226- ret > 0
227- ? $ "{ hashCode } { ResUI . MsgUpdateSubscriptionEnd } "
228- : $ "{ hashCode } { ResUI . MsgFailedImportSubscription } ") ;
229- }
230- _updateFunc ? . Invoke ( false , "-------------------------------------------------------" ) ;
231-
232- //await ConfigHandler.DedupServerList(config, id);
233- }
234-
235- _updateFunc ? . Invoke ( true , $ "{ ResUI . MsgUpdateSubscriptionEnd } ") ;
236- }
237-
238107 public async Task UpdateGeoFileAll ( Config config , Action < bool , string > updateFunc )
239108 {
240109 await UpdateGeoFiles ( config , updateFunc ) ;
0 commit comments