Skip to content

Commit 6f5f9be

Browse files
cmaglieFederico Fissore
authored and
Federico Fissore
committed
Library Installer: Allows libraries to be updated
1 parent 2c234a0 commit 6f5f9be

File tree

3 files changed

+27
-13
lines changed

3 files changed

+27
-13
lines changed

app/src/cc/arduino/libraries/contributions/ui/ContributedLibraryTableCell.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void hyperlinkUpdate(HyperlinkEvent e) {
110110
installButton.addActionListener(new ActionListener() {
111111
@Override
112112
public void actionPerformed(ActionEvent e) {
113-
onInstall(editorValue.getSelected());
113+
onInstall(editorValue.getSelected(), editorValue.getInstalled());
114114
}
115115
});
116116
int width = installButton.getPreferredSize().width;
@@ -135,7 +135,7 @@ public void actionPerformed(ActionEvent e) {
135135
public void actionPerformed(ActionEvent e) {
136136
ContributedLibrary selected;
137137
selected = (ContributedLibrary) downgradeChooser.getSelectedItem();
138-
onInstall(selected);//, editorValue.getInstalled());
138+
onInstall(selected, editorValue.getInstalled());
139139
}
140140
});
141141

@@ -199,11 +199,11 @@ public void itemStateChanged(ItemEvent e) {
199199
panel.add(Box.createVerticalStrut(10));
200200
}
201201

202-
protected void onRemove(ContributedLibrary contributedPlatform) {
202+
protected void onRemove(ContributedLibrary selectedLib) {
203203
// Empty
204204
}
205205

206-
protected void onInstall(ContributedLibrary contributedPlatform) {
206+
protected void onInstall(ContributedLibrary selectedLib, ContributedLibrary installedLib) {
207207
// Empty
208208
}
209209

app/src/cc/arduino/libraries/contributions/ui/LibraryInstaller.java

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void updateIndex() throws Exception {
8888
rescanLibraryIndex(progress);
8989
}
9090

91-
public void install(ContributedLibrary lib) throws Exception {
91+
public void install(ContributedLibrary lib, ContributedLibrary replacedLib) throws Exception {
9292
if (lib.isInstalled())
9393
throw new Exception(_("Library is already installed!"));
9494

@@ -109,12 +109,26 @@ public void install(ContributedLibrary lib) throws Exception {
109109
// Step 2: Unpack library on the correct location
110110
progress.setStatus(_("Installing library..."));
111111
onProgress(progress);
112-
File destFolder = new File(indexer.getSketchbookLibrariesFolder(), lib.getName());
113-
destFolder.mkdirs();
114-
ArchiveExtractor.extract(lib.getDownloadedFile(), destFolder, 1);
112+
File libsFolder = indexer.getSketchbookLibrariesFolder();
113+
File tmpFolder = FileUtils.createTempFolderIn(libsFolder);
114+
try {
115+
ArchiveExtractor.extract(lib.getDownloadedFile(), tmpFolder, 1);
116+
} catch (Exception e) {
117+
if (tmpFolder.exists())
118+
FileUtils.recursiveDelete(tmpFolder);
119+
}
115120
progress.stepDone();
116121

117-
// Step 3: Rescan index
122+
// Step 3: Remove replaced library and move installed one to the correct location
123+
// TODO: Fix progress bar...
124+
if (replacedLib != null) {
125+
remove(replacedLib);
126+
}
127+
File destFolder = new File(libsFolder, lib.getName());
128+
tmpFolder.renameTo(destFolder);
129+
progress.stepDone();
130+
131+
// Step 4: Rescan index
118132
rescanLibraryIndex(progress);
119133
}
120134

app/src/cc/arduino/libraries/contributions/ui/LibraryManagerUI.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,8 @@ protected InstallerTableCell createCellRenderer() {
6262
protected InstallerTableCell createCellEditor() {
6363
return new ContributedLibraryTableCell() {
6464
@Override
65-
protected void onInstall(ContributedLibrary selectedPlatform) {
66-
onInstallPressed(selectedPlatform);
65+
protected void onInstall(ContributedLibrary selectedLibrary, ContributedLibrary installedLibrary) {
66+
onInstallPressed(selectedLibrary, installedLibrary);
6767
}
6868

6969
@Override
@@ -148,13 +148,13 @@ public void run() {
148148
installerThread.start();
149149
}
150150

151-
public void onInstallPressed(final ContributedLibrary lib) {
151+
public void onInstallPressed(final ContributedLibrary lib, final ContributedLibrary replaced) {
152152
installerThread = new Thread(new Runnable() {
153153
@Override
154154
public void run() {
155155
try {
156156
setProgressVisible(true, _("Installing..."));
157-
installer.install(lib);
157+
installer.install(lib, replaced);
158158
onIndexesUpdated(); // TODO: Do a better job in refreshing only the needed element
159159
//getContribModel().updateLibrary(lib);
160160
} catch (Exception e) {

0 commit comments

Comments
 (0)