mirror of
https://github.com/GopeedLab/gopeed.git
synced 2026-11-13 20:03:46 +00:00
feat: extension support (#78)
This commit is contained in:
118 files changed
+6971
-780
No files matched your search
@@ -3,8 +3,23 @@ import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
|
||||
class Util {
|
||||
static String? _storageDir;
|
||||
|
||||
static String cleanPath(String path) {
|
||||
path = path.replaceAll(RegExp(r'\\'), "/");
|
||||
if (path.startsWith(".")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
static String safeDir(String path) {
|
||||
if (path == "." || path == "./" || path == ".\\") {
|
||||
return "";
|
||||
@@ -33,6 +48,24 @@ class Util {
|
||||
}
|
||||
}
|
||||
|
||||
static Future<void> initStorageDir() async {
|
||||
var storageDir = "./";
|
||||
if (Platform.isAndroid) {
|
||||
storageDir = (await getExternalStorageDirectory())?.path ?? storageDir;
|
||||
} else if (Platform.isIOS) {
|
||||
storageDir = (await getLibraryDirectory()).path;
|
||||
}
|
||||
_storageDir = storageDir;
|
||||
}
|
||||
|
||||
static String getStorageDir() {
|
||||
return _storageDir!;
|
||||
}
|
||||
|
||||
static String getStorageAsset(String asset) {
|
||||
return path.join(getStorageDir(), asset);
|
||||
}
|
||||
|
||||
static isAndroid() {
|
||||
return !kIsWeb && Platform.isAndroid;
|
||||
}
|
||||
@@ -76,7 +109,7 @@ class Util {
|
||||
return [];
|
||||
}
|
||||
const ls = LineSplitter();
|
||||
return ls.convert(text);
|
||||
return ls.convert(text).where((line) => line.isNotEmpty).toList();
|
||||
}
|
||||
|
||||
// if one future complete, return the result, only all future error, return the last error
|
||||
|
||||
Reference in new issue
Block a user