From 8cf7d3505ec951bf41c4340a0ca5fc29c5daa69f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 14 Mar 2016 15:55:44 +0100 Subject: DB: deleteGame(GameRecord) -> deleteGame(int) --- core/src/ch/asynk/rustanddust/menu/PlayMenu.java | 2 +- core/src/ch/asynk/rustanddust/util/DB.java | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java index 2c9caa4..f1dbe47 100644 --- a/core/src/ch/asynk/rustanddust/menu/PlayMenu.java +++ b/core/src/ch/asynk/rustanddust/menu/PlayMenu.java @@ -49,7 +49,7 @@ public class PlayMenu extends Patch implements MenuCtrl.Panel public MenuCtrl.MenuType postAnswer(boolean ok) { if (ok) { - game.db.deleteGame(GameRecord.remove(getList().getIdx())); + game.db.deleteGame(GameRecord.remove(getList().getIdx()).id); getList().unselect(); showBtns(false); if (GameRecord.list.size() <= 0) diff --git a/core/src/ch/asynk/rustanddust/util/DB.java b/core/src/ch/asynk/rustanddust/util/DB.java index 44cb79c..3b769a2 100644 --- a/core/src/ch/asynk/rustanddust/util/DB.java +++ b/core/src/ch/asynk/rustanddust/util/DB.java @@ -300,24 +300,25 @@ public class DB cursor.next(); r = from(cursor); if (!r.hash.equals(getDigest(r.payload))) { - // TODO recover from that big shit RustAndDust.error(String.format("corrupted game %d", game)); r = null; } } } catch (SQLiteGdxException e) { RustAndDust.error("loadGame"); } + if (r == null) + deleteGame(game); return r; } private static final String DELETE_GAME = "delete from games where _id=%d;"; private static final String DELETE_TURNS = "delete from turns where game=%d;"; - public boolean deleteGame(GameRecord game) + public boolean deleteGame(int game) { RustAndDust.debug("deleteGame"); try { - exec(String.format(DELETE_TURNS, game.id)); - exec(String.format(DELETE_GAME, game.id)); + exec(String.format(DELETE_TURNS, game)); + exec(String.format(DELETE_GAME, game)); } catch (SQLiteGdxException e) { RustAndDust.error("deleteGame"); return false; -- cgit v1.1-2-g2b99