From 3d30197a7f37d15da1649a9b40a24774b4aae06d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Wed, 27 Nov 2019 14:43:52 +0100 Subject: better sqlite path on unix --- core/src/ch/asynk/rustanddust/RustAndDust.java | 8 ++++++-- core/src/ch/asynk/rustanddust/util/DB.java | 13 ++++++------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/core/src/ch/asynk/rustanddust/RustAndDust.java b/core/src/ch/asynk/rustanddust/RustAndDust.java index c25862f..af6dcee 100644 --- a/core/src/ch/asynk/rustanddust/RustAndDust.java +++ b/core/src/ch/asynk/rustanddust/RustAndDust.java @@ -65,6 +65,7 @@ public class RustAndDust extends Game public static final String DOM = "RustAndDust"; public static final String DB_FILE = "rustanddust.sqlite"; + public static final String CONFIG_PATH = ".config/rustanddust"; public AssetManager manager; public Factory factory; @@ -122,7 +123,11 @@ public class RustAndDust extends Game { switch (Gdx.app.getType()) { case Desktop: - return String.format("data/%s", DB_FILE); + if (!System.getProperty("os.name").startsWith("Windo")) { + final String dir = String.format("%s/%s", System.getProperty("user.home"), CONFIG_PATH); + new java.io.File(dir).mkdir(); + return String.format("%s/%s", dir, DB_FILE); + } } return DB_FILE; } @@ -135,7 +140,6 @@ public class RustAndDust extends Game debug("create() [" + Gdx.graphics.getWidth() + ";" + Gdx.graphics.getHeight() + "] " + Gdx.graphics.getDensity() + " -> " + hudCorrection); db = new DB(Gdx.files.internal(dbFile()).path(), false); - db.setup(); manager = new AssetManager(); factory = new Factory(this); diff --git a/core/src/ch/asynk/rustanddust/util/DB.java b/core/src/ch/asynk/rustanddust/util/DB.java index 21d87ed..25e3dfb 100644 --- a/core/src/ch/asynk/rustanddust/util/DB.java +++ b/core/src/ch/asynk/rustanddust/util/DB.java @@ -69,17 +69,16 @@ public class DB this.db = DatabaseFactory.getNewDatabase(dbPath, DB_SCHEMA_VERSION, null, null); this.db.setupDatabase(); this.debug = debug; - } - public void setup() - { try { - md = MessageDigest.getInstance(DIGEST); - } catch (java.security.NoSuchAlgorithmException e) { RustAndDust.error("NoSuchAlgorithm"); } + db.openOrCreateDatabase(); + } catch (SQLiteGdxException e) { + RustAndDust.error(String.format("openOrCreateDatabase : %s", dbPath)); + } try { - db.openOrCreateDatabase(); - } catch (SQLiteGdxException e) { RustAndDust.error("openOrCreateDatabase"); } + md = MessageDigest.getInstance(DIGEST); + } catch (java.security.NoSuchAlgorithmException e) { RustAndDust.error("NoSuchAlgorithm"); } Boolean version = checkVersion(); if(version == null) -- cgit v1.1-2-g2b99