forked from cake-tech/cake_wallet
-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathpathForWallet.dart
More file actions
76 lines (63 loc) · 2.3 KB
/
pathForWallet.dart
File metadata and controls
76 lines (63 loc) · 2.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import 'dart:io';
import 'package:cw_core/wallet_type.dart';
import 'package:path_provider/path_provider.dart';
Future<String> pathForWalletDir(
{required String name, required WalletType type}) async {
Directory root = await applicationRootDirectory();
final prefix = walletTypeToString(type).toLowerCase();
final walletsDir = Directory('${root.path}/wallets');
final walletDire = Directory('${walletsDir.path}/$prefix/$name');
if (!walletDire.existsSync()) {
walletDire.createSync(recursive: true);
}
return walletDire.path;
}
Future<String> pathForWallet(
{required String name, required WalletType type}) async =>
await pathForWalletDir(name: name, type: type)
.then((path) => path + '/$name');
Future<String> outdatedAndroidPathForWalletDir({String? name}) async {
Directory directory = await applicationRootDirectory();
final pathDir = directory.path + '/$name';
return pathDir;
}
Future<Directory> applicationRootDirectory() async {
Directory appDirectory;
// todo: can merge and do same as regular linux home dir?
if (bool.fromEnvironment("IS_ARM")) {
appDirectory = await getApplicationDocumentsDirectory();
appDirectory = Directory("${appDirectory.path}/.stackduo");
} else if (Platform.isLinux) {
appDirectory = Directory("${Platform.environment['HOME']}/.stackduo");
} else if (Platform.isWindows) {
// TODO: windows root .stackduo dir location
throw Exception("Unsupported platform");
} else if (Platform.isMacOS) {
// currently run in ipad mode??
throw Exception("Unsupported platform");
} else if (Platform.isIOS) {
// todo: check if we need different behaviour here
if (await isDesktop()) {
appDirectory = await getLibraryDirectory();
} else {
appDirectory = await getLibraryDirectory();
}
} else if (Platform.isAndroid) {
appDirectory = await getApplicationDocumentsDirectory();
} else {
throw Exception("Unsupported platform");
}
if (!appDirectory.existsSync()) {
await appDirectory.create(recursive: true);
}
return appDirectory;
}
Future<bool> isDesktop() async {
if (Platform.isIOS) {
Directory libraryPath = await getLibraryDirectory();
if (!libraryPath.path.contains("/var/mobile/")) {
return true;
}
}
return Platform.isLinux || Platform.isMacOS || Platform.isWindows;
}