mirror of
https://github.com/arduino/Arduino.git
synced 2025-03-14 11:29:26 +01:00
Moved saveFile() from Base to BaseNoGui (work in progress).
This commit is contained in:
parent
4443911746
commit
64c6fe536c
@ -2718,28 +2718,7 @@ public class Base {
|
|||||||
* Spew the contents of a String object out to a file.
|
* Spew the contents of a String object out to a file.
|
||||||
*/
|
*/
|
||||||
static public void saveFile(String str, File file) throws IOException {
|
static public void saveFile(String str, File file) throws IOException {
|
||||||
File temp = File.createTempFile(file.getName(), null, file.getParentFile());
|
BaseNoGui.saveFile(str, file);
|
||||||
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()
|
|
||||||
)
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -3,6 +3,7 @@ package processing.app;
|
|||||||
import static processing.app.I18n._;
|
import static processing.app.I18n._;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -14,6 +15,7 @@ import processing.app.debug.TargetPlatformException;
|
|||||||
import processing.app.helpers.OSUtils;
|
import processing.app.helpers.OSUtils;
|
||||||
import processing.app.helpers.PreferencesMap;
|
import processing.app.helpers.PreferencesMap;
|
||||||
import processing.app.helpers.filefilters.OnlyDirs;
|
import processing.app.helpers.filefilters.OnlyDirs;
|
||||||
|
import processing.app.legacy.PApplet;
|
||||||
|
|
||||||
public class BaseNoGui {
|
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()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -969,7 +969,7 @@ public class Compiler implements MessageConsumer {
|
|||||||
// shtuff so that unicode bunk is properly handled
|
// shtuff so that unicode bunk is properly handled
|
||||||
String filename = sc.getFileName(); //code[i].name + ".java";
|
String filename = sc.getFileName(); //code[i].name + ".java";
|
||||||
try {
|
try {
|
||||||
Base.saveFile(sc.getProgram(), new File(buildPath, filename));
|
BaseNoGui.saveFile(sc.getProgram(), new File(buildPath, filename));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));
|
throw new RunnerException(I18n.format(_("Problem moving {0} to the build folder"), filename));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user