Skip to content

Commit 64c6fe5

Browse files
bitroncmaglie
authored andcommitted
Moved saveFile() from Base to BaseNoGui (work in progress).
1 parent 4443911 commit 64c6fe5

File tree

3 files changed

+28
-23
lines changed

3 files changed

+28
-23
lines changed

app/src/processing/app/Base.java

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2718,28 +2718,7 @@ static public String loadFile(File file) throws IOException {
27182718
* Spew the contents of a String object out to a file.
27192719
*/
27202720
static public void saveFile(String str, File file) throws IOException {
2721-
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
2722-
PApplet.saveStrings(temp, new String[] { str });
2723-
if (file.exists()) {
2724-
boolean result = file.delete();
2725-
if (!result) {
2726-
throw new IOException(
2727-
I18n.format(
2728-
_("Could not remove old version of {0}"),
2729-
file.getAbsolutePath()
2730-
)
2731-
);
2732-
}
2733-
}
2734-
boolean result = temp.renameTo(file);
2735-
if (!result) {
2736-
throw new IOException(
2737-
I18n.format(
2738-
_("Could not replace {0}"),
2739-
file.getAbsolutePath()
2740-
)
2741-
);
2742-
}
2721+
BaseNoGui.saveFile(str, file);
27432722
}
27442723

27452724

app/src/processing/app/BaseNoGui.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import static processing.app.I18n._;
44

55
import java.io.File;
6+
import java.io.IOException;
67
import java.util.Arrays;
78
import java.util.HashMap;
89
import java.util.Map;
@@ -14,6 +15,7 @@
1415
import processing.app.helpers.OSUtils;
1516
import processing.app.helpers.PreferencesMap;
1617
import processing.app.helpers.filefilters.OnlyDirs;
18+
import processing.app.legacy.PApplet;
1719

1820
public class BaseNoGui {
1921

@@ -211,4 +213,28 @@ static protected void loadHardware(File folder) {
211213
}
212214
}
213215

216+
/**
217+
* Spew the contents of a String object out to a file.
218+
*/
219+
static public void saveFile(String str, File file) throws IOException {
220+
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
221+
PApplet.saveStrings(temp, new String[] { str });
222+
if (file.exists()) {
223+
boolean result = file.delete();
224+
if (!result) {
225+
throw new IOException(
226+
I18n.format(
227+
_("Could not remove old version of {0}"),
228+
file.getAbsolutePath()));
229+
}
230+
}
231+
boolean result = temp.renameTo(file);
232+
if (!result) {
233+
throw new IOException(
234+
I18n.format(
235+
_("Could not replace {0}"),
236+
file.getAbsolutePath()));
237+
}
238+
}
239+
214240
}

app/src/processing/app/debug/Compiler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,7 @@ public void preprocess(String buildPath, PdePreprocessor preprocessor) throws Ru
969969
// shtuff so that unicode bunk is properly handled
970970
String filename = sc.getFileName(); //code[i].name + ".java";
971971
try {
972-
Base.saveFile(sc.getProgram(), new File(buildPath, filename));
972+
BaseNoGui.saveFile(sc.getProgram(), new File(buildPath, filename));
973973
} catch (IOException e) {
974974
e.printStackTrace();
975975
throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));

0 commit comments

Comments
 (0)