Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_DownloadSequence.c
Go to the documentation of this file.
1
9
10//-----------------------------------------------------------------------------------------------
13
14//-----------------------------------------------------------------------------------------------
15void ScriptInvoker_DownloadSequenceDependencies(SCR_DownloadSequence sequence, array<ref SCR_WorkshopItem> dependencies);
17
18//------------------------------------------------------------------------------------------------
20{
21 // When true, we will subscribe automatically when download is started
22 protected bool m_bSubscribeToAddons;
23
24 protected ref array<ref SCR_WorkshopItem> m_aDependencies = {};
25 protected bool m_bWaitingResponse; // Set to false when data fetching is complete
26 protected bool m_bCanceled; // When true, finishing data reception will not trigger further downloading or other actions.
27 protected bool m_bFailed; // True when failed due to timeour or error
28 protected bool m_bRestrictedAddons;
29 protected bool m_bBlockedAddons;
30 protected bool m_bPatchSizeLoaded;
31
32 // True - skip loading of addon details which speed up loading time, useful for getting downloading list like in Server broweser
33 protected bool m_bSkipDetails;
34
35//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
36// No need for = 0, it's the default value for ints already
37
40
41 protected int m_iPatchesLoaded = 0;
42
43//---- REFACTOR NOTE END ----
44
45 protected ref array<ref SCR_BackendCallbackWorkshopItem> m_aPatchSizeCallbacks = {};
46
47 protected ref array<ref SCR_WorkshopItem> m_aDependenciesIssues = {};
48
49 //------------------------------------------------------------------------------------------------
50 // Invokers
51 //------------------------------------------------------------------------------------------------
52
53 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnInit;
54 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnDetailsLoaded;
55 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnDependenciesLoaded;
56 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies> m_OnRestrictedDependencies;
57 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies> m_OnDependenciesLoadingPrevented;
58 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnError;
59 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnReady;
60
61 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnCancel;
62 protected ref ScriptInvokerBase<ScriptInvoker_DownloadSequence> m_OnDestroyed;
63
64 //------------------------------------------------------------------------------------------------
65 ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies> GetOnRestrictedDependency()
66 {
68 m_OnRestrictedDependencies = new ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies>();
69
71 }
72
73 //------------------------------------------------------------------------------------------------
74 ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies> GetOnDependenciesLoadingPrevented()
75 {
77 m_OnDependenciesLoadingPrevented = new ScriptInvokerBase<ScriptInvoker_DownloadSequenceDependencies>();
78
80 }
81
82 //------------------------------------------------------------------------------------------------
83 ScriptInvokerBase<ScriptInvoker_DownloadSequence> GetOnError()
84 {
85 if (!m_OnError)
86 m_OnError = new ScriptInvokerBase<ScriptInvoker_DownloadSequence>();
87
88 return m_OnError;
89 }
90
91 //------------------------------------------------------------------------------------------------
92 ScriptInvokerBase<ScriptInvoker_DownloadSequence> GetOnReady()
93 {
94 if (!m_OnReady)
95 m_OnReady = new ScriptInvokerBase<ScriptInvoker_DownloadSequence>();
96
97 return m_OnReady;
98 }
99
100 //------------------------------------------------------------------------------------------------
101 ScriptInvokerBase<ScriptInvoker_DownloadSequence> GetOnCancel()
102 {
103 if (!m_OnCancel)
104 m_OnCancel = new ScriptInvokerBase<ScriptInvoker_DownloadSequence>();
105
106 return m_OnCancel;
107 }
108
109 //------------------------------------------------------------------------------------------------
110 // Public
111 //------------------------------------------------------------------------------------------------
112
113 //------------------------------------------------------------------------------------------------
114 static SCR_DownloadSequence Create(array<ref SCR_WorkshopItem> dependencies, SCR_DownloadSequence previous, bool skipDetails = false)
115 {
116 if (previous && previous.m_bWaitingResponse)
117 return previous;
118
120 sequence.Setup(dependencies, skipDetails);
121
122 return sequence;
123 }
124
125 //------------------------------------------------------------------------------------------------
126 // Call on creating to start download sequence
127 // Start load details
128 void Init()
129 {
130 m_bWaitingResponse = true;
131 m_bRestrictedAddons = false;
132 m_bBlockedAddons = false;
133
134 // Skip details loading
135 if (m_bSkipDetails)
136 {
138 return;
139 }
140
141 // Load
143 }
144
145//---- REFACTOR NOTE START: This code will need to be refactored as current implementation is not conforming to the standards ----
146// A comment on top of the class states "This class only solves functionality, not UI " ...and then it does UI
147
148 //------------------------------------------------------------------------------------------------
152 {
153 array<ref SCR_WorkshopItem> restrictedDependencies = SCR_AddonManager.SelectItemsBasic(m_aDependencies, EWorkshopItemQuery.RESTRICTED);
154 SCR_AddonListDialog addonsDialog = SCR_AddonListDialog.CreateRestrictedAddonsDownload(restrictedDependencies);
155
156 // Handle cancel reports done
157 SCR_ReportedAddonsDialog reportedDialog = SCR_ReportedAddonsDialog.Cast(addonsDialog);
158 if (reportedDialog)
159 reportedDialog.GetOnAllReportsCanceled().Insert(OnAllReportsCanceled);
160
161 return reportedDialog;
162 }
163
164//---- REFACTOR NOTE END ----
165
166 //------------------------------------------------------------------------------------------------
168 void Cancel()
169 {
170 m_bCanceled = true;
171 m_bWaitingResponse = false;
172
173 if (m_OnCancel)
174 m_OnCancel.Invoke(this);
175 }
176
177 //------------------------------------------------------------------------------------------------
178 // Protected
179 //------------------------------------------------------------------------------------------------
180
181 //------------------------------------------------------------------------------------------------
183 protected void Setup(notnull array<ref SCR_WorkshopItem> dependencies, bool skipDetails)
184 {
186 m_bSkipDetails = skipDetails;
187
188 foreach (SCR_WorkshopItem dependency : dependencies)
189 {
190 m_aDependencies.Insert(dependency);
191 }
192 }
193
194 //------------------------------------------------------------------------------------------------
196 protected bool HasAllDetails()
197 {
199 return false;
200
202 return false;
203
204 return true;
205 }
206
207 //------------------------------------------------------------------------------------------------
208 // Load all dependencies details in list
209 protected void LoadDependenciesDetails()
210 {
212
213 // No dependenciees - Skip dependency loading
214 if (m_aDependencies.IsEmpty())
215 {
217 return;
218 }
219
220 // Load details of all dependencies
221 foreach (SCR_WorkshopItem dep : m_aDependencies)
222 {
223 // Skip loaded
224 if (dep.GetDetailsLoaded() || dep.GetOffline())
225 {
227 continue;
228 }
229
230 // Setup callbacks and load details
231 dep.m_OnGetAsset.Insert(OnDependencyDetailsLoaded);
232 dep.m_OnError.Insert(OnItemError);
233 dep.m_OnTimeout.Insert(OnItemError);
234
235 dep.LoadDetails();
236 }
237 }
238
239 //------------------------------------------------------------------------------------------------
242 {
244
245 // Bail if this was canceled or failed
246 if (m_bFailed || m_bCanceled)
247 return;
248
249 // Check if any dependencies are restricted
250 array<ref SCR_WorkshopItem> restricted = SCR_AddonManager.SelectItemsBasic(m_aDependencies, EWorkshopItemQuery.RESTRICTED);
251 if (!restricted.IsEmpty())
252 {
253 m_bRestrictedAddons = true;
254
255 array<ref SCR_WorkshopItem> blocked = SCR_AddonManager.SelectItemsBasic(restricted, EWorkshopItemQuery.BLOCKED);
256 m_bBlockedAddons = !blocked.IsEmpty();
257
259 m_OnRestrictedDependencies.Invoke(this, restricted);
260 }
261
262 // Skip dependencies patch size loading
263 if (m_aDependencies.IsEmpty())
264 {
266 return;
267 }
268
269 // Load dependencies patch sizes
271
272 foreach (SCR_WorkshopItem dependency : m_aDependencies)
273 {
274 // Skip blocked (banned)
275 if (dependency.GetBlocked())
276 {
278 continue;
279 }
280
281 // Catch missing
282 Revision revision;
283 // server browser still uses Dependency class
284 if (dependency.GetDependency())
285 revision = dependency.GetDependency().GetRevision();
286 // workshop uses WorkshopItem only
287 else
288 revision = dependency.GetLatestRevision();
289
290 // Pending download
291 if (!revision)
292 revision = dependency.GetWorkshopItem().GetPendingDownload();
293
294 if (!revision)
295 continue;
296
297 // Skip patch compute if dependency is running download
299
300 if (downloading)
301 {
302 // Proccess with same version
304
305 continue;
306 }
307
308 // Skip patch size compute if addon is not downloaded
309 if (!dependency.GetOffline())
310 {
311 SetDependencySize(dependency, dependency.GetSizeBytes());
312 continue;
313 }
314
315 // Setup callback and compute
317 callback.SetOnSuccess(OnDependencyPatchSizeLoadResponse);
318 callback.SetOnError(OnDependencyPatchSizeLoadError);
319 m_aPatchSizeCallbacks.Insert(callback);
320
321 revision.ComputePatchSize(callback);
322 }
323 }
324
325 //------------------------------------------------------------------------------------------------
326 protected array<ref SCR_WorkshopItem> MissingWorkshopItems()
327 {
328 array<ref SCR_WorkshopItem> missingItems = {};
329
330 foreach (SCR_WorkshopItem dependency : m_aDependencies)
331 {
332 if (!dependency.GetWorkshopItem())
333 missingItems.Insert(dependency);
334 }
335
336 return missingItems;
337 }
338
339 //------------------------------------------------------------------------------------------------
340 protected void AllPatchSizeLoaded()
341 {
342 m_bWaitingResponse = false;
343
344 if (m_OnReady && HasAllDetails())
345 m_OnReady.Invoke(this);
346 }
347
348 //------------------------------------------------------------------------------------------------
357
358 //------------------------------------------------------------------------------------------------
359 // Callbacks
360 //------------------------------------------------------------------------------------------------
361
362 //------------------------------------------------------------------------------------------------
364 protected void OnDependencyDetailsLoaded(notnull SCR_WorkshopItem item)
365 {
366 item.m_OnGetAsset.Remove(OnDependencyDetailsLoaded);
367
369
370 // All details loaded
373 }
374
375 //------------------------------------------------------------------------------------------------
378 {
379 float size;
380 callback.GetItem().GetDependency().GetRevision().GetPatchSize(size);
381 callback.GetItem().SetTargetRevisionPatchSize(size);
382
385 }
386
387 //------------------------------------------------------------------------------------------------
390 {
391 OnItemError(callback.GetItem());
392 }
393
394 //------------------------------------------------------------------------------------------------
395 protected void SetDependencySize(SCR_WorkshopItem item, float size)
396 {
398
401 }
402
403 //------------------------------------------------------------------------------------------------
404 protected void CheckAllPatchSizeLoaded()
405 {
406 // All loaded
407 if (m_iPatchesLoaded == m_aDependencies.Count())
408 {
409 m_aPatchSizeCallbacks.Clear();
411 }
412
413 // Check issues
416 }
417
418 //------------------------------------------------------------------------------------------------
419 protected void OnItemError(SCR_WorkshopItem item)
420 {
421 if (m_OnError)
422 m_OnError.Invoke(this);
423 }
424
425 //------------------------------------------------------------------------------------------------
426 protected void OnItemTimeout(SCR_WorkshopItem item)
427 {
428 if (m_OnError)
429 m_OnError.Invoke(this);
430 }
431
432 //------------------------------------------------------------------------------------------------
433 // Get set
434 //------------------------------------------------------------------------------------------------
435
436 //------------------------------------------------------------------------------------------------
438 {
439 return m_bRestrictedAddons;
440 }
441
442 //------------------------------------------------------------------------------------------------
444 {
445 return m_bBlockedAddons;
446 }
447
448 //------------------------------------------------------------------------------------------------
449 // Construct
450 //------------------------------------------------------------------------------------------------
451
452 //------------------------------------------------------------------------------------------------
454 {
455 // Unsubscribe
456
457 if (m_OnDestroyed)
458 m_OnDestroyed.Invoke(this);
459 }
460}
int size
EWorkshopItemQuery
void SCR_BackendCallbackWorkshopItem(SCR_WorkshopItem item)
func ScriptInvoker_DownloadSequence
func ScriptInvoker_DownloadSequenceDependencies
Shows a list of addons and some text.
static SCR_AddonListDialog CreateRestrictedAddonsDownload(array< ref SCR_WorkshopItem > items)
Dialog when downloading restricted addons.
static array< ref SCR_WorkshopItem > SelectItemsBasic(array< ref SCR_WorkshopItem > items, EWorkshopItemQuery query)
SCR_WorkshopItemActionDownload DownloadingActionAddonById(string id, bool runningOnly=true)
Return true if there is addon with given id in download queue.
static SCR_DownloadManager GetInstance()
ScriptInvokerBase< ScriptInvoker_DownloadSequence > GetOnReady()
ScriptInvokerBase< ScriptInvoker_DownloadSequenceDependencies > GetOnDependenciesLoadingPrevented()
void OnDependencyDetailsLoaded(notnull SCR_WorkshopItem item)
Call when dependency details are successfully loaded.
void SetDependencySize(SCR_WorkshopItem item, float size)
void OnDependencyPatchSizeLoadError(SCR_BackendCallbackWorkshopItem callback)
Call on error response to dependency patch size.
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnDependenciesLoaded
ref array< ref SCR_WorkshopItem > m_aDependencies
void Setup(notnull array< ref SCR_WorkshopItem > dependencies, bool skipDetails)
Setup new created download sequence.
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnInit
void OnItemTimeout(SCR_WorkshopItem item)
ref array< ref SCR_BackendCallbackWorkshopItem > m_aPatchSizeCallbacks
ref array< ref SCR_WorkshopItem > m_aDependenciesIssues
array< ref SCR_WorkshopItem > MissingWorkshopItems()
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnDestroyed
ScriptInvokerBase< ScriptInvoker_DownloadSequence > GetOnCancel()
ScriptInvokerBase< ScriptInvoker_DownloadSequenceDependencies > GetOnRestrictedDependency()
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnDetailsLoaded
ref ScriptInvokerBase< ScriptInvoker_DownloadSequenceDependencies > m_OnDependenciesLoadingPrevented
static SCR_DownloadSequence Create(array< ref SCR_WorkshopItem > dependencies, SCR_DownloadSequence previous, bool skipDetails=false)
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnReady
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnError
void OnAllReportsCanceled(SCR_ReportedAddonsDialog dialog)
Call when all reports from dialog are cancled to clear invoker actions and display download dialog.
void OnItemError(SCR_WorkshopItem item)
void Cancel()
Cancels this download request.
ScriptInvokerBase< ScriptInvoker_DownloadSequence > GetOnError()
void OnAllDependenciesDetailsLoaded()
Called when finally all the details of all dependencies are loaded.
void OnDependencyPatchSizeLoadResponse(SCR_BackendCallbackWorkshopItem callback)
Call on any response to dependency patch size.
bool HasAllDetails()
Returns true if all details were loaded successfully.
ref ScriptInvokerBase< ScriptInvoker_DownloadSequenceDependencies > m_OnRestrictedDependencies
ref ScriptInvokerBase< ScriptInvoker_DownloadSequence > m_OnCancel
SCR_ReportedAddonsDialog ShowRestrictedDependenciesDialog()
Show list of reported mods and provide option to cancel reports.
void SetTargetRevisionPatchSize(float size)