Pato05
f126ffef46
use get_url api by default, and fall back to old generation if get_url failed start to write a better cachemanager to implement in all systems write in more appropriate directories on windows and linux improve check for Connectivity by adding a fallback (needed for example on linux systems without NetworkManager) allow to dynamically change track quality without rebuilding the object
50 lines
1.6 KiB
Dart
50 lines
1.6 KiB
Dart
import 'dart:io';
|
|
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:path/path.dart' as path;
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
class Paths {
|
|
static Future<String> dataDirectory() async {
|
|
switch (defaultTargetPlatform) {
|
|
case TargetPlatform.linux:
|
|
final home = Platform.environment['HOME'];
|
|
if (home == null) return path.dirname(Platform.resolvedExecutable);
|
|
if (await Directory(path.join(home, '.local', 'share')).exists()) {
|
|
final target =
|
|
await Directory(path.join(home, '.local', 'share', 'freezer'))
|
|
.create();
|
|
return target.path;
|
|
}
|
|
return path.dirname(Platform.resolvedExecutable);
|
|
case TargetPlatform.windows:
|
|
String? home = Platform.environment['USERPROFILE'];
|
|
if (home == null) {
|
|
final drive = Platform.environment['HOMEDRIVE'];
|
|
final homepath = Platform.environment['HOMEPATH'];
|
|
if (drive == null || homepath == null) {
|
|
return path.dirname(Platform.resolvedExecutable);
|
|
}
|
|
|
|
home = drive + homepath;
|
|
}
|
|
|
|
final target =
|
|
await Directory(path.join(home, 'AppData', 'Freezer')).create();
|
|
return target.path;
|
|
default:
|
|
return (await getApplicationDocumentsDirectory()).path;
|
|
}
|
|
}
|
|
|
|
static Future<String> cacheDir() async {
|
|
if (Platform.isLinux || Platform.isWindows) {
|
|
final dataDir = await dataDirectory();
|
|
final target = await Directory(path.join(dataDir, 'cache')).create();
|
|
return target.path;
|
|
}
|
|
|
|
return (await getTemporaryDirectory()).path;
|
|
}
|
|
}
|