39
39
import org .apache .commons .compress .utils .IOUtils ;
40
40
import processing .app .BaseNoGui ;
41
41
import processing .app .I18n ;
42
- import processing .app .helpers .FileUtils ;
43
42
import processing .app .helpers .filefilters .OnlyDirs ;
44
43
import processing .app .packages .LegacyUserLibrary ;
45
44
import processing .app .packages .LibraryList ;
46
45
import processing .app .packages .UserLibrary ;
46
+ import processing .app .packages .UserLibraryFolder ;
47
+ import processing .app .packages .UserLibraryFolder .Location ;
47
48
48
49
import java .io .File ;
49
50
import java .io .FileInputStream ;
@@ -59,10 +60,9 @@ public class LibrariesIndexer {
59
60
60
61
private LibrariesIndex index ;
61
62
private final LibraryList installedLibraries = new LibraryList ();
62
- private List <File > librariesFolders ;
63
+ private List <UserLibraryFolder > librariesFolders ;
63
64
private final File indexFile ;
64
65
private final File stagingFolder ;
65
- private File sketchbookLibrariesFolder ;
66
66
67
67
private final List <String > badLibNotified = new ArrayList <>();
68
68
@@ -104,12 +104,12 @@ private void parseIndex(File file) throws IOException {
104
104
}
105
105
}
106
106
107
- public void setLibrariesFolders (List <File > _librariesFolders ) {
108
- librariesFolders = _librariesFolders ;
107
+ public void setLibrariesFolders (List <UserLibraryFolder > folders ) {
108
+ librariesFolders = folders ;
109
109
rescanLibraries ();
110
110
}
111
111
112
- public List <File > getLibrariesFolders () {
112
+ public List <UserLibraryFolder > getLibrariesFolders () {
113
113
return librariesFolders ;
114
114
}
115
115
@@ -126,8 +126,8 @@ public void rescanLibraries() {
126
126
}
127
127
128
128
// Rescan libraries
129
- for (File folder : librariesFolders ) {
130
- scanInstalledLibraries (folder , folder . equals ( sketchbookLibrariesFolder ) );
129
+ for (UserLibraryFolder folderDesc : librariesFolders ) {
130
+ scanInstalledLibraries (folderDesc );
131
131
}
132
132
133
133
installedLibraries .stream ().filter (new TypePredicate ("Contributed" )).filter (new LibraryInstalledInsideCore ()).forEach (userLibrary -> {
@@ -136,46 +136,47 @@ public void rescanLibraries() {
136
136
});
137
137
}
138
138
139
- private void scanInstalledLibraries (File folder , boolean isSketchbook ) {
140
- File list [] = folder .listFiles (OnlyDirs .ONLY_DIRS );
139
+ private void scanInstalledLibraries (UserLibraryFolder folderDesc ) {
140
+ File list [] = folderDesc . folder .listFiles (OnlyDirs .ONLY_DIRS );
141
141
// if a bad folder or something like that, this might come back null
142
142
if (list == null )
143
143
return ;
144
144
145
145
for (File subfolder : list ) {
146
- if (!BaseNoGui .isSanitaryName (subfolder .getName ())) {
146
+ String subfolderName = subfolder .getName ();
147
+ if (!BaseNoGui .isSanitaryName (subfolderName )) {
147
148
148
149
// Detect whether the current folder name has already had a notification.
149
- if (!badLibNotified .contains (subfolder . getName () )) {
150
+ if (!badLibNotified .contains (subfolderName )) {
150
151
151
- badLibNotified .add (subfolder . getName () );
152
+ badLibNotified .add (subfolderName );
152
153
153
154
String mess = I18n .format (tr ("The library \" {0}\" cannot be used.\n "
154
155
+ "Library names must contain only basic letters and numbers.\n "
155
156
+ "(ASCII only and no spaces, and it cannot start with a number)" ),
156
- subfolder . getName () );
157
+ subfolderName );
157
158
BaseNoGui .showMessage (tr ("Ignoring bad library name" ), mess );
158
159
}
159
160
continue ;
160
161
}
161
162
162
163
try {
163
- scanLibrary (subfolder , isSketchbook );
164
+ scanLibrary (new UserLibraryFolder ( subfolder , folderDesc . location ) );
164
165
} catch (IOException e ) {
165
166
System .out .println (I18n .format (tr ("Invalid library found in {0}: {1}" ), subfolder , e .getMessage ()));
166
167
}
167
168
}
168
169
}
169
170
170
- private void scanLibrary (File folder , boolean isSketchbook ) throws IOException {
171
- boolean readOnly = ! FileUtils . isSubDirectory ( sketchbookLibrariesFolder , folder );
171
+ private void scanLibrary (UserLibraryFolder folderDesc ) throws IOException {
172
+ boolean readOnly = ( folderDesc . location == Location . SKETCHBOOK );
172
173
173
174
// A library is considered "legacy" if it doesn't contains
174
175
// a file called "library.properties"
175
- File check = new File (folder , "library.properties" );
176
+ File check = new File (folderDesc . folder , "library.properties" );
176
177
if (!check .exists () || !check .isFile ()) {
177
178
// Create a legacy library and exit
178
- LegacyUserLibrary lib = LegacyUserLibrary .create (folder );
179
+ LegacyUserLibrary lib = LegacyUserLibrary .create (folderDesc );
179
180
String [] headers = BaseNoGui .headerListFromIncludePath (lib .getSrcFolder ());
180
181
if (headers .length == 0 ) {
181
182
throw new IOException (lib .getSrcFolder ().getAbsolutePath ());
@@ -185,7 +186,7 @@ private void scanLibrary(File folder, boolean isSketchbook) throws IOException {
185
186
}
186
187
187
188
// Create a regular library
188
- UserLibrary lib = UserLibrary .create (folder );
189
+ UserLibrary lib = UserLibrary .create (folderDesc );
189
190
String [] headers = BaseNoGui .headerListFromIncludePath (lib .getSrcFolder ());
190
191
if (headers .length == 0 ) {
191
192
throw new IOException (lib .getSrcFolder ().getAbsolutePath ());
@@ -221,19 +222,6 @@ public File getStagingFolder() {
221
222
return stagingFolder ;
222
223
}
223
224
224
- /**
225
- * Set the sketchbook library folder. <br />
226
- * New libraries will be installed here. <br />
227
- * Libraries not found on this folder will be marked as read-only.
228
- */
229
- public void setSketchbookLibrariesFolder (File folder ) {
230
- this .sketchbookLibrariesFolder = folder ;
231
- }
232
-
233
- public File getSketchbookLibrariesFolder () {
234
- return sketchbookLibrariesFolder ;
235
- }
236
-
237
225
public File getIndexFile () {
238
226
return indexFile ;
239
227
}
0 commit comments