Class CampaignSaveBackup

java.lang.Object
mekhq.campaign.io.CampaignSaveBackup

public final class CampaignSaveBackup extends Object
Copies a campaign save before it is upgraded, so the player can return to it if the upgrade goes wrong.

The copy sits next to the save and keeps its extension, so it still appears in the list of campaigns to load. Its name records the version it came from, for example Kestrel's Lancers (backup from 0.50.11).cpnx.gz. An existing file is never overwritten; a number is added instead.

Since:
0.51.01
  • Method Details

    • backupFileFor

      public static File backupFileFor(File save, megamek.Version fromVersion) throws IOException
      Picks a free file name for a backup of a save.
      Parameters:
      save - the save to back up
      fromVersion - the version the save was made in
      Returns:
      a file next to the save that does not exist yet
      Throws:
      IOException - if no free name could be found
    • createBackup

      public static File createBackup(File save, megamek.Version fromVersion) throws IOException
      Copies a save to a new backup file next to it.
      Parameters:
      save - the save to back up
      fromVersion - the version the save was made in
      Returns:
      the backup file
      Throws:
      IOException - if the save can't be read or the copy can't be written