Line data Source code
1 : // Copyright 2023 The terCAD team. All rights reserved.
2 : // Use of this source code is governed by a CC BY-NC-ND 4.0 license that can be found in the LICENSE file.
3 :
4 : import 'package:app_finance/_classes/controller/encryption_handler.dart';
5 : import 'package:app_finance/_classes/storage/transaction_log.dart';
6 :
7 : abstract class AbstractProtocol {
8 0 : Future<List<int>> exportTransactions() async {
9 0 : List<int> codeUnits = [];
10 0 : await for (String line in TransactionLog.read()) {
11 0 : codeUnits.addAll(line.codeUnits);
12 0 : codeUnits.addAll('\n'.codeUnits);
13 : }
14 : return codeUnits;
15 : }
16 :
17 0 : void clearTransactions() => TransactionLog.clear();
18 :
19 0 : void importTransactions(List<int> codeUnits, [bool isEncrypted = true]) {
20 0 : List<String> lines = String.fromCharCodes(codeUnits).split('\n');
21 0 : for (String line in lines) {
22 0 : if (line.trim() == '') {
23 : continue;
24 : }
25 : try {
26 : if (isEncrypted) {
27 0 : line = EncryptionHandler.decrypt(line);
28 : }
29 0 : TransactionLog.save(line);
30 : } catch (e) {
31 : // ... ignore failures
32 : }
33 : }
34 : }
35 : }
|