@@ -1215,34 +1215,45 @@ void runRecipe(String recipe) throws RunnerException, PreferencesMapException {
1215
1215
execAsynchronously (cmdArray );
1216
1216
}
1217
1217
1218
- private File mergeSketchWithBootloaderIfAppropriate (String className , PreferencesMap prefs ) throws IOException {
1218
+ private void mergeSketchWithBootloaderIfAppropriate (String className , PreferencesMap prefs ) throws IOException {
1219
1219
if (!prefs .containsKey ("bootloader.noblink" ) && !prefs .containsKey ("bootloader.file" )) {
1220
- return null ;
1220
+ return ;
1221
1221
}
1222
1222
1223
1223
String buildPath = prefs .get ("build.path" );
1224
- File sketch = new File (buildPath , className + ".hex" );
1225
- if (!sketch .exists ()) {
1226
- return null ;
1224
+
1225
+ Path sketch ;
1226
+ Path sketchInSubfolder = Paths .get (buildPath , "sketch" , className + ".hex" );
1227
+ Path sketchInBuildPath = Paths .get (buildPath , className + ".hex" );
1228
+ if (Files .exists (sketchInSubfolder )) {
1229
+ sketch = sketchInSubfolder ;
1230
+ } else if (Files .exists (sketchInBuildPath )) {
1231
+ sketch = sketchInBuildPath ;
1232
+ } else {
1233
+ return ;
1227
1234
}
1228
1235
1229
1236
String bootloaderNoBlink = prefs .get ("bootloader.noblink" );
1230
1237
if (bootloaderNoBlink == null ) {
1231
1238
bootloaderNoBlink = prefs .get ("bootloader.file" );
1232
1239
}
1233
1240
1234
- File bootloader = new File ( new File ( prefs .get ("runtime.platform.path" ), "bootloaders" ) , bootloaderNoBlink );
1235
- if (!bootloader .exists ()) {
1241
+ Path bootloader = Paths . get ( prefs .get ("runtime.platform.path" ), "bootloaders" , bootloaderNoBlink );
1242
+ if (!Files .exists (bootloader )) {
1236
1243
System .err .println (I18n .format (_ ("Bootloader file specified but missing: {0}" ), bootloader ));
1237
- return null ;
1244
+ return ;
1238
1245
}
1239
1246
1240
- File mergedSketch = new File (buildPath , className + ".with_bootloader.hex" );
1241
- FileUtils .copyFile (sketch , mergedSketch );
1247
+ Path mergedSketch ;
1248
+ if ("sketch" .equals (sketch .getParent ().getFileName ().toString ())) {
1249
+ mergedSketch = Paths .get (buildPath , "sketch" , className + ".with_bootloader.hex" );
1250
+ } else {
1251
+ mergedSketch = Paths .get (buildPath , className + ".with_bootloader.hex" );
1252
+ }
1242
1253
1243
- new MergeSketchWithBooloader (). merge ( mergedSketch , bootloader );
1254
+ Files . copy ( sketch , mergedSketch , StandardCopyOption . REPLACE_EXISTING );
1244
1255
1245
- return mergedSketch ;
1256
+ new MergeSketchWithBooloader (). merge ( mergedSketch . toFile (), bootloader . toFile ()) ;
1246
1257
}
1247
1258
1248
1259
//7. Save the .hex file
@@ -1280,11 +1291,19 @@ private void saveHex(String compiledSketch, String copyOfCompiledSketch, Prefere
1280
1291
compiledSketch = StringReplacer .replaceFromMapping (compiledSketch , dict );
1281
1292
copyOfCompiledSketch = StringReplacer .replaceFromMapping (copyOfCompiledSketch , dict );
1282
1293
1283
- File compiledSketchFile = new File (prefs .get ("build.path" ), compiledSketch );
1284
- File copyOfCompiledSketchFile = new File (sketch .getFolder (), copyOfCompiledSketch );
1294
+ Path compiledSketchPath ;
1295
+ Path compiledSketchPathInSubfolder = Paths .get (prefs .get ("build.path" ), "sketch" , compiledSketch );
1296
+ Path compiledSketchPathInBuildPath = Paths .get (prefs .get ("build.path" ), compiledSketch );
1297
+ if (Files .exists (compiledSketchPathInSubfolder )) {
1298
+ compiledSketchPath = compiledSketchPathInSubfolder ;
1299
+ } else {
1300
+ compiledSketchPath = compiledSketchPathInBuildPath ;
1301
+ }
1302
+
1303
+ Path copyOfCompiledSketchFilePath = Paths .get (this .sketch .getFolder ().getAbsolutePath (), copyOfCompiledSketch );
1285
1304
1286
- FileUtils . copyFile ( compiledSketchFile , copyOfCompiledSketchFile );
1287
- } catch (Exception e ) {
1305
+ Files . copy ( compiledSketchPath , copyOfCompiledSketchFilePath , StandardCopyOption . REPLACE_EXISTING );
1306
+ } catch (IOException e ) {
1288
1307
throw new RunnerException (e );
1289
1308
}
1290
1309
}
0 commit comments