mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
LibraryInstaller now autodetects if a library is being replaced
It's no more required to pass this information from outside, just library that is being installed is now sufficient.
This commit is contained in:
parent
4266b3a700
commit
67e38bc80a
@ -85,7 +85,7 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
||||
if (mayInstalledLibrary.isPresent() && selectedLibrary.isIDEBuiltIn()) {
|
||||
onRemovePressed(mayInstalledLibrary.get());
|
||||
} else {
|
||||
onInstallPressed(selectedLibrary, mayInstalledLibrary);
|
||||
onInstallPressed(selectedLibrary);
|
||||
}
|
||||
}
|
||||
|
||||
@ -213,12 +213,12 @@ public class LibraryManagerUI extends InstallerJDialog<ContributedLibraryRelease
|
||||
installerThread.start();
|
||||
}
|
||||
|
||||
public void onInstallPressed(final ContributedLibrary lib, final Optional<ContributedLibrary> mayReplaced) {
|
||||
public void onInstallPressed(final ContributedLibrary lib) {
|
||||
clearErrorMessage();
|
||||
installerThread = new Thread(() -> {
|
||||
try {
|
||||
setProgressVisible(true, tr("Installing..."));
|
||||
installer.install(lib, mayReplaced, this::setProgress);
|
||||
installer.install(lib, this::setProgress);
|
||||
// TODO: Do a better job in refreshing only the needed element
|
||||
if (contribTable.getCellEditor() != null) {
|
||||
contribTable.getCellEditor().stopCellEditing();
|
||||
|
@ -384,7 +384,7 @@ public class Base {
|
||||
library, mayInstalled.get().getParsedVersion())));
|
||||
libraryInstaller.remove(mayInstalled.get(), progressListener);
|
||||
} else {
|
||||
libraryInstaller.install(selected, mayInstalled, progressListener);
|
||||
libraryInstaller.install(selected, progressListener);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -43,6 +43,8 @@ import processing.app.helpers.FileUtils;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
import static processing.app.I18n.tr;
|
||||
@ -86,22 +88,35 @@ public class LibraryInstaller {
|
||||
rescanLibraryIndex(progress, progressListener);
|
||||
}
|
||||
|
||||
public synchronized void install(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener) throws Exception {
|
||||
public synchronized void install(ContributedLibrary lib, ProgressListener progressListener) throws Exception {
|
||||
final MultiStepProgress progress = new MultiStepProgress(4);
|
||||
|
||||
// Do install library (3 steps)
|
||||
performInstall(lib, mayReplacedLib, progressListener, progress);
|
||||
performInstall(lib, progressListener, progress);
|
||||
|
||||
// Rescan index (1 step)
|
||||
rescanLibraryIndex(progress, progressListener);
|
||||
}
|
||||
|
||||
private void performInstall(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
|
||||
private void performInstall(ContributedLibrary lib, ProgressListener progressListener, MultiStepProgress progress) throws Exception {
|
||||
if (lib.isLibraryInstalled()) {
|
||||
System.out.println(I18n.format(tr("Library is already installed: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
|
||||
return;
|
||||
}
|
||||
|
||||
File libsFolder = BaseNoGui.getSketchbookLibrariesFolder().folder;
|
||||
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
|
||||
|
||||
// Check if we are replacing an already installed lib
|
||||
LibrariesIndex index = BaseNoGui.librariesIndexer.getIndex();
|
||||
Optional<ContributedLibrary> replacedLib = index.find(lib.getName()).stream() //
|
||||
.filter(l -> l.getInstalledLibrary().isPresent()) //
|
||||
.filter(l -> l.getInstalledLibrary().get().getInstalledFolder().equals(destFolder)) //
|
||||
.findAny();
|
||||
if (!replacedLib.isPresent() && destFolder.exists()) {
|
||||
System.out.println(I18n.format(tr("Library {0} is already installed in: {1}"), lib.getName(), destFolder));
|
||||
return;
|
||||
}
|
||||
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
|
||||
|
||||
// Step 1: Download library
|
||||
@ -120,7 +135,6 @@ public class LibraryInstaller {
|
||||
// Step 2: Unpack library on the correct location
|
||||
progress.setStatus(I18n.format(tr("Installing library: {0}:{1}"), lib.getName(), lib.getParsedVersion()));
|
||||
progressListener.onProgress(progress);
|
||||
File libsFolder = BaseNoGui.getSketchbookLibrariesFolder().folder;
|
||||
File tmpFolder = FileUtils.createTempFolder(libsFolder);
|
||||
try {
|
||||
new ArchiveExtractor(platform).extract(lib.getDownloadedFile(), tmpFolder, 1);
|
||||
@ -132,10 +146,9 @@ public class LibraryInstaller {
|
||||
|
||||
// Step 3: Remove replaced library and move installed one to the correct location
|
||||
// TODO: Fix progress bar...
|
||||
if (mayReplacedLib.isPresent()) {
|
||||
remove(mayReplacedLib.get(), progressListener);
|
||||
if (replacedLib.isPresent()) {
|
||||
remove(replacedLib.get(), progressListener);
|
||||
}
|
||||
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
|
||||
tmpFolder.renameTo(destFolder);
|
||||
progress.stepDone();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user