use of jgnash.engine.DataStoreType in project jgnash by ccavanaugh.
the class BootEngineTask method checkAndBackupOldVersion.
/**
* Check and determine if the file is an old format and backup in necessary.
*
* @param fileName fileName to verify
* @param password assumed password
* @return true if no errors are encountered
*/
private static boolean checkAndBackupOldVersion(final String fileName, final char[] password) {
boolean result = false;
if (Files.exists(Paths.get(fileName))) {
final float version = EngineFactory.getFileVersion(Paths.get(fileName), password);
final DataStoreType type = EngineFactory.getDataStoreByType(fileName);
boolean oldSchema = false;
if (type == DataStoreType.H2_DATABASE || type == DataStoreType.HSQL_DATABASE) {
oldSchema = SqlUtils.useOldPersistenceUnit(fileName, password);
}
if (type == DataStoreType.H2_DATABASE && oldSchema) {
Platform.runLater(() -> StaticUIMethods.displayMessage(ResourceUtils.getString("Message.Info.LongUpgrade")));
final PackDatabaseTask packDatabaseTask = new PackDatabaseTask(fileName, password);
new Thread(packDatabaseTask).start();
Platform.runLater(() -> StaticUIMethods.displayTaskProgress(packDatabaseTask));
try {
// block until complete
packDatabaseTask.get();
} catch (final InterruptedException | ExecutionException e) {
Logger.getLogger(BootEngineTask.class.getName()).log(Level.SEVERE, e.getLocalizedMessage(), e);
}
}
if (type == DataStoreType.HSQL_DATABASE && oldSchema) {
final String errorMessage = ResourceUtils.getString("Message.Error.OldHsqlFile");
Platform.runLater(() -> StaticUIMethods.displayError(errorMessage));
} else if (version <= 0) {
final String errorMessage = ResourceUtils.getString("Message.Error.InvalidUserPass");
Platform.runLater(() -> StaticUIMethods.displayError(errorMessage));
} else {
result = true;
// make a versioned backup first
if (version < Engine.CURRENT_VERSION) {
FileUtils.copyFile(Paths.get(fileName), Paths.get(fileName + "." + version));
Platform.runLater(() -> StaticUIMethods.displayMessage(ResourceUtils.getString("Message.Info.Upgrade", fileName + "." + version)));
}
}
}
return result;
}
use of jgnash.engine.DataStoreType in project jgnash by ccavanaugh.
the class NewFileOne method getSettings.
@Override
public void getSettings(Map<Enum<?>, Object> map) {
DataStoreType type = (DataStoreType) map.get(NewFileDialog.Settings.TYPE);
if (type != null) {
typeCombo.setSelectedItem(type);
}
String fileName = (String) map.get(NewFileDialog.Settings.DATABASE_NAME);
if (FileUtils.fileHasExtension(fileName)) {
dbNameField.setText(fileName);
} else {
dbNameField.setText(fileName + typeCombo.getSelectedDataStoreType().getDataStore().getFileExt());
}
checkForOverwrite();
}
Aggregations