mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-15 12:53:41 +00:00
fix: incorrect storage path in linux (#270)
This commit is contained in:
9 files changed
+164
-85
No files matched your search
@@ -6,6 +6,8 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
import 'log_util.dart';
|
||||
|
||||
class Util {
|
||||
static String? _storageDir;
|
||||
|
||||
@@ -55,6 +57,16 @@ class Util {
|
||||
storageDir = (await getExternalStorageDirectory())?.path ?? storageDir;
|
||||
} else if (Platform.isIOS) {
|
||||
storageDir = (await getLibraryDirectory()).path;
|
||||
} else if (Util.isLinux()) {
|
||||
storageDir = File(Platform.resolvedExecutable).parent.path;
|
||||
// check has write permission, if not, fallback to application support dir
|
||||
try {
|
||||
final testFile = File(path.join(storageDir, ".test"));
|
||||
await testFile.writeAsString("test");
|
||||
await testFile.delete();
|
||||
} catch (e) {
|
||||
storageDir = (await getApplicationSupportDirectory()).path;
|
||||
}
|
||||
}
|
||||
_storageDir = storageDir;
|
||||
}
|
||||
@@ -63,10 +75,6 @@ class Util {
|
||||
return _storageDir!;
|
||||
}
|
||||
|
||||
static String getStorageAsset(String asset) {
|
||||
return path.join(getStorageDir(), asset);
|
||||
}
|
||||
|
||||
static isAndroid() {
|
||||
return !kIsWeb && Platform.isAndroid;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user