30
30
import java .util .*;
31
31
import java .util .regex .*;
32
32
import javax .swing .*;
33
+ import javax .swing .filechooser .*;
33
34
import javax .swing .event .DocumentEvent ;
34
35
import javax .swing .event .DocumentListener ;
35
36
import org .apache .commons .codec .digest .DigestUtils ;
@@ -121,43 +122,43 @@ public void run() {
121
122
}
122
123
123
124
private String getBuildFolderPath (Sketch s ) {
124
- // first of all try the getBuildPath() function introduced with IDE 1.6.12
125
- // see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03
126
- try {
127
- String buildpath = s .getBuildPath ().getAbsolutePath ();
128
- return buildpath ;
129
- }
130
- catch (IOException er ) {
131
- editor .statusError (er );
132
- }
133
- catch (Exception er ) {
134
- try {
135
- File buildFolder = FileUtils .createTempFolder ("build" , DigestUtils .md5Hex (s .getMainFilePath ()) + ".tmp" );
136
- //DeleteFilesOnShutdown.add(buildFolder);
137
- return buildFolder .getAbsolutePath ();
138
- }
139
- catch (IOException e ) {
140
- editor .statusError (e );
141
- }
142
- catch (Exception e ) {
143
- // Arduino 1.6.5 doesn't have FileUtils.createTempFolder
144
- // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
145
- java .lang .reflect .Method method ;
146
- try {
147
- method = BaseNoGui .class .getMethod ("getBuildFolder" );
148
- File f = (File ) method .invoke (null );
149
- return f .getAbsolutePath ();
150
- } catch (SecurityException ex ) {
151
- editor .statusError (ex );
152
- } catch (IllegalAccessException ex ) {
153
- editor .statusError (ex );
154
- } catch (InvocationTargetException ex ) {
155
- editor .statusError (ex );
156
- } catch (NoSuchMethodException ex ) {
157
- editor .statusError (ex );
158
- }
159
- }
160
- }
125
+ // first of all try the getBuildPath() function introduced with IDE 1.6.12
126
+ // see commit arduino/Arduino#fd1541eb47d589f9b9ea7e558018a8cf49bb6d03
127
+ try {
128
+ String buildpath = s .getBuildPath ().getAbsolutePath ();
129
+ return buildpath ;
130
+ }
131
+ catch (IOException er ) {
132
+ editor .statusError (er );
133
+ }
134
+ catch (Exception er ) {
135
+ try {
136
+ File buildFolder = FileUtils .createTempFolder ("build" , DigestUtils .md5Hex (s .getMainFilePath ()) + ".tmp" );
137
+ //DeleteFilesOnShutdown.add(buildFolder);
138
+ return buildFolder .getAbsolutePath ();
139
+ }
140
+ catch (IOException e ) {
141
+ editor .statusError (e );
142
+ }
143
+ catch (Exception e ) {
144
+ // Arduino 1.6.5 doesn't have FileUtils.createTempFolder
145
+ // String buildPath = BaseNoGui.getBuildFolder().getAbsolutePath();
146
+ java .lang .reflect .Method method ;
147
+ try {
148
+ method = BaseNoGui .class .getMethod ("getBuildFolder" );
149
+ File f = (File ) method .invoke (null );
150
+ return f .getAbsolutePath ();
151
+ } catch (SecurityException ex ) {
152
+ editor .statusError (ex );
153
+ } catch (IllegalAccessException ex ) {
154
+ editor .statusError (ex );
155
+ } catch (InvocationTargetException ex ) {
156
+ editor .statusError (ex );
157
+ } catch (NoSuchMethodException ex ) {
158
+ editor .statusError (ex );
159
+ }
160
+ }
161
+ }
161
162
return "" ;
162
163
}
163
164
@@ -169,14 +170,39 @@ private long getIntPref(String name){
169
170
else return Integer .parseInt (data );
170
171
}
171
172
173
+ class ElfFilter extends FileFilter {
174
+ public String getExtension (File f ) {
175
+ String ext = null ;
176
+ String s = f .getName ();
177
+ int i = s .lastIndexOf ('.' );
178
+ if (i > 0 && i < s .length () - 1 ) {
179
+ ext = s .substring (i +1 ).toLowerCase ();
180
+ }
181
+ return ext ;
182
+ }
183
+ public boolean accept (File f ) {
184
+ if (f .isDirectory ()) {
185
+ return true ;
186
+ }
187
+ String extension = getExtension (f );
188
+ if (extension != null ) {
189
+ return extension .equals ("elf" );
190
+ }
191
+ return false ;
192
+ }
193
+ public String getDescription () {
194
+ return "*.elf files" ;
195
+ }
196
+ }
197
+
172
198
private void createAndUpload (){
173
- if (!PreferencesData .get ("target_platform" ).contentEquals ("esp8266" ) && !PreferencesData .get ("target_platform" ).contentEquals ("esp31b " ) && !PreferencesData .get ("target_platform" ).contentEquals ("ESP31B" )){
199
+ if (!PreferencesData .get ("target_platform" ).contentEquals ("esp8266" ) && !PreferencesData .get ("target_platform" ).contentEquals ("esp32 " ) && !PreferencesData .get ("target_platform" ).contentEquals ("ESP31B" )){
174
200
System .err .println ();
175
201
editor .statusError ("Not Supported on " +PreferencesData .get ("target_platform" ));
176
202
return ;
177
203
}
178
204
179
- String tc = "esp108 " ;
205
+ String tc = "esp32 " ;
180
206
if (PreferencesData .get ("target_platform" ).contentEquals ("esp8266" )){
181
207
tc = "lx106" ;
182
208
}
@@ -205,9 +231,18 @@ private void createAndUpload(){
205
231
if (!elf .exists () || !elf .isFile ()) {
206
232
elf = new File (getBuildFolderPath (editor .getSketch ()), editor .getSketch ().getName () + ".cpp.elf" );
207
233
if (!elf .exists () || !elf .isFile ()){
208
- editor .statusError ("ERROR: neither " +editor .getSketch ().getName () + ".ino.elf or " +editor .getSketch ().getName () + ".cpp.elf were found!" );
209
- System .err .println ("Did you forget to compile the sketch?" );
210
- return ;
234
+ //lets give the user a chance to select the elf
235
+ final JFileChooser fc = new JFileChooser ();
236
+ fc .addChoosableFileFilter (new ElfFilter ());
237
+ fc .setAcceptAllFileFilterUsed (false );
238
+ int returnVal = fc .showDialog (editor , "Select ELF" );
239
+ if (returnVal == JFileChooser .APPROVE_OPTION ) {
240
+ elf = fc .getSelectedFile ();
241
+ } else {
242
+ editor .statusError ("ERROR: elf was not found!" );
243
+ System .err .println ("Open command cancelled by user." );
244
+ return ;
245
+ }
211
246
}
212
247
}
213
248
0 commit comments