mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Removing previously installed platform on upgrade
This commit is contained in:
parent
b1e0249a4f
commit
fe6718ce4f
@ -98,7 +98,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
installButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onInstall(editorValue.getSelected());
|
||||
onInstall(editorValue.getSelected(), editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
|
||||
@ -129,7 +129,7 @@ public class ContributedPlatformTableCell extends InstallerTableCell {
|
||||
// Empty
|
||||
}
|
||||
|
||||
protected void onInstall(ContributedPlatform contributedPlatform) {
|
||||
protected void onInstall(ContributedPlatform contributedPlatform, ContributedPlatform installed) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,17 @@
|
||||
*/
|
||||
package cc.arduino.packages.contributions.ui;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import cc.arduino.packages.contributions.ContributedPackage;
|
||||
import cc.arduino.packages.contributions.ContributedPlatform;
|
||||
import cc.arduino.packages.contributions.ContributionsIndex;
|
||||
import cc.arduino.ui.FilteredAbstractTableModel;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static processing.app.I18n._;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public class ContributionIndexTableModel extends FilteredAbstractTableModel {
|
||||
|
||||
@ -69,9 +72,21 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
|
||||
}
|
||||
|
||||
public ContributedPlatform getInstalled() {
|
||||
for (ContributedPlatform plat : releases)
|
||||
if (plat.isInstalled())
|
||||
return plat;
|
||||
List<ContributedPlatform> installedPlatforms = new LinkedList<ContributedPlatform>();
|
||||
for (ContributedPlatform platform : releases) {
|
||||
if (platform.isInstalled()) {
|
||||
installedPlatforms.add(platform);
|
||||
}
|
||||
}
|
||||
|
||||
if (installedPlatforms.size() > 1) {
|
||||
throw new IllegalStateException(_("More than one platform is currently installed! Only one can be installed at any given time"));
|
||||
}
|
||||
|
||||
if (!installedPlatforms.isEmpty()) {
|
||||
return installedPlatforms.get(0);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@ -112,9 +127,9 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
|
||||
|
||||
private List<ContributedPlatformReleases> contributions = new ArrayList<ContributedPlatformReleases>();
|
||||
|
||||
private String[] columnNames = { "Description" };
|
||||
private String[] columnNames = {"Description"};
|
||||
|
||||
private Class<?>[] columnTypes = { ContributedPlatform.class };
|
||||
private Class<?>[] columnTypes = {ContributedPlatform.class};
|
||||
|
||||
private ContributionsIndex index;
|
||||
|
||||
@ -141,11 +156,11 @@ public class ContributionIndexTableModel extends FilteredAbstractTableModel {
|
||||
/**
|
||||
* Check if <b>string</b> contains all the substrings in <b>set</b>. The
|
||||
* compare is case insensitive.
|
||||
*
|
||||
*
|
||||
* @param string
|
||||
* @param set
|
||||
* @return <b>true<b> if all the strings in <b>set</b> are contained in
|
||||
* <b>string</b>.
|
||||
* <b>string</b>.
|
||||
*/
|
||||
private boolean stringContainsAll(String string, String set[]) {
|
||||
if (set == null)
|
||||
|
@ -63,8 +63,8 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
protected InstallerTableCell createCellEditor() {
|
||||
return new ContributedPlatformTableCell() {
|
||||
@Override
|
||||
protected void onInstall(ContributedPlatform selectedPlatform) {
|
||||
onInstallPressed(selectedPlatform);
|
||||
protected void onInstall(ContributedPlatform selectedPlatform, ContributedPlatform installed) {
|
||||
onInstallPressed(selectedPlatform, installed);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -146,13 +146,16 @@ public class ContributionManagerUI extends InstallerJDialog {
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onInstallPressed(final ContributedPlatform platform) {
|
||||
public void onInstallPressed(final ContributedPlatform platformToInstall, final ContributedPlatform platformToRemove) {
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true);
|
||||
installer.install(platform);
|
||||
installer.install(platformToInstall);
|
||||
if (platformToRemove != null) {
|
||||
installer.remove(platformToRemove);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// TODO Show ERROR
|
||||
e.printStackTrace();
|
||||
|
@ -1123,7 +1123,7 @@ public class Base {
|
||||
rebuildExamplesMenu(Editor.examplesMenu);
|
||||
}
|
||||
|
||||
private void openInstallBoardDialog() {
|
||||
private void openInstallBoardDialog() throws Exception {
|
||||
// Create dialog for contribution manager
|
||||
@SuppressWarnings("serial")
|
||||
ContributionManagerUI managerUI = new ContributionManagerUI(activeEditor) {
|
||||
@ -1139,14 +1139,9 @@ public class Base {
|
||||
// Installer dialog is modal, waits here until closed
|
||||
|
||||
// Reload all boards (that may have been installed/updated/removed)
|
||||
try {
|
||||
BaseNoGui.initPackages();
|
||||
rebuildBoardsMenu();
|
||||
onBoardOrPortChange();
|
||||
} catch (Exception e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
BaseNoGui.initPackages();
|
||||
rebuildBoardsMenu();
|
||||
onBoardOrPortChange();
|
||||
}
|
||||
|
||||
public void rebuildBoardsMenu() throws Exception {
|
||||
@ -1158,7 +1153,12 @@ public class Base {
|
||||
@SuppressWarnings("serial")
|
||||
Action runInstaller = new AbstractAction("Install boards...") {
|
||||
public void actionPerformed(ActionEvent actionevent) {
|
||||
openInstallBoardDialog();
|
||||
try {
|
||||
openInstallBoardDialog();
|
||||
} catch (Exception e) {
|
||||
//TODO show error
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
};
|
||||
boardMenu.add(new JMenuItem(runInstaller));
|
||||
|
@ -66,7 +66,6 @@ public class LibrariesIndexer {
|
||||
|
||||
public void parseIndex() throws JsonParseException, IOException {
|
||||
parseIndex(indexFile);
|
||||
System.out.println(index);
|
||||
|
||||
index.fillCategories();
|
||||
// TODO: resolve libraries inner references
|
||||
|
@ -60,8 +60,9 @@ public class ContributionInstaller {
|
||||
}
|
||||
|
||||
public void install(ContributedPlatform platform) throws Exception {
|
||||
if (platform.isInstalled())
|
||||
if (platform.isInstalled()) {
|
||||
throw new Exception("Platform is already installed!");
|
||||
}
|
||||
|
||||
// Do not download already installed tools
|
||||
List<ContributedTool> tools = new LinkedList<ContributedTool>(platform.getResolvedTools());
|
||||
@ -111,13 +112,11 @@ public class ContributionInstaller {
|
||||
File toolsFolder = new File(packageFolder, "tools");
|
||||
int i = 1;
|
||||
for (ContributedTool tool : platform.getResolvedTools()) {
|
||||
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i,
|
||||
tools.size()));
|
||||
progress.setStatus(format(_("Installing tools ({0}/{1})..."), i, tools.size()));
|
||||
onProgress(progress);
|
||||
i++;
|
||||
DownloadableContribution toolContrib = tool.getDownloadableContribution();
|
||||
File destFolder = new File(toolsFolder, tool.getName() + File.separator +
|
||||
tool.getVersion());
|
||||
File destFolder = new File(toolsFolder, tool.getName() + File.separator + tool.getVersion());
|
||||
|
||||
destFolder.mkdirs();
|
||||
ArchiveExtractor.extract(toolContrib.getDownloadedFile(), destFolder, 1);
|
||||
@ -129,8 +128,7 @@ public class ContributionInstaller {
|
||||
// Unpack platform on the correct location
|
||||
progress.setStatus(_("Installing boards..."));
|
||||
onProgress(progress);
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator +
|
||||
platform.getArchitecture());
|
||||
File platformFolder = new File(packageFolder, "hardware" + File.separator + platform.getArchitecture());
|
||||
File destFolder = new File(platformFolder, platform.getVersion());
|
||||
destFolder.mkdirs();
|
||||
ArchiveExtractor.extract(platform.getDownloadedFile(), destFolder, 1);
|
||||
|
@ -612,7 +612,6 @@ public class BaseNoGui {
|
||||
}
|
||||
indexer.parseIndex();
|
||||
indexer.syncWithFilesystem();
|
||||
System.out.println(indexer);
|
||||
|
||||
packages = new HashMap<String, TargetPackage>();
|
||||
loadHardware(getHardwareFolder());
|
||||
|
Loading…
x
Reference in New Issue
Block a user