Revision: 3354
Author: [email protected]
Date: Thu Mar 4 09:30:17 2010
Log: NEW - bug 2722: Unable to open existing project
http://trillian.sqlpower.ca/bugzilla/show_bug.cgi?id=2722
Users will now be prompted when saving a file if the file was loaded with a
different version than the current app version.
This is to prevent users from saving over an older file or newer file
without knowing it and possibly corrupting a file.
http://code.google.com/p/power-architect/source/detail?r=3354
Modified:
/trunk/src/ca/sqlpower/architect/ProjectLoader.java
/trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java
=======================================
--- /trunk/src/ca/sqlpower/architect/ProjectLoader.java Thu Mar 4 08:03:38
2010
+++ /trunk/src/ca/sqlpower/architect/ProjectLoader.java Thu Mar 4 09:30:17
2010
@@ -174,6 +174,15 @@
protected int progress = 0;
protected ArchitectSession session;
+
+ /**
+ * This stores the version of the file that this project loader would
+ * overwrite on save. If the user is overwriting a file that is not
the same
+ * version as the Architect that they are using they should be
prompted.
+ * This will be null if the current project was not loaded or saved
(ie: it
+ * is new).
+ */
+ protected String fileVersion;
public ProjectLoader(ArchitectSession session) {
this.session = session;
@@ -309,13 +318,14 @@
d.addRule("architect-project", new Rule() {
@Override
public void begin(String namespace, String name, Attributes
attributes) throws Exception {
- String appVersion = attributes.getValue("appversion");
+ fileVersion = attributes.getValue("appversion");
String loadingMessage;
try {
- if (appVersion == null) {
+ if (fileVersion == null) {
loadingMessage = "The version of the file cannot
be found.";
+ fileVersion = "0";
} else if (ArchitectVersion.APP_FULL_VERSION.compareTo(
- new ArchitectVersion(appVersion)) < 0) {
+ new ArchitectVersion(fileVersion)) < 0) {
loadingMessage = "This file was last saved with a
newer version.\n" +
"Loading with an older version may cause data
loss.";
} else {
=======================================
--- /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Thu
Mar 4 08:08:10 2010
+++ /trunk/src/ca/sqlpower/architect/swingui/SwingUIProjectLoader.java Thu
Mar 4 09:30:17 2010
@@ -637,6 +637,29 @@
// write problems with architect file will muck up the save
process
throw new
SQLObjectException(Messages.getString("SwingUIProject.errorSavingProject",
file.getAbsolutePath())); //$NON-NLS-1$
}
+
+ if (fileVersion != null
&& !fileVersion.equals(ArchitectVersion.APP_FULL_VERSION.toString())) {
+ String message;
+ try {
+ ArchitectVersion oldFileVersion = new
ArchitectVersion(fileVersion);
+ if
(oldFileVersion.compareTo(ArchitectVersion.APP_FULL_VERSION) < 0) {
+ message = "Overwriting older file. Older versions may
have problems " +
+ "loading the newer file format.";
+ } else {
+ message = "Overwriting newer file. Some data loss from
loading may occur.";
+ }
+ } catch (Exception e) {
+ message = "Overwriting file with an invalid version.";
+ }
+ UserPrompter prompter =
getSession().createUserPrompter(message +
+ "\nDo you wish to continue?", UserPromptType.BOOLEAN,
+ UserPromptOptions.OK_CANCEL, UserPromptResponse.OK,
+ UserPromptResponse.OK, "OK", "Cancel");
+ UserPromptResponse response = prompter.promptUser();
+ if (response.equals(UserPromptResponse.CANCEL)) {
+ return;
+ }
+ }
File backupFile = new File (file.getParent(), file.getName()+"~");
//$NON-NLS-1$
@@ -699,6 +722,7 @@
Messages.getString("SwingUIProject.couldNotRenameTempFile",
tempFile.toString(), file.toString()))); //$NON-NLS-1$
}
logger.debug("rename tempFile to current file: " + fstatus);
//$NON-NLS-1$
+ fileVersion = ArchitectVersion.APP_FULL_VERSION.toString();
}
XMLHelper ioo = new XMLHelper();