2024-04-30 23:38:49 +08:00
|
|
|
import 'dart:async';
|
|
|
|
|
import 'dart:io';
|
|
|
|
|
|
|
|
|
|
import 'package:path/path.dart';
|
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
|
|
|
|
|
|
import 'constant.dart';
|
|
|
|
|
|
|
|
|
|
class AppPath {
|
|
|
|
|
static AppPath? _instance;
|
2024-09-26 14:29:04 +08:00
|
|
|
Completer<Directory> dataDir = Completer();
|
2024-08-04 08:21:14 +08:00
|
|
|
Completer<Directory> downloadDir = Completer();
|
2024-09-26 14:29:04 +08:00
|
|
|
Completer<Directory> tempDir = Completer();
|
|
|
|
|
late String appDirPath;
|
2024-06-19 13:13:31 +08:00
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
AppPath._internal() {
|
2024-09-26 14:29:04 +08:00
|
|
|
appDirPath = join(dirname(Platform.resolvedExecutable));
|
2024-06-19 13:13:31 +08:00
|
|
|
getApplicationSupportDirectory().then((value) {
|
2024-09-26 14:29:04 +08:00
|
|
|
dataDir.complete(value);
|
|
|
|
|
});
|
2024-12-03 21:47:12 +08:00
|
|
|
getTemporaryDirectory().then((value) {
|
|
|
|
|
tempDir.complete(value);
|
2024-06-19 13:13:31 +08:00
|
|
|
});
|
2024-08-04 08:21:14 +08:00
|
|
|
getDownloadsDirectory().then((value) {
|
|
|
|
|
downloadDir.complete(value);
|
|
|
|
|
});
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory AppPath() {
|
|
|
|
|
_instance ??= AppPath._internal();
|
|
|
|
|
return _instance!;
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
String get executableExtension {
|
|
|
|
|
return Platform.isWindows ? ".exe" : "";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get executableDirPath {
|
|
|
|
|
final currentExecutablePath = Platform.resolvedExecutable;
|
|
|
|
|
return dirname(currentExecutablePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get corePath {
|
|
|
|
|
return join(executableDirPath, "FlClashCore$executableExtension");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
String get helperPath {
|
|
|
|
|
return join(executableDirPath, "$appHelperService$executableExtension");
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 23:32:00 +08:00
|
|
|
Future<String> get downloadDirPath async {
|
2024-08-04 08:21:14 +08:00
|
|
|
final directory = await downloadDir.future;
|
|
|
|
|
return directory.path;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 23:32:00 +08:00
|
|
|
Future<String> get homeDirPath async {
|
2024-09-26 14:29:04 +08:00
|
|
|
final directory = await dataDir.future;
|
2024-04-30 23:38:49 +08:00
|
|
|
return directory.path;
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 23:32:00 +08:00
|
|
|
Future<String> get lockFilePath async {
|
2024-12-03 21:47:12 +08:00
|
|
|
final directory = await dataDir.future;
|
|
|
|
|
return join(directory.path, "FlClash.lock");
|
|
|
|
|
}
|
|
|
|
|
|
2025-02-03 23:32:00 +08:00
|
|
|
Future<String> get sharedPreferencesPath async {
|
|
|
|
|
final directory = await dataDir.future;
|
|
|
|
|
return join(directory.path, "shared_preferences.json");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String> get profilesPath async {
|
2024-09-26 14:29:04 +08:00
|
|
|
final directory = await dataDir.future;
|
2024-05-20 15:15:09 +08:00
|
|
|
return join(directory.path, profilesDirectoryName);
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String?> getProfilePath(String? id) async {
|
|
|
|
|
if (id == null) return null;
|
2025-02-03 23:32:00 +08:00
|
|
|
final directory = await profilesPath;
|
2024-04-30 23:38:49 +08:00
|
|
|
return join(directory, "$id.yaml");
|
|
|
|
|
}
|
2024-09-26 14:29:04 +08:00
|
|
|
|
2024-12-03 21:47:12 +08:00
|
|
|
Future<String?> getProvidersPath(String? id) async {
|
|
|
|
|
if (id == null) return null;
|
2025-02-03 23:32:00 +08:00
|
|
|
final directory = await profilesPath;
|
2024-12-03 21:47:12 +08:00
|
|
|
return join(directory, "providers", id);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-26 14:29:04 +08:00
|
|
|
Future<String> get tempPath async {
|
|
|
|
|
final directory = await tempDir.future;
|
|
|
|
|
return directory.path;
|
|
|
|
|
}
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final appPath = AppPath();
|