added warning for failed file checksum veification

This commit is contained in:
dstark5
2024-02-04 17:26:11 +05:30
parent 73a294fb89
commit 95288271fa
7 changed files with 67 additions and 16 deletions

View File

@ -114,7 +114,7 @@ class _HomePageState extends ConsumerState<HomePage> {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
title: const Text("Openlib"),
titleTextStyle: Theme.of(context).textTheme.displayLarge,
),

View File

@ -35,7 +35,7 @@ Future<String?> _getAliveMirror(List<String> mirrors, Dio dio) async {
dio.close();
return url;
}
} catch (e) {
} catch (_) {
// print("timeOut");
}
}
@ -81,7 +81,7 @@ Future<void> downloadFile(
mirrorStatus(true);
cancelDownlaod(chunkedDownloader);
} catch (e) {
} catch (_) {
onDownlaodFailed();
}
} else {
@ -97,14 +97,11 @@ Future<bool> verifyFileCheckSum(
final file = File(filePath);
final stream = file.openRead();
final hash = await md5.bind(stream).first;
print('md5 Checksum $md5Hash');
print('file hash ${hash.toString()}');
if (md5Hash == hash.toString()) {
return true;
}
return false;
} catch (e) {
print(e);
} catch (_) {
return false;
}
}

View File

@ -74,8 +74,10 @@ class GoodReads {
?.attributes['title']
.toString()
.trim(),
thumbnail:
thumbnail.toString().replaceAll("._SY75_.", "._SY225_.")),
thumbnail: thumbnail
.toString()
.replaceAll("._SY75_.", "._SY225_.")
.replaceAll("._SX50_.", "._SX148_.")),
);
}
}

View File

@ -11,7 +11,7 @@ class AboutPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
title: const Text("Openlib"),
titleTextStyle: Theme.of(context).textTheme.displayLarge,
),

View File

@ -43,7 +43,7 @@ class BookInfoPage extends ConsumerWidget {
final bookInfo = ref.watch(bookInfoProvider(url));
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
title: const Text("Openlib"),
titleTextStyle: Theme.of(context).textTheme.displayLarge,
),
@ -311,8 +311,11 @@ class _ShowDialog extends ConsumerWidget {
if (downloadProgress == 1.0 &&
(checkSumVerifyState == CheckSumProcessState.failed ||
checkSumVerifyState == CheckSumProcessState.success)) {
Future.delayed(const Duration(seconds: 3), () {
Future.delayed(const Duration(seconds: 2), () {
Navigator.of(context).pop();
if (checkSumVerifyState == CheckSumProcessState.failed) {
_showWarningFileDialog(context);
}
});
}
@ -409,7 +412,7 @@ class _ShowDialog extends ConsumerWidget {
children: [
switch (downloadProcessState) {
ProcessState.waiting => Icon(
Icons.timer,
Icons.timer_sharp,
size: 15,
color: Theme.of(context)
.colorScheme
@ -458,7 +461,7 @@ class _ShowDialog extends ConsumerWidget {
children: [
switch (checkSumVerifyState) {
CheckSumProcessState.waiting => Icon(
Icons.timer,
Icons.timer_sharp,
size: 15,
color: Theme.of(context)
.colorScheme
@ -575,3 +578,52 @@ class _ShowDialog extends ConsumerWidget {
);
}
}
Future<void> _showWarningFileDialog(BuildContext context) async {
return showDialog<void>(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return AlertDialog(
title: Text(
'Checksum failed!',
style: TextStyle(
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
decoration: TextDecoration.none,
letterSpacing: 1),
),
content: SingleChildScrollView(
child: ListBody(
children: <Widget>[
Text(
'The downloaded book may be malicious. Delete it and get the same book from another source, or use the book at your own risk.',
style: TextStyle(
fontSize: 12,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.tertiary.withAlpha(170),
),
),
],
),
),
actions: <Widget>[
TextButton(
child: Text(
'Okay',
style: TextStyle(
fontSize: 13,
fontWeight: FontWeight.bold,
color: Theme.of(context).colorScheme.secondary,
decoration: TextDecoration.none,
letterSpacing: 1),
),
onPressed: () {
Navigator.of(context).pop();
},
),
],
);
},
);
}

View File

@ -15,7 +15,7 @@ class BookPage extends StatelessWidget {
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
title: const Text("Openlib"),
titleTextStyle: Theme.of(context).textTheme.displayLarge,
),

View File

@ -20,7 +20,7 @@ class ResultPage extends ConsumerWidget {
return Scaffold(
appBar: AppBar(
backgroundColor: Theme.of(context).colorScheme.primary,
backgroundColor: Theme.of(context).colorScheme.background,
title: const Text("Openlib"),
titleTextStyle: Theme.of(context).textTheme.displayLarge,
),