Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
WorkshopItemActions.c
Go to the documentation of this file.
1/*
2Specific workshop item actions, inherited from base action class.
3*/
4
5//-----------------------------------------------------------------------------------------------
7class SCR_WorkshopItemActionDownloadDependenciesLatest : SCR_WorkshopItemActionComposite
8{
9 // Optionally it is possible to provide dependencies externally,
10 // In this case only these will be downloaded.
11 ref array<ref SCR_WorkshopItem> m_aProvidedDependencies;
12
13 //-----------------------------------------------------------------------------------------------
15 void SCR_WorkshopItemActionDownloadDependenciesLatest(SCR_WorkshopItem wrapper, array<ref SCR_WorkshopItem> dependencies)
16 {
17 if (dependencies.Count() > 0)
18 {
19 // Copy the provided dependencies
20 m_aProvidedDependencies = new array<ref SCR_WorkshopItem>;
21 foreach (auto dep : dependencies)
22 m_aProvidedDependencies.Insert(dep);
23
24 // Create actions for all dependencies
25 #ifdef WORKSHOP_DEBUG
26 _print("New() Creating actions:");
27 #endif
28 m_aActions.Clear();
29 foreach (SCR_WorkshopItem dep : m_aProvidedDependencies)
30 {
31 if (!dep.GetOffline() || dep.GetUpdateAvailable())
32 {
33 #ifdef WORKSHOP_DEBUG
34 _print(string.Format(" Dependency: %1 - Creating action", dep.GetName()));
35 #endif
36
37 SCR_WorkshopItemAction action = dep.DownloadLatestVersion();
38 m_aActions.Insert(action);
39 }
40 else
41 {
42 #ifdef WORKSHOP_DEBUG
43 _print(string.Format(" Dependency: %1 - Download is not required.", dep.GetName()));
44 #endif
45 }
46 }
47 }
48 }
49
50 //-----------------------------------------------------------------------------------------------
51 protected override bool OnActivate()
52 {
53 bool success = true;
54
55 // Activate all created actions
56 foreach (auto action : m_aActions)
57 {
58 if (action.IsPaused())
59 success = success && action.Resume();
60 else if (action.IsInactive())
61 success = success && action.Activate();
62 }
63
64 return success;
65 }
66
67 //-----------------------------------------------------------------------------------------------
68 protected override bool OnReactivate()
69 {
70 return OnActivate();
71 }
72
73 //-----------------------------------------------------------------------------------------------
74 protected override bool OnCancel()
75 {
76 CancelAll();
77 return true;
78 }
79
80 //-----------------------------------------------------------------------------------------------
81 protected override bool OnPause()
82 {
83 PauseAll();
84 return true;
85 }
86
87 //-----------------------------------------------------------------------------------------------
88 protected override bool OnResume()
89 {
90 ResumeAll();
91 return true;
92 }
93
94 //-----------------------------------------------------------------------------------------------
95 override void Internal_Update(float timeSlice)
96 {
97 if (!m_Wrapper)
98 return;
99
100 // Check if comms have failed
102 {
103 if (m_Wrapper.GetRequestFailed())
104 this.Fail();
105 }
106
107 // Unregister dependnecy actions which were canceled
108 array<SCR_WorkshopItemAction> removeActions = new array<SCR_WorkshopItemAction>;
109 foreach (SCR_WorkshopItemAction action : m_aActions)
110 {
111 if (action.IsCanceled() || action.IsPaused() || action.IsFailed()) // todo should paused actions be removed too?
112 removeActions.Insert(action);
113 }
114 UnregisterActions(removeActions);
115
116 // Complete when all actions are completed
117 if (AllCompleted())
118 {
119 this.Complete();
120 }
121 }
122};
123
124//-----------------------------------------------------------------------------------------------
127{
128 ref BackendCallback m_Callback;
129
130 //-----------------------------------------------------------------------------------------------
131 protected bool OnActivateInternal();
132
133 //-----------------------------------------------------------------------------------------------
134 protected override bool OnActivate()
135 {
136 m_Callback = new BackendCallback();
137 m_Callback.SetOnSuccess(Callback_OnSuccess);
138 m_Callback.SetOnError(Callback_OnError);
139
140 bool success = OnActivateInternal();
141 return success;
142 }
143
144
145 //-----------------------------------------------------------------------------------------------
146 protected override bool OnReactivate()
147 {
148 return this.OnActivate();
149 }
150
151 //-----------------------------------------------------------------------------------------------
153 {
154 Fail();
155 if (cb.GetRestResult() == ERestResult.EREST_ERROR_TIMEOUT)
156 {
157 SCR_CommonDialogs.CreateTimeoutOkDialog();
158 }
159 else
160 {
161 SCR_CommonDialogs.CreateRequestErrorDialog();
162 }
163 }
164
165 //-----------------------------------------------------------------------------------------------
166 protected void Callback_OnSuccess()
167 {
168 this.Complete();
169 }
170};
171
172//-----------------------------------------------------------------------------------------------
175{
177 protected string m_sMessage;
178
179 //-----------------------------------------------------------------------------------------------
181 {
182 m_eReportType = eReport;
183 m_sMessage = sMessage;
184 }
185
186
187 //-----------------------------------------------------------------------------------------------
188 protected override bool OnActivateInternal()
189 {
190 return m_Wrapper.Internal_Report(m_eReportType, m_sMessage, m_Callback);
191 }
192};
193
194
195
196//-----------------------------------------------------------------------------------------------
199{
200 protected override bool OnActivateInternal()
201 {
202 return m_Wrapper.Internal_CancelReport(m_Callback);
203 }
204};
205
206
207//-----------------------------------------------------------------------------------------------
210{
211 protected override bool OnActivateInternal()
212 {
213 return m_Wrapper.Internal_AddAuthorBlock(m_Callback);
214 }
215};
216
217//-----------------------------------------------------------------------------------------------
220{
221 protected override bool OnActivateInternal()
222 {
223 return m_Wrapper.Internal_RemoveAuthorBlock(m_Callback);
224 }
225};
Action for canceling report of an item.
Composite action which includes multiple subactions.
void UnregisterActions(array< SCR_WorkshopItemAction > actions)
void Fail(int reason=-1)
Action must call this when it has failed.
void SCR_WorkshopItemAction(SCR_WorkshopItem wrapper)
void Complete()
Action must call this when it is completed.
void _print(string str, LogLevel logLevel=LogLevel.DEBUG)
Action for removing author mod content blocking.
Action for reporting an item.
void Callback_OnError(BackendCallback cb)
void SCR_WorkshopItemActionReport(SCR_WorkshopItem wrapper, EWorkshopReportType eReport, string sMessage)
ERestResult
States and result + error code produced by RestApi.
Definition ERestResult.c:14
EWorkshopReportType