Improve backup file date format

This commit is contained in:
Bane Stojkovic
2023-03-28 16:54:00 +02:00
parent e0d2964e12
commit 57a7932675
5 changed files with 15 additions and 12 deletions
Binary file not shown.
@@ -4326,6 +4326,14 @@
<changeType>NEW_FEATURE</changeType>
<description>Configurable max switch combination count for circuit analysis (using org.diylc.maxSwitchCombinations argument)</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>Added resilience to the code that saves the configuration file to avoid it getting corrupted</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>IMPROVEMENT</changeType>
<description>When backing up the configuration file, append the current timestamp at the end instead of a '~'</description>
</org.diylc.appframework.update.Change>
<org.diylc.appframework.update.Change>
<changeType>BUG_FIX</changeType>
<description>General application slowness when Inductor component is added to the drawing</description>
Binary file not shown.
Binary file not shown.
@@ -23,11 +23,10 @@ import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Date;
import java.util.EnumSet;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
@@ -129,15 +128,11 @@ public class AutoSavePlugin implements IPlugIn {
name = name.substring(0, name.length() - 4);
// append date and time
Date date = new Date();
DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
file = new File(AUTO_SAVE_PATH + File.separator + name + "." + dateFormat.format(date) + ".diy");
// make sure that it doesn't already exist
int i = 2;
while (file.exists()) {
file = new File(AUTO_SAVE_PATH + File.separator + name + "." + dateFormat.format(date) + "-" + i + ".diy");
i++;
}
String timestamp = LocalDateTime.now()
.format(DateTimeFormatter.ISO_LOCAL_DATE_TIME)
.substring(0, 19)
.replace(':', '-');
file = new File(AUTO_SAVE_PATH + File.separator + name + "." + timestamp + ".diy");
return file.getAbsolutePath();
}