@@ -171,6 +171,84 @@ void PluginInstaller::createXmlFile()
171171 }
172172}
173173
174+ int PluginInstaller::checkForPluginUpdates ()
175+ {
176+ LOGD (" Checking for plugin updates..." );
177+
178+ File xmlFile = getPluginsDirectory ().getChildFile (" installedPlugins.xml" );
179+
180+ XmlDocument doc (xmlFile);
181+ std::unique_ptr<XmlElement> xml (doc.getDocumentElement ());
182+
183+ if (xml == 0 || ! xml->hasTagName (" PluginInstaller" ))
184+ {
185+ LOGD (" [PluginInstaller] installedPlugins.xml not found." );
186+ return 0 ;
187+ }
188+
189+ auto child = xml->getFirstChildElement ();
190+
191+ String baseUrl = " https://open-ephys-plugin-gateway.herokuapp.com/" ;
192+ String response = URL (baseUrl).readEntireTextStream ();
193+
194+ if (response.isEmpty ())
195+ {
196+ LOGE (" Unable to fetch plugin updates! Please check your internet connection." );
197+ return 0 ;
198+ }
199+
200+ var gatewayData;
201+ Result result = JSON::parse (response, gatewayData);
202+ gatewayData = gatewayData.getProperty (" plugins" , var ());
203+
204+ updatablePlugins.clear ();
205+
206+ for (auto * e : child->getChildIterator ())
207+ {
208+ String pName = e->getTagName ();
209+ String latestVer;
210+
211+ // Get latest compatible version for this plugin
212+ for (int i = 0 ; i < gatewayData.size (); i++)
213+ {
214+ if (gatewayData[i].getProperty (" name" , " NULL" ).toString ().equalsIgnoreCase (pName))
215+ {
216+ auto allVersions = gatewayData[i].getProperty (" versions" , " NULL" ).getArray ();
217+ StringArray compatibleVersions;
218+
219+ for (String depVersion : *allVersions)
220+ {
221+ String apiVer = depVersion.substring (depVersion.indexOf (" I" ) + 1 );
222+
223+ if (apiVer.equalsIgnoreCase (String (PLUGIN_API_VER)))
224+ compatibleVersions.add (depVersion);
225+ }
226+
227+ if (! compatibleVersions.isEmpty ())
228+ {
229+ compatibleVersions.sort (false );
230+ latestVer = compatibleVersions[compatibleVersions.size () - 1 ];
231+ }
232+ else
233+ {
234+ latestVer = " 0.0.0-API" + String (PLUGIN_API_VER);
235+ }
236+
237+ break ;
238+ }
239+ }
240+
241+ if (latestVer.isNotEmpty () && latestVer.compareNatural (e->getAttributeValue (0 )) > 0 )
242+ {
243+ updatablePlugins.add (pName);
244+ LOGD (" Plugin update available: " , pName);
245+ }
246+ }
247+
248+ LOGD (" Found " , updatablePlugins.size (), " plugin(s) with updates available." );
249+ return updatablePlugins.size ();
250+ }
251+
174252void PluginInstaller::installPluginAndDependency (const String& plugin, String version)
175253{
176254 PluginInfoComponent tempInfoComponent;
0 commit comments