mirror of
https://github.com/TeamNewPipe/NewPipe
synced 2024-11-06 01:56:24 +00:00
Expose all import/export errors to the user
This commit is contained in:
parent
8e192acb63
commit
7da1d30010
@ -27,38 +27,34 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
fun exportDatabase(preferences: SharedPreferences, file: StoredFileHelper) {
|
fun exportDatabase(preferences: SharedPreferences, file: StoredFileHelper) {
|
||||||
file.create()
|
file.create()
|
||||||
ZipOutputStream(SharpOutputStream(file.stream).buffered()).use { outZip ->
|
ZipOutputStream(SharpOutputStream(file.stream).buffered()).use { outZip ->
|
||||||
try {
|
// add the database
|
||||||
// add the database
|
ZipHelper.addFileToZip(
|
||||||
ZipHelper.addFileToZip(
|
outZip,
|
||||||
outZip,
|
BackupFileLocator.FILE_NAME_DB,
|
||||||
BackupFileLocator.FILE_NAME_DB,
|
fileLocator.db.path,
|
||||||
fileLocator.db.path,
|
)
|
||||||
)
|
|
||||||
|
|
||||||
// add the legacy vulnerable serialized preferences (will be removed in the future)
|
// add the legacy vulnerable serialized preferences (will be removed in the future)
|
||||||
ZipHelper.addFileToZip(
|
ZipHelper.addFileToZip(
|
||||||
outZip,
|
outZip,
|
||||||
BackupFileLocator.FILE_NAME_SERIALIZED_PREFS
|
BackupFileLocator.FILE_NAME_SERIALIZED_PREFS
|
||||||
) { byteOutput ->
|
) { byteOutput ->
|
||||||
ObjectOutputStream(byteOutput).use { output ->
|
ObjectOutputStream(byteOutput).use { output ->
|
||||||
output.writeObject(preferences.all)
|
output.writeObject(preferences.all)
|
||||||
output.flush()
|
output.flush()
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// add the JSON preferences
|
// add the JSON preferences
|
||||||
ZipHelper.addFileToZip(
|
ZipHelper.addFileToZip(
|
||||||
outZip,
|
outZip,
|
||||||
BackupFileLocator.FILE_NAME_JSON_PREFS
|
BackupFileLocator.FILE_NAME_JSON_PREFS
|
||||||
) { byteOutput ->
|
) { byteOutput ->
|
||||||
JsonWriter
|
JsonWriter
|
||||||
.indent("")
|
.indent("")
|
||||||
.on(byteOutput)
|
.on(byteOutput)
|
||||||
.`object`(preferences.all)
|
.`object`(preferences.all)
|
||||||
.done()
|
.done()
|
||||||
}
|
|
||||||
} catch (e: Exception) {
|
|
||||||
Log.e(TAG, "Unable to export serialized settings", e)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,7 +129,7 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!editor.commit()) {
|
if (!editor.commit()) {
|
||||||
Log.e(TAG, "Unable to loadSerializedPrefs")
|
throw IOException("Unable to commit loadSerializedPrefs")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}.let { fileExists ->
|
}.let { fileExists ->
|
||||||
@ -168,7 +164,7 @@ class ImportExportManager(private val fileLocator: BackupFileLocator) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!editor.commit()) {
|
if (!editor.commit()) {
|
||||||
Log.e(TAG, "Unable to loadJsonPrefs")
|
throw IOException("Unable to commit loadJsonPrefs")
|
||||||
}
|
}
|
||||||
}.let { fileExists ->
|
}.let { fileExists ->
|
||||||
if (!fileExists) {
|
if (!fileExists) {
|
||||||
|
Loading…
Reference in New Issue
Block a user