@@ -104,10 +104,18 @@ internal async Task InstallOrUpdateAsync(UserPlugin plugin)
104
104
if ( MessageBox . Show ( Context . API . GetTranslation ( "plugin_pluginsmanager_update_exists" ) ,
105
105
Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
106
106
MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
107
- Context
108
- . API
109
- . ChangeQuery (
107
+ {
108
+ if ( File . Exists ( plugin . UrlDownload ) )
109
+ {
110
+ Context . API . ChangeQuery (
111
+ $ "{ Context . CurrentPluginMetadata . ActionKeywords . FirstOrDefault ( ) } { Settings . UpdateCommand } { plugin . UrlDownload } ") ;
112
+ }
113
+ else
114
+ {
115
+ Context . API . ChangeQuery (
110
116
$ "{ Context . CurrentPluginMetadata . ActionKeywords . FirstOrDefault ( ) } { Settings . UpdateCommand } { plugin . Name } ") ;
117
+ }
118
+ }
111
119
112
120
var mainWindow = Application . Current . MainWindow ;
113
121
mainWindow . Show ( ) ;
@@ -201,6 +209,110 @@ internal async ValueTask<List<Result>> RequestUpdateAsync(string search, Cancell
201
209
{
202
210
await PluginsManifest . UpdateManifestAsync ( token , usePrimaryUrlOnly ) ;
203
211
212
+ if ( File . Exists ( search ) && search . Split ( '.' ) . Last ( ) == zip )
213
+ {
214
+ var plugin = null as UserPlugin ;
215
+
216
+ using ( ZipArchive archive = ZipFile . OpenRead ( search ) )
217
+ {
218
+ var pluginJsonPath = archive . Entries . FirstOrDefault ( x => x . Name == "plugin.json" ) . ToString ( ) ;
219
+ ZipArchiveEntry pluginJsonEntry = archive . GetEntry ( pluginJsonPath ) ;
220
+
221
+ if ( pluginJsonEntry != null )
222
+ {
223
+ using ( StreamReader reader = new StreamReader ( pluginJsonEntry . Open ( ) ) )
224
+ {
225
+ string pluginJsonContent = await reader . ReadToEndAsync ( ) ;
226
+ plugin = JsonConvert . DeserializeObject < UserPlugin > ( pluginJsonContent ) ;
227
+ plugin . IcoPath = "Images\\ zipfolder.png" ;
228
+ }
229
+ }
230
+ }
231
+ if ( plugin == null )
232
+ {
233
+ return new List < Result >
234
+ {
235
+ new Result
236
+ {
237
+ Title = Context . API . GetTranslation ( "plugin_pluginsmanager_update_noresult_title" ) ,
238
+ SubTitle = Context . API . GetTranslation ( "plugin_pluginsmanager_update_noresult_subtitle" ) ,
239
+ IcoPath = icoPath
240
+ }
241
+ } ;
242
+ }
243
+
244
+ var pluginOld = Context . API . GetAllPlugins ( ) . FirstOrDefault ( x => x . Metadata . ID == plugin . ID ) ;
245
+
246
+ return new List < Result > {
247
+ new Result
248
+ {
249
+
250
+ Title = $ "{ plugin . Name } by { plugin . Author } ",
251
+ SubTitle = $ "Update from version { pluginOld . Metadata . Version } to { plugin . Version } ",
252
+ IcoPath = pluginOld . Metadata . IcoPath ,
253
+ Action = e =>
254
+ {
255
+ string message ;
256
+ if ( Settings . AutoRestartAfterChanging )
257
+ {
258
+ message = string . Format (
259
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_prompt" ) ,
260
+ plugin . Name , plugin . Author ,
261
+ Environment . NewLine , Environment . NewLine ) ;
262
+ }
263
+ else
264
+ {
265
+ message = string . Format (
266
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_prompt_no_restart" ) ,
267
+ plugin . Name , plugin . Author ,
268
+ Environment . NewLine ) ;
269
+ }
270
+
271
+ if ( MessageBox . Show ( message ,
272
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
273
+ MessageBoxButton . YesNo ) != MessageBoxResult . Yes )
274
+ {
275
+ return false ;
276
+ }
277
+
278
+ var downloadToFilePath = search ;
279
+
280
+
281
+ PluginManager . UpdatePlugin ( pluginOld . Metadata , plugin ,
282
+ downloadToFilePath ) ;
283
+
284
+ if ( Settings . AutoRestartAfterChanging )
285
+ {
286
+ Context . API . ShowMsg (
287
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
288
+ string . Format (
289
+ Context . API . GetTranslation (
290
+ "plugin_pluginsmanager_update_success_restart" ) ,
291
+ plugin . Name ) ) ;
292
+ Context . API . RestartApp ( ) ;
293
+ }
294
+ else
295
+ {
296
+ Context . API . ShowMsg (
297
+ Context . API . GetTranslation ( "plugin_pluginsmanager_update_title" ) ,
298
+ string . Format (
299
+ Context . API . GetTranslation (
300
+ "plugin_pluginsmanager_update_success_no_restart" ) ,
301
+ plugin . Name ) ) ;
302
+ }
303
+
304
+ return true ;
305
+
306
+ } ,
307
+ ContextData =
308
+ new UserPlugin
309
+ {
310
+ Website = plugin . Website ,
311
+ UrlSourceCode = plugin . UrlSourceCode
312
+ }
313
+ } } ;
314
+ }
315
+
204
316
var resultsForUpdate = (
205
317
from existingPlugin in Context . API . GetAllPlugins ( )
206
318
join pluginFromManifest in PluginsManifest . UserPlugins
@@ -498,7 +610,7 @@ internal List<Result> InstallFromLocal(string path)
498
610
{
499
611
string pluginJsonContent = reader . ReadToEnd ( ) ;
500
612
plugin = JsonConvert . DeserializeObject < UserPlugin > ( pluginJsonContent ) ;
501
- plugin . IcoPath = Path . Combine ( path , pluginJsonEntry . FullName . Split ( '/' ) [ 0 ] , plugin . IcoPath ) ;
613
+ plugin . IcoPath = "Images \\ zipfolder.png" ;
502
614
}
503
615
}
504
616
}
@@ -584,7 +696,11 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
584
696
try
585
697
{
586
698
PluginManager . InstallPlugin ( plugin , downloadedFilePath ) ;
587
- File . Delete ( downloadedFilePath ) ;
699
+ if ( downloadedFilePath . StartsWith ( Path . GetTempPath ( ) ) )
700
+ {
701
+ File . Delete ( downloadedFilePath ) ;
702
+ }
703
+
588
704
}
589
705
catch ( FileNotFoundException e )
590
706
{
0 commit comments