diff --git a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt index 31814a40..d598568b 100644 --- a/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt +++ b/ui/BankingAndroidApp/src/main/java/net/dankito/banking/ui/android/di/BankingModule.kt @@ -62,32 +62,40 @@ class BankingModule(private val applicationContext: Context) { @Singleton @Named(DataFolderKey) fun provideDataFolder(applicationContext: Context) : File { - return File(applicationContext.filesDir, "data") + return ensureFolderExists(applicationContext.filesDir, "data") } @Provides @Singleton @Named(DatabaseFolderKey) fun provideDatabaseFolder(@Named(DataFolderKey) dataFolder: File) : File { - return File(dataFolder, "db") + return ensureFolderExists(dataFolder, "db") } @Provides @Singleton @Named(IndexFolderKey) fun provideIndexFolder(@Named(DataFolderKey) dataFolder: File) : File { - return File(dataFolder, "index") + return ensureFolderExists(dataFolder, "index") + } + + private fun ensureFolderExists(parentFolder: File, folderName: String): File { + val folder = File(parentFolder, folderName) + + folder.mkdirs() + + return folder } @Provides @Singleton fun provideBankingPresenter(bankingClientCreator: IBankingClientCreator, bankFinder: IBankFinder, - @Named(DatabaseFolderKey) databaseFolder: File, @Named(DataFolderKey) dataFolder: File, + @Named(DataFolderKey) dataFolder: File, persister: IBankingPersistence, remitteeSearcher: IRemitteeSearcher, bankIconFinder: IBankIconFinder, textExtractorRegistry: ITextExtractorRegistry, router: IRouter, invoiceDataExtractor: IInvoiceDataExtractor, serializer: ISerializer, threadPool: IThreadPool) : BankingPresenter { - return BankingPresenter(bankingClientCreator, bankFinder, databaseFolder, dataFolder, persister, + return BankingPresenter(bankingClientCreator, bankFinder, dataFolder, persister, remitteeSearcher, bankIconFinder, textExtractorRegistry, router, invoiceDataExtractor, serializer, threadPool) } diff --git a/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt b/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt index aa6c2e69..f5cfed2d 100755 --- a/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt +++ b/ui/BankingJavaFxApp/src/main/kotlin/net/dankito/banking/ui/javafx/dialogs/mainwindow/MainWindow.kt @@ -26,11 +26,11 @@ import java.io.File class MainWindow : View(messages["application.title"]) { - private val dataFolder = File("data") + private val dataFolder = ensureFolderExists(File("."), "data") - private val databaseFolder = File(dataFolder, "db") + private val databaseFolder = ensureFolderExists(dataFolder, "db") - private val indexFolder = File(dataFolder, "index") + private val indexFolder = ensureFolderExists(dataFolder, "index") private val tesseractTextExtractor = Tesseract4CommandlineImageTextExtractor(TesseractConfig(listOf(OcrLanguage.English, OcrLanguage.German))) @@ -41,9 +41,9 @@ class MainWindow : View(messages["application.title"]) { )) private val presenter = BankingPresenter(fints4kBankingClientCreator(OkHttpWebClient(), Base64ServiceJava8()), - LuceneBankFinder(indexFolder), databaseFolder, dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder), + LuceneBankFinder(indexFolder), dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder), LuceneRemitteeSearcher(indexFolder), BankIconFinder(), textExtractorRegistry, RouterJavaFx()) -// private val presenter = BankingPresenter(hbci4jBankingClientCreator(), LuceneBankFinder(indexFolder), databaseFolder, +// private val presenter = BankingPresenter(hbci4jBankingClientCreator(), LuceneBankFinder(indexFolder), // dataFolder, LuceneBankingPersistence(indexFolder, databaseFolder), LuceneRemitteeSearcher(indexFolder), // BankIconFinder(), textExtractorRegistry, RouterJavaFx()) @@ -68,4 +68,13 @@ class MainWindow : View(messages["application.title"]) { } } + + private fun ensureFolderExists(parentFolder: File, folderName: String): File { + val folder = File(parentFolder, folderName) + + folder.mkdirs() + + return folder + } + } \ No newline at end of file diff --git a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt index 3aadaf45..f075ee78 100644 --- a/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt +++ b/ui/BankingUiCommon/src/main/java/net/dankito/banking/ui/presenter/BankingPresenter.kt @@ -46,7 +46,6 @@ import kotlin.collections.ArrayList open class BankingPresenter( protected val bankingClientCreator: IBankingClientCreator, protected val bankFinder: IBankFinder, - protected val databaseFolder: File, protected val dataFolder: File, protected val persister: IBankingPersistence, protected val remitteeSearcher: IRemitteeSearcher, @@ -124,8 +123,6 @@ open class BankingPresenter( protected open fun readPersistedAccounts() { try { - databaseFolder.mkdirs() - val deserializedAccounts = persister.readPersistedAccounts() deserializedAccounts.forEach { account -> @@ -133,7 +130,7 @@ open class BankingPresenter( val bankInfo = BankInfo(bank.name, bank.bankCode, bank.bic, "", "", "", bank.finTsServerAddress, "FinTS V3.0", null) val newClient = bankingClientCreator.createClient(bankInfo, account.customerId, account.password, - databaseFolder, threadPool, callback) + dataFolder, threadPool, callback) try { newClient.restoreData() @@ -161,7 +158,7 @@ open class BankingPresenter( // TODO: move BankInfo out of fints4k open fun addAccountAsync(bankInfo: BankInfo, customerId: String, pin: String, callback: (AddAccountResponse) -> Unit) { - val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, databaseFolder, threadPool, this.callback) + val newClient = bankingClientCreator.createClient(bankInfo, customerId, pin, dataFolder, threadPool, this.callback) val startDate = Date() diff --git a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/fints4kBankingClient.kt b/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/fints4kBankingClient.kt index 4add3f33..f2bdb5a2 100644 --- a/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/fints4kBankingClient.kt +++ b/ui/fints4kBankingClient/src/main/kotlin/net/dankito/banking/fints4kBankingClient.kt @@ -113,7 +113,7 @@ open class fints4kBankingClient( override fun getTransactionsAsync(bankAccount: BankAccount, parameter: GetTransactionsParameter, callback: (GetTransactionsResponse) -> Unit) { val account = mapper.findAccountForBankAccount(customer, bankAccount) - if (account == null) { + if (account == null) { // TODO: in this case retrieve data from bank, all data should be re-creatable callback(GetTransactionsResponse(bankAccount, false, "Cannot find account for ${bankAccount.identifier}")) // TODO: translate } else { @@ -159,14 +159,18 @@ open class fints4kBankingClient( protected open fun saveData() { try { - serializer.serializeObject(customer, getFints4kClientDataFile()) + val clientDataFile = getFints4kClientDataFile() + + clientDataFile.parentFile.mkdirs() + + serializer.serializeObject(customer, clientDataFile) } catch (e: Exception) { log.error("Could not save customer data for $customer", e) } } protected open fun getFints4kClientDataFile(): File { - return File(dataFolder, "${bank.bankCode}_${customer.customerId}_$fints4kClientDataFilename") + return File(File(dataFolder, "fints4k-client"), "${bank.bankCode}_${customer.customerId}_$fints4kClientDataFilename") } } \ No newline at end of file diff --git a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt index 272f017a..c8a29d1d 100644 --- a/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt +++ b/ui/hbci4jBankingClient/src/main/kotlin/net/dankito/banking/hbci4jBankingClient.kt @@ -298,8 +298,10 @@ open class hbci4jBankingClient( // Die Datei kann problemlos geloescht werden. Sie wird beim naechsten mal automatisch neu erzeugt, // wenn der Parameter "client.passport.PinTan.init" den Wert "1" hat (siehe unten). // Wir speichern die Datei der Einfachheit halber im aktuellen Verzeichnis. - dataFolder.mkdirs() - val passportFile = File(dataFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat") + val hbciClientFolder = File(dataFolder, "hbci4j-client") + hbciClientFolder.mkdirs() + + val passportFile = File(hbciClientFolder, "passport_${credentials.bankCode}_${credentials.customerId}.dat") // Wir setzen die Kernel-Parameter zur Laufzeit. Wir koennten sie alternativ // auch oben in "props" setzen.