From 22bd3da2a9813aa2416c630afb46666795e28693 Mon Sep 17 00:00:00 2001 From: Gonk Date: Tue, 10 Sep 2019 21:38:03 +0200 Subject: [PATCH 1/2] development savegames are marked and overwriting regular savegames is not allowed in development mode --- .../rpg/AndorsTrail/AndorsTrailApplication.java | 3 ++- .../AndorsTrail/activity/LoadSaveActivity.java | 16 ++++++++++++++++ .../gpl/rpg/AndorsTrail/savegames/Savegames.java | 2 +- 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java index 26b81a953..f7c168643 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/AndorsTrailApplication.java @@ -28,7 +28,8 @@ public final class AndorsTrailApplication extends Application { public static final boolean DEVELOPMENT_VALIDATEDATA = true; public static final boolean DEVELOPMENT_DEBUGMESSAGES = true; public static final boolean DEVELOPMENT_INCOMPATIBLE_SAVEGAMES = DEVELOPMENT_DEBUGRESOURCES || DEVELOPMENT_DEBUGBUTTONS || DEVELOPMENT_FASTSPEED; - public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? 999 : 47; + public static final int DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION = 999; + public static final int CURRENT_VERSION = DEVELOPMENT_INCOMPATIBLE_SAVEGAMES ? DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION : 47; public static final String CURRENT_VERSION_DISPLAY = "0.7.6dev"; public static final boolean IS_RELEASE_VERSION = !CURRENT_VERSION_DISPLAY.matches(".*[a-d].*"); diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java index 89ef0591a..aefa71f32 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java @@ -160,6 +160,22 @@ public final class LoadSaveActivity extends Activity implements OnClickListener @Override public void onClick(View view) { final int slot = (Integer) view.getTag(); + + if (!isLoading && slot != SLOT_NUMBER_CREATE_NEW_SLOT && AndorsTrailApplication.CURRENT_VERSION == AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) { + final FileHeader header = Savegames.quickload(this, slot); + if (header.fileversion != AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) { + final Dialog d = CustomDialogFactory.createDialog(this, + "Overwriting not allowed", + getResources().getDrawable(android.R.drawable.ic_dialog_alert), + "You are currently using a development version of Andor's trail. Overwriting a regular savegame is not allowed in development mode.", + null, + true); + CustomDialogFactory.addDismissButton(d, android.R.string.ok); + CustomDialogFactory.show(d); + return; + } + } + final String message = getConfirmOverwriteQuestion(slot); if (message != null) { diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java index b4e5e1619..2c9ae0e9b 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/savegames/Savegames.java @@ -186,7 +186,7 @@ public final class Savegames { public boolean skipIcon = false; public String describe() { - return playerName + ", " + displayInfo; + return (fileversion == AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION ? "(D) " : "") + playerName + ", " + displayInfo; } From 5812f49fc3ee70851d376a144dab4ea5651cafec Mon Sep 17 00:00:00 2001 From: Gonk Date: Tue, 10 Sep 2019 22:33:37 +0200 Subject: [PATCH 2/2] added null check --- .../src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java index aefa71f32..81e9fe83c 100644 --- a/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java +++ b/AndorsTrail/src/com/gpl/rpg/AndorsTrail/activity/LoadSaveActivity.java @@ -163,7 +163,7 @@ public final class LoadSaveActivity extends Activity implements OnClickListener if (!isLoading && slot != SLOT_NUMBER_CREATE_NEW_SLOT && AndorsTrailApplication.CURRENT_VERSION == AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) { final FileHeader header = Savegames.quickload(this, slot); - if (header.fileversion != AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) { + if (header != null && header.fileversion != AndorsTrailApplication.DEVELOPMENT_INCOMPATIBLE_SAVEGAME_VERSION) { final Dialog d = CustomDialogFactory.createDialog(this, "Overwriting not allowed", getResources().getDrawable(android.R.drawable.ic_dialog_alert),