From 4266b3a70004378c22a610f7e3cf7c65515dd34f Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Thu, 26 Jan 2017 17:35:10 +0100 Subject: [PATCH] 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. --- .../libraries/LibraryInstaller.java | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java index 4b4fb7f7d..ef1729b6c 100644 --- a/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java +++ b/arduino-core/src/cc/arduino/contributions/libraries/LibraryInstaller.java @@ -87,6 +87,16 @@ public class LibraryInstaller { } public synchronized void install(ContributedLibrary lib, Optional 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 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 {