139 lines
4.3 KiB
Dart
139 lines
4.3 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:path/path.dart' as p;
|
|
|
|
class AppPaths {
|
|
static const _appDirName = 'peyawallet';
|
|
static const _legacyAppDirName = 'com.peya.wallet';
|
|
|
|
static Future<Directory> appSupportDir() async {
|
|
final dir = Directory(_targetAppSupportPath());
|
|
await dir.create(recursive: true);
|
|
return dir;
|
|
}
|
|
|
|
static Future<Directory> configDir() async {
|
|
final dir = Directory(p.join((await appSupportDir()).path, 'config'));
|
|
await dir.create(recursive: true);
|
|
return dir;
|
|
}
|
|
|
|
static Future<File> configFile() async {
|
|
return File(p.join((await configDir()).path, 'config.json'));
|
|
}
|
|
|
|
static Future<File> walletOpenMarkerFile() async {
|
|
return File(p.join((await configDir()).path, 'wallet_open.pending'));
|
|
}
|
|
|
|
static Future<Directory> walletsDir({String? overridePath}) async {
|
|
final dir = Directory(
|
|
overridePath ?? p.join((await appSupportDir()).path, 'wallets'));
|
|
await dir.create(recursive: true);
|
|
return dir;
|
|
}
|
|
|
|
static Future<Directory> p2poolDir() async {
|
|
final dir = Directory(p.join((await appSupportDir()).path, 'p2pool'));
|
|
await dir.create(recursive: true);
|
|
return dir;
|
|
}
|
|
|
|
static Future<File> p2poolPidFile() async {
|
|
return File(p.join((await p2poolDir()).path, 'p2pool.pid'));
|
|
}
|
|
|
|
static Future<File> localNodePidFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'peyad.pid'));
|
|
}
|
|
|
|
static Future<File> localNodeLogFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'peyad.log'));
|
|
}
|
|
|
|
static Future<File> localNodeLauncherLogFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'peyad-launcher.log'));
|
|
}
|
|
|
|
static Future<File> minerPidFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'xmrig.pid'));
|
|
}
|
|
|
|
static Future<File> minerLogFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'xmrig.log'));
|
|
}
|
|
|
|
static Future<File> minerLauncherLogFile() async {
|
|
return File(p.join((await appSupportDir()).path, 'xmrig-launcher.log'));
|
|
}
|
|
|
|
static Future<List<File>> legacyConfigFiles() async {
|
|
final targetRoot = Directory(_targetAppSupportPath());
|
|
final legacyRoot = Directory(_legacyAppSupportPath());
|
|
return [
|
|
File(p.join(targetRoot.path, 'config.json')),
|
|
File(p.join(legacyRoot.path, 'config.json')),
|
|
File(p.join(legacyRoot.path, 'config', 'config.json')),
|
|
];
|
|
}
|
|
|
|
static Future<List<File>> legacyWalletOpenMarkerFiles() async {
|
|
final targetRoot = Directory(_targetAppSupportPath());
|
|
final legacyRoot = Directory(_legacyAppSupportPath());
|
|
return [
|
|
File(p.join(targetRoot.path, 'wallet_open.pending')),
|
|
File(p.join(legacyRoot.path, 'wallet_open.pending')),
|
|
];
|
|
}
|
|
|
|
static String _targetAppSupportPath() {
|
|
if (Platform.isWindows) {
|
|
final appData = Platform.environment['APPDATA'];
|
|
if (appData != null && appData.isNotEmpty) {
|
|
return p.join(appData, _appDirName);
|
|
}
|
|
}
|
|
|
|
if (Platform.isLinux) {
|
|
final xdgDataHome = Platform.environment['XDG_DATA_HOME'];
|
|
if (xdgDataHome != null && xdgDataHome.isNotEmpty) {
|
|
return p.join(xdgDataHome, _appDirName);
|
|
}
|
|
final home = Platform.environment['HOME'] ?? Directory.current.path;
|
|
return p.join(home, '.local', 'share', _appDirName);
|
|
}
|
|
|
|
if (Platform.isMacOS) {
|
|
final home = Platform.environment['HOME'] ?? Directory.current.path;
|
|
return p.join(home, 'Library', 'Application Support', _appDirName);
|
|
}
|
|
|
|
return p.join(Directory.current.path, _appDirName);
|
|
}
|
|
|
|
static String _legacyAppSupportPath() {
|
|
if (Platform.isWindows) {
|
|
final appData = Platform.environment['APPDATA'];
|
|
if (appData != null && appData.isNotEmpty) {
|
|
return p.join(appData, _legacyAppDirName);
|
|
}
|
|
}
|
|
|
|
if (Platform.isLinux) {
|
|
final xdgDataHome = Platform.environment['XDG_DATA_HOME'];
|
|
if (xdgDataHome != null && xdgDataHome.isNotEmpty) {
|
|
return p.join(xdgDataHome, _legacyAppDirName);
|
|
}
|
|
final home = Platform.environment['HOME'] ?? Directory.current.path;
|
|
return p.join(home, '.local', 'share', _legacyAppDirName);
|
|
}
|
|
|
|
if (Platform.isMacOS) {
|
|
final home = Platform.environment['HOME'] ?? Directory.current.path;
|
|
return p.join(home, 'Library', 'Application Support', _legacyAppDirName);
|
|
}
|
|
|
|
return p.join(Directory.current.path, _legacyAppDirName);
|
|
}
|
|
}
|