From 8e00662cb7d9eccaaccd3e6f8a48cc5be06350a4 Mon Sep 17 00:00:00 2001 From: Federico Fissore Date: Mon, 17 Dec 2012 11:25:45 +0100 Subject: [PATCH] introducing template sketch with empty setup and loop functions. see #1138 --- app/src/processing/app/Base.java | 5 ++- app/src/processing/app/helpers/FileUtils.java | 40 ++++++++++--------- build/build.xml | 3 ++ build/shared/TemplateSketch.ino | 9 +++++ 4 files changed, 38 insertions(+), 19 deletions(-) create mode 100644 build/shared/TemplateSketch.ino diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index afa62e18b..ac3616346 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -652,7 +652,10 @@ public class Base { // Make an empty pde file File newbieFile = new File(newbieDir, newbieName + ".ino"); - new FileOutputStream(newbieFile); // create the file + if (!newbieFile.createNewFile()) { + throw new IOException(); + } + FileUtils.copyFile(new File(System.getProperty("user.dir"), "TemplateSketch.ino"), newbieFile); return newbieFile.getAbsolutePath(); } diff --git a/app/src/processing/app/helpers/FileUtils.java b/app/src/processing/app/helpers/FileUtils.java index fb80d2e4f..fc12616b0 100644 --- a/app/src/processing/app/helpers/FileUtils.java +++ b/app/src/processing/app/helpers/FileUtils.java @@ -35,6 +35,27 @@ public class FileUtils { return false; } + public static void copyFile(File source, File dest) throws IOException { + FileInputStream fis = null; + FileOutputStream fos = null; + try { + fis = new FileInputStream(source); + fos = new FileOutputStream(dest); + byte[] buf = new byte[4096]; + int readBytes = -1; + while ((readBytes = fis.read(buf, 0, buf.length)) != -1) { + fos.write(buf, 0, readBytes); + } + } finally { + if (fis != null) { + fis.close(); + } + if (fos != null) { + fos.close(); + } + } + } + public static void copy(File sourceFolder, File destFolder) throws IOException { for (File file : sourceFolder.listFiles()) { File destFile = new File(destFolder, file.getName()); @@ -44,24 +65,7 @@ public class FileUtils { } copy(file, destFile); } else { - FileInputStream fis = null; - FileOutputStream fos = null; - try { - fis = new FileInputStream(file); - fos = new FileOutputStream(destFile); - byte[] buf = new byte[4096]; - int readBytes = -1; - while ((readBytes = fis.read(buf, 0, buf.length)) != -1) { - fos.write(buf, 0, readBytes); - } - } finally { - if (fis != null) { - fis.close(); - } - if (fos != null) { - fos.close(); - } - } + copyFile(file, destFile); } } } diff --git a/build/build.xml b/build/build.xml index dfff2e7ef..8ac613b3e 100644 --- a/build/build.xml +++ b/build/build.xml @@ -97,6 +97,9 @@ + + + diff --git a/build/shared/TemplateSketch.ino b/build/shared/TemplateSketch.ino new file mode 100644 index 000000000..c9c84ceca --- /dev/null +++ b/build/shared/TemplateSketch.ino @@ -0,0 +1,9 @@ +void setup() { + // put your setup code here, to run once: + +} + +void loop() { + // put your main code here, to run repeatedly: + +}