From 64c6fe536cacdf7a0ac8cba40f39d33a64ff8fc3 Mon Sep 17 00:00:00 2001 From: Claudio Indellicati Date: Thu, 21 Aug 2014 13:43:10 +0200 Subject: [PATCH] Moved saveFile() from Base to BaseNoGui (work in progress). --- app/src/processing/app/Base.java | 23 +------------------ app/src/processing/app/BaseNoGui.java | 26 ++++++++++++++++++++++ app/src/processing/app/debug/Compiler.java | 2 +- 3 files changed, 28 insertions(+), 23 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 7ac04de10..b1ead8892 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -2718,28 +2718,7 @@ public class Base { * Spew the contents of a String object out to a file. */ static public void saveFile(String str, File file) throws IOException { - File temp = File.createTempFile(file.getName(), null, file.getParentFile()); - PApplet.saveStrings(temp, new String[] { str }); - if (file.exists()) { - boolean result = file.delete(); - if (!result) { - throw new IOException( - I18n.format( - _("Could not remove old version of {0}"), - file.getAbsolutePath() - ) - ); - } - } - boolean result = temp.renameTo(file); - if (!result) { - throw new IOException( - I18n.format( - _("Could not replace {0}"), - file.getAbsolutePath() - ) - ); - } + BaseNoGui.saveFile(str, file); } diff --git a/app/src/processing/app/BaseNoGui.java b/app/src/processing/app/BaseNoGui.java index 7d6891928..fbf091fad 100644 --- a/app/src/processing/app/BaseNoGui.java +++ b/app/src/processing/app/BaseNoGui.java @@ -3,6 +3,7 @@ package processing.app; import static processing.app.I18n._; import java.io.File; +import java.io.IOException; import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -14,6 +15,7 @@ import processing.app.debug.TargetPlatformException; import processing.app.helpers.OSUtils; import processing.app.helpers.PreferencesMap; import processing.app.helpers.filefilters.OnlyDirs; +import processing.app.legacy.PApplet; public class BaseNoGui { @@ -211,4 +213,28 @@ public class BaseNoGui { } } + /** + * Spew the contents of a String object out to a file. + */ + static public void saveFile(String str, File file) throws IOException { + File temp = File.createTempFile(file.getName(), null, file.getParentFile()); + PApplet.saveStrings(temp, new String[] { str }); + if (file.exists()) { + boolean result = file.delete(); + if (!result) { + throw new IOException( + I18n.format( + _("Could not remove old version of {0}"), + file.getAbsolutePath())); + } + } + boolean result = temp.renameTo(file); + if (!result) { + throw new IOException( + I18n.format( + _("Could not replace {0}"), + file.getAbsolutePath())); + } + } + } diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index 258a37750..5daa88837 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -969,7 +969,7 @@ public class Compiler implements MessageConsumer { // shtuff so that unicode bunk is properly handled String filename = sc.getFileName(); //code[i].name + ".java"; try { - Base.saveFile(sc.getProgram(), new File(buildPath, filename)); + BaseNoGui.saveFile(sc.getProgram(), new File(buildPath, filename)); } catch (IOException e) { e.printStackTrace(); throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));