3
3
using Flow . Launcher . Infrastructure . Logger ;
4
4
using Flow . Launcher . Infrastructure . UserSettings ;
5
5
using Flow . Launcher . Plugin . PluginsManager . Models ;
6
- using ICSharpCode . SharpZipLib . Zip ;
7
- using Newtonsoft . Json ;
8
6
using System ;
9
7
using System . Collections . Generic ;
10
8
using System . IO ;
11
9
using System . Linq ;
12
10
using System . Net ;
13
- using System . Text ;
14
11
using System . Windows ;
15
12
16
13
namespace Flow . Launcher . Plugin . PluginsManager
@@ -37,29 +34,23 @@ internal void PluginInstall(UserPlugin plugin)
37
34
}
38
35
39
36
var filePath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } .zip") ;
40
- PluginDownload ( plugin . UrlDownload , filePath ) ;
41
- Application . Current . Dispatcher . Invoke ( ( ) => Install ( plugin , filePath ) ) ;
42
- }
43
-
44
- private void PluginDownload ( string downloadUrl , string toFilePath )
45
- {
37
+
46
38
try
47
39
{
48
- using ( var wc = new WebClient { Proxy = Http . WebProxy ( ) } )
49
- {
50
- wc . DownloadFile ( downloadUrl , toFilePath ) ;
51
- }
40
+ Utilities . Download ( plugin . UrlDownload , filePath ) ;
52
41
53
42
context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
54
- context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
43
+ context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
55
44
}
56
- catch ( Exception e )
45
+ catch ( Exception e )
57
46
{
58
47
context . API . ShowMsg ( context . API . GetTranslation ( "plugin_pluginsmanager_downloading_plugin" ) ,
59
48
context . API . GetTranslation ( "plugin_pluginsmanager_download_success" ) ) ;
60
49
61
50
Log . Exception ( "PluginsManager" , "An error occured while downloading plugin" , e , "PluginDownload" ) ;
62
51
}
52
+
53
+ Application . Current . Dispatcher . Invoke ( ( ) => Install ( plugin , filePath ) ) ;
63
54
}
64
55
65
56
internal void PluginUpdate ( )
@@ -127,7 +118,7 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
127
118
128
119
File . Move ( downloadedFilePath , zipFilePath ) ;
129
120
130
- UnZip ( zipFilePath , tempPluginFolderPath , true ) ;
121
+ Utilities . UnZip ( zipFilePath , tempPluginFolderPath , true ) ;
131
122
132
123
var unzippedParentFolderPath = tempPluginFolderPath ;
133
124
@@ -203,43 +194,5 @@ private void Install(UserPlugin plugin, string downloadedFilePath)
203
194
}
204
195
}
205
196
}
206
-
207
- /// <summary>
208
- /// unzip plugin contents to the given directory.
209
- /// </summary>
210
- /// <param name="zipFilePath">The path to the zip file.</param>
211
- /// <param name="strDirectory">The output directory.</param>
212
- /// <param name="overwrite">overwrite</param>
213
- private void UnZip ( string zipFilePath , string strDirectory , bool overwrite )
214
- {
215
- if ( strDirectory == "" )
216
- strDirectory = Directory . GetCurrentDirectory ( ) ;
217
-
218
- using ( ZipInputStream zipStream = new ZipInputStream ( File . OpenRead ( zipFilePath ) ) )
219
- {
220
- ZipEntry theEntry ;
221
-
222
- while ( ( theEntry = zipStream . GetNextEntry ( ) ) != null )
223
- {
224
- var pathToZip = theEntry . Name ;
225
- var directoryName = string . IsNullOrEmpty ( pathToZip ) ? "" : Path . GetDirectoryName ( pathToZip ) ;
226
- var fileName = Path . GetFileName ( pathToZip ) ;
227
- var destinationDir = Path . Combine ( strDirectory , directoryName ) ;
228
- var destinationFile = Path . Combine ( destinationDir , fileName ) ;
229
-
230
- Directory . CreateDirectory ( destinationDir ) ;
231
-
232
- if ( string . IsNullOrEmpty ( fileName ) || ( File . Exists ( destinationFile ) && ! overwrite ) )
233
- continue ;
234
-
235
- using ( FileStream streamWriter = File . Create ( destinationFile ) )
236
- {
237
- zipStream . CopyTo ( streamWriter ) ;
238
- }
239
- }
240
- }
241
- }
242
-
243
- //delete the zip file when done
244
197
}
245
198
}
0 commit comments