2023-04-13 23:48:51 +00:00
|
|
|
import 'dart:io';
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
String? _rootDirPath;
|
|
|
|
|
2023-09-22 14:50:51 +00:00
|
|
|
void setRootDirFromEnv() => _rootDirPath = Platform.environment['CAKE_WALLET_DIR'];
|
2023-04-13 23:48:51 +00:00
|
|
|
|
|
|
|
Future<Directory> getAppDir({String appName = 'cake_wallet'}) async {
|
2023-09-22 14:50:51 +00:00
|
|
|
Directory dir;
|
2023-04-13 23:48:51 +00:00
|
|
|
|
2023-09-22 14:50:51 +00:00
|
|
|
if (_rootDirPath != null && _rootDirPath!.isNotEmpty) {
|
|
|
|
dir = Directory.fromUri(Uri.file(_rootDirPath!));
|
|
|
|
dir.create(recursive: true);
|
|
|
|
} else {
|
|
|
|
if (Platform.isLinux) {
|
2023-09-26 18:50:08 +00:00
|
|
|
String appDirPath;
|
|
|
|
|
|
|
|
try {
|
|
|
|
dir = await getApplicationDocumentsDirectory();
|
|
|
|
appDirPath = '${dir.path}/$appName';
|
|
|
|
} catch (e) {
|
|
|
|
appDirPath = '/home/${Platform.environment['USER']}/.$appName';
|
|
|
|
}
|
|
|
|
|
2023-09-22 14:50:51 +00:00
|
|
|
dir = Directory.fromUri(Uri.file(appDirPath));
|
|
|
|
await dir.create(recursive: true);
|
|
|
|
} else {
|
|
|
|
dir = await getApplicationDocumentsDirectory();
|
|
|
|
}
|
|
|
|
}
|
2023-04-13 23:48:51 +00:00
|
|
|
|
2023-09-22 14:50:51 +00:00
|
|
|
return dir;
|
|
|
|
}
|