1
0
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:
Federico Fissore 2015-02-23 12:47:48 +01:00
parent b1e0249a4f
commit fe6718ce4f
7 changed files with 49 additions and 35 deletions

View File

@ -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
}

View File

@ -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;
}

View File

@ -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();

View File

@ -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();
}
}
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) {
try {
openInstallBoardDialog();
} catch (Exception e) {
//TODO show error
e.printStackTrace();
}
}
};
boardMenu.add(new JMenuItem(runInstaller));

View File

@ -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

View File

@ -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);

View File

@ -612,7 +612,6 @@ public class BaseNoGui {
}
indexer.parseIndex();
indexer.syncWithFilesystem();
System.out.println(indexer);
packages = new HashMap<String, TargetPackage>();
loadHardware(getHardwareFolder());