added download database
This commit is contained in:
@ -13,7 +13,7 @@ import java.io.FileOutputStream
|
|||||||
object DatabaseDownloader {
|
object DatabaseDownloader {
|
||||||
|
|
||||||
private const val DB_NAME = "questionnaire_database"
|
private const val DB_NAME = "questionnaire_database"
|
||||||
private const val SERVER_DOWNLOAD_URL = "http://49.13.157.44/exported_encrypted_database.db"
|
private const val SERVER_DOWNLOAD_URL = "http://49.13.157.44/uploads/exported_encrypted_database.db"
|
||||||
|
|
||||||
private val client = OkHttpClient()
|
private val client = OkHttpClient()
|
||||||
|
|
||||||
@ -58,7 +58,10 @@ object DatabaseDownloader {
|
|||||||
}
|
}
|
||||||
decryptedFile.copyTo(dbFile, overwrite = true)
|
decryptedFile.copyTo(dbFile, overwrite = true)
|
||||||
|
|
||||||
Log.d("DOWNLOAD", "Neue Datenbank erfolgreich eingesetzt.")
|
Log.d("DOWNLOAD", "Neue Datenbank erfolgreich eingesetzt")
|
||||||
|
|
||||||
|
// Datenbankinhalt nach Download ausgeben (Hex-String)
|
||||||
|
logFileContentAsHex(dbFile, "DOWNLOAD")
|
||||||
|
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("DOWNLOAD", "Fehler beim Download oder Ersetzen der DB", e)
|
Log.e("DOWNLOAD", "Fehler beim Download oder Ersetzen der DB", e)
|
||||||
@ -71,4 +74,21 @@ object DatabaseDownloader {
|
|||||||
// TODO: hier echte Entschlüsselungslogik einfügen
|
// TODO: hier echte Entschlüsselungslogik einfügen
|
||||||
encryptedFile.copyTo(outputFile, overwrite = true)
|
encryptedFile.copyTo(outputFile, overwrite = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun logFileContentAsHex(file: File, tag: String) {
|
||||||
|
try {
|
||||||
|
val bytes = file.readBytes()
|
||||||
|
// Zum Loggen den Hex-String in Blöcke teilen, max 4000 Zeichen pro Log (Android Logcat Limit)
|
||||||
|
val hexString = bytes.joinToString(separator = "") { "%02X".format(it) }
|
||||||
|
val chunkSize = 4000
|
||||||
|
var start = 0
|
||||||
|
while (start < hexString.length) {
|
||||||
|
val end = (start + chunkSize).coerceAtMost(hexString.length)
|
||||||
|
Log.d(tag, "DB HEX Content: ${hexString.substring(start, end)}")
|
||||||
|
start = end
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(tag, "Fehler beim Lesen der Datei zum Loggen", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -33,6 +33,9 @@ object DatabaseUploader {
|
|||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Datenbankinhalt vor Upload ausgeben (Hex-String)
|
||||||
|
logFileContentAsHex(dbFile, "UPLOAD")
|
||||||
|
|
||||||
val exportFile = File(context.cacheDir, ENCRYPTED_FILE_NAME)
|
val exportFile = File(context.cacheDir, ENCRYPTED_FILE_NAME)
|
||||||
dbFile.copyTo(exportFile, overwrite = true)
|
dbFile.copyTo(exportFile, overwrite = true)
|
||||||
|
|
||||||
@ -85,4 +88,21 @@ object DatabaseUploader {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
private fun logFileContentAsHex(file: File, tag: String) {
|
||||||
|
try {
|
||||||
|
val bytes = file.readBytes()
|
||||||
|
// Zum Loggen den Hex-String in Blöcke teilen, max 4000 Zeichen pro Log (Android Logcat Limit)
|
||||||
|
val hexString = bytes.joinToString(separator = "") { "%02X".format(it) }
|
||||||
|
val chunkSize = 4000
|
||||||
|
var start = 0
|
||||||
|
while (start < hexString.length) {
|
||||||
|
val end = (start + chunkSize).coerceAtMost(hexString.length)
|
||||||
|
Log.d(tag, "DB HEX Content: ${hexString.substring(start, end)}")
|
||||||
|
start = end
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(tag, "Fehler beim Lesen der Datei zum Loggen", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user