Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AddonLineValidateRepairComponent.c
Go to the documentation of this file.
2{
3 protected const int REFRESH_DELAY = 1000;
4
6
9
10 protected ref SCR_WorkshopItem m_Item;
12
13 protected bool m_bIsAddonEnabled;
14 protected bool m_bIsInitialized; // Is the Addon details loaded
15 protected bool m_bIsReSubscribing; // Are we currently trying to fix the mod by completely removing it and downloading it from scratch
17 protected bool m_bChangedState;
18 protected float m_fCurrentProgress; // 0.0 to 1.0
19
20 protected SCR_EAddonValidateState m_eCurrentState;
21 protected string m_sDownloadText;
22
25
28
31
34
35 //------------------------------------------------------------------------------------------------
36 bool IsBusy()
37 {
38 return (m_eCurrentState == SCR_EAddonValidateState.VALIDATING || m_eCurrentState == SCR_EAddonValidateState.REPAIRING || m_eCurrentState == SCR_EAddonValidateState.DOWNLOADING || m_eCurrentState == SCR_EAddonValidateState.UPDATING || m_eCurrentState == SCR_EAddonValidateState.NEED_UPDATING);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 bool HasFailed()
43 {
44 return (m_eCurrentState == SCR_EAddonValidateState.VALIDATING_FAILED || m_eCurrentState == SCR_EAddonValidateState.REPAIRING_FAILED);
45 }
46
47 //------------------------------------------------------------------------------------------------
49 {
50 return m_eCurrentState == SCR_EAddonValidateState.DOWNLOADING_FAILED;
51 }
52
53 //------------------------------------------------------------------------------------------------
54 protected bool IsBusyExtended()
55 {
56 if (IsBusy() || !m_Item || m_Item.IsDownloadRunning())
57 return true;
58
59 WorkshopItem workshop = m_Item.GetWorkshopItem();
60 if (!workshop || workshop.IsVerificationRunning())
61 return true;
62
63 return false;
64 }
65
66 //------------------------------------------------------------------------------------------------
68 {
69 return m_Item;
70 }
71
72 //------------------------------------------------------------------------------------------------
73 protected void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
74 {
75 if (newDevice != EInputDeviceType.MOUSE)
76 m_Widgets.m_RedownloadButtonComponent0.SetVisible(false);
77 }
78
79 //------------------------------------------------------------------------------------------------
80 override bool OnFocus(Widget w, int x, int y)
81 {
82 bool result = super.OnFocus(w, x, y);
83
84 if (HasFailed() && !IsBusy() && !HasFailedDownloading())
85 m_Widgets.m_RedownloadButtonComponent0.SetVisible(GetGame().GetInputManager().GetLastUsedInputDevice() == EInputDeviceType.MOUSE);
86
88
89 return result;
90 }
91
92 //------------------------------------------------------------------------------------------------
93 override bool OnFocusLost(Widget w, int x, int y)
94 {
95 bool result = super.OnFocusLost(w, x, y);
96
97 m_Widgets.m_RedownloadButtonComponent0.SetVisible(false);
99
100 return result;
101 }
102
103 //------------------------------------------------------------------------------------------------
105 protected void UpdateAllWidgets()
106 {
107 if (!m_Item)
108 return;
109
110 // Update name
111 m_Widgets.m_wNameText.SetText(m_Item.GetName());
112 UpdateImage();
114 }
115
116 //------------------------------------------------------------------------------------------------
117 protected void UpdateImage()
118 {
120 return;
121
122 m_BackendImageComponent.SetImage(m_Item.GetThumbnail());
123 }
124
125 //------------------------------------------------------------------------------------------------
127 {
128 if (!m_Widgets)
129 return;
130
131 float progress = 1;
132 switch(m_eCurrentState)
133 {
134 case SCR_EAddonValidateState.VALIDATING:
135 progress = m_Item.GetWorkshopItem().GetVerificationProgress();
136 break;
137 case SCR_EAddonValidateState.NEED_UPDATING:
138 case SCR_EAddonValidateState.IDLE:
139 progress = 0;
140 break;
141 case SCR_EAddonValidateState.REPAIRING:
142 case SCR_EAddonValidateState.DOWNLOADING:
143 case SCR_EAddonValidateState.UPDATING:
144 progress = m_Item.GetWorkshopItem().GetProgress();
145 break;
146 }
147
148 if (m_bChangedState || m_fCurrentProgress != progress)
149 {
150 if (m_eCurrentState == SCR_EAddonValidateState.DOWNLOADING && progress == 1.0)
151 {
153 return; // Early return so we dont update the visuals twice
154 }
155 else if (m_eCurrentState == SCR_EAddonValidateState.UPDATING && progress == 1.0)
156 {
158 return; // Early return so we dont update the visuals twice
159 }
160
161 if (m_bChangedState)
162 {
163 SCR_AddonLineValidateState currentState = m_mVisualStates.Get(m_eCurrentState);
164 m_sDownloadText = currentState.GetText();
165
166 m_Widgets.m_ProgressComponent.SetSliderColor(currentState.GetColor());
167 m_Widgets.m_wDownloadStateText.SetColor(currentState.GetColor());
168 m_Widgets.m_LoadingOverlayComponent.SetShown(IsBusy());
169
170 m_bChangedState = false;
171 }
172
173 m_fCurrentProgress = progress;
174 int progressInt = m_fCurrentProgress * 100;
175 m_Widgets.m_wDownloadStateText.SetTextFormat(m_sDownloadText, progressInt);
176 m_Widgets.m_ProgressComponent.StopProgressAnimation();
177 m_Widgets.m_ProgressComponent.SetValue(m_fCurrentProgress);
178 }
179 }
180
181 //------------------------------------------------------------------------------------------------
182 protected void StartContinuousUpdate()
183 {
185 return;
186
188
189 m_Widgets.m_LoadingOverlayComponent.SetShown(true);
190
192
193 GetGame().GetCallqueue().CallLater(ContinuousUpdate, REFRESH_DELAY, true);
194
196 }
197
198 //------------------------------------------------------------------------------------------------
199 protected void StopContinuousUpdate(bool skipUIUpdate = false)
200 {
202 GetGame().GetCallqueue().Remove(ContinuousUpdate);
203
204 if (!skipUIUpdate)
205 {
207 m_Widgets.m_LoadingOverlayComponent.SetShown(false);
208 }
209
211 }
212
213 //------------------------------------------------------------------------------------------------
214 protected void ContinuousUpdate()
215 {
216 if (!m_Item)
217 {
218 m_eCurrentState = SCR_EAddonValidateState.IDLE;
219 m_bChangedState = true;
220
222 }
223
225 }
226
227 //------------------------------------------------------------------------------------------------
229 {
230 if (IsBusyExtended())
231 return false;
232
233 m_Widgets.m_wDownloadErrorText.SetText(string.Empty);
234
235 WorkshopItem workshop = m_Item.GetWorkshopItem();
236
238 m_Callback.SetOnSuccess(OnValidationSuccess);
239 m_Callback.SetOnError(OnValidationError);
240 workshop.VerifyIntegrity(m_Callback);
241
242 m_eCurrentState = SCR_EAddonValidateState.VALIDATING;
243 m_bChangedState = true;
244
246 m_OnValidateStart.Invoke(this);
247
249
250 return true;
251 }
252
253 //------------------------------------------------------------------------------------------------
254 void StopValidating(bool skipUIUpdate = false)
255 {
256 if (m_Item)
257 m_Item.GetWorkshopItem().CancelVerification();
258
259 if (m_OnValidateEnd)
260 m_OnValidateEnd.Invoke(this);
261
262 m_eCurrentState = SCR_EAddonValidateState.IDLE;
263 m_bChangedState = true;
264
265 StopContinuousUpdate(skipUIUpdate);
266 }
267
268 //------------------------------------------------------------------------------------------------
269 protected void OnValidationSuccess()
270 {
271 m_eCurrentState = SCR_EAddonValidateState.FINISHED;
272 m_bChangedState = true;
273
275
276 if (m_OnValidateEnd)
277 m_OnValidateEnd.Invoke(this);
278
279 PrintFormat("ValidateAndRepair: Validated Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.DEBUG);
280
281 if (m_Item.GetWorkshopItem().GetActiveRevision().IsCorrupted())
282 {
283 if (!StartRepairing())
284 {
286 return;
287 }
288 }
289
290
291 if (m_OnValidateEnd)
292 m_OnValidateEnd.Invoke(this);
293 }
294
295 //------------------------------------------------------------------------------------------------
296 protected void OnValidationError()
297 {
298 m_eCurrentState = SCR_EAddonValidateState.VALIDATING_FAILED;
299 m_bChangedState = true;
300
302
303 if (m_OnValidateEnd)
304 m_OnValidateEnd.Invoke(this);
305
306 PrintFormat("ERROR !!! ValidateAndRepair: Unable to Validate Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.WARNING);
307
308 SetErrorMessage(m_Callback.GetBackendError());
309 }
310
311 //------------------------------------------------------------------------------------------------
313 {
314 if (IsBusyExtended() || !m_Item.GetWorkshopItem().GetActiveRevision().IsCorrupted())
315 return false;
316
317 WorkshopItem workshop = m_Item.GetWorkshopItem();
318
319 m_Widgets.m_wDownloadErrorText.SetText(string.Empty);
320
322 m_Callback.SetOnSuccess(OnRepairingSuccess);
323 m_Callback.SetOnError(OnRepairingError);
324 workshop.RepairIntegrity(m_Callback);
325
326 m_eCurrentState = SCR_EAddonValidateState.REPAIRING;
327 m_bChangedState = true;
328
329 if (m_OnRepairStart)
330 m_OnRepairStart.Invoke(this);
331
333
334 return true;
335 }
336
337 //------------------------------------------------------------------------------------------------
338 void StopRepairing(bool skipUIUpdate = false)
339 {
340 if (m_Item)
341 m_Item.GetWorkshopItem().Cancel(null);
342
343 if (m_OnRepairEnd)
344 m_OnRepairEnd.Invoke(this);
345
346 m_eCurrentState = SCR_EAddonValidateState.IDLE;
347 m_bChangedState = true;
348
349 StopContinuousUpdate(skipUIUpdate);
350 }
351
352 //------------------------------------------------------------------------------------------------
353 protected void OnRepairingSuccess()
354 {
355 m_eCurrentState = SCR_EAddonValidateState.FINISHED;
356 m_bChangedState = true;
357
358 if (m_OnRepairEnd)
359 m_OnRepairEnd.Invoke(this);
360
361 PrintFormat("ValidateAndRepair: Repaired Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.DEBUG);
362
364 m_Item.SetEnabled(true);
365
367 }
368
369 //------------------------------------------------------------------------------------------------
370 protected void OnRepairingError()
371 {
372 m_eCurrentState = SCR_EAddonValidateState.REPAIRING_FAILED;
373 m_bChangedState = true;
374
375 if (m_OnRepairEnd)
376 m_OnRepairEnd.Invoke(this);
377
378 PrintFormat("ERROR !!! ValidateAndRepair: Unable to Repair Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.WARNING);
379
380 SetErrorMessage(m_Callback.GetBackendError());
381
383 }
384
385 //------------------------------------------------------------------------------------------------
387 {
389 }
390
391 //------------------------------------------------------------------------------------------------
393 {
394 if (IsBusyExtended())
395 return false;
396
397 m_Widgets.m_wDownloadErrorText.SetText(string.Empty);
398
399 m_Item.DeleteLocally();
400
401 Revision revision = m_Item.GetLatestRevision();
403
404 m_DownloadRequest.GetOnReady().Insert(OnDownloadStart);
405 m_DownloadRequest.GetOnCancel().Insert(OnDownloadError);
406 m_DownloadRequest.GetOnError().Insert(OnDownloadError);
407
408 return true;
409 }
410
411 //------------------------------------------------------------------------------------------------
412 protected void OnDownloadStart(SCR_DownloadSequence sequence)
413 {
414 m_eCurrentState = SCR_EAddonValidateState.DOWNLOADING;
415 m_bChangedState = true;
416
418 m_OnDownloadStart.Invoke(this);
419
421 }
422
423 //------------------------------------------------------------------------------------------------
424 protected void OnDownloadFinished()
425 {
426 m_eCurrentState = SCR_EAddonValidateState.FINISHED;
427 m_bChangedState = true;
428
430
431 if (m_OnDownloadEnd)
432 m_OnDownloadEnd.Invoke(this);
433
434 PrintFormat("ValidateAndRepair: Downloaded Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.DEBUG);
435 }
436
437 //------------------------------------------------------------------------------------------------
438 protected void OnDownloadError(SCR_DownloadSequence sequence)
439 {
440 m_eCurrentState = SCR_EAddonValidateState.DOWNLOADING_FAILED;
441 m_bChangedState = true;
442
444
445 if (m_OnDownloadEnd)
446 m_OnDownloadEnd.Invoke(this);
447
448 PrintFormat("ERROR !!! ValidateAndRepair: Unable to Download Addon (%1 %2) with code:%3", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.WARNING);
449
450 SetErrorMessage(SCR_EAddonValidateError.UNKNOWN);
451 }
452
453 //------------------------------------------------------------------------------------------------
454 protected bool StartUpdating()
455 {
456 m_eCurrentState = SCR_EAddonValidateState.UPDATING;
457 m_bChangedState = true;
458
460
461 return true;
462 }
463
464 //------------------------------------------------------------------------------------------------
465 protected void FinishedUpdating()
466 {
467 m_eCurrentState = SCR_EAddonValidateState.IDLE;
468 m_bChangedState = true;
469
471
472 PrintFormat("ValidateAndRepair: Finished Updating Addon (%1 %2)", m_Item.GetName(), m_Item.GetId(), level: LogLevel.DEBUG);
473
475 }
476
477 //------------------------------------------------------------------------------------------------
478 protected bool NeedUpdating()
479 {
480 m_eCurrentState = SCR_EAddonValidateState.NEED_UPDATING;
481 m_bChangedState = true;
482
484
485 return true;
486 }
487
488 //------------------------------------------------------------------------------------------------
489 protected void SetErrorMessage(int code)
490 {
491 string errorMsg;
492 if (m_mErrorMessages.Find(code, errorMsg))
493 m_Widgets.m_wDownloadErrorText.SetTextFormat(errorMsg, code);
494 else
495 m_Widgets.m_wDownloadErrorText.SetTextFormat(m_mErrorMessages.Get(SCR_EAddonValidateError.UNKNOWN), code);
496 }
497
498 // --- Callbacks ---
499 //------------------------------------------------------------------------------------------------
500 protected void OnWorkshopItemChange()
501 {
502 // If the addon was deleted/unsubscribed, remove from the list
503 if (m_Item && !m_Item.GetSubscribed())
504 {
505 PrintFormat("ERROR !!! ValidateAndRepair: Addon (%1 %2) with code:%3 is not subscribed", m_Item.GetName(), m_Item.GetId(), m_Callback.GetBackendError(), level: LogLevel.WARNING);
506 return;
507 }
508
510 }
511
512 //------------------------------------------------------------------------------------------------
513 protected void OnWorkshopItemLoaded()
514 {
515 if (m_Item)
516 {
517 m_Item.m_OnGetAsset.Remove(OnWorkshopItemChange);
518 m_Item.m_OnChanged.Insert(OnWorkshopItemChange);
519 }
520
522 }
523
524 // --- Invokers ---
525 //------------------------------------------------------------------------------------------------
533
534 //------------------------------------------------------------------------------------------------
542
543 //------------------------------------------------------------------------------------------------
551
552 //------------------------------------------------------------------------------------------------
560
561 //------------------------------------------------------------------------------------------------
564 {
565 m_Item = item;
566
567 if (!m_Item.GetDetailsLoaded())
568 {
569 m_Item.m_OnGetAsset.Insert(OnWorkshopItemLoaded);
570 m_Item.LoadDetails();
571 }
572 else
573 m_Item.m_OnChanged.Insert(OnWorkshopItemChange);
574
575 m_mVisualStates = states;
576 m_mErrorMessages = errorMessages;
577
578 m_bIsAddonEnabled = m_Item.GetEnabled();
579
580 // We should not validate/repair something currently being downloaded or outdated
581 if (item.IsDownloadRunning())
583 else if (item.GetUpdateAvailable())
584 NeedUpdating();
585
588 }
589
590 //------------------------------------------------------------------------------------------------
591 override void HandlerAttached(Widget w)
592 {
594 return;
595
596 m_Widgets.Init(w);
597 m_Widgets.m_wDownloadStateText.SetText(string.Empty);
598 m_Widgets.m_ProgressComponent.SetValue(0, false);
599 m_Widgets.m_ProgressComponent.SetAnimationTime(0.2);
600 m_Widgets.m_RedownloadButtonComponent0.SetVisible(false);
601
602 m_Widgets.m_RedownloadButtonComponent0.m_OnClicked.Insert(OnClickAttemptResubscribing);
603
605
606 GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceChange);
607
608 super.HandlerAttached(w);
609 }
610
611 //------------------------------------------------------------------------------------------------
612 override void HandlerDeattached(Widget w)
613 {
614 if (m_eCurrentState == SCR_EAddonValidateState.VALIDATING)
615 StopValidating(true);
616 else if (m_eCurrentState == SCR_EAddonValidateState.REPAIRING)
617 StopRepairing(true);
618
619 if (m_OnRepairStart)
620 m_OnRepairStart.Clear();
621
622 if (m_OnRepairEnd)
623 m_OnRepairEnd.Clear();
624
626 m_OnValidateStart.Clear();
627
628 if (m_OnValidateEnd)
629 m_OnValidateEnd.Clear();
630
631 super.HandlerDeattached(w);
632 }
633}
634
635enum SCR_EAddonValidateError
636{
637 UNKNOWN = EBackendError.EBERR_UNKNOWN,
638 AVAILABLE_SPACE = EBackendError.EBERR_STORAGE_IS_FULL,
639 INTERNET = EBackendError.EBERR_AUTH_FAILED,
640 BUSY = EBackendError.EBERR_BUSY
641}
642
643enum SCR_EAddonValidateState
644{
645 IDLE,
646
647 VALIDATING,
648 VALIDATING_FAILED, // Should only be happening if the addon is already busy
649
650 REPAIRING,
651 REPAIRING_FAILED,
652
654 DOWNLOADING_FAILED,
655
656 UPDATING, // We cant validate a addon if its already being processed by something else, in this case an update being downloaded
657 NEED_UPDATING, // While we can validate outdated mods, we should encourage to update first
658
660}
661
663class SCR_AddonLineValidateError
664{
665 [Attribute(SCR_EAddonValidateError.UNKNOWN.ToString(), UIWidgets.ComboBox, string.Empty, string.Empty, enumType: SCR_EAddonValidateError)]
666 protected SCR_EAddonValidateError m_eId;
667
668 [Attribute("", UIWidgets.EditBox, "The Error message for the error id")]
669 protected string m_sText;
670
671 //------------------------------------------------------------------------------------------------
672 SCR_EAddonValidateError GetErrorCode()
673 {
674 return m_eId;
675 }
676
677 //------------------------------------------------------------------------------------------------
678 string GetText()
679 {
680 return m_sText;
681 }
682}
683
685class SCR_AddonLineValidateState
686{
687 [Attribute(SCR_EAddonValidateState.IDLE.ToString(), UIWidgets.ComboBox, string.Empty, string.Empty, enumType: SCR_EAddonValidateState)]
688 protected SCR_EAddonValidateState m_eState;
689
690 [Attribute("", UIWidgets.EditBox, "Text to display while in this state")]
691 protected string m_sText;
692
693 [Attribute(UIColors.GetColorAttribute(Color.Black), UIWidgets.ColorPicker)]
694 protected ref Color m_Color;
695
696 //------------------------------------------------------------------------------------------------
697 SCR_EAddonValidateState GetState()
698 {
699 return m_eState;
700 }
701
702 //------------------------------------------------------------------------------------------------
703 string GetText()
704 {
705 return m_sText;
706 }
707
708 //------------------------------------------------------------------------------------------------
709 Color GetColor()
710 {
711 return m_Color;
712 }
713}
714
715[BaseContainerProps(configRoot : true)]
716class SCR_AddonLineValidateStates
717{
718 [Attribute("")]
719 ref array<ref SCR_AddonLineValidateState> m_aStates;
720
721 [Attribute("")]
722 ref array<ref SCR_AddonLineValidateError> m_aErrors;
723}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
SCR_AIGroupInfoComponentClass IDLE
Group has no waypoints and does not engage an enemy.
EAITargetClusterState m_eState
SCR_AddonLineValidateRepairComponent AVAILABLE_SPACE
SCR_AddonLineValidateRepairComponent INTERNET
Server list provided by Backend.
string GetText()
InputManager GetInputManager()
ref Color m_Color
ScriptInvokerBase< ScriptInvokerScriptedWidgetComponentMethod > ScriptInvokerScriptedWidgetComponent
class SCR_WorkshopUiCommon DOWNLOADING
void Init(notnull SCR_WorkshopItem item, notnull map< SCR_EAddonValidateState, ref SCR_AddonLineValidateState > states, notnull map< int, string > errorMessages)
Setup line.
ScriptInvokerScriptedWidgetComponent GetOnRepairEnd()
ScriptInvokerScriptedWidgetComponent GetOnRepairStart()
ref ScriptInvokerScriptedWidgetComponent m_OnDownloadEnd
ref ScriptInvokerScriptedWidgetComponent m_OnDownloadStart
ref ScriptInvokerScriptedWidgetComponent m_OnRepairEnd
ref ScriptInvokerScriptedWidgetComponent m_OnRepairStart
ref ScriptInvokerScriptedWidgetComponent m_OnValidateEnd
ScriptInvokerScriptedWidgetComponent GetOnValidateEnd()
void OnInputDeviceChange(EInputDeviceType oldDevice, EInputDeviceType newDevice)
ref ScriptInvokerScriptedWidgetComponent m_OnValidateStart
override bool OnFocusLost(Widget w, int x, int y)
ref map< SCR_EAddonValidateState, ref SCR_AddonLineValidateState > m_mVisualStates
ScriptInvokerScriptedWidgetComponent GetOnValidateStart()
override void HandlerAttached(Widget w)
static bool IsEditMode()
Definition Functions.c:1566
void UpdateModularButtons()
static SCR_WorkshopDownloadSequence Create(SCR_WorkshopItem item, Revision itemTargetRevision, SCR_WorkshopDownloadSequence previous)
Tries to create a new request if previous doesn't exist or finished. Otherwise returns the previous r...
Workshop Item instance.
Definition Types.c:486
@ FINISHED
Job was successfully finished.
Definition ENodeResult.c:19
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
proto void PrintFormat(string fmt, void param1=NULL, void param2=NULL, void param3=NULL, void param4=NULL, void param5=NULL, void param6=NULL, void param7=NULL, void param8=NULL, void param9=NULL, LogLevel level=LogLevel.NORMAL)
SCR_FieldOfViewSettings Attribute
proto external EParticleEffectState GetState()
@ UNKNOWN
Definition EPlatform.c:24
string m_sText
Definition EnWidgets.c:82
EBackendError
Backend error.