Add file hash comparison to optimize asset copying in aniyomiBridge
This commit is contained in:
Binary file not shown.
@@ -57,6 +57,14 @@ packages:
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "1.19.1"
|
||||
crypto:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: crypto
|
||||
sha256: c8ea0233063ba03258fbcf2ca4d6dadfefe14f02fab57702265467a19f27fadf
|
||||
url: "https://pub.dev"
|
||||
source: hosted
|
||||
version: "3.0.7"
|
||||
cupertino_icons:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
||||
@@ -10,6 +10,7 @@ import 'package:k3vinb5_aniyomi_bridge/models/extension.dart';
|
||||
import 'package:logger/logger.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:path/path.dart' as path;
|
||||
import 'package:crypto/crypto.dart';
|
||||
import 'package:k3vinb5_aniyomi_bridge/jmodels/jvideo.dart';
|
||||
import 'package:k3vinb5_aniyomi_bridge/jmodels/jsanime.dart';
|
||||
import 'package:k3vinb5_aniyomi_bridge/jmodels/jsepisode.dart';
|
||||
@@ -369,7 +370,19 @@ class AniyomiBridge {
|
||||
_aniyomiBridgeJarName,
|
||||
);
|
||||
File aniyomiBridgeCore = File(aniyomiBridgeCorePath);
|
||||
bool needsCopy = false;
|
||||
if (!(await aniyomiBridgeCore.exists())) {
|
||||
needsCopy = true;
|
||||
} else {
|
||||
String assetPath = "$_packageAssetsDir/$_aniyomiBridgeJarName";
|
||||
String existingFileHash = await _computeFileHash(aniyomiBridgeCore);
|
||||
String assetHash = await _computeAssetHash(assetPath);
|
||||
if (existingFileHash != assetHash) {
|
||||
needsCopy = true;
|
||||
}
|
||||
}
|
||||
if (needsCopy) {
|
||||
_logger.i("Copying new aniyomiBridgeCore binary to $aniyomiBridgeCorePath");
|
||||
await _copyAssetToFile(
|
||||
"$_packageAssetsDir/$_aniyomiBridgeJarName",
|
||||
aniyomiBridgeCorePath,
|
||||
@@ -377,6 +390,19 @@ class AniyomiBridge {
|
||||
}
|
||||
}
|
||||
|
||||
Future<String> _computeFileHash(File file) async {
|
||||
final bytes = await file.readAsBytes();
|
||||
final digest = sha256.convert(bytes);
|
||||
return digest.toString();
|
||||
}
|
||||
|
||||
Future<String> _computeAssetHash(String assetPath) async {
|
||||
final byteData = await rootBundle.load(assetPath);
|
||||
final bytes = byteData.buffer.asUint8List();
|
||||
final digest = sha256.convert(bytes);
|
||||
return digest.toString();
|
||||
}
|
||||
|
||||
Future<File> _copyAssetToFile(String assetPath, String outPath) async {
|
||||
final byteData = await rootBundle.load(assetPath);
|
||||
final buffer = byteData.buffer.asUint8List();
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
name: k3vinb5_aniyomi_bridge
|
||||
description: "A new Flutter package project."
|
||||
version: 0.0.1
|
||||
homepage:
|
||||
|
||||
environment:
|
||||
sdk: ^3.8.1
|
||||
@@ -10,11 +9,15 @@ environment:
|
||||
dependencies:
|
||||
flutter:
|
||||
sdk: flutter
|
||||
# FFI / Native Integration
|
||||
jni: ^0.14.2
|
||||
jnigen: ^0.14.2
|
||||
# Logger
|
||||
logger: ^2.6.2
|
||||
# Storage
|
||||
path: ^1.9.1
|
||||
path_provider: ^2.1.5
|
||||
crypto: ^3.0.7
|
||||
|
||||
dev_dependencies:
|
||||
flutter_test:
|
||||
|
||||
Reference in New Issue
Block a user