stack_wallet/lib/utilities/stack_file_system.dart

101 lines
2.8 KiB
Dart
Raw Normal View History

2023-05-26 21:21:16 +00:00
/*
* This file is part of Stack Wallet.
*
* Copyright (c) 2023 Cypher Stack
* All Rights Reserved.
* The code is distributed under GPLv3 license, see LICENSE file for details.
* Generated by Cypher Stack on 2023-05-26
*
*/
2022-11-12 22:04:16 +00:00
import 'dart:io';
import 'package:path_provider/path_provider.dart';
import 'package:stackwallet/utilities/logger.dart';
import 'package:stackwallet/utilities/util.dart';
abstract class StackFileSystem {
static Future<Directory> applicationRootDirectory() async {
Directory appDirectory;
// todo: can merge and do same as regular linux home dir?
if (Logging.isArmLinux) {
appDirectory = await getApplicationDocumentsDirectory();
appDirectory = Directory("${appDirectory.path}/.stackwallet");
} else if (Platform.isLinux) {
appDirectory = Directory("${Platform.environment['HOME']}/.stackwallet");
} else if (Platform.isWindows) {
2022-12-29 16:45:29 +00:00
appDirectory = await getApplicationSupportDirectory();
2022-11-12 22:04:16 +00:00
} else if (Platform.isMacOS) {
2023-07-17 16:36:45 +00:00
appDirectory = await getLibraryDirectory();
appDirectory = Directory("${appDirectory.path}/stackwallet");
2022-11-12 22:04:16 +00:00
} else if (Platform.isIOS) {
// todo: check if we need different behaviour here
if (Util.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;
}
static Future<Directory> applicationIsarDirectory() async {
final root = await applicationRootDirectory();
if (Util.isDesktop) {
final dir = Directory("${root.path}/isar");
if (!dir.existsSync()) {
await dir.create();
}
return dir;
} else {
return root;
}
}
2023-08-07 16:39:04 +00:00
static Future<Directory> applicationTorDirectory() async {
final root = await applicationRootDirectory();
if (Util.isDesktop) {
final dir = Directory("${root.path}/tor");
if (!dir.existsSync()) {
await dir.create();
}
return dir;
} else {
return root;
}
}
2022-11-12 22:04:16 +00:00
static Future<Directory> applicationHiveDirectory() async {
final root = await applicationRootDirectory();
if (Util.isDesktop) {
final dir = Directory("${root.path}/hive");
if (!dir.existsSync()) {
await dir.create();
}
return dir;
} else {
return root;
}
}
2023-07-04 00:25:18 +00:00
static Future<void> initThemesDir() async {
final root = await applicationRootDirectory();
2023-07-04 00:25:18 +00:00
final dir = Directory("${root.path}/themes");
if (!dir.existsSync()) {
await dir.create();
}
2023-07-04 00:25:18 +00:00
themesDir = dir;
}
2023-07-04 00:25:18 +00:00
static Directory? themesDir;
2022-11-12 22:04:16 +00:00
}