From f2aa2ec3921e60dc06c05a76cdfeb3039063c5c7 Mon Sep 17 00:00:00 2001 From: Hanh Date: Tue, 22 Nov 2022 23:17:25 +0800 Subject: [PATCH] 301 --- docker/Dockerfile-builder-linux | 3 +++ lib/coin/coin.dart | 6 ++---- lib/main.dart | 28 ++++++++++++++++++++++------ lib/store.dart | 3 +-- misc/ywallet.metainfo.xml | 2 +- pubspec.yaml | 2 +- 6 files changed, 30 insertions(+), 14 deletions(-) diff --git a/docker/Dockerfile-builder-linux b/docker/Dockerfile-builder-linux index b6f5678..f746627 100755 --- a/docker/Dockerfile-builder-linux +++ b/docker/Dockerfile-builder-linux @@ -19,4 +19,7 @@ RUN cargo install cargo-make RUN curl -o flutter.tar.xz https://storage.googleapis.com/flutter_infra_release/releases/stable/linux/flutter_linux_3.3.8-stable.tar.xz RUN tar xvf flutter.tar.xz RUN rm -f flutter.tar.xz +RUN mkdir /root/.zcash-params +RUN curl -o /root/.zcash-params/sapling-spend.params https://download.z.cash/downloads/sapling-spend.params +RUN curl -o /root/.zcash-params/sapling-output.params https://download.z.cash/downloads/sapling-output.params diff --git a/lib/coin/coin.dart b/lib/coin/coin.dart index 382b915..749585c 100644 --- a/lib/coin/coin.dart +++ b/lib/coin/coin.dart @@ -49,8 +49,7 @@ abstract class CoinBase { Future tryImport(PlatformFile file) async { if (file.name == dbName) { - Directory tempDir = await getTemporaryDirectory(); - final dest = p.join(tempDir.path, dbName); + final dest = p.join(settings.tempDir, dbName); await File(file.path!).copy(dest); // save to temporary directory return true; } @@ -58,8 +57,7 @@ abstract class CoinBase { } Future importFromTemp() async { - Directory tempDir = await getTemporaryDirectory(); - final src = File(p.join(tempDir.path, dbName)); + final src = File(p.join(settings.tempDir, dbName)); print("Import from ${src.path}"); if (await src.exists()) { print("copied to ${dbFullPath}"); diff --git a/lib/main.dart b/lib/main.dart index d4e0974..34acf59 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,6 +5,7 @@ import 'dart:io'; import 'dart:math'; import 'dart:ui'; +import 'package:path/path.dart' as p; import 'package:csv/csv.dart'; import 'package:currency_text_input_formatter/currency_text_input_formatter.dart'; import 'package:decimal/decimal.dart'; @@ -817,8 +818,8 @@ Future saveFile(String data, String filename, String title) async { if (isMobile()) { final context = navigatorKey.currentContext!; Size size = MediaQuery.of(context).size; - Directory tempDir = await getTemporaryDirectory(); - String fn = "${tempDir.path}/$filename"; + final tempDir = settings.tempDir; + String fn = p.join(tempDir, filename); final file = File(fn); await file.writeAsString(data); return Share.shareFiles([fn], subject: title, sharePositionOrigin: Rect.fromLTWH(0, 0, size.width, size.height / 2)); @@ -850,8 +851,7 @@ Future exportFile(BuildContext context, String path, String title) async { } Future getRecoveryFile() async { - Directory tempDir = await getTemporaryDirectory(); - String fn = "${tempDir.path}/$RECOVERY_FILE"; + String fn = p.join(settings.tempDir, RECOVERY_FILE); final f = File(fn); return f; } @@ -921,13 +921,29 @@ DynamicLibrary _openOnLinux() { } } -Future getDbPath() async { - if (isMobile()) return await getDatabasesPath(); +Future getDataPath() async { String? home; if (Platform.isWindows) home = Platform.environment['LOCALAPPDATA']; if (Platform.isLinux) home = Platform.environment['XDG_DATA_HOME']; if (Platform.isMacOS) home = Platform.environment['HOME']; final h = home ?? ""; + return h; +} + +Future getTempPath() async { + if (isMobile()) { + final d = await getTemporaryDirectory(); + return d.path; + } + final dataPath = await getDataPath(); + final tempPath = p.join(dataPath, "tmp"); + Directory(tempPath).createSync(recursive: true); + return tempPath; +} + +Future getDbPath() async { + if (isMobile()) return await getDatabasesPath(); + final h = await getDataPath(); return "$h/databases"; } diff --git a/lib/store.dart b/lib/store.dart index 9577bf5..96c6791 100644 --- a/lib/store.dart +++ b/lib/store.dart @@ -213,8 +213,7 @@ abstract class _Settings with Store { @action Future restore() async { - final tempDirectory = await getTemporaryDirectory(); - tempDir = tempDirectory.path; + tempDir = await getTempPath(); final prefs = await SharedPreferences.getInstance(); version = prefs.getString('version') ?? "1.0.0"; simpleMode = prefs.getBool('simple_mode') ?? true; diff --git a/misc/ywallet.metainfo.xml b/misc/ywallet.metainfo.xml index aa75596..1aad8c4 100644 --- a/misc/ywallet.metainfo.xml +++ b/misc/ywallet.metainfo.xml @@ -21,6 +21,6 @@ Hanh Huynh Huu - + diff --git a/pubspec.yaml b/pubspec.yaml index ed27024..ce596d8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev # In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion. # Read more about iOS versioning at # https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html -version: 1.2.16+300 +version: 1.2.16+301 environment: sdk: ">=2.12.0 <3.0.0"