mirror of
https://github.com/arduino/Arduino.git
synced 2024-12-01 12:24:14 +01:00
Lib installer: factored out method to perform lib installation
The new method will be used in next commits to handle installations of multiple libraries. This commit fix also minor bug in progress bar.
This commit is contained in:
parent
d6f561bd53
commit
4266b3a700
@ -87,6 +87,16 @@ public class LibraryInstaller {
|
||||
}
|
||||
|
||||
public synchronized void install(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, ProgressListener progressListener) throws Exception {
|
||||
final MultiStepProgress progress = new MultiStepProgress(4);
|
||||
|
||||
// Do install library (3 steps)
|
||||
performInstall(lib, mayReplacedLib, progressListener, progress);
|
||||
|
||||
// Rescan index (1 step)
|
||||
rescanLibraryIndex(progress, progressListener);
|
||||
}
|
||||
|
||||
private void performInstall(ContributedLibrary lib, Optional<ContributedLibrary> mayReplacedLib, 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;
|
||||
@ -94,8 +104,6 @@ public class LibraryInstaller {
|
||||
|
||||
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader(BaseNoGui.librariesIndexer.getStagingFolder());
|
||||
|
||||
final MultiStepProgress progress = new MultiStepProgress(3);
|
||||
|
||||
// Step 1: Download library
|
||||
try {
|
||||
downloader.download(lib, progress, I18n.format(tr("Downloading library: {0}"), lib.getName()), progressListener);
|
||||
@ -103,6 +111,7 @@ public class LibraryInstaller {
|
||||
// Download interrupted... just exit
|
||||
return;
|
||||
}
|
||||
progress.stepDone();
|
||||
|
||||
// TODO: Extract to temporary folders and move to the final destination only
|
||||
// once everything is successfully unpacked. If the operation fails remove
|
||||
@ -129,9 +138,6 @@ public class LibraryInstaller {
|
||||
File destFolder = new File(libsFolder, lib.getName().replaceAll(" ", "_"));
|
||||
tmpFolder.renameTo(destFolder);
|
||||
progress.stepDone();
|
||||
|
||||
// Step 4: Rescan index
|
||||
rescanLibraryIndex(progress, progressListener);
|
||||
}
|
||||
|
||||
public synchronized void remove(ContributedLibrary lib, ProgressListener progressListener) throws IOException {
|
||||
|
Loading…
Reference in New Issue
Block a user