mirror of
https://github.com/arduino/Arduino.git
synced 2025-02-18 12:54:25 +01:00
Library Installer: Allows libraries to be updated
This commit is contained in:
parent
2c234a09f1
commit
6f5f9bedb4
@ -110,7 +110,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
installButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
onInstall(editorValue.getSelected());
|
||||
onInstall(editorValue.getSelected(), editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
int width = installButton.getPreferredSize().width;
|
||||
@ -135,7 +135,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
ContributedLibrary selected;
|
||||
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
||||
onInstall(selected);//, editorValue.getInstalled());
|
||||
onInstall(selected, editorValue.getInstalled());
|
||||
}
|
||||
});
|
||||
|
||||
@ -199,11 +199,11 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||
panel.add(Box.createVerticalStrut(10));
|
||||
}
|
||||
|
||||
protected void onRemove(ContributedLibrary contributedPlatform) {
|
||||
protected void onRemove(ContributedLibrary selectedLib) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
protected void onInstall(ContributedLibrary contributedPlatform) {
|
||||
protected void onInstall(ContributedLibrary selectedLib, ContributedLibrary installedLib) {
|
||||
// Empty
|
||||
}
|
||||
|
||||
|
@ -88,7 +88,7 @@ public class LibraryInstaller {
|
||||
rescanLibraryIndex(progress);
|
||||
}
|
||||
|
||||
public void install(ContributedLibrary lib) throws Exception {
|
||||
public void install(ContributedLibrary lib, ContributedLibrary replacedLib) throws Exception {
|
||||
if (lib.isInstalled())
|
||||
throw new Exception(_("Library is already installed!"));
|
||||
|
||||
@ -109,12 +109,26 @@ public class LibraryInstaller {
|
||||
// Step 2: Unpack library on the correct location
|
||||
progress.setStatus(_("Installing library..."));
|
||||
onProgress(progress);
|
||||
File destFolder = new File(indexer.getSketchbookLibrariesFolder(), lib.getName());
|
||||
destFolder.mkdirs();
|
||||
ArchiveExtractor.extract(lib.getDownloadedFile(), destFolder, 1);
|
||||
File libsFolder = indexer.getSketchbookLibrariesFolder();
|
||||
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
|
||||
try {
|
||||
ArchiveExtractor.extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
} catch (Exception e) {
|
||||
if (tmpFolder.exists())
|
||||
FileUtils.recursiveDelete(tmpFolder);
|
||||
}
|
||||
progress.stepDone();
|
||||
|
||||
// Step 3: Rescan index
|
||||
// Step 3: Remove replaced library and move installed one to the correct location
|
||||
// TODO: Fix progress bar...
|
||||
if (replacedLib != null) {
|
||||
remove(replacedLib);
|
||||
}
|
||||
File destFolder = new File(libsFolder, lib.getName());
|
||||
tmpFolder.renameTo(destFolder);
|
||||
progress.stepDone();
|
||||
|
||||
// Step 4: Rescan index
|
||||
rescanLibraryIndex(progress);
|
||||
}
|
||||
|
||||
|
@ -62,8 +62,8 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
protected InstallerTableCell createCellEditor() {
|
||||
return new ContributedLibraryTableCell() {
|
||||
@Override
|
||||
protected void onInstall(ContributedLibrary selectedPlatform) {
|
||||
onInstallPressed(selectedPlatform);
|
||||
protected void onInstall(ContributedLibrary selectedLibrary, ContributedLibrary installedLibrary) {
|
||||
onInstallPressed(selectedLibrary, installedLibrary);
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -148,13 +148,13 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onInstallPressed(final ContributedLibrary lib) {
|
||||
public void onInstallPressed(final ContributedLibrary lib, final ContributedLibrary replaced) {
|
||||
installerThread = new Thread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
setProgressVisible(true, _("Installing..."));
|
||||
installer.install(lib);
|
||||
installer.install(lib, replaced);
|
||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||
//getContribModel().updateLibrary(lib);
|
||||
} catch (Exception e) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user