Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 15 additions & 9 deletions flutter/lib/benchmark/state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,15 +143,21 @@ class BenchmarkState extends ChangeNotifier {
modes: [taskRunner.perfMode, taskRunner.accuracyMode],
benchmarks: benchmarks,
);
await resourceManager.handleResources(
resources,
needToPurgeCache,
downloadMissing,
);
print('Finished loading resources with downloadMissing=$downloadMissing');
error = null;
stackTrace = null;
taskConfigFailedToLoad = false;
try {
await resourceManager.handleResources(
resources,
needToPurgeCache,
downloadMissing,
);
print('Finished loading resources with downloadMissing=$downloadMissing');
error = null;
stackTrace = null;
taskConfigFailedToLoad = false;
} on SocketException catch (e, s) {
print('Could not load resources due to error: $e');
error = e;
stackTrace = s;
}
await Wakelock.disable();
}

Expand Down
1 change: 1 addition & 0 deletions flutter/lib/l10n/app_en.arb
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
"dialogContentMissingFilesHint": "Please go to the menu Resources to download the missing files.",
"dialogContentChecksumError": "The following files failed checksum validation:",
"dialogContentNoSelectedBenchmarkError": "Please select at least one benchmark.",
"dialogNoInternetError": "A network error has occured. Please make sure you're connected to the internet.",


"benchModePerformanceOnly": "Performance Only",
Expand Down
71 changes: 39 additions & 32 deletions flutter/lib/resources/resource_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,42 +100,49 @@ class ResourceManager {
_loadingProgress = 0.001;
_done = false;
_onUpdate();
try {
var internetResources = <Resource>[];
for (final resource in resources) {
if (resource.path.startsWith(_dataPrefix)) continue;
if (isInternetResource(resource.path)) {
internetResources.add(resource);
continue;
}
throw 'forbidden path: ${resource.path} (only http://, https:// and local:// resources are allowed)';
}

var internetResources = <Resource>[];
for (final resource in resources) {
if (resource.path.startsWith(_dataPrefix)) continue;
if (isInternetResource(resource.path)) {
internetResources.add(resource);
continue;
final internetPaths = internetResources.map((e) => e.path).toList();
await cacheManager.cache(
internetPaths,
(double currentProgress, String currentPath) {
_loadingProgress = currentProgress;
_loadingPath = currentPath;
_onUpdate();
},
purgeOldCache,
downloadMissing,
);

final checksumFailed = await validateResourcesChecksum(resources);
if (checksumFailed.isNotEmpty) {
final mismatchedPaths = checksumFailed.map((e) => '\n${e.path}').join();
throw 'Checksum validation failed for: $mismatchedPaths';
}
throw 'forbidden path: ${resource.path} (only http://, https:// and local:// resources are allowed)';
}

final internetPaths = internetResources.map((e) => e.path).toList();
await cacheManager.cache(
internetPaths,
(double currentProgress, String currentPath) {
_loadingProgress = currentProgress;
_loadingPath = currentPath;
_onUpdate();
},
purgeOldCache,
downloadMissing,
);

final checksumFailed = await validateResourcesChecksum(resources);
if (checksumFailed.isNotEmpty) {
final mismatchedPaths = checksumFailed.map((e) => '\n${e.path}').join();
throw 'Checksum validation failed for: $mismatchedPaths';
// delete downloaded archives to free up disk space
await cacheManager.deleteArchives(internetPaths);

_loadingPath = '';
_loadingProgress = 1.0;
_done = true;
_onUpdate();
} catch (e) {
_loadingPath = '';
_loadingProgress = 1.0;
_done = true;
_onUpdate();
rethrow;
}

// delete downloaded archives to free up disk space
await cacheManager.deleteArchives(internetPaths);

_loadingPath = '';
_loadingProgress = 1.0;
_done = true;
_onUpdate();
}

static Future<String> getApplicationDirectory() async {
Expand Down
14 changes: 12 additions & 2 deletions flutter/lib/ui/settings/resources_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import 'package:mlperfbench/benchmark/state.dart';
import 'package:mlperfbench/localizations/app_localizations.dart';
import 'package:mlperfbench/store.dart';
import 'package:mlperfbench/ui/confirm_dialog.dart';
import 'package:mlperfbench/ui/error_dialog.dart';

class ResourcesScreen extends StatefulWidget {
const ResourcesScreen({super.key});
Expand Down Expand Up @@ -169,8 +170,17 @@ class _ResourcesScreen extends State<ResourcesScreen> {
return AbsorbPointer(
absorbing: downloading,
child: ElevatedButton(
onPressed: () {
state.loadResources(downloadMissing: true);
onPressed: () async {
await state.loadResources(downloadMissing: true);
if (state.error != null) {
// Reset both the error and stacktrace for further operation
state.error = null;
state.stackTrace = null;

if (!mounted) return;
await showErrorDialog(
context, <String>[l10n.dialogNoInternetError]);
}
},
style: ElevatedButton.styleFrom(
backgroundColor: downloading ? Colors.grey : Colors.blue),
Expand Down
Loading