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-06-19 13:13:31 +08:00
|
|
|
Completer<Directory> cacheDir = Completer();
|
2024-08-04 08:21:14 +08:00
|
|
|
Completer<Directory> downloadDir = Completer();
|
2024-06-19 13:13:31 +08:00
|
|
|
|
|
|
|
|
// Future<Directory> _createDesktopCacheDir() async {
|
|
|
|
|
// final path = join(dirname(Platform.resolvedExecutable), 'cache');
|
|
|
|
|
// final dir = Directory(path);
|
|
|
|
|
// if (await dir.exists()) {
|
|
|
|
|
// await dir.create(recursive: true);
|
|
|
|
|
// }
|
|
|
|
|
// return dir;
|
|
|
|
|
// }
|
2024-04-30 23:38:49 +08:00
|
|
|
|
|
|
|
|
AppPath._internal() {
|
2024-06-19 13:13:31 +08:00
|
|
|
getApplicationSupportDirectory().then((value) {
|
|
|
|
|
cacheDir.complete(value);
|
|
|
|
|
});
|
2024-08-04 08:21:14 +08:00
|
|
|
getDownloadsDirectory().then((value) {
|
|
|
|
|
downloadDir.complete(value);
|
|
|
|
|
});
|
2024-06-19 13:13:31 +08:00
|
|
|
// if (Platform.isAndroid) {
|
|
|
|
|
// getApplicationSupportDirectory().then((value) {
|
|
|
|
|
// cacheDir.complete(value);
|
|
|
|
|
// });
|
|
|
|
|
// } else {
|
|
|
|
|
// _createDesktopCacheDir().then((value) {
|
|
|
|
|
// cacheDir.complete(value);
|
|
|
|
|
// });
|
|
|
|
|
// }
|
2024-04-30 23:38:49 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
factory AppPath() {
|
|
|
|
|
_instance ??= AppPath._internal();
|
|
|
|
|
return _instance!;
|
|
|
|
|
}
|
|
|
|
|
|
2024-08-04 08:21:14 +08:00
|
|
|
Future<String> getDownloadDirPath() async {
|
|
|
|
|
final directory = await downloadDir.future;
|
|
|
|
|
return directory.path;
|
|
|
|
|
}
|
|
|
|
|
|
2024-04-30 23:38:49 +08:00
|
|
|
Future<String> getHomeDirPath() async {
|
2024-06-19 13:13:31 +08:00
|
|
|
final directory = await cacheDir.future;
|
2024-04-30 23:38:49 +08:00
|
|
|
return directory.path;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<String> getProfilesPath() async {
|
2024-06-19 13:13:31 +08:00
|
|
|
final directory = await cacheDir.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;
|
|
|
|
|
final directory = await getProfilesPath();
|
|
|
|
|
return join(directory, "$id.yaml");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
final appPath = AppPath();
|