mirror of
https://github.com/localsend/localsend.git
synced 2026-08-07 07:14:52 +00:00
40 lines
1.4 KiB
Dart
40 lines
1.4 KiB
Dart
import 'dart:io' show Directory, Platform;
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:path_provider/path_provider.dart' as path;
|
|
|
|
Future<String> getDefaultDestinationDirectory() async {
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.android:
|
|
final dir = await path.getDownloadsDirectory();
|
|
return dir?.path ?? '/storage/emulated/0/Download';
|
|
case TargetPlatform.iOS:
|
|
return (await path.getApplicationDocumentsDirectory()).path;
|
|
case TargetPlatform.linux:
|
|
case TargetPlatform.macOS:
|
|
case TargetPlatform.windows:
|
|
case TargetPlatform.fuchsia:
|
|
var downloadDir = await path.getDownloadsDirectory();
|
|
if (downloadDir == null) {
|
|
if (defaultTargetPlatform == TargetPlatform.windows) {
|
|
downloadDir = Directory('${Platform.environment['HOMEPATH']}/Downloads');
|
|
if (!downloadDir.existsSync()) {
|
|
downloadDir = Directory(Platform.environment['HOMEPATH']!);
|
|
}
|
|
} else {
|
|
downloadDir = Directory('${Platform.environment['HOME']}/Downloads');
|
|
if (!downloadDir.existsSync()) {
|
|
downloadDir = Directory(Platform.environment['HOME']!);
|
|
}
|
|
}
|
|
}
|
|
return downloadDir.path.replaceAll('\\', '/');
|
|
}
|
|
}
|
|
|
|
Future<String> getCacheDirectory() async {
|
|
final dir = await path.getTemporaryDirectory();
|
|
await dir.create(recursive: true);
|
|
return dir.path;
|
|
}
|