pull/171/head
FongMi 2 years ago
parent 04a353919a
commit cbf3669c18
  1. 4
      app/build.gradle
  2. 6
      app/src/main/java/com/fongmi/android/tv/db/AppDatabase.java
  3. 2
      app/src/mobile/java/com/fongmi/android/tv/ui/activity/MainActivity.java
  4. 7
      catvod/src/main/java/com/github/catvod/utils/Path.java

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

@ -50,6 +50,10 @@ public abstract class AppDatabase extends RoomDatabase {
return file.exists() ? Util.format(new SimpleDateFormat("yyyyMMdd", Locale.getDefault()), file.lastModified()) : "";
}
public static File getBackupKey() {
return new File(Path.tv(), "." + Util.getDeviceId());
}
public static void backup(com.fongmi.android.tv.impl.Callback callback) {
App.execute(() -> {
File db = App.get().getDatabasePath(NAME).getAbsoluteFile();
@ -59,6 +63,7 @@ public abstract class AppDatabase extends RoomDatabase {
if (wal.exists()) Path.copy(wal, new File(Path.tv(), wal.getName()));
if (shm.exists()) Path.copy(shm, new File(Path.tv(), shm.getName()));
Prefers.backup(new File(Path.tv(), NAME + "-pref"));
Path.newFile(getBackupKey());
App.post(callback::success);
});
}
@ -74,6 +79,7 @@ public abstract class AppDatabase extends RoomDatabase {
if (shm.exists()) Path.move(shm, App.get().getDatabasePath(shm.getName()).getAbsoluteFile());
if (pref.exists()) Prefers.restore(pref);
App.post(callback::success);
Path.clear(getBackupKey());
});
}

@ -112,7 +112,7 @@ public class MainActivity extends BaseActivity implements NavigationBarView.OnIt
@Override
public void error(String msg) {
if (TextUtils.isEmpty(msg) && AppDatabase.getDate().length() > 0) onRestore();
if (TextUtils.isEmpty(msg) && AppDatabase.getBackupKey().exists()) onRestore();
else RefreshEvent.empty();
RefreshEvent.config();
Notify.show(msg);

@ -201,6 +201,13 @@ public class Path {
}
}
public static void newFile(File file) {
try {
file.createNewFile();
} catch (Exception ignored) {
}
}
public static List<File> list(File dir) {
File[] files = dir.listFiles();
return files == null ? Collections.emptyList() : Arrays.asList(files);

Loading…
Cancel
Save