import 'dart:async'; import 'dart:io'; import 'package:fl_clash/common/common.dart'; import 'package:path/path.dart'; import 'package:path_provider/path_provider.dart'; class AppPath { static AppPath? _instance; Completer dataDir = Completer(); Completer downloadDir = Completer(); Completer tempDir = Completer(); Completer cacheDir = Completer(); late String appDirPath; AppPath._internal() { appDirPath = join(dirname(Platform.resolvedExecutable)); getApplicationSupportDirectory().then((value) { dataDir.complete(value); }); getTemporaryDirectory().then((value) { tempDir.complete(value); }); getDownloadsDirectory().then((value) { downloadDir.complete(value); }); getApplicationCacheDirectory().then((value) { cacheDir.complete(value); }); } factory AppPath() { _instance ??= AppPath._internal(); return _instance!; } String get executableExtension { return system.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'); } Future get downloadDirPath async { final directory = await downloadDir.future; return directory.path; } Future get homeDirPath async { final directory = await dataDir.future; return directory.path; } Future get databasePath async { final mHomeDirPath = await homeDirPath; return join(mHomeDirPath, 'database.sqlite'); } Future get backupFilePath async { final mHomeDirPath = await homeDirPath; return join(mHomeDirPath, 'backup.zip'); } Future get restoreDirPath async { final mHomeDirPath = await homeDirPath; return join(mHomeDirPath, 'restore'); } Future get tempFilePath async { final mTempDir = await tempDir.future; return join(mTempDir.path, 'temp${utils.id}'); } Future get lockFilePath async { final homeDirPath = await appPath.homeDirPath; return join(homeDirPath, 'FlClash.lock'); } Future get configFilePath async { final mHomeDirPath = await homeDirPath; return join(mHomeDirPath, 'config.yaml'); } Future get sharedFilePath async { final mHomeDirPath = await homeDirPath; return join(mHomeDirPath, 'shared.json'); } Future get sharedPreferencesPath async { final directory = await dataDir.future; return join(directory.path, 'shared_preferences.json'); } Future get profilesPath async { final directory = await dataDir.future; return join(directory.path, profilesDirectoryName); } Future getProfilePath(String fileName) async { return join(await profilesPath, '$fileName.yaml'); } Future get scriptsDirPath async { final path = await homeDirPath; return join(path, 'scripts'); } Future getScriptPath(String fileName) async { final path = await scriptsDirPath; return join(path, '$fileName.js'); } Future getIconsCacheDir() async { final directory = await cacheDir.future; return join(directory.path, 'icons'); } Future getProvidersRootPath() async { final directory = await profilesPath; return join(directory, 'providers'); } Future getProvidersDirPath(String id) async { final directory = await profilesPath; return join(directory, 'providers', id); } Future getProvidersFilePath( String id, String type, String url, ) async { final directory = await profilesPath; return join(directory, 'providers', id, type, url.toMd5()); } Future get tempPath async { final directory = await tempDir.future; return directory.path; } } final appPath = AppPath();