stack_wallet/lib/utilities/stack_file_system.dart

118 lines
3.3 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 String? overrideDir;
2022-11-12 22:04:16 +00:00
static Future<Directory> applicationRootDirectory() async {
Directory appDirectory;
2023-12-29 16:34:41 +00:00
// if this is changed, the directories in libmonero must also be changed!!!!!
const dirName = "stackwallet";
2022-11-12 22:04:16 +00:00
// todo: can merge and do same as regular linux home dir?
if (Logging.isArmLinux) {
appDirectory = await getApplicationDocumentsDirectory();
2023-12-29 16:34:41 +00:00
appDirectory = Directory("${appDirectory.path}/.$dirName");
2022-11-12 22:04:16 +00:00
} else if (Platform.isLinux) {
if (overrideDir != null) {
appDirectory = Directory(overrideDir!);
} else {
2023-12-29 16:34:41 +00:00
appDirectory = Directory("${Platform.environment['HOME']}/.$dirName");
}
2022-11-12 22:04:16 +00:00
} else if (Platform.isWindows) {
if (overrideDir != null) {
appDirectory = Directory(overrideDir!);
} else {
appDirectory = await getApplicationSupportDirectory();
}
2022-11-12 22:04:16 +00:00
} else if (Platform.isMacOS) {
if (overrideDir != null) {
appDirectory = Directory(overrideDir!);
} else {
appDirectory = await getLibraryDirectory();
2023-12-29 16:34:41 +00:00
appDirectory = Directory("${appDirectory.path}/$dirName");
}
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
}