@@ -24,13 +24,24 @@ internal PluginsManager(PluginInitContext context)
24
24
}
25
25
internal void InstallOrUpdate ( UserPlugin plugin )
26
26
{
27
- if ( PluginExists ( ) )
27
+ if ( PluginExists ( plugin . ID ) )
28
28
{
29
- //prompt user if want to install
29
+ var updateMessage = $ "Do you want to update following plugin?{ Environment . NewLine } { Environment . NewLine } " +
30
+ $ "Name: { plugin . Name } { Environment . NewLine } " +
31
+ $ "{ Environment . NewLine } New Version: { plugin . Version } " +
32
+ $ "{ Environment . NewLine } Author: { plugin . Author } ";
30
33
31
- return ;
34
+ throw new NotImplementedException ( ) ;
32
35
}
33
36
37
+ var message = $ "Do you want to install following plugin?{ Environment . NewLine } { Environment . NewLine } " +
38
+ $ "Name: { plugin . Name } { Environment . NewLine } " +
39
+ $ "Version: { plugin . Version } { Environment . NewLine } " +
40
+ $ "Author: { plugin . Author } ";
41
+
42
+ if ( MessageBox . Show ( message , "Install plugin" , MessageBoxButton . YesNo ) == MessageBoxResult . No )
43
+ return ;
44
+
34
45
var filePath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } .zip") ;
35
46
36
47
try
@@ -53,17 +64,18 @@ internal void InstallOrUpdate(UserPlugin plugin)
53
64
54
65
internal void Update ( )
55
66
{
56
-
67
+ throw new NotImplementedException ( ) ;
57
68
}
58
69
59
- internal bool PluginExists ( )
70
+ internal bool PluginExists ( string id )
60
71
{
61
- return false ;
72
+ return Context . API . GetAllPlugins ( ) . Any ( x => x . Metadata . ID == id ) ;
62
73
}
63
74
64
75
internal void PluginsManifestSiteOpen ( )
65
76
{
66
77
//Open from context menu https://git.vcmq.workers.dev/Flow-Launcher/Flow.Launcher.PluginsManifest
78
+ throw new NotImplementedException ( ) ;
67
79
}
68
80
69
81
internal List < Result > Search ( List < Result > results , string searchName )
@@ -105,89 +117,43 @@ internal List<Result> RequestInstallOrUpdate(string searchName)
105
117
106
118
private void Install ( UserPlugin plugin , string downloadedFilePath )
107
119
{
108
- if ( File . Exists ( downloadedFilePath ) )
109
- {
110
- var tempFolderPath = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher" ) ;
111
- var tempPluginFolderPath = Path . Combine ( tempFolderPath , "plugin" ) ;
112
-
113
- if ( Directory . Exists ( tempFolderPath ) )
114
- {
115
- Directory . Delete ( tempFolderPath , true ) ;
116
- }
117
-
118
- Directory . CreateDirectory ( tempFolderPath ) ;
119
-
120
- var zipFilePath = Path . Combine ( tempFolderPath , Path . GetFileName ( downloadedFilePath ) ) ;
121
-
122
- File . Move ( downloadedFilePath , zipFilePath ) ;
123
-
124
- Utilities . UnZip ( zipFilePath , tempPluginFolderPath , true ) ;
125
-
126
- var unzippedParentFolderPath = tempPluginFolderPath ;
127
-
128
- var metadataJsonFilePath = string . Empty ;
129
-
130
- var pluginFolderPath = string . Empty ;
131
-
132
- var unzippedFolderCount = Directory . GetDirectories ( unzippedParentFolderPath ) . Length ;
133
- var unzippedFilesCount = Directory . GetFiles ( unzippedParentFolderPath ) . Length ;
134
-
135
- // addjust path depending on how the plugin is zipped up
136
- // the recommended should be to zip up the folder not the contents
137
- if ( unzippedFolderCount == 1 && unzippedFilesCount == 0 )
138
- // folder is zipped up, unzipped plugin directory structure: tempPath/unzippedParentPluginFolder/pluginFolderName/
139
- pluginFolderPath = Directory . GetDirectories ( unzippedParentFolderPath ) [ 0 ] ;
140
-
141
- if ( unzippedFilesCount > 1 )
142
- // content is zipped up, unzipped plugin directory structure: tempPath/unzippedParentPluginFolder/
143
- pluginFolderPath = unzippedParentFolderPath ;
120
+ if ( ! File . Exists ( downloadedFilePath ) )
121
+ return ;
122
+
123
+ var tempFolderPath = Path . Combine ( Path . GetTempPath ( ) , "flowlauncher" ) ;
124
+ var tempFolderPluginPath = Path . Combine ( tempFolderPath , "plugin" ) ;
125
+
126
+ if ( Directory . Exists ( tempFolderPath ) )
127
+ Directory . Delete ( tempFolderPath , true ) ;
144
128
145
- if ( File . Exists ( Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ) )
146
- metadataJsonFilePath = Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ;
129
+ Directory . CreateDirectory ( tempFolderPath ) ;
147
130
148
- if ( string . IsNullOrEmpty ( metadataJsonFilePath ) || string . IsNullOrEmpty ( pluginFolderPath ) )
149
- {
150
- MessageBox . Show ( "Install failed: unable to find the plugin.json metadata file" ) ;
151
- return ;
152
- }
131
+ var zipFilePath = Path . Combine ( tempFolderPath , Path . GetFileName ( downloadedFilePath ) ) ;
153
132
154
- string newPluginPath = Path . Combine ( DataLocation . PluginsDirectory , $ " { plugin . Name } { plugin . ID } " ) ;
133
+ File . Move ( downloadedFilePath , zipFilePath ) ;
155
134
156
- string content = $ "Do you want to install following plugin?{ Environment . NewLine } { Environment . NewLine } " +
157
- $ "Name: { plugin . Name } { Environment . NewLine } " +
158
- $ "Version: { plugin . Version } { Environment . NewLine } " +
159
- $ "Author: { plugin . Author } ";
135
+ Utilities . UnZip ( zipFilePath , tempFolderPluginPath , true ) ;
160
136
161
- var existingPlugin = Context . API . GetAllPlugins ( ) . Where ( x => x . Metadata . ID == plugin . ID ) . FirstOrDefault ( ) ;
137
+ var pluginFolderPath = Utilities . GetContainingFolderPathAfterUnzip ( tempFolderPluginPath ) ;
162
138
163
- if ( existingPlugin != null )
164
- {
165
- content = $ "Do you want to update following plugin?{ Environment . NewLine } { Environment . NewLine } " +
166
- $ "Name: { plugin . Name } { Environment . NewLine } " +
167
- $ "Old Version: { existingPlugin . Metadata . Version } " +
168
- $ "{ Environment . NewLine } New Version: { plugin . Version } " +
169
- $ "{ Environment . NewLine } Author: { plugin . Author } ";
170
- }
139
+ var metadataJsonFilePath = string . Empty ;
140
+ if ( File . Exists ( Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ) )
141
+ metadataJsonFilePath = Path . Combine ( pluginFolderPath , Constant . PluginMetadataFileName ) ;
171
142
172
- var result = MessageBox . Show ( content , "Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
173
- if ( result == MessageBoxResult . Yes )
174
- {
175
- if ( existingPlugin != null && Directory . Exists ( existingPlugin . Metadata . PluginDirectory ) )
176
- {
177
- //when plugin is in use, we can't delete them. That's why we need to make plugin folder a random name
178
- File . Create ( Path . Combine ( existingPlugin . Metadata . PluginDirectory , "NeedDelete.txt" ) ) . Close ( ) ;
179
- }
143
+ if ( string . IsNullOrEmpty ( metadataJsonFilePath ) || string . IsNullOrEmpty ( pluginFolderPath ) )
144
+ {
145
+ MessageBox . Show ( "Install failed: unable to find the plugin.json metadata file from the new plugin" ) ;
146
+ return ;
147
+ }
180
148
181
- Directory . Move ( pluginFolderPath , newPluginPath ) ;
149
+ string newPluginPath = Path . Combine ( DataLocation . PluginsDirectory , $ "{ plugin . Name } { plugin . ID } ") ;
150
+
151
+ Directory . Move ( pluginFolderPath , newPluginPath ) ;
182
152
183
- if ( MessageBox . Show ( $ "You have installed plugin { plugin . Name } successfully.{ Environment . NewLine } " +
184
- "Restart Flow Launcher to take effect?" ,
185
- "Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) == MessageBoxResult . Yes )
186
- {
187
- Context . API . RestartApp ( ) ;
188
- }
189
- }
190
- }
153
+ if ( MessageBox . Show ( $ "You have installed plugin { plugin . Name } successfully.{ Environment . NewLine } " +
154
+ "Restart Flow Launcher to take effect?" ,
155
+ "Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) == MessageBoxResult . Yes )
156
+ Context . API . RestartApp ( ) ;
191
157
}
192
158
193
159
internal List < Result > RequestUninstall ( string search )
@@ -221,14 +187,13 @@ private void Uninstall(PluginMetadata plugin)
221
187
222
188
if ( MessageBox . Show ( message , "Flow Launcher" , MessageBoxButton . YesNo ) == MessageBoxResult . Yes )
223
189
{
224
- File . Create ( Path . Combine ( plugin . PluginDirectory , "NeedDelete.txt" ) ) . Close ( ) ;
190
+ using var _ = File . CreateText ( Path . Combine ( plugin . PluginDirectory , "NeedDelete.txt" ) ) ;
191
+
225
192
var result = MessageBox . Show ( $ "You have uninstalled plugin { plugin . Name } successfully.{ Environment . NewLine } " +
226
193
"Restart Flow Launcher to take effect?" ,
227
194
"Install plugin" , MessageBoxButton . YesNo , MessageBoxImage . Question ) ;
228
195
if ( result == MessageBoxResult . Yes )
229
- {
230
196
Context . API . RestartApp ( ) ;
231
- }
232
197
}
233
198
}
234
199
}
0 commit comments