diff --git a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java index b84629376..9e6fe1950 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java +++ b/app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java @@ -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 } diff --git a/app/src/cc/arduino/libraries/contributions/ui/LibraryInstaller.java b/app/src/cc/arduino/libraries/contributions/ui/LibraryInstaller.java index a1e54e8ee..2f83b24d0 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/LibraryInstaller.java +++ b/app/src/cc/arduino/libraries/contributions/ui/LibraryInstaller.java @@ -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); } diff --git a/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java b/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java index b9ef14094..2a5c88789 100644 --- a/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java +++ b/app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java @@ -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) {