Commit 508ea5fc authored by Daniel Wolf's avatar Daniel Wolf
Browse files

Incrementally export queries (only append the new queries)

parent 87a28082
Pipeline #4185 passed with stage
in 4 minutes and 22 seconds
......@@ -4,6 +4,7 @@ import android.content.Context
import com.frostnerd.smokescreen.database.converters.StringListConverter
import com.frostnerd.smokescreen.database.dao.DnsQueryDao
import com.frostnerd.smokescreen.database.entities.DnsQuery
import com.frostnerd.smokescreen.getPreferences
import kotlinx.coroutines.*
import java.io.BufferedWriter
import java.io.File
......@@ -60,17 +61,23 @@ class DnsQueryRepository(val dnsQueryDao: DnsQueryDao) {
val exportDir = File(context.filesDir, "queryexport/")
exportDir.mkdirs()
val exportFile = File(exportDir, "queries.csv")
exportFile.delete()
val start = context.getPreferences().exportedQueryCount
val existed = if(start == 0 && exportFile.exists()) {
exportFile.delete()
false
} else exportFile.exists()
return GlobalScope.launch {
val outStream = BufferedWriter(FileWriter(exportFile))
outStream.write("Name,Short Name,Type Name,Type ID,Asked Server,Answered from Cache,Question time,Response Time,Responses(JSON-Array of Base64)")
outStream.newLine()
val outStream = BufferedWriter(FileWriter(exportFile, true))
if(!existed) {
outStream.write("Name,Short Name,Type Name,Type ID,Asked Server,Answered from Cache,Question time,Response Time,Responses(JSON-Array of Base64)")
outStream.newLine()
}
val builder = StringBuilder()
val responseConverter = StringListConverter()
var total = 0L
val count = dnsQueryDao.getCount()
for(i in 0..count step 5000) {
var total = start.toLong()
for(i in start..count step 5000) {
val all = dnsQueryDao.getAll(5000, i.toLong())
for (query in all) {
total++
......@@ -91,6 +98,7 @@ class DnsQueryRepository(val dnsQueryDao: DnsQueryDao) {
}
}
outStream.close()
context.getPreferences().exportedQueryCount = count
fileReadyCallback(exportFile)
}
}
......
......@@ -97,6 +97,7 @@ interface AppSettings {
var hasRatedApp: Boolean
var previousInstalledVersion:Int // Maintained in ChangelogDialog
var showChangelog:Boolean // Maintained in ChangelogDialog
var exportedQueryCount:Int
fun isUsingKeweon(): Boolean {
return dnsServerConfig.servers.any {
......@@ -150,6 +151,7 @@ class AppSettingsSharedPreferences(context: Context) : AppSettings, SimpleTypedP
override var hasRatedApp: Boolean by booleanPref("has_rated_app", false)
override var previousInstalledVersion:Int by nonOptionalOf(intPref("previous_version"),true, BuildConfig.VERSION_CODE)
override var showChangelog:Boolean by booleanPref("show_changelog", true)
override var exportedQueryCount:Int by intPref("exported_query_count", 0)
override var theme: Theme by ThemePreference("theme", Theme.MONO)
override var startAppOnBoot: Boolean by booleanPref("start_on_boot", true)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment