1010 JSON: TJSONObject;
1111 Queue: TStringArray;
1212 URL: String;
13+ Timeout: TCountDown;
1314 end;
1415
1516function TWLAssets.GetJSON(url: String): TJSONObject;
6667 idx: Integer;
6768begin
6869 if not InRange(result.Response.AsInteger, 200, 299) then
69- raise GetDebugLn('WLAssets', result.Exception);
70+ begin
71+ WriteLn GetDebugLn('WLAssets', result.Exception, ELogLevel.ERROR);
72+ raise GetDebugLn('WLAssets', 'If you keep having issues please delete your Assets and Cache folders.');
73+ end;
7074 idx := Self.Queue.IndexOf(result.Data);
7175 if idx = -1 then
7276 raise GetDebugLn('WLAssets', 'Can''t find ' + result.Data + ' in the download queue.');
7377 Delete(Self.Queue, idx, 1);
78+ Self.Timeout.Extend(-18 * ONE_SECOND);
7479end;
7580
7681procedure TWLAssets.Update();
7782var
7883 i: Integer;
79- timer, timeout : TCountDown;
84+ timer: TCountDown;
8085 key, path: String;
8186begin
8287 Self.JSON := Self.GetJSON('https://db.waspscripts.dev/storage/v1/object/public/data/');
9196 FileDelete(WLEnv.AssetsDir + 'hashes.json');
9297 TJSONParser(Self.JSON).Save(WLEnv.AssetsDir + 'hashes.json');
9398
94- timeout. Start(10 );
99+ Self.Timeout. Start(1 );
95100 for i := 0 to Self.JSON.Count-1 do
96101 begin
97102 key := Self.JSON.Key[i];
@@ -103,7 +108,7 @@ begin
103108 FileDelete(path);
104109 DirCreate(PathExtractDir(path));
105110 Self.Queue += path;
106- timeout .Extend(20 * ONE_SECOND);
111+ Self.Timeout .Extend(20 * ONE_SECOND);
107112 Async.HTTPGetFile(Self.URL + key, path, @Self.DownloadFinished);
108113 end;
109114 end;
@@ -116,12 +121,13 @@ begin
116121 if timer.IsFinished then
117122 begin
118123 WriteLn GetDebugLn('WLAssets', 'Downloading files. ' + ToStr(Length(Self.Queue)) + ' files left, please wait.');
119- WriteLn GetDebugLn('WLAssets', 'Files left: ' + ToStr(Self.Queue));
124+ WriteLn GetDebugLn('WLAssets', 'Files left: ' + ToStr(Self.Queue).Replace(WLEnv.AssetsDir, '') );
120125 timer.Restart();
121126 end;
122127
123- if timeout .IsFinished then
128+ if Self.Timeout .IsFinished then
124129 begin
130+ if Self.Queue = [] then Exit;
125131 for i := 0 to High(Self.Queue) do
126132 FileDelete(Self.Queue[i]);
127133 raise GetDebugLn('WLAssets', 'Timed out downloading assets: ' + ToStr(Self.Queue));
0 commit comments