Create a backup of the specified file, but only if backups are enabled, the file exists and the file is not empty. @param outFile The file to be backed up.
(File outFile)
| 128 | * @param outFile The file to be backed up. |
| 129 | */ |
| 130 | public void createBackupForFile(File outFile) |
| 131 | { |
| 132 | // Make a backup of the old file, if it exists and isn't empty |
| 133 | if (PCGenSettings.getCreatePcgBackup() && outFile.exists() && outFile.length() > 0) |
| 134 | { |
| 135 | String file = outFile.getName(); |
| 136 | String backupPcgPath = PCGenSettings.getBackupPcgDir(); |
| 137 | if (backupPcgPath == null || backupPcgPath.isEmpty()) |
| 138 | { |
| 139 | backupPcgPath = outFile.getParent(); |
| 140 | } |
| 141 | final String BAK_PREFIX = ".bak"; //$NON-NLS-1$ |
| 142 | File bakFile = new File(backupPcgPath, file + BAK_PREFIX); |
| 143 | |
| 144 | if (bakFile.exists() && outFile.exists() && outFile.length() > 0) |
| 145 | { |
| 146 | bakFile.delete(); |
| 147 | } |
| 148 | outFile.renameTo(bakFile); |
| 149 | } |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Reads the contents of the given PlayerCharacter from a stream |
no test coverage detected