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
|
|
|
|
2024-01-30 17:20:10 +00:00
|
|
|
Future<Directory> getAppDir({String appName = 'cake_wallet', required bool isFlatpak}) 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) {
|
2024-01-30 17:20:10 +00:00
|
|
|
String appDirPath = '';
|
2023-09-26 18:50:08 +00:00
|
|
|
|
2024-01-30 17:20:10 +00:00
|
|
|
if (isFlatpak) {
|
|
|
|
appDirPath =
|
|
|
|
'/home/${Platform.environment['USER']}/.var/app/com.cakewallet.CakeWallet/data/.$appName';
|
|
|
|
} else {
|
|
|
|
final homePath = '/home/${Platform.environment['USER']}/.$appName';
|
|
|
|
|
|
|
|
if (await Directory(homePath).exists()) {
|
|
|
|
appDirPath = homePath;
|
|
|
|
} else {
|
|
|
|
final docPath = await getApplicationDocumentsDirectory();
|
|
|
|
|
|
|
|
if (await docPath.exists()) {
|
|
|
|
appDirPath = docPath.path;
|
|
|
|
}
|
|
|
|
}
|
2023-09-26 18:50:08 +00:00
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
}
|