Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

migrate deprecated assets loader

Predidit2ae0f0850921
diff --git a/lib/plugins/plugins_controller.dart b/lib/plugins/plugins_controller.dart
index e1b93564..432ebe2c 100644
--- a/lib/plugins/plugins_controller.dart
+++ b/lib/plugins/plugins_controller.dart
@@ -1,7 +1,7 @@
import 'dart:io';
import 'dart:convert';
import 'package:mobx/mobx.dart';
-import 'package:flutter/services.dart' show rootBundle;
+import 'package:flutter/services.dart' show rootBundle, AssetManifest;
import 'package:path_provider/path_provider.dart';
import 'package:kazumi/plugins/plugins.dart';
import 'package:kazumi/plugins/plugin_validity_tracker.dart';
@@ -14,7 +14,6 @@ import 'package:kazumi/request/api.dart';
part 'plugins_controller.g.dart';
-
// 从 1.5.1 版本开始,规则文件储存在单一的 plugins.json 文件中。
// 之前的版本中,规则以分离文件形式存储,版本更新后将这些分离文件合并为单一的 plugins.json 文件。
@@ -34,7 +33,7 @@ abstract class _PluginsController with Store {
final installTimeTracker = PluginInstallTimeTracker();
String pluginsFileName = "plugins.json";
-
+
Directory? oldPluginDirectory;
Directory? newPluginDirectory;
@@ -56,13 +55,15 @@ abstract class _PluginsController with Store {
// Loads all plugins from the directory, populates the plugin list, and saves to plugins.json if needed
Future<void> loadAllPlugins() async {
pluginList.clear();
- KazumiLogger().log(Level.info, 'Plugins Directory: ${newPluginDirectory!.path}');
+ KazumiLogger()
+ .log(Level.info, 'Plugins Directory: ${newPluginDirectory!.path}');
if (await newPluginDirectory!.exists()) {
final pluginsFile = File('${newPluginDirectory!.path}/$pluginsFileName');
if (await pluginsFile.exists()) {
final jsonString = await pluginsFile.readAsString();
pluginList.addAll(getPluginListFromJson(jsonString));
- KazumiLogger().log(Level.info, 'Current Plugin number: ${pluginList.length}');
+ KazumiLogger()
+ .log(Level.info, 'Current Plugin number: ${pluginList.length}');
} else {
// No plugins.json
var jsonFiles = await getPluginFiles();
@@ -97,11 +98,10 @@ abstract class _PluginsController with Store {
// Copies plugin JSON files from the assets to the plugin directory
Future<void> copyPluginsToExternalDirectory() async {
- final manifestContent = await rootBundle.loadString('AssetManifest.json');
- final Map<String, dynamic> manifestMap = json.decode(manifestContent);
-
- final jsonFiles = manifestMap.keys.where((String key) =>
- key.startsWith('assets/plugins/') && key.endsWith('.json'));
+ final assetManifest = await AssetManifest.loadFromAssetBundle(rootBundle);
+ final assets = assetManifest.listAssets();
+ final jsonFiles = assets.where((String asset) =>
+ asset.startsWith('assets/plugins/') && asset.endsWith('.json'));
for (var filePath in jsonFiles) {
final jsonString = await rootBundle.loadString(filePath);
@@ -109,8 +109,8 @@ abstract class _PluginsController with Store {
pluginList.add(plugin);
}
await savePlugins();
- KazumiLogger().log(
- Level.info, '${jsonFiles.length} plugin files copied to ${newPluginDirectory!.path}');
+ KazumiLogger().log(Level.info,
+ '${jsonFiles.length} plugin files copied to ${newPluginDirectory!.path}');
}
List<dynamic> pluginListToJson() {
diff --git a/lib/shaders/shaders_controller.dart b/lib/shaders/shaders_controller.dart
index 003313b5..d54f0ea7 100644
--- a/lib/shaders/shaders_controller.dart
+++ b/lib/shaders/shaders_controller.dart
@@ -1,7 +1,6 @@
import 'dart:io';
-import 'dart:convert';
import 'package:mobx/mobx.dart';
-import 'package:flutter/services.dart' show rootBundle;
+import 'package:flutter/services.dart' show rootBundle, AssetManifest;
import 'package:path_provider/path_provider.dart';
import 'package:logger/logger.dart';
import 'package:path/path.dart' as path;
@@ -15,18 +14,19 @@ abstract class _ShadersController with Store {
late Directory shadersDirectory;
Future<void> copyShadersToExternalDirectory() async {
- final manifestContent = await rootBundle.loadString('AssetManifest.json');
- final Map<String, dynamic> manifestMap = json.decode(manifestContent);
+ final assetManifest = await AssetManifest.loadFromAssetBundle(rootBundle);
+ final assets = assetManifest.listAssets();
final directory = await getApplicationSupportDirectory();
shadersDirectory = Directory(path.join(directory.path, 'anime_shaders'));
if (!await shadersDirectory.exists()) {
await shadersDirectory.create(recursive: true);
- KazumiLogger().log(Level.info, 'Create GLSL Shader: ${shadersDirectory.path}');
+ KazumiLogger()
+ .log(Level.info, 'Create GLSL Shader: ${shadersDirectory.path}');
}
- final shaderFiles = manifestMap.keys.where((String key) =>
- key.startsWith('assets/shaders/') && key.endsWith('.glsl'));
+ final shaderFiles = assets.where((String asset) =>
+ asset.startsWith('assets/shaders/') && asset.endsWith('.glsl'));
int copiedFilesCount = 0;
@@ -34,7 +34,8 @@ abstract class _ShadersController with Store {
final fileName = filePath.split('/').last;
final targetFile = File(path.join(shadersDirectory.path, fileName));
if (await targetFile.exists()) {
- KazumiLogger().log(Level.info, 'GLSL Shader exists, skip: ${targetFile.path}');
+ KazumiLogger()
+ .log(Level.info, 'GLSL Shader exists, skip: ${targetFile.path}');
continue;
}
@@ -49,7 +50,7 @@ abstract class _ShadersController with Store {
}
}
- KazumiLogger().log(
- Level.info, '$copiedFilesCount GLSL files copied to ${shadersDirectory.path}');
+ KazumiLogger().log(Level.info,
+ '$copiedFilesCount GLSL files copied to ${shadersDirectory.path}');
}
}