okjack
FongMi 3 years ago
parent ff1cde6125
commit 9f66bda9f7
  1. 4
      app/build.gradle
  2. 20
      app/src/main/java/com/fongmi/android/tv/db/AppDatabase.java

@ -21,12 +21,12 @@ android {
leanback {
dimension "mode"
versionCode 207
versionName "20231104#4"
versionName "20231104#5"
}
mobile {
dimension "mode"
versionCode 207
versionName "20231104#4"
versionName "20231104#5"
}
java {
dimension "api"

@ -51,29 +51,25 @@ public abstract class AppDatabase extends RoomDatabase {
public static void backup(com.fongmi.android.tv.impl.Callback callback) {
App.execute(() -> {
if (get().isOpen()) get().close();
File db = App.get().getDatabasePath(NAME).getAbsoluteFile();
File wal = App.get().getDatabasePath(NAME + "-wal").getAbsoluteFile();
File shm = App.get().getDatabasePath(NAME + "-shm").getAbsoluteFile();
boolean exists = db.exists() && wal.exists() && shm.exists();
if (exists) Path.copy(db, new File(Path.tv(), db.getName()));
if (exists) Path.copy(wal, new File(Path.tv(), wal.getName()));
if (exists) Path.copy(shm, new File(Path.tv(), shm.getName()));
if (exists) App.post(callback::success);
if (db.exists()) Path.copy(db, new File(Path.tv(), db.getName()));
if (wal.exists()) Path.copy(wal, new File(Path.tv(), wal.getName()));
if (shm.exists()) Path.copy(shm, new File(Path.tv(), shm.getName()));
if (db.exists()) App.post(callback::success);
});
}
public static void restore(com.fongmi.android.tv.impl.Callback callback) {
App.execute(() -> {
if (get().isOpen()) get().close();
File db = new File(Path.tv(), NAME);
File wal = new File(Path.tv(), NAME + "-wal");
File shm = new File(Path.tv(), NAME + "-shm");
boolean exists = db.exists() && wal.exists() && shm.exists();
if (exists) Path.copy(db, App.get().getDatabasePath(db.getName()).getAbsoluteFile());
if (exists) Path.copy(wal, App.get().getDatabasePath(wal.getName()).getAbsoluteFile());
if (exists) Path.copy(shm, App.get().getDatabasePath(shm.getName()).getAbsoluteFile());
if (exists) App.post(callback::success);
if (db.exists()) Path.copy(db, App.get().getDatabasePath(db.getName()).getAbsoluteFile());
if (wal.exists()) Path.copy(wal, App.get().getDatabasePath(wal.getName()).getAbsoluteFile());
if (shm.exists()) Path.copy(shm, App.get().getDatabasePath(shm.getName()).getAbsoluteFile());
if (db.exists()) App.post(callback::success);
});
}

Loading…
Cancel
Save