mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Ripped out function to make Backup and restore operations easier :)
This commit is contained in:
parent
1b129920f3
commit
3f5ff71163
1 changed files with 53 additions and 50 deletions
|
@ -88,14 +88,7 @@ object BackupUtils {
|
||||||
@JsonProperty("settings") val settings: BackupVars
|
@JsonProperty("settings") val settings: BackupVars
|
||||||
)
|
)
|
||||||
|
|
||||||
fun FragmentActivity.backup() {
|
fun Context.getBackup(): BackupFile {
|
||||||
try {
|
|
||||||
if (checkWrite()) {
|
|
||||||
val subDir = getBasePath().first
|
|
||||||
val date = SimpleDateFormat("yyyy_MM_dd_HH_mm").format(Date(currentTimeMillis()))
|
|
||||||
val ext = "json"
|
|
||||||
val displayName = "CS3_Backup_${date}"
|
|
||||||
|
|
||||||
val allData = getSharedPrefs().all.filter { it.key.isTransferable() }
|
val allData = getSharedPrefs().all.filter { it.key.isTransferable() }
|
||||||
val allSettings = getDefaultSharedPrefs().all.filter { it.key.isTransferable() }
|
val allSettings = getDefaultSharedPrefs().all.filter { it.key.isTransferable() }
|
||||||
|
|
||||||
|
@ -117,10 +110,44 @@ object BackupUtils {
|
||||||
allSettings.filter { it.value as? Set<String> != null } as? Map<String, Set<String>>
|
allSettings.filter { it.value as? Set<String> != null } as? Map<String, Set<String>>
|
||||||
)
|
)
|
||||||
|
|
||||||
val backupFile = BackupFile(
|
return BackupFile(
|
||||||
allDataSorted,
|
allDataSorted,
|
||||||
allSettingsSorted
|
allSettingsSorted
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Context.restore(
|
||||||
|
backupFile: BackupFile,
|
||||||
|
restoreSettings: Boolean,
|
||||||
|
restoreDataStore: Boolean
|
||||||
|
) {
|
||||||
|
if (restoreSettings) {
|
||||||
|
restoreMap(backupFile.settings._Bool, true)
|
||||||
|
restoreMap(backupFile.settings._Int, true)
|
||||||
|
restoreMap(backupFile.settings._String, true)
|
||||||
|
restoreMap(backupFile.settings._Float, true)
|
||||||
|
restoreMap(backupFile.settings._Long, true)
|
||||||
|
restoreMap(backupFile.settings._StringSet, true)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (restoreDataStore) {
|
||||||
|
restoreMap(backupFile.datastore._Bool)
|
||||||
|
restoreMap(backupFile.datastore._Int)
|
||||||
|
restoreMap(backupFile.datastore._String)
|
||||||
|
restoreMap(backupFile.datastore._Float)
|
||||||
|
restoreMap(backupFile.datastore._Long)
|
||||||
|
restoreMap(backupFile.datastore._StringSet)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fun FragmentActivity.backup() {
|
||||||
|
try {
|
||||||
|
if (checkWrite()) {
|
||||||
|
val subDir = getBasePath().first
|
||||||
|
val date = SimpleDateFormat("yyyy_MM_dd_HH_mm").format(Date(currentTimeMillis()))
|
||||||
|
val ext = "json"
|
||||||
|
val displayName = "CS3_Backup_${date}"
|
||||||
|
val backupFile = getBackup()
|
||||||
|
|
||||||
val steam =
|
val steam =
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && subDir?.isDownloadDir() == true) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q && subDir?.isDownloadDir() == true) {
|
||||||
|
@ -251,28 +278,4 @@ object BackupUtils {
|
||||||
setKeyRaw(it.key, it.value, isEditingAppSettings)
|
setKeyRaw(it.key, it.value, isEditingAppSettings)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun Context.restore(
|
|
||||||
backupFile: BackupFile,
|
|
||||||
restoreSettings: Boolean,
|
|
||||||
restoreDataStore: Boolean
|
|
||||||
) {
|
|
||||||
if (restoreSettings) {
|
|
||||||
restoreMap(backupFile.settings._Bool, true)
|
|
||||||
restoreMap(backupFile.settings._Int, true)
|
|
||||||
restoreMap(backupFile.settings._String, true)
|
|
||||||
restoreMap(backupFile.settings._Float, true)
|
|
||||||
restoreMap(backupFile.settings._Long, true)
|
|
||||||
restoreMap(backupFile.settings._StringSet, true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if (restoreDataStore) {
|
|
||||||
restoreMap(backupFile.datastore._Bool)
|
|
||||||
restoreMap(backupFile.datastore._Int)
|
|
||||||
restoreMap(backupFile.datastore._String)
|
|
||||||
restoreMap(backupFile.datastore._Float)
|
|
||||||
restoreMap(backupFile.datastore._Long)
|
|
||||||
restoreMap(backupFile.datastore._StringSet)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
Loading…
Reference in a new issue