Skip to content

Commit 30dae8d

Browse files
committed
Fix plugin version comparison in Plugin Installer
Show loading window when fetching plugin updates
1 parent 5117e36 commit 30dae8d

2 files changed

Lines changed: 68 additions & 51 deletions

File tree

Source/UI/PluginInstaller.cpp

Lines changed: 61 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ PluginInstaller::PluginInstaller(MainWindow* mainWindow)
8787
setVisible(true);
8888

8989
// Constraining the window's size doesn't seem to work:
90-
setResizeLimits(640, 480, 8192, 5120);
90+
setResizeLimits(854, 480, 8192, 5120);
9191

9292
createXmlFile();
9393

@@ -159,9 +159,58 @@ void PluginInstaller::createXmlFile()
159159
}
160160
}
161161

162+
int versionCompare(const String& v1, const String& v2)
163+
{
164+
String nv1 = v1.substring(0, v1.indexOf("-"));
165+
String nv2 = v2.substring(0, v2.indexOf("-"));
166+
167+
// vnum stores each numeric part of version
168+
int vnum1 = 0, vnum2 = 0;
169+
170+
// loop untill both numeric versions are processed
171+
for (int i=0, j=0; (i<nv1.length() || j<nv2.length()); )
172+
{
173+
// storing numeric part of version 1 in vnum1
174+
while (i < nv1.length() && nv1[i] != '.')
175+
{
176+
vnum1 = vnum1 * 10 + (nv1[i] - '0');
177+
i++;
178+
}
179+
180+
// storing numeric part of version 2 in vnum2
181+
while (j < nv2.length() && nv2[j] != '.')
182+
{
183+
vnum2 = vnum2 * 10 + (nv2[j] - '0');
184+
j++;
185+
}
186+
187+
if (vnum1 > vnum2)
188+
return 1;
189+
if (vnum2 > vnum1)
190+
return -1;
191+
192+
// if equal, reset variables and go for next numeric part
193+
vnum1 = vnum2 = 0;
194+
i++;
195+
j++;
196+
}
197+
198+
// Numeric versions match, check API versions
199+
int av1 = v1.substring(v1.indexOf("I") + 1).getIntValue();
200+
int av2 = v2.substring(v2.indexOf("I") + 1).getIntValue();
201+
202+
if (av1 > av2)
203+
return 1;
204+
if (av1 < av2)
205+
return -1;
206+
207+
return 0;
208+
}
209+
210+
162211
/* ================================== Plugin Installer Component ================================== */
163212

164-
PluginInstallerComponent::PluginInstallerComponent()
213+
PluginInstallerComponent::PluginInstallerComponent() : ThreadWithProgressWindow("Plugin Installer", false, false)
165214
{
166215
font = Font("FiraSans", 18, Font::plain);
167216
setSize(getWidth() - 10, getHeight() - 10);
@@ -289,7 +338,7 @@ void PluginInstallerComponent::comboBoxChanged(ComboBox* comboBoxThatHasChanged)
289338
}
290339
}
291340

292-
void PluginInstallerComponent::loadInstalledPluginNames()
341+
void PluginInstallerComponent::run()
293342
{
294343
String fileStr = "plugins" + File::separatorString + "installedPlugins.xml";
295344
File xmlFile = getPluginsLocationDirectory().getChildFile(fileStr);
@@ -317,6 +366,7 @@ void PluginInstallerComponent::loadInstalledPluginNames()
317366

318367
if (updatesButton.getToggleState())
319368
{
369+
setStatusMessage("Fetching plugin updates...");
320370
//Get latest version
321371
String versionUrl = baseUrl + pName + "/" + pName + "-" + osType + "/versions/_latest";
322372

@@ -325,7 +375,7 @@ void PluginInstallerComponent::loadInstalledPluginNames()
325375

326376
String latest_ver = vReply.getProperty("name", "NULL").toString();
327377

328-
if (!latest_ver.equalsIgnoreCase(e->getAttributeValue(0)))
378+
if (versionCompare(latest_ver, e->getAttributeValue(0)) > 0)
329379
updatablePlugins.add(pName);
330380
}
331381
}
@@ -342,8 +392,7 @@ void PluginInstallerComponent::buttonClicked(Button* button)
342392

343393
if(button == &installedButton)
344394
{
345-
//if(installedPlugins.isEmpty())
346-
loadInstalledPluginNames();
395+
this->run();
347396

348397
pluginListAndInfo.pluginArray.clear();
349398
pluginListAndInfo.pluginArray.addArray(installedPlugins);
@@ -357,8 +406,7 @@ void PluginInstallerComponent::buttonClicked(Button* button)
357406
}
358407
else if(button == &updatesButton)
359408
{
360-
//if(installedPlugins.isEmpty())
361-
loadInstalledPluginNames();
409+
this->runThread();
362410

363411
pluginListAndInfo.pluginArray.clear();
364412
pluginListAndInfo.pluginArray.addArray(updatablePlugins);
@@ -914,42 +962,7 @@ void PluginInfoComponent::run()
914962
}
915963

916964
}
917-
918-
int PluginInfoComponent::versionCompare(const String& v1, const String& v2)
919-
{
920-
// vnum stores each numeric part of version
921-
int vnum1 = 0, vnum2 = 0;
922-
923-
// loop untill both string are processed
924-
for (int i=0, j=0; (i<v1.length() || j<v2.length()); )
925-
{
926-
// storing numeric part of version 1 in vnum1
927-
while (i < v1.length() && v1[i] != '.')
928-
{
929-
vnum1 = vnum1 * 10 + (v1[i] - '0');
930-
i++;
931-
}
932-
933-
// storing numeric part of version 2 in vnum2
934-
while (j < v2.length() && v2[j] != '.')
935-
{
936-
vnum2 = vnum2 * 10 + (v2[j] - '0');
937-
j++;
938-
}
939-
940-
if (vnum1 > vnum2)
941-
return 1;
942-
if (vnum2 > vnum1)
943-
return -1;
944-
945-
// if equal, reset variables and go for next numeric
946-
// part
947-
vnum1 = vnum2 = 0;
948-
i++;
949-
j++;
950-
}
951-
return 0;
952-
}
965+
953966

954967
void PluginInfoComponent::comboBoxChanged(ComboBox* comboBoxThatHasChanged)
955968
{
@@ -965,9 +978,7 @@ void PluginInfoComponent::comboBoxChanged(ComboBox* comboBoxThatHasChanged)
965978
}
966979
else
967980
{
968-
String selected = pInfo.selectedVersion.substring(0, pInfo.selectedVersion.indexOf("-"));
969-
String installed = pInfo.installedVersion.substring(0, pInfo.installedVersion.indexOf("-"));
970-
int result = versionCompare(selected, installed);
981+
int result = versionCompare(pInfo.selectedVersion, pInfo.installedVersion);
971982

972983
if (result == 0)
973984
{
@@ -1003,7 +1014,10 @@ void PluginInfoComponent::setPluginInfo(const SelectedPluginInfo& p)
10031014
versionMenu.clear(dontSendNotification);
10041015

10051016
if (pInfo.versions.isEmpty())
1017+
{
10061018
downloadButton.setEnabled(false);
1019+
downloadButton.setButtonText("Unavailable");
1020+
}
10071021
else
10081022
{
10091023
for (int i = 0; i < pInfo.versions.size(); i++)

Source/UI/PluginInstaller.h

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ struct SelectedPluginInfo
6363
String docURL;
6464
};
6565

66+
/** Compares two different version numbers **/
67+
int versionCompare(const String& v1, const String& v2);
68+
6669
/**
6770
* Create Info Panel for the selected plugin from the table
6871
*/
@@ -83,9 +86,6 @@ class PluginInfoComponent : public Component,
8386
/** Called when any of the buttons inside this component is clicked that has a listener **/
8487
void buttonClicked(Button* button) override;
8588

86-
/** Compares two different version numbers **/
87-
int versionCompare(const String& v1, const String& v2);
88-
8989
void comboBoxChanged(ComboBox* comboBoxThatHasChanged) override;
9090

9191
/** Sets selected plugin's info obtained from bintray**/
@@ -190,7 +190,8 @@ class PluginListBoxComponent : public Component,
190190

191191
class PluginInstallerComponent : public Component,
192192
public ComboBox::Listener,
193-
public Button::Listener
193+
public Button::Listener,
194+
public ThreadWithProgressWindow
194195
{
195196
public:
196197

@@ -224,6 +225,8 @@ class PluginInstallerComponent : public Component,
224225
ToggleButton filterType, sourceType, sinkType, otherType;
225226

226227
Font font;
228+
229+
void run() override;
227230

228231
JUCE_DECLARE_NON_COPYABLE_WITH_LEAK_DETECTOR (PluginInstallerComponent);
229232

0 commit comments

Comments
 (0)