mirror of
https://github.com/venera-app/venera.git
synced 2025-09-27 15:57:25 +00:00
Feat/saf (#81)
* [Android] Use SAF to change local path * Use IOOverrides to replace openDirectoryPlatform and openFilePlatform * fix io
This commit is contained in:
@@ -1,5 +1,4 @@
|
||||
import 'dart:async' show Future, StreamController, scheduleMicrotask;
|
||||
import 'dart:collection';
|
||||
import 'dart:convert';
|
||||
import 'dart:ui' as ui show Codec;
|
||||
import 'dart:ui';
|
||||
@@ -108,7 +107,7 @@ abstract class BaseImageProvider<T extends BaseImageProvider<T>>
|
||||
}
|
||||
}
|
||||
|
||||
static final _cache = LinkedHashMap<String, Uint8List>();
|
||||
static final _cache = <String, Uint8List>{};
|
||||
|
||||
static var _cacheSize = 0;
|
||||
|
||||
|
@@ -1,5 +1,4 @@
|
||||
import 'dart:async' show Future, StreamController;
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:venera/network/images.dart';
|
||||
@@ -25,7 +24,7 @@ class CachedImageProvider
|
||||
@override
|
||||
Future<Uint8List> load(StreamController<ImageChunkEvent> chunkEvents) async {
|
||||
if(url.startsWith("file://")) {
|
||||
var file = openFilePlatform(url.substring(7));
|
||||
var file = File(url.substring(7));
|
||||
return file.readAsBytes();
|
||||
}
|
||||
await for (var progress in ImageDownloader.loadThumbnail(url, sourceKey, cid)) {
|
||||
|
@@ -71,7 +71,7 @@ class LocalComic with HistoryMixin implements Comic {
|
||||
downloadedChapters = List.from(jsonDecode(row[8] as String)),
|
||||
createdAt = DateTime.fromMillisecondsSinceEpoch(row[9] as int);
|
||||
|
||||
File get coverFile => openFilePlatform(FilePath.join(
|
||||
File get coverFile => File(FilePath.join(
|
||||
baseDir,
|
||||
cover,
|
||||
));
|
||||
@@ -151,6 +151,8 @@ class LocalManager with ChangeNotifier {
|
||||
/// path to the directory where all the comics are stored
|
||||
late String path;
|
||||
|
||||
Directory get directory => Directory(path);
|
||||
|
||||
// return error message if failed
|
||||
Future<String?> setNewPath(String newPath) async {
|
||||
var newDir = Directory(newPath);
|
||||
@@ -162,7 +164,7 @@ class LocalManager with ChangeNotifier {
|
||||
}
|
||||
try {
|
||||
await copyDirectoryIsolate(
|
||||
Directory(path),
|
||||
directory,
|
||||
newDir,
|
||||
);
|
||||
await File(FilePath.join(App.dataPath, 'local_path')).writeAsString(newPath);
|
||||
@@ -170,7 +172,7 @@ class LocalManager with ChangeNotifier {
|
||||
Log.error("IO", e, s);
|
||||
return e.toString();
|
||||
}
|
||||
await Directory(path).deleteIgnoreError(recursive:true);
|
||||
await directory.deleteContents(recursive: true);
|
||||
path = newPath;
|
||||
return null;
|
||||
}
|
||||
@@ -217,15 +219,15 @@ class LocalManager with ChangeNotifier {
|
||||
''');
|
||||
if (File(FilePath.join(App.dataPath, 'local_path')).existsSync()) {
|
||||
path = File(FilePath.join(App.dataPath, 'local_path')).readAsStringSync();
|
||||
if (!Directory(path).existsSync()) {
|
||||
if (!directory.existsSync()) {
|
||||
path = await findDefaultPath();
|
||||
}
|
||||
} else {
|
||||
path = await findDefaultPath();
|
||||
}
|
||||
try {
|
||||
if (!Directory(path).existsSync()) {
|
||||
await Directory(path).create();
|
||||
if (!directory.existsSync()) {
|
||||
await directory.create();
|
||||
}
|
||||
}
|
||||
catch(e, s) {
|
||||
@@ -354,12 +356,12 @@ class LocalManager with ChangeNotifier {
|
||||
throw "Invalid ep";
|
||||
}
|
||||
var comic = find(id, type) ?? (throw "Comic Not Found");
|
||||
var directory = openDirectoryPlatform(comic.baseDir);
|
||||
var directory = Directory(comic.baseDir);
|
||||
if (comic.chapters != null) {
|
||||
var cid = ep is int
|
||||
? comic.chapters!.keys.elementAt(ep - 1)
|
||||
: (ep as String);
|
||||
directory = openDirectoryPlatform(FilePath.join(directory.path, cid));
|
||||
directory = Directory(FilePath.join(directory.path, cid));
|
||||
}
|
||||
var files = <File>[];
|
||||
await for (var entity in directory.list()) {
|
||||
@@ -406,10 +408,10 @@ class LocalManager with ChangeNotifier {
|
||||
String id, ComicType type, String name) async {
|
||||
var comic = find(id, type);
|
||||
if (comic != null) {
|
||||
return openDirectoryPlatform(FilePath.join(path, comic.directory));
|
||||
return Directory(FilePath.join(path, comic.directory));
|
||||
}
|
||||
var dir = findValidDirectoryName(path, name);
|
||||
return openDirectoryPlatform(FilePath.join(path, dir)).create().then((value) => value);
|
||||
return Directory(FilePath.join(path, dir)).create().then((value) => value);
|
||||
}
|
||||
|
||||
void completeTask(DownloadTask task) {
|
||||
@@ -468,7 +470,7 @@ class LocalManager with ChangeNotifier {
|
||||
|
||||
void deleteComic(LocalComic c, [bool removeFileOnDisk = true]) {
|
||||
if(removeFileOnDisk) {
|
||||
var dir = openDirectoryPlatform(FilePath.join(path, c.directory));
|
||||
var dir = Directory(FilePath.join(path, c.directory));
|
||||
dir.deleteIgnoreError(recursive: true);
|
||||
}
|
||||
//Deleting a local comic means that it's nolonger available, thus both favorite and history should be deleted.
|
||||
|
Reference in New Issue
Block a user