11 protected ref Revision m_StartVersion;
12 protected ref Revision m_TargetRevision;
14 protected bool m_bTargetVersionLatest;
18 protected float m_fSizeBytes;
21 protected bool m_bWaitingForRevisions;
24 protected bool m_bDownloadStarted;
26 protected float m_fProgress;
27 protected float m_fProcessingProgress;
28 protected float m_fDownloadedSize;
31 protected bool m_bAddonEnabledAtStart;
35 protected bool m_bRunningImmediate;
36 protected bool m_bRunningAsync;
38 protected ref ScriptInvokerBase<ScriptInvoker_ActionDownloadProgress> m_OnDownloadProgress;
39 protected ref ScriptInvokerBase<ScriptInvoker_ActionDownloadFullStorage> m_OnFullStorageError;
42 ScriptInvokerBase<ScriptInvoker_ActionDownloadProgress> GetOnDownloadProgress()
44 if (!m_OnDownloadProgress)
45 m_OnDownloadProgress =
new ScriptInvokerBase<ScriptInvoker_ActionDownloadProgress>();
47 return m_OnDownloadProgress;
51 ScriptInvokerBase<ScriptInvoker_ActionDownloadFullStorage> GetOnFullStorageError()
53 if (!m_OnFullStorageError)
54 m_OnFullStorageError =
new ScriptInvokerBase<ScriptInvoker_ActionDownloadFullStorage>();
56 return m_OnFullStorageError;
62 m_bTargetVersionLatest = latestVersion;
63 m_TargetRevision = revision;
64 m_StartVersion = wrapper.GetCurrentLocalRevision();
74 Revision GetTargetRevision()
76 return m_TargetRevision;
82 Revision GetStartRevision()
84 return m_StartVersion;
88 bool GetTargetedAtLatestVersion()
90 return m_bTargetVersionLatest;
97 return m_StartVersion;
110 float GetProcessingProgress()
112 return m_fProcessingProgress;
123 protected override bool OnActivate()
125 m_bRunningImmediate =
true;
126 m_bRunningAsync =
true;
128 m_fDownloadedSize = 0;
131 m_bAddonEnabledAtStart = m_Wrapper.GetEnabled();
135 return StartDownloadOrLoadDetails();
139 protected override bool OnReactivate()
145 protected override bool OnCancel()
147 bool success = m_Wrapper.Internal_CancelDownload();
149 return success && !IsFailed();
153 bool GetRunningAsync()
155 return m_bRunningAsync;
159 bool IsRunningAsyncSolved()
161 return m_bRunningImmediate && m_bRunningAsync;
165 bool IsPauseAsyncSolved()
167 return !m_bRunningImmediate && !m_bRunningAsync;
171 protected override bool OnPause()
174 WorkshopItem item = m_Wrapper.GetWorkshopItem();
179 if (m_bDownloadStarted)
181 m_bRunningImmediate =
false;
183 m_PauseDownloadCallback.GetEventOnResponse().Insert(OnPauseResponse);
184 item.PauseDownload(m_PauseDownloadCallback);
194 callback.GetEventOnResponse().Remove(OnPauseResponse);
200 m_bRunningImmediate =
true;
205 m_bRunningAsync =
false;
210 protected override bool OnResume()
213 WorkshopItem item = m_Wrapper.GetWorkshopItem();
218 if (m_bDownloadStarted)
220 m_bRunningImmediate =
true;
224 m_bRunningAsync =
true;
225 item.ResumeDownload(
null);
232 return StartDownloadOrLoadDetails();
238 callback.GetEventOnResponse().Remove(OnResumeResponse);
244 m_bRunningImmediate =
false;
249 m_bRunningAsync =
true;
255 protected override void OnComplete()
258 m_Wrapper.SetEnabled(m_bAddonEnabledAtStart);
264 protected bool StartDownloadOrLoadDetails()
266 #ifdef WORKSHOP_DEBUG
267 _print(
"StartDownloadOrLoadDetails()");
270 #ifdef WORKSHOP_DEBUG
271 _print(
"StartDownloadOrLoadDetails(): Revisions are loaded, starting the download");
276 if (m_Wrapper.GetRestricted())
283 m_Callback.m_OnError.Insert(Callback_OnError);
284 m_Callback.m_OnTimeout.Insert(Callback_OnTimeout);
286 if (m_bTargetVersionLatest)
288 m_TargetRevision = m_Wrapper.GetLatestRevision();
289 #ifdef WORKSHOP_DEBUG
290 _print(
"StartDownloadOrLoadDetails(): Download of latest version was requested");
294 #ifdef WORKSHOP_DEBUG
295 _print(
string.Format(
"StartDownloadOrLoadDetails(): Target version: %1", m_TargetRevision.GetVersion()));
298 bool success = m_Wrapper.Internal_StartDownload(m_TargetRevision,
m_Callback);
300 m_bWaitingForRevisions =
false;
301 m_bDownloadStarted =
true;
303 return success && !IsFailed();
307 override void Internal_Update(
float timeSlice)
315 if (m_Wrapper.GetRequestFailed())
322 if (m_bWaitingForRevisions)
325 if (m_Wrapper.GetRevisionsLoaded())
326 StartDownloadOrLoadDetails();
330 bool offline = m_Wrapper.GetOffline();
331 Revision currentVersion = m_Wrapper.GetCurrentLocalRevision();
337 float progress = m_Wrapper.Internal_GetDownloadProgress();
338 float processingProgress = m_Wrapper.Internal_GetProcessingProgress();
341 if (progress > m_fProgress)
343 float currentDownloadSize = m_Wrapper.GetTargetRevisionPatchSize() * progress;
345 if (m_OnDownloadProgress)
346 m_OnDownloadProgress.Invoke(
this, currentDownloadSize - m_fDownloadedSize);
348 m_fProgress = progress;
349 m_fDownloadedSize = currentDownloadSize;
355 else if (processingProgress > m_fProcessingProgress)
357 m_fProcessingProgress = processingProgress;
361 if (offline && Revision.AreEqual(currentVersion, m_TargetRevision))
374 callback.m_OnError.Remove(Callback_OnError);
375 callback.m_OnTimeout.Remove(Callback_OnTimeout);
380 if (code == EBackendError.EBERR_STORAGE_IS_FULL)
385 else if ((restCode >= 400 && restCode < 500) || (code == EBackendError.EBERR_VALIDATION_FAILED))
387 m_Wrapper.DeleteDownloadProgress();
393 void FullStorageFail()
395 if (m_OnFullStorageError)
397 float size = m_Wrapper.GetItemTargetRevision().GetTotalSize();
400 m_OnFullStorageError.Invoke(
this, size);
414 m_Wrapper.RetryDownload(m_TargetRevision);
424 float GetDownloadSize()
426 return m_fDownloadedSize;
432 return m_Wrapper && m_Wrapper.Internal_GetIsProcessing();