118 lines
3.4 KiB
Dart
118 lines
3.4 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 = await _resolveAppSupportDir();
|
|
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<Directory> _resolveAppSupportDir() async {
|
|
final target = Directory(_targetAppSupportPath());
|
|
if (await target.exists()) {
|
|
return target;
|
|
}
|
|
|
|
final legacy = Directory(_legacyAppSupportPath());
|
|
if (await legacy.exists()) {
|
|
try {
|
|
return await legacy.rename(target.path);
|
|
} catch (_) {
|
|
return legacy;
|
|
}
|
|
}
|
|
|
|
return target;
|
|
}
|
|
|
|
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);
|
|
}
|
|
}
|