28
28
import java .util .*;
29
29
30
30
import javax .swing .*;
31
- import javax .swing .filechooser .FileNameExtensionFilter ;
32
31
33
32
import processing .app .debug .Compiler ;
34
33
import processing .app .debug .Target ;
35
34
import processing .app .helpers .FileUtils ;
36
35
import processing .app .helpers .filefilters .OnlyDirs ;
36
+ import processing .app .javax .swing .filechooser .FileNameExtensionFilter ;
37
37
import processing .app .tools .ZipDeflater ;
38
38
import processing .core .*;
39
39
import static processing .app .I18n ._ ;
@@ -120,7 +120,7 @@ static public void main(String args[]) {
120
120
File versionFile = getContentFile ("lib/version.txt" );
121
121
if (versionFile .exists ()) {
122
122
String version = PApplet .loadStrings (versionFile )[0 ];
123
- if (!version .equals (VERSION_NAME )) {
123
+ if (!version .equals (VERSION_NAME ) && ! version . equals ( "${version}" ) ) {
124
124
VERSION_NAME = version ;
125
125
RELEASE = true ;
126
126
}
@@ -129,6 +129,10 @@ static public void main(String args[]) {
129
129
e .printStackTrace ();
130
130
}
131
131
132
+ // help 3rd party installers find the correct hardware path
133
+ Preferences .set ("last.ide." + VERSION_NAME + ".hardwarepath" , getHardwarePath ());
134
+ Preferences .set ("last.ide." + VERSION_NAME + ".daterun" , "" + (new Date ()).getTime () / 1000 );
135
+
132
136
// if (System.getProperty("mrj.version") != null) {
133
137
// //String jv = System.getProperty("java.version");
134
138
// String ov = System.getProperty("os.version");
@@ -1207,62 +1211,51 @@ public void actionPerformed(ActionEvent event) {
1207
1211
boolean ifound = false ;
1208
1212
1209
1213
for (String potentialName : list ) {
1210
- File subfolder = new File (folder , potentialName );
1211
- // File libraryFolder = new File(subfolder, "library");
1212
- // File libraryJar = new File(libraryFolder, potentialName + ".jar");
1213
- // // If a .jar file of the same prefix as the folder exists
1214
- // // inside the 'library' subfolder of the sketch
1215
- // if (libraryJar.exists()) {
1216
- String sanityCheck = Sketch .sanitizeName (potentialName );
1217
- if (!sanityCheck .equals (potentialName )) {
1218
- String mess = I18n .format (
1219
- _ ("The library \" {0}\" cannot be used.\n " +
1220
- "Library names must contain only basic letters and numbers.\n " +
1221
- "(ASCII only and no spaces, and it cannot start with a number)" ),
1222
- potentialName
1223
- );
1224
- Base .showMessage (_ ("Ignoring bad library name" ), mess );
1225
- continue ;
1226
- }
1214
+ File libFolder = new File (folder , potentialName );
1215
+ String sanityCheck = Sketch .sanitizeName (potentialName );
1216
+ if (!sanityCheck .equals (potentialName )) {
1217
+ String mess = I18n .format (_ ("The library \" {0}\" cannot be used.\n "
1218
+ + "Library names must contain only basic letters and numbers.\n "
1219
+ + "(ASCII only and no spaces, and it cannot start with a number)" ),
1220
+ potentialName );
1221
+ Base .showMessage (_ ("Ignoring bad library name" ), mess );
1222
+ continue ;
1223
+ }
1227
1224
1228
- String libraryName = potentialName ;
1229
- // // get the path for all .jar files in this code folder
1230
- // String libraryClassPath =
1231
- // Compiler.contentsToClassPath(libraryFolder);
1232
- // // grab all jars and classes from this folder,
1233
- // // and append them to the library classpath
1234
- // librariesClassPath +=
1235
- // File.pathSeparatorChar + libraryClassPath;
1236
- // // need to associate each import with a library folder
1237
- // String packages[] =
1238
- // Compiler.packageListFromClassPath(libraryClassPath);
1239
- libraries .add (subfolder );
1225
+ String libraryName = potentialName ;
1226
+ libraries .add (libFolder );
1227
+ String libFolderPath = libFolder .getAbsolutePath ();
1240
1228
try {
1241
- String packages [] =
1242
- Compiler .headerListFromIncludePath (subfolder .getAbsolutePath ());
1243
- for (String pkg : packages ) {
1244
- importToLibraryTable .put (pkg , subfolder );
1229
+ String headers [] = Compiler .headerListFromIncludePath (libFolderPath );
1230
+ for (String header : headers ) {
1231
+ // Extract file name (without extension ".h")
1232
+ String name = header .substring (0 , header .length () - 2 );
1233
+
1234
+ // If the header name equals to the current library folder use it
1235
+ if (libFolderPath .endsWith (name )) {
1236
+ importToLibraryTable .put (header , libFolder );
1237
+ continue ;
1238
+ }
1239
+
1240
+ // If a library was already found with this header, keep it if
1241
+ // the library's directory name matches the header name.
1242
+ File old = importToLibraryTable .get (header );
1243
+ if (old != null ) {
1244
+ if (old .getPath ().endsWith (name ))
1245
+ continue ;
1246
+ }
1247
+ importToLibraryTable .put (header , libFolder );
1245
1248
}
1246
1249
} catch (IOException e ) {
1247
- showWarning (_ ("Error" ), I18n .format ("Unable to list header files in {0}" , subfolder ), e );
1250
+ showWarning (_ ("Error" ), I18n .format (
1251
+ "Unable to list header files in {0}" , libFolder ), e );
1248
1252
}
1249
1253
1250
- JMenuItem item = new JMenuItem (libraryName );
1251
- item .addActionListener (listener );
1252
- item .setActionCommand (subfolder .getAbsolutePath ());
1253
- menu .add (item );
1254
- ifound = true ;
1255
-
1256
- // XXX: DAM: should recurse here so that library folders can be nested
1257
- // } else { // not a library, but is still a folder, so recurse
1258
- // JMenu submenu = new JMenu(libraryName);
1259
- // // needs to be separate var, otherwise would set ifound to false
1260
- // boolean found = addLibraries(submenu, subfolder);
1261
- // if (found) {
1262
- // menu.add(submenu);
1263
- // ifound = true;
1264
- // }
1265
- // }
1254
+ JMenuItem item = new JMenuItem (libraryName );
1255
+ item .addActionListener (listener );
1256
+ item .setActionCommand (libFolderPath );
1257
+ menu .add (item );
1258
+ ifound = true ;
1266
1259
}
1267
1260
return ifound ;
1268
1261
}
0 commit comments