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';
|
2024-05-23 15:20:11 +00:00
|
|
|
|
|
|
|
import '../app_config.dart';
|
2024-05-23 00:37:06 +00:00
|
|
|
import 'logger.dart';
|
|
|
|
import 'util.dart';
|
2022-11-12 22:04:16 +00:00
|
|
|
|
|
|
|
abstract class StackFileSystem {
|
2024-05-23 15:20:11 +00:00
|
|
|
static String? _overrideDesktopDirPath;
|
|
|
|
static bool _overrideDirSet = false;
|
|
|
|
static void setDesktopOverrideDir(String dirPath) {
|
|
|
|
if (_overrideDirSet) {
|
|
|
|
throw Exception(
|
|
|
|
"Attempted to change StackFileSystem._overrideDir unexpectedly",
|
|
|
|
);
|
|
|
|
}
|
|
|
|
_overrideDesktopDirPath = dirPath;
|
|
|
|
_overrideDirSet = true;
|
|
|
|
}
|
2023-11-16 18:03:15 +00:00
|
|
|
|
2022-11-12 22:04:16 +00:00
|
|
|
static Future<Directory> applicationRootDirectory() async {
|
|
|
|
Directory appDirectory;
|
|
|
|
|
|
|
|
// todo: can merge and do same as regular linux home dir?
|
|
|
|
if (Logging.isArmLinux) {
|
|
|
|
appDirectory = await getApplicationDocumentsDirectory();
|
2024-05-23 15:20:11 +00:00
|
|
|
appDirectory =
|
|
|
|
Directory("${appDirectory.path}/.${AppConfig.appDefaultDataDirName}");
|
2022-11-12 22:04:16 +00:00
|
|
|
} else if (Platform.isLinux) {
|
2024-05-23 15:20:11 +00:00
|
|
|
if (_overrideDesktopDirPath != null) {
|
|
|
|
appDirectory = Directory(_overrideDesktopDirPath!);
|
2023-11-16 18:03:15 +00:00
|
|
|
} else {
|
2024-05-23 15:20:11 +00:00
|
|
|
appDirectory = Directory(
|
2024-05-27 23:56:22 +00:00
|
|
|
"${Platform.environment['HOME']}/.${AppConfig.appDefaultDataDirName}",
|
|
|
|
);
|
2023-11-16 18:03:15 +00:00
|
|
|
}
|
2022-11-12 22:04:16 +00:00
|
|
|
} else if (Platform.isWindows) {
|
2024-05-23 15:20:11 +00:00
|
|
|
if (_overrideDesktopDirPath != null) {
|
|
|
|
appDirectory = Directory(_overrideDesktopDirPath!);
|
2023-11-16 18:03:15 +00:00
|
|
|
} else {
|
|
|
|
appDirectory = await getApplicationSupportDirectory();
|
|
|
|
}
|
2022-11-12 22:04:16 +00:00
|
|
|
} else if (Platform.isMacOS) {
|
2024-05-23 15:20:11 +00:00
|
|
|
if (_overrideDesktopDirPath != null) {
|
|
|
|
appDirectory = Directory(_overrideDesktopDirPath!);
|
2023-11-16 18:03:15 +00:00
|
|
|
} else {
|
|
|
|
appDirectory = await getLibraryDirectory();
|
2024-05-23 15:20:11 +00:00
|
|
|
appDirectory = Directory(
|
2024-05-27 23:56:22 +00:00
|
|
|
"${appDirectory.path}/${AppConfig.appDefaultDataDirName}",
|
|
|
|
);
|
2023-11-16 18:03:15 +00:00
|
|
|
}
|
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-04-21 14:34:47 +00:00
|
|
|
|
2023-07-04 00:25:18 +00:00
|
|
|
static Future<void> initThemesDir() async {
|
2023-04-21 14:34:47 +00:00
|
|
|
final root = await applicationRootDirectory();
|
2023-07-04 00:25:18 +00:00
|
|
|
|
2023-05-09 23:27:48 +00:00
|
|
|
final dir = Directory("${root.path}/themes");
|
|
|
|
if (!dir.existsSync()) {
|
|
|
|
await dir.create();
|
2023-04-21 14:34:47 +00:00
|
|
|
}
|
2023-07-04 00:25:18 +00:00
|
|
|
themesDir = dir;
|
2023-04-21 14:34:47 +00:00
|
|
|
}
|
2023-07-04 00:25:18 +00:00
|
|
|
|
|
|
|
static Directory? themesDir;
|
2022-11-12 22:04:16 +00:00
|
|
|
}
|