mirror of
https://github.com/bancika/diy-layout-creator
synced 2026-11-11 01:32:08 +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>
|
||||
<changeType>IMPROVEMENT</changeType>
|
||||
<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>
|
||||
<changeType>BUG_FIX</changeType>
|
||||
<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)
|
||||
throws IOException {
|
||||
if (!isBackup) {
|
||||
LOG.info(String.format("saveProjectToFile(%s)", fileName));
|
||||
LOG.info(String.format("serializeProjectToFile(%s)", fileName));
|
||||
}
|
||||
FileOutputStream fos;
|
||||
fos = new FileOutputStream(fileName);
|
||||
FileOutputStream fos;
|
||||
// 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.write("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n");
|
||||
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) {
|
||||
this.currentFileName = fileName;
|
||||
this.modified = false;
|
||||
|
||||
Reference in New Issue
Block a user