private static void getStorage() { if (filestats != null) return; File file = new File(Simple.getFilesDir(), "filestats.act.json"); if (!file.exists()) file = new File(Simple.getFilesDir(), "filestats.bak.json"); try { if (!file.exists()) { filestats = new JSONObject(); } else { String json = Simple.getFileContent(file); filestats = (json != null) ? new JSONObject(json) : new JSONObject(); } } catch (Exception ex) { OopsService.log(LOGTAG, ex); } }
private static void putStorage() { if (filestats == null) return; File tmp = new File(Simple.getFilesDir(), "filestats.tmp.json"); File bak = new File(Simple.getFilesDir(), "filestats.bak.json"); File act = new File(Simple.getFilesDir(), "filestats.act.json"); try { if (Simple.putFileContent(tmp, Json.defuck(Json.toPretty(filestats)))) { boolean ok = true; if (bak.exists()) ok = bak.delete(); if (act.exists()) ok &= act.renameTo(bak); if (tmp.exists()) ok &= tmp.renameTo(act); Log.d(LOGTAG, "putStorage: ok=" + ok); } } catch (Exception ex) { OopsService.log(LOGTAG, ex); } }