@@ -100,42 +100,47 @@ class ResourceManager {
100100 _loadingProgress = 0.001 ;
101101 _done = false ;
102102 _onUpdate ();
103-
104- var internetResources = < Resource > [];
105- for (final resource in resources) {
106- if (resource.path.startsWith (_dataPrefix)) continue ;
107- if (isInternetResource (resource.path)) {
108- internetResources.add (resource);
109- continue ;
103+ try {
104+ var internetResources = < Resource > [];
105+ for (final resource in resources) {
106+ if (resource.path.startsWith (_dataPrefix)) continue ;
107+ if (isInternetResource (resource.path)) {
108+ internetResources.add (resource);
109+ continue ;
110+ }
111+ throw 'forbidden path: ${resource .path } (only http://, https:// and local:// resources are allowed)' ;
110112 }
111- throw 'forbidden path: ${resource .path } (only http://, https:// and local:// resources are allowed)' ;
112- }
113113
114- final internetPaths = internetResources.map ((e) => e.path).toList ();
115- await cacheManager.cache (
116- internetPaths,
117- (double currentProgress, String currentPath) {
118- _loadingProgress = currentProgress;
119- _loadingPath = currentPath;
120- _onUpdate ();
121- },
122- purgeOldCache,
123- downloadMissing,
124- );
125-
126- final checksumFailed = await validateResourcesChecksum (resources);
127- if (checksumFailed.isNotEmpty) {
128- final mismatchedPaths = checksumFailed.map ((e) => '\n ${e .path }' ).join ();
129- throw 'Checksum validation failed for: $mismatchedPaths ' ;
130- }
114+ final internetPaths = internetResources.map ((e) => e.path).toList ();
115+ try {
116+ await cacheManager.cache (
117+ internetPaths,
118+ (double currentProgress, String currentPath) {
119+ _loadingProgress = currentProgress;
120+ _loadingPath = currentPath;
121+ _onUpdate ();
122+ },
123+ purgeOldCache,
124+ downloadMissing,
125+ );
126+ } on SocketException {
127+ throw 'A network error has occurred. Please make sure you are connected to the internet.' ;
128+ }
131129
132- // delete downloaded archives to free up disk space
133- await cacheManager.deleteArchives (internetPaths);
130+ final checksumFailed = await validateResourcesChecksum (resources);
131+ if (checksumFailed.isNotEmpty) {
132+ final mismatchedPaths = checksumFailed.map ((e) => '\n ${e .path }' ).join ();
133+ throw 'Checksum validation failed for: $mismatchedPaths ' ;
134+ }
134135
135- _loadingPath = '' ;
136- _loadingProgress = 1.0 ;
137- _done = true ;
138- _onUpdate ();
136+ // delete downloaded archives to free up disk space
137+ await cacheManager.deleteArchives (internetPaths);
138+ } finally {
139+ _loadingPath = '' ;
140+ _loadingProgress = 1.0 ;
141+ _done = true ;
142+ _onUpdate ();
143+ }
139144 }
140145
141146 static Future <String > getApplicationDirectory () async {
0 commit comments