@@ -82,22 +82,35 @@ public synchronized void updateIndex(ProgressListener progressListener) throws E
82
82
rescanLibraryIndex (progress , progressListener );
83
83
}
84
84
85
- public synchronized void install (ContributedLibrary lib , ContributedLibrary replacedLib , ProgressListener progressListener ) throws Exception {
85
+ public synchronized void install (ContributedLibrary lib , ProgressListener progressListener ) throws Exception {
86
86
final MultiStepProgress progress = new MultiStepProgress (4 );
87
87
88
88
// Do install library (3 steps)
89
- performInstall (lib , replacedLib , progressListener , progress );
89
+ performInstall (lib , progressListener , progress );
90
90
91
91
// Rescan index (1 step)
92
92
rescanLibraryIndex (progress , progressListener );
93
93
}
94
94
95
- private void performInstall (ContributedLibrary lib , ContributedLibrary replacedLib , ProgressListener progressListener , MultiStepProgress progress ) throws Exception {
95
+ private void performInstall (ContributedLibrary lib , ProgressListener progressListener , MultiStepProgress progress ) throws Exception {
96
96
if (lib .isInstalled ()) {
97
97
System .out .println (I18n .format (tr ("Library is already installed: {0} version {1}" ), lib .getName (), lib .getParsedVersion ()));
98
98
return ;
99
99
}
100
100
101
+ File libsFolder = BaseNoGui .librariesIndexer .getSketchbookLibrariesFolder ();
102
+ File destFolder = new File (libsFolder , lib .getName ().replaceAll (" " , "_" ));
103
+
104
+ // Check if we are replacing an already installed lib
105
+ ContributedLibrary replacedLib = null ;
106
+ LibrariesIndex index = BaseNoGui .librariesIndexer .getIndex ();
107
+ for (ContributedLibrary l : index .find (lib .getName ())) {
108
+ if (l .isInstalled () && l .getInstalledFolder ().equals (destFolder )) {
109
+ replacedLib = l ;
110
+ break ;
111
+ }
112
+ }
113
+
101
114
DownloadableContributionsDownloader downloader = new DownloadableContributionsDownloader (BaseNoGui .librariesIndexer .getStagingFolder ());
102
115
103
116
// Step 1: Download library
@@ -116,7 +129,6 @@ private void performInstall(ContributedLibrary lib, ContributedLibrary replacedL
116
129
// Step 2: Unpack library on the correct location
117
130
progress .setStatus (I18n .format (tr ("Installing library: {0}" ), lib .getName ()));
118
131
progressListener .onProgress (progress );
119
- File libsFolder = BaseNoGui .librariesIndexer .getSketchbookLibrariesFolder ();
120
132
File tmpFolder = FileUtils .createTempFolder (libsFolder );
121
133
try {
122
134
new ArchiveExtractor (platform ).extract (lib .getDownloadedFile (), tmpFolder , 1 );
@@ -129,7 +141,6 @@ private void performInstall(ContributedLibrary lib, ContributedLibrary replacedL
129
141
// Step 3: Remove replaced library and move installed one to the correct location
130
142
// TODO: Fix progress bar...
131
143
remove (replacedLib , progressListener );
132
- File destFolder = new File (libsFolder , lib .getName ().replaceAll (" " , "_" ));
133
144
tmpFolder .renameTo (destFolder );
134
145
progress .stepDone ();
135
146
}
0 commit comments