JAL-3141 Added warning/confirmation when suffixReverse is changed without changing...
[jalview.git] / src / jalview / io / BackupFiles.java
index e913fbc..695349c 100644 (file)
@@ -93,7 +93,7 @@ public class BackupFiles
   // REVERSE_ORDER
   public BackupFiles(File file)
   {
-    this(file, ".v" + NUM_PLACEHOLDER, false, 4, 3, false);
+    this(file, ".bak" + NUM_PLACEHOLDER, false, 3, 3, false);
   }
 
   public BackupFiles(File file, String defaultSuffix, boolean defaultNoMax,
@@ -208,15 +208,15 @@ public class BackupFiles
   public boolean rollBackupFiles()
   {
 
-    // file doesn't yet exist or backups are not enabled
-    if ((!file.exists()) || (!enabled) || (max < 0))
+    // file doesn't yet exist or backups are not enabled or template is null or
+    // empty
+    if ((!file.exists()) || (!enabled) || max < 0 || suffix == null
+            || suffix.length() == 0)
     {
       // nothing to do
       return true;
     }
 
-    // split filename up to insert suffix template in the right place. template
-    // and backupMax can be set in .jalview_properties
     String dir = "";
     File dirFile;
     try
@@ -280,7 +280,7 @@ public class BackupFiles
         {
           // int n = tempMax - m;
           String backupfilename = dir + File.separatorChar
-                  + BackupFilenameFilter.getBackupFilename(n, basename,
+                  + BackupFilenameParts.getBackupFilename(n, basename,
                           suffix, digits);
           File backupfile_n = new File(backupfilename);
 
@@ -352,7 +352,7 @@ public class BackupFiles
 
     // Let's make the new backup file!! yay, got there at last!
     String latestBackupFilename = dir + File.separatorChar
-            + BackupFilenameFilter.getBackupFilename(nextIndexNum, basename,
+            + BackupFilenameParts.getBackupFilename(nextIndexNum, basename,
                     suffix, digits);
     File latestBackupFile = new File(latestBackupFilename);
     ret = ret && file.renameTo(latestBackupFile);
@@ -370,7 +370,6 @@ public class BackupFiles
       boolean delete = false;
       if (confirmDelete)
       {
-        // Object[] confirmMessageArray = {};
         StringBuilder confirmMessage = new StringBuilder();
         confirmMessage.append(MessageManager
                 .getString("label.backupfiles_confirm_delete_old_files"));
@@ -412,7 +411,8 @@ public class BackupFiles
     }
   }
 
-  private TreeMap sortBackupFilesAsTreeMap(File[] backupFiles,
+  private TreeMap<Integer, File> sortBackupFilesAsTreeMap(
+          File[] backupFiles,
           String basename)
   {
     // sort the backup files (based on integer found in the suffix) using a
@@ -481,12 +481,10 @@ public class BackupFiles
 
     File file = new File(fileName);
 
-    String dir = "";
     File dirFile;
     try
     {
       dirFile = file.getParentFile();
-      dir = dirFile.getCanonicalPath();
     } catch (Exception e)
     {
       System.out.println(