mirror of https://github.com/noisymime/Arduino.git
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() {
|
installButton.addActionListener(new ActionListener() {
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
onInstall(editorValue.getSelected());
|
onInstall(editorValue.getSelected(), editorValue.getInstalled());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
int width = installButton.getPreferredSize().width;
|
int width = installButton.getPreferredSize().width;
|
||||||
|
@ -135,7 +135,7 @@ public class ContributedLibraryTableCell extends InstallerTableCell {
|
||||||
public void actionPerformed(ActionEvent e) {
|
public void actionPerformed(ActionEvent e) {
|
||||||
ContributedLibrary selected;
|
ContributedLibrary selected;
|
||||||
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
|
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));
|
panel.add(Box.createVerticalStrut(10));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onRemove(ContributedLibrary contributedPlatform) {
|
protected void onRemove(ContributedLibrary selectedLib) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onInstall(ContributedLibrary contributedPlatform) {
|
protected void onInstall(ContributedLibrary selectedLib, ContributedLibrary installedLib) {
|
||||||
// Empty
|
// Empty
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,7 +88,7 @@ public class LibraryInstaller {
|
||||||
rescanLibraryIndex(progress);
|
rescanLibraryIndex(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void install(ContributedLibrary lib) throws Exception {
|
public void install(ContributedLibrary lib, ContributedLibrary replacedLib) throws Exception {
|
||||||
if (lib.isInstalled())
|
if (lib.isInstalled())
|
||||||
throw new Exception(_("Library is already installed!"));
|
throw new Exception(_("Library is already installed!"));
|
||||||
|
|
||||||
|
@ -109,12 +109,26 @@ public class LibraryInstaller {
|
||||||
// Step 2: Unpack library on the correct location
|
// Step 2: Unpack library on the correct location
|
||||||
progress.setStatus(_("Installing library..."));
|
progress.setStatus(_("Installing library..."));
|
||||||
onProgress(progress);
|
onProgress(progress);
|
||||||
File destFolder = new File(indexer.getSketchbookLibrariesFolder(), lib.getName());
|
File libsFolder = indexer.getSketchbookLibrariesFolder();
|
||||||
destFolder.mkdirs();
|
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
|
||||||
ArchiveExtractor.extract(lib.getDownloadedFile(), destFolder, 1);
|
try {
|
||||||
|
ArchiveExtractor.extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||||
|
} catch (Exception e) {
|
||||||
|
if (tmpFolder.exists())
|
||||||
|
FileUtils.recursiveDelete(tmpFolder);
|
||||||
|
}
|
||||||
progress.stepDone();
|
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);
|
rescanLibraryIndex(progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -62,8 +62,8 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||||
protected InstallerTableCell createCellEditor() {
|
protected InstallerTableCell createCellEditor() {
|
||||||
return new ContributedLibraryTableCell() {
|
return new ContributedLibraryTableCell() {
|
||||||
@Override
|
@Override
|
||||||
protected void onInstall(ContributedLibrary selectedPlatform) {
|
protected void onInstall(ContributedLibrary selectedLibrary, ContributedLibrary installedLibrary) {
|
||||||
onInstallPressed(selectedPlatform);
|
onInstallPressed(selectedLibrary, installedLibrary);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,13 +148,13 @@ public class LibraryManagerUI extends InstallerJDialog {
|
||||||
installerThread.start();
|
installerThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onInstallPressed(final ContributedLibrary lib) {
|
public void onInstallPressed(final ContributedLibrary lib, final ContributedLibrary replaced) {
|
||||||
installerThread = new Thread(new Runnable() {
|
installerThread = new Thread(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
try {
|
try {
|
||||||
setProgressVisible(true, _("Installing..."));
|
setProgressVisible(true, _("Installing..."));
|
||||||
installer.install(lib);
|
installer.install(lib, replaced);
|
||||||
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
|
||||||
//getContribModel().updateLibrary(lib);
|
//getContribModel().updateLibrary(lib);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
|
Loading…
Reference in New Issue