@@ -15,28 +15,28 @@ internal static void Install(string path)
15
15
{
16
16
if ( File . Exists ( path ) )
17
17
{
18
- string tempFoler = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher\\ plugins" ) ;
19
- if ( Directory . Exists ( tempFoler ) )
18
+ string tempFolder = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher" , " plugins") ;
19
+ if ( Directory . Exists ( tempFolder ) )
20
20
{
21
- Directory . Delete ( tempFoler , true ) ;
21
+ Directory . Delete ( tempFolder , true ) ;
22
22
}
23
- UnZip ( path , tempFoler , true ) ;
23
+ UnZip ( path , tempFolder , true ) ;
24
24
25
- string iniPath = Path . Combine ( tempFoler , Constant . PluginMetadataFileName ) ;
26
- if ( ! File . Exists ( iniPath ) )
25
+ string jsonPath = Path . Combine ( tempFolder , Constant . PluginMetadataFileName ) ;
26
+ if ( ! File . Exists ( jsonPath ) )
27
27
{
28
28
MessageBox . Show ( "Install failed: plugin config is missing" ) ;
29
29
return ;
30
30
}
31
31
32
- PluginMetadata plugin = GetMetadataFromJson ( tempFoler ) ;
32
+ PluginMetadata plugin = GetMetadataFromJson ( tempFolder ) ;
33
33
if ( plugin == null || plugin . Name == null )
34
34
{
35
35
MessageBox . Show ( "Install failed: plugin config is invalid" ) ;
36
36
return ;
37
37
}
38
38
39
- string pluginFolerPath = Infrastructure . UserSettings . DataLocation . PluginsDirectory ;
39
+ string pluginFolderPath = Infrastructure . UserSettings . DataLocation . PluginsDirectory ;
40
40
41
41
string newPluginName = plugin . Name
42
42
. Replace ( "/" , "_" )
@@ -48,7 +48,9 @@ internal static void Install(string path)
48
48
. Replace ( "*" , "_" )
49
49
. Replace ( "|" , "_" )
50
50
+ "-" + Guid . NewGuid ( ) ;
51
- string newPluginPath = Path . Combine ( pluginFolerPath , newPluginName ) ;
51
+
52
+ string newPluginPath = Path . Combine ( pluginFolderPath , newPluginName ) ;
53
+
52
54
string content = $ "Do you want to install following plugin?{ Environment . NewLine } { Environment . NewLine } " +
53
55
$ "Name: { plugin . Name } { Environment . NewLine } " +
54
56
$ "Version: { plugin . Version } { Environment . NewLine } " +
@@ -73,8 +75,7 @@ internal static void Install(string path)
73
75
File . Create ( Path . Combine ( existingPlugin . Metadata . PluginDirectory , "NeedDelete.txt" ) ) . Close ( ) ;
74
76
}
75
77
76
- UnZip ( path , newPluginPath , true ) ;
77
- Directory . Delete ( tempFoler , true ) ;
78
+ Directory . Move ( tempFolder , newPluginPath ) ;
78
79
79
80
//exsiting plugins may be has loaded by application,
80
81
//if we try to delelte those kind of plugins, we will get a error that indicate the
@@ -130,58 +131,38 @@ private static PluginMetadata GetMetadataFromJson(string pluginDirectory)
130
131
}
131
132
132
133
/// <summary>
133
- /// unzip
134
+ /// unzip plugin contents to the given directory.
134
135
/// </summary>
135
- /// <param name="zipedFile ">The ziped file.</param>
136
- /// <param name="strDirectory">The STR directory.</param>
136
+ /// <param name="zipFile ">The path to the zip file.</param>
137
+ /// <param name="strDirectory">The output directory.</param>
137
138
/// <param name="overWrite">overwirte</param>
138
- private static void UnZip ( string zipedFile , string strDirectory , bool overWrite )
139
+ private static void UnZip ( string zipFile , string strDirectory , bool overWrite )
139
140
{
140
141
if ( strDirectory == "" )
141
142
strDirectory = Directory . GetCurrentDirectory ( ) ;
142
- if ( ! strDirectory . EndsWith ( "\\ " ) )
143
- strDirectory = strDirectory + "\\ " ;
144
143
145
- using ( ZipInputStream s = new ZipInputStream ( File . OpenRead ( zipedFile ) ) )
144
+ using ( ZipInputStream zipStream = new ZipInputStream ( File . OpenRead ( zipFile ) ) )
146
145
{
147
146
ZipEntry theEntry ;
148
147
149
- while ( ( theEntry = s . GetNextEntry ( ) ) != null )
148
+ while ( ( theEntry = zipStream . GetNextEntry ( ) ) != null )
150
149
{
151
- string directoryName = "" ;
152
- string pathToZip = "" ;
153
- pathToZip = theEntry . Name ;
150
+ var pathToZip = theEntry . Name ;
151
+ var directoryName = String . IsNullOrEmpty ( pathToZip ) ? "" : Path . GetDirectoryName ( pathToZip ) ;
152
+ var fileName = Path . GetFileName ( pathToZip ) ;
153
+ var destinationDir = Path . Combine ( strDirectory , directoryName ) ;
154
+ var destinationFile = Path . Combine ( destinationDir , fileName ) ;
154
155
155
- if ( pathToZip != "" )
156
- directoryName = Path . GetDirectoryName ( pathToZip ) + "\\ " ;
156
+ Directory . CreateDirectory ( destinationDir ) ;
157
157
158
- string fileName = Path . GetFileName ( pathToZip ) ;
158
+ if ( String . IsNullOrEmpty ( fileName ) || ( File . Exists ( destinationFile ) && ! overWrite ) )
159
+ continue ;
159
160
160
- Directory . CreateDirectory ( strDirectory + directoryName ) ;
161
-
162
- if ( fileName != "" )
161
+ using ( FileStream streamWriter = File . Create ( destinationFile ) )
163
162
{
164
- if ( ( File . Exists ( strDirectory + directoryName + fileName ) && overWrite ) || ( ! File . Exists ( strDirectory + directoryName + fileName ) ) )
165
- {
166
- using ( FileStream streamWriter = File . Create ( strDirectory + directoryName + fileName ) )
167
- {
168
- byte [ ] data = new byte [ 2048 ] ;
169
- while ( true )
170
- {
171
- int size = s . Read ( data , 0 , data . Length ) ;
172
-
173
- if ( size > 0 )
174
- streamWriter . Write ( data , 0 , size ) ;
175
- else
176
- break ;
177
- }
178
- streamWriter . Close ( ) ;
179
- }
180
- }
163
+ zipStream . CopyTo ( streamWriter ) ;
181
164
}
182
165
}
183
-
184
- s . Close ( ) ;
185
166
}
186
167
}
187
168
}
0 commit comments