Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow override of default backup filename #237

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 22 additions & 15 deletions src/org/openlcb/cdi/swing/CdiPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -448,23 +448,30 @@ public void runBackup() {
}
}

private String generateFileName() {
String fileName = rep.getRemoteNodeAsString();
if (!nodeName.isEmpty()) {
fileName += "-"+nodeName;
}
if (rep.getCdiRep() != null && rep.getCdiRep().getIdentification() != null) {
// info not present if configuration hasn't been read yet
fileName += "-"+rep.getCdiRep().getIdentification().getSoftwareVersion();
}
fileName += "-"+java.time.LocalDate.now();
fileName += "-"+java.time.LocalTime.now().format( // use default time zone
java.time.format.DateTimeFormatter.ofPattern("HH-mm-ss")
);
// Class that generates the filename for a Backup operation.
public static class FileNameGenerator {
public String generateFileName(ConfigRepresentation rep, String nodeName) {
String fileName = rep.getRemoteNodeAsString();
if (!nodeName.isEmpty()) {
fileName += "-"+nodeName;
}
if (rep.getCdiRep() != null && rep.getCdiRep().getIdentification() != null) {
// info not present if configuration hasn't been read yet
fileName += "-"+rep.getCdiRep().getIdentification().getSoftwareVersion();
}
fileName += "-"+java.time.LocalDate.now();
fileName += "-"+java.time.LocalTime.now().format( // use default time zone
java.time.format.DateTimeFormatter.ofPattern("HH-mm-ss")
);

fileName = fileName.replace(" ", "_"); // don't use spaces in file names!
fileName = fileName.replace(" ", "_"); // don't use spaces in file names!

return "config." + fileName + ".txt";
return "config." + fileName + ".txt";
}
}
public static FileNameGenerator fileNameGenerator = new FileNameGenerator(); // this can be replaced to change the generated file name pattern
private String generateFileName() {
return fileNameGenerator.generateFileName(rep, nodeName);
}


Expand Down
Loading