Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@ import androidx.compose.ui.tooling.preview.Preview
import androidx.compose.ui.unit.dp
import androidx.compose.ui.window.Dialog
import com.opencsv.CSVReader
import com.opencsv.exceptions.CsvMalformedLineException
import com.yogeshpaliyal.common.data.AccountModel
import com.yogeshpaliyal.keypass.R
import com.yogeshpaliyal.keypass.ui.redux.actions.Action
import com.yogeshpaliyal.keypass.ui.redux.actions.ToastAction
import java.io.FileNotFoundException

class ChromeAccountImporter : AccountsImporter {
override fun getImporterTitle(): Int = R.string.google_backup
Expand All @@ -39,27 +41,33 @@ class ChromeAccountImporter : AccountsImporter {
val context = LocalContext.current

LaunchedEffect(key1 = file, block = {
val inputStream = context.contentResolver.openInputStream(file)
val reader = CSVReader(inputStream?.reader())
val myEntries: List<Array<String>> = reader.readAll()
val headers = myEntries[0]
val result = myEntries.drop(1).map { data ->
headers.zip(data).toMap()
}
val listOfAccounts = ArrayList<AccountModel>()
result.forEach {
listOfAccounts.add(
AccountModel(
title = it["name"],
notes = it["note"],
password = it["password"],
username = it["username"],
site = it["url"]
try {
val inputStream = context.contentResolver.openInputStream(file)
val reader = CSVReader(inputStream?.reader())
val myEntries: List<Array<String>> = reader.readAll()
val headers = myEntries[0]
val result = myEntries.drop(1).map { data ->
headers.zip(data).toMap()
}
val listOfAccounts = ArrayList<AccountModel>()
result.forEach {
listOfAccounts.add(
AccountModel(
title = it["name"],
notes = it["note"],
password = it["password"],
username = it["username"],
site = it["url"]
)
)
)
}
resolve(listOfAccounts)
onCompleteOrCancel(ToastAction(R.string.backup_restored))
} catch (e: CsvMalformedLineException) {
onCompleteOrCancel(ToastAction(R.string.invalid_csv_file))
} catch (e: FileNotFoundException) {
onCompleteOrCancel(ToastAction(R.string.file_not_found))
}
resolve(listOfAccounts)
onCompleteOrCancel(ToastAction(R.string.backup_restored))
})

LoadingDialog()
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -111,5 +111,7 @@
<string name="keepass_backup_desc">Choose KeePass CSV file to import</string>
<string name="generate_qr_code">Export</string>
<string name="invalid_secret_key">Invalid secret key format</string>
<string name="invalid_csv_file">Invalid CSV File</string>
<string name="file_not_found">File not found (please try again)</string>

</resources>