mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-10 17:22:09 +10:00
Make file writes more resilient to crashes to avoid loss of data
This commit is contained in:
@@ -3133,7 +3133,11 @@
|
|||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>IMPROVEMENT</changeType>
|
<changeType>IMPROVEMENT</changeType>
|
||||||
<description>Improved Dutch translation</description>
|
<description>Improved Dutch translation</description>
|
||||||
</org.diylc.appframework.update.Change>
|
</org.diylc.appframework.update.Change>
|
||||||
|
<org.diylc.appframework.update.Change>
|
||||||
|
<changeType>IMPROVEMENT</changeType>
|
||||||
|
<description>Make file writes more resilient to crashes to avoid loss of data</description>
|
||||||
|
</org.diylc.appframework.update.Change>
|
||||||
<org.diylc.appframework.update.Change>
|
<org.diylc.appframework.update.Change>
|
||||||
<changeType>BUG_FIX</changeType>
|
<changeType>BUG_FIX</changeType>
|
||||||
<description>"Outline Mode" produces rendering issues when "Cache Boost" feature is enabled</description>
|
<description>"Outline Mode" produces rendering issues when "Cache Boost" feature is enabled</description>
|
||||||
|
|||||||
@@ -148,14 +148,19 @@ public class ProjectFileManager {
|
|||||||
public synchronized void serializeProjectToFile(Project project, String fileName, boolean isBackup)
|
public synchronized void serializeProjectToFile(Project project, String fileName, boolean isBackup)
|
||||||
throws IOException {
|
throws IOException {
|
||||||
if (!isBackup) {
|
if (!isBackup) {
|
||||||
LOG.info(String.format("saveProjectToFile(%s)", fileName));
|
LOG.info(String.format("serializeProjectToFile(%s)", fileName));
|
||||||
}
|
}
|
||||||
FileOutputStream fos;
|
FileOutputStream fos;
|
||||||
fos = new FileOutputStream(fileName);
|
// write to a temp file to avoid loss of data in case of crash
|
||||||
|
String tempName = fileName + ".temp";
|
||||||
|
fos = new FileOutputStream(tempName);
|
||||||
Writer writer = new OutputStreamWriter(fos, "UTF-8");
|
Writer writer = new OutputStreamWriter(fos, "UTF-8");
|
||||||
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
||||||
xStream.toXML(project, writer);
|
xStream.toXML(project, writer);
|
||||||
fos.close();
|
fos.close();
|
||||||
|
// switch the files at the end
|
||||||
|
new File(fileName).delete();
|
||||||
|
new File(tempName).renameTo(new File(fileName));
|
||||||
if (!isBackup) {
|
if (!isBackup) {
|
||||||
this.currentFileName = fileName;
|
this.currentFileName = fileName;
|
||||||
this.modified = false;
|
this.modified = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user