26 ref ScriptInvoker m_OnChanged =
new ScriptInvoker();
27 ref ScriptInvoker m_OnGetAsset =
new ScriptInvoker();
28 ref ScriptInvoker m_OnDependenciesLoaded =
new ScriptInvoker();
29 ref ScriptInvoker m_OnScenariosLoaded =
new ScriptInvoker();
30 ref ScriptInvoker m_OnError =
new ScriptInvoker();
31 ref ScriptInvoker m_OnTimeout =
new ScriptInvoker();
32 ref ScriptInvoker m_OnDownloadComplete =
new ScriptInvoker();
33 ref ScriptInvoker m_OnOfflineStateChanged =
new ScriptInvoker();
34 ref ScriptInvoker m_OnReportStateChanged =
new ScriptInvoker();
35 ref ScriptInvoker m_OnMyReportLoaded =
new ScriptInvoker();
36 ref ScriptInvoker m_OnMyReportLoadError =
new ScriptInvoker();
37 ref ScriptInvoker m_OnRedownload =
new ScriptInvoker();
38 ref ScriptInvoker m_OnCanceled =
new ScriptInvoker();
42 protected ref WorkshopItem m_Item;
43 protected ref Dependency m_Dependency;
46 protected ref Revision m_ItemTargetRevision;
47 protected float m_fTargetRevisionPatchSize;
49 protected ref array<MissionWorkshopItem> m_aMissions;
50 protected ref array<ref SCR_WorkshopItem> m_aDependencies;
51 protected ref array<SCR_WorkshopItem> m_aDependent =
new array<SCR_WorkshopItem>;
52 protected ref array<Revision> m_aRevisions;
57 protected string m_sId;
61 protected bool m_bDetailsLoaded;
72 protected bool m_bMyRating;
73 protected bool m_bMyRatingSet;
74 protected bool m_bFavourite;
75 protected bool m_bSubscribed;
76 protected bool m_bChanged;
77 protected bool m_bRequestFailed;
78 protected bool m_bOffline;
79 protected int m_iAccessState;
82 protected bool m_bWaitingLoadDetails;
83 protected float m_fPrevDownloadProgress;
99 WorkshopItem GetWorkshopItem() {
return m_Item; }
100 Dependency GetDependency() {
return m_Dependency; }
103 bool GetItemDataLoaded() {
return m_Item !=
null; }
104 bool GetDetailsLoaded() {
return m_bDetailsLoaded; }
105 bool GetScenariosLoaded() {
return m_aMissions !=
null; }
106 bool GetRevisionsLoaded() {
return m_aRevisions !=
null; }
108 bool GetRequestFailed() {
return m_bRequestFailed; }
111 bool IsDownloadRunning()
113 if (!m_ActionDownload)
116 return m_ActionDownload.IsActive();
123 bool myRating, myRatingSet;
124 GetMyRating(myRatingSet, myRating);
126 string description = GetDescription();
127 if (description.Length() > 32)
129 description = description.Substring(0, 32);
130 description = description +
" <truncated>";
133 string summary = GetSummary();
134 if (summary.Length() > 32)
136 summary = summary.Substring(0, 32);
137 summary = summary +
" <truncated>";
142 array<ref SCR_WorkshopItem> dependencies = GetLatestDependencies();
144 _print(
"\nLogState:");
145 _print(
string.Format(
" Name: %1", GetName()));
146 _print(
string.Format(
" ID: %1", GetId()));
147 _print(
string.Format(
" Dependency: %1", m_Dependency));
148 _print(
string.Format(
" WorkshopItem: %1",
m_Item));
149 _print(
string.Format(
" Subscribed: %1", GetSubscribed()));
150 _print(
string.Format(
" Enabled: %1", GetEnabled()));
151 _print(
string.Format(
" Online: %1", GetOnline()));
152 _print(
string.Format(
" Offline: %1", GetOffline()));
153 _print(
string.Format(
" Blocked: %1", GetBlocked()));
154 _print(
string.Format(
" ReportedByMe: %1", GetReportedByMe()));
155 if (GetCurrentLocalRevision())
156 _print(
string.Format(
" CurrentLocalVersion: %1", GetCurrentLocalRevision().GetVersion()));
158 if (GetLatestVersion())
159 _print(
string.Format(
" LatestVersion: %1", GetLatestVersion()));
161 _print(
string.Format(
" ItemDataLoaded: %1", GetItemDataLoaded()));
162 _print(
string.Format(
" DetailsLoaded: %1", GetDetailsLoaded()));
163 _print(
string.Format(
" ScenariosLoaded: %1", GetScenariosLoaded()));
164 _print(
string.Format(
" DependenciesLoaded: %1", GetDependenciesLoaded()));
165 _print(
string.Format(
" RequestFailed: %1", GetRequestFailed()));
167 _print(
string.Format(
" AuthorName: %1", GetAuthorName()));
168 _print(
string.Format(
" MyRating: %1", myRating));
169 _print(
string.Format(
" MyRatingSet: %1", myRatingSet));
170 _print(
string.Format(
" Favourite: %1", GetFavourite()));
171 _print(
string.Format(
" Corrupted: %1", GetCorrupted()));
172 _print(
string.Format(
" Description: %1", description));
173 _print(
string.Format(
" Summary: %1", summary));
174 _print(
string.Format(
" RatingCount: %1", GetRatingCount()));
175 _print(
string.Format(
" SizeBytes: %1", GetSizeBytes()));
176 _print(
string.Format(
" UpdateAvailable: %1", GetUpdateAvailable()));
177 _print(
string.Format(
" EnabledExternally: %1", mgr.GetAddonEnabledExternally(
this)));
178 _print(
string.Format(
" TimeSinceLastPlay: %1, %2", GetTimeSinceLastPlay(),
SCR_FormatHelper.GetTimeSinceEventImprecise(GetTimeSinceLastPlay())));
179 _print(
string.Format(
" TimeSinceFirstDl: %1, %2", GetTimeSinceFirstDownload(),
SCR_FormatHelper.GetTimeSinceEventImprecise(GetTimeSinceFirstDownload())));
184 _print(
string.Format(
" AnyDepDisabled: %1", GetEnabledAndAnyDependencyDisabled()));
185 _print(
string.Format(
" AnyDepOutdated: %1", GetAnyDependencyUpdateAvailable()));
186 _print(
string.Format(
" AnyDepMissing: %1", GetAnyDependencyMissing()));
188 _print(
string.Format(
" Dependencies: %1", dependencies.Count()));
191 _print(
string.Format(
" - %1, Offline: %2, Update Available: %3", dep.GetName(), dep.GetOffline(), dep.GetUpdateAvailable()));
203 #ifdef WORKSHOP_DEBUG
204 _print(
"LoadDetails");
207 if (
m_Item || m_Dependency)
209 Internal_LoadDetails();
214 void ClearLoadDetails()
216 m_bDetailsLoaded =
false;
217 m_bWaitingLoadDetails =
false;
222 void GetScenarios(array<MissionWorkshopItem> scenarios)
228 scenarios.Copy(m_aMissions);
234 array<ref SCR_WorkshopItem> GetLatestDependencies()
236 array<ref SCR_WorkshopItem> dependencies =
new array<ref SCR_WorkshopItem>;
242 dependencies.Insert(a);
249 array<ref SCR_WorkshopItem> GetDependentAddons()
251 array<ref SCR_WorkshopItem> dependent =
new array<ref SCR_WorkshopItem>;
256 foreach (
auto a : m_aDependent)
266 string GetLatestVersion()
268 Revision rev = GetLatestRevision();
273 return rev.GetVersion();
278 array<string> GetVersions()
280 array<string> versions =
new array<string>;
282 if (!GetRevisionsLoaded())
285 foreach (
auto rev : m_aRevisions)
287 versions.Insert(rev.GetVersion());
295 bool IsDownloadedVersionCompatible()
301 string targetClientVersion =
"1.0.0";
302 string addonClientVersion =
m_Item.GetActiveRevision().GetGameVersion();
304 array<string> targetNumbers = {};
305 targetClientVersion.Split(
".", targetNumbers,
false);
307 array<string> addonNumbers = {};
308 addonClientVersion.Split(
".", addonNumbers,
false);
310 for (
int i = 0, count = targetNumbers.Count(); i < count; i++)
312 int targetNumber = targetNumbers[i].ToInt();
313 int addonNumber = addonNumbers[i].ToInt();
315 if (targetNumber > addonNumber)
323 void SetMyRating(
bool newRating)
328 m_bMyRatingSet =
true;
329 m_bMyRating = newRating;
331 #ifdef WORKSHOP_DEBUG
332 _print(
"WorkshopItem.Rate(%1)", newRating);
335 m_Item.Rate(newRating,
null);
337 #ifdef WORKSHOP_DEBUG
338 _print(
"OnChanged: SetMyRating()");
351 m_bMyRatingSet =
false;
353 #ifdef WORKSHOP_DEBUG
354 _print(
"WorkshopItem.ResetRating()");
359 #ifdef WORKSHOP_DEBUG
360 _print(
"OnChanged: ResetMyRating()");
368 void GetMyRating(out
bool ratingSet, out
bool rating)
370 ratingSet = m_bMyRatingSet;
371 rating = m_bMyRating;
376 void SetFavourite(
bool favourite)
384 m_bFavourite = favourite;
386 #ifdef WORKSHOP_DEBUG
387 _print(
"OnChanged: SetFavourite()");
401 void SetSubscribed(
bool subscribe)
411 m_bSubscribed = subscribe;
413 #ifdef WORKSHOP_DEBUG
414 _print(
"OnChanged: Subscribe()");
423 return m_bSubscribed;
427 void SetEnabled(
bool enable)
434 #ifdef WORKSHOP_DEBUG
435 _print(
"OnChanged: SetEnabled()");
447 void SetDependenciesEnabled(
bool enable)
454 if (!missing.IsEmpty())
463 if (dep.GetOffline() && dep.GetEnabled() != enable)
465 dep.SetEnabled(enable);
479 return m_Item.IsEnabled();
498 int accessState =
m_Item.GetAccessState();
499 return accessState & EWorkshopItemAccessState.EWASTATE_BLOCKED;
506 bool GetReportedByMe()
509 return m_Item.GetAccessState() & EWorkshopItemAccessState.EWASTATE_REPORTED;
515 bool GetModAuthorReportedByMe()
519 WorkshopAuthor author =
m_Item.Author();
522 return author.IsBlocked();
534 return GetBlocked() || GetReportedByMe() || GetModAuthorReportedByMe();
544 Revision downloadingRevision =
m_Item.GetDownloadingRevision();
546 if (!downloadingRevision && !GetOffline())
551 #ifdef WORKSHOP_DEBUG
552 _print(
"OnChanged: DeleteLocally()");
560 void DeleteDownloadProgress()
564 m_Item.DeleteDownloadProgress();
572 else if (m_Dependency)
573 return m_Dependency.GetName();
583 else if (m_Dependency)
584 return m_Dependency.GetID();
590 string GetAuthorName()
594 WorkshopAuthor author =
m_Item.Author();
597 return author.Name();
608 return m_Item.GetStateFlags() & EWorkshopItemState.EWSTATE_ONLINE;
609 else if (m_Dependency)
620 return m_Item.GetStateFlags() & EWorkshopItemState.EWSTATE_OFFLINE;
621 else if (m_Dependency)
622 return m_Dependency.IsOffline();
629 Revision GetCurrentLocalRevision()
631 if (
m_Item && GetOffline())
632 return m_Item.GetActiveRevision();
639 bool GetCurrentLocalVersionMatchDependency()
641 if (!
m_Item || !m_Dependency)
645 Revision ActiveV = GetCurrentLocalRevision();
646 Revision RequiredV = m_Dependency.GetRevision();
648 return Revision.AreEqual(ActiveV, RequiredV);
656 return (
m_Item.GetStateFlags() & EWorkshopItemState.EWSTATE_CORRUPTED);
657 else if (m_Dependency)
664 BackendImage GetThumbnail()
669 return m_Item.Thumbnail();
673 array<BackendImage> GetGallery()
675 array<BackendImage> gallery = {};
685 string GetDescription()
690 return m_Item.Description();
708 return m_Item.RatingCount();
715 return m_Item.GetSizeBytes();
716 else if(m_Dependency)
717 return m_Dependency.TotalFileSize();
723 float GetAverageRating()
728 return m_Item.AverageRating();
733 void GetDownloadState(out
bool inProgress, out
bool paused, out
float progress, out Revision targetRevision)
735 if (!m_ActionDownload || !
m_Item)
740 targetRevision =
null;
744 inProgress = m_ActionDownload.IsActive() || m_ActionDownload.IsPaused();
745 paused = m_ActionDownload.IsPaused();
746 progress =
m_Item.GetProgress();
747 targetRevision = m_ActionDownload.GetTargetRevision();
754 return m_ActionDownload;
761 return m_ActionDependency;
766 bool GetUpdateAvailable()
768 bool rawUpdateAvailable =
false;
770 rawUpdateAvailable = !
m_Item.HasLatestVersion();
772 bool updateAvailableByVersions = Internal_GetUpdateAvailable();
774 return rawUpdateAvailable || updateAvailableByVersions;
779 array<ref SCR_WorkshopItem> GetMissingDependencies()
781 array<ref SCR_WorkshopItem> dependencies = GetLatestDependencies();
787 bool GetAnyDependencyMissing()
797 bool GetAnyDependencyUpdateAvailable()
808 bool GetEnabledAndAnyDependencyDisabled()
829 if (GetAnyDependencyMissing())
831 else if (GetEnabledAndAnyDependencyDisabled())
833 else if (GetUpdateAvailable())
835 else if (GetAnyDependencyUpdateAvailable())
843 array<ref SCR_WorkshopItem> GetOutdatedDependencies()
845 array<ref SCR_WorkshopItem> dependencies = GetLatestDependencies();
847 if (dependencies.IsEmpty())
848 return new array<ref SCR_WorkshopItem>;
855 int GetTimeSinceLastPlay()
860 return m_Item.GetTimeSinceLastPlay();
865 int GetTimeSinceFirstDownload()
870 return m_Item.GetTimeSinceFirstDownload();
879 if (!
m_Item && !m_Dependency)
882 bool latestRevision = (targetRevision ==
null);
885 if (!m_ActionDownload)
888 SCR_AddonManager.GetInstance().Internal_OnNewDownload(
this, m_ActionDownload);
890 return m_ActionDownload;
894 if (isDownloadRunning)
897 return m_ActionDownload;
901 m_ActionDownload.Cancel();
902 m_ActionDownload.Internal_Detach();
903 m_ActionDownload =
null;
906 SCR_AddonManager.GetInstance().Internal_OnNewDownload(
this, m_ActionDownload);
907 return m_ActionDownload;
924 #ifdef WORKSHOP_DEBUG
926 _print(
string.Format(
"Download: %1", targetRevision.GetVersion()));
928 _print(
string.Format(
"Download: the latest one"));
931 bool running =
false;
932 if (m_ActionDownload && targetRevision)
933 running = Revision.AreEqual(m_ActionDownload.GetTargetRevision(), targetRevision);
935 return DownloadRevision(targetRevision, running);
941 #ifdef WORKSHOP_DEBUG
942 _print(
"DownloadLatestVersion()");
945 Revision latestRevision = GetLatestRevision();
947 bool running =
false;
948 if (m_ActionDownload && latestRevision)
949 running = m_ActionDownload.GetTargetedAtLatestVersion() || Revision.AreEqual(latestRevision, m_ActionDownload.GetTargetRevision());
951 return DownloadRevision(
null, running);
955 void RetryDownload(Revision targetRevision)
957 if (!m_ActionDownload)
960 SCR_AddonManager.GetInstance().Internal_OnNewDownload(
this, m_ActionDownload);
962 m_ActionDownload.Activate();
971 #ifdef WORKSHOP_DEBUG
972 _print(
"DownloadDependenciesLatest()");
978 if (m_ActionDependency)
989 m_ActionDependency.Cancel();
990 m_ActionDependency.Internal_Detach();
991 m_ActionDependency =
null;
994 m_ActionDependency = action;
1001 m_ActionDependency = action;
1008 bool PauseDownload()
1013 if (m_ActionDownload)
1015 return m_ActionDownload.Pause();
1023 bool CancelDownload()
1028 if (m_ActionDownload)
1030 return m_ActionDownload.Cancel();
1038 bool ResumeDownload()
1043 if (m_ActionDownload)
1045 return m_ActionDownload.Resume();
1068 return m_ActionReport;
1073 return m_ActionReport;
1084 if (!m_CallbackLoadMyReport)
1087 m_CallbackLoadMyReport.m_OnSuccess.Insert(Callback_LoadMyReport_OnSuccess);
1088 m_CallbackLoadMyReport.m_OnTimeout.Insert(Callback_LoadMyReport_OnTimeout);
1089 m_CallbackLoadMyReport.m_OnError.Insert(Callback_LoadMyReport_OnError);
1092 m_Item.LoadReport(m_CallbackLoadMyReport);
1099 void GetReport(out EWorkshopReportType reportType, out
string reportDescription)
1103 reportType = EWorkshopReportType.EWREPORT_OTHER;
1104 reportDescription =
string.Empty;
1108 reportType =
m_Item.GetReportType();
1109 reportDescription =
m_Item.GetReportDescription();
1124 return m_ActionCancelReport;
1129 return m_ActionCancelReport;
1140 if (!m_ActionAddAuthorBlock)
1143 return m_ActionAddAuthorBlock;
1153 if (!m_ActionRemoveAuthorBlock)
1156 return m_ActionRemoveAuthorBlock;
1161 Revision FindRevision(
string version)
1166 foreach (Revision r : m_aRevisions)
1168 if (r.GetVersion() == version)
1181 Revision GetLatestRevision()
1186 return m_Item.GetLatestRevision();
1198 protected void Callback_AskDetails_OnGetAsset()
1200 #ifdef WORKSHOP_DEBUG
1201 _print(
"Callback_AskDetails_OnGetAsset()");
1204 TryLoadItemFromDependency();
1208 if (!m_aRevisions || m_aRevisions.IsEmpty())
1210 #ifdef WORKSHOP_DEBUG
1211 _print(
"Callback_AskDetails_OnGetAsset(): Received no revisions", LogLevel.ERROR);
1216 #ifdef WORKSHOP_DEBUG
1217 _print(
"Callback_AskDetails_OnGetAsset(): Received revisions:");
1218 array<string> versions = GetVersions();
1219 foreach (
string ver : versions)
1221 _print(
string.Format(
"Callback_AskDetails_OnGetAsset(): %1", ver));
1225 if (!m_CallbackLoadDependencies)
1228 m_CallbackLoadDependencies.m_OnSuccess.Insert(Callback_LoadDependencies_OnSuccess);
1229 m_CallbackLoadDependencies.m_OnError.Insert(Callback_LoadDependencies_OnError);
1230 m_CallbackLoadDependencies.m_OnTimeout.Insert(Callback_LoadDependencies_OnTimeout);
1233 if (!m_CallbackLoadScenarios)
1236 m_CallbackLoadScenarios.m_OnSuccess.Insert(Callback_LoadScenarios_OnSuccess);
1237 m_CallbackLoadScenarios.m_OnError.Insert(Callback_LoadScenarios_OnError);
1238 m_CallbackLoadScenarios.m_OnTimeout.Insert(Callback_LoadScenarios_OnTimeout);
1243 Revision latestRevision = GetLatestRevision();
1244 m_Item.LoadDependencies(m_CallbackLoadDependencies, latestRevision);
1245 m_Item.LoadScenarios(m_CallbackLoadScenarios, latestRevision);
1249 m_bDetailsLoaded =
true;
1250 m_OnGetAsset.Invoke(
this);
1252 #ifdef WORKSHOP_DEBUG
1253 _print(
"OnChanged: Callback_AskDetails_OnGetAsset");
1258 m_bWaitingLoadDetails =
false;
1263 protected void Callback_AskDetails_OnTimeout()
1265 #ifdef WORKSHOP_DEBUG
1266 _print(
"Callback_AskDetails_OnTimeout()");
1269 m_bWaitingLoadDetails =
false;
1271 m_OnTimeout.Invoke(
this);
1277 m_bRequestFailed =
true;
1278 m_bWaitingLoadDetails =
false;
1281 m_OnGetAsset.Invoke(
this);
1290 protected void Callback_LoadDependencies_OnSuccess()
1292 #ifdef WORKSHOP_DEBUG
1293 _print(
"Callback_LoadDependencies_OnSuccess()");
1296 TryLoadDependencies();
1300 protected void Callback_LoadDependencies_OnError()
1302 #ifdef WORKSHOP_DEBUG
1303 _print(
"Callback_LoadDependencies_OnError()");
1306 m_OnError.Invoke(
this);
1308 CustomDebugError(
"SCR_WorkshopItem failed to load dependencies");
1312 protected void Callback_LoadDependencies_OnTimeout()
1314 #ifdef WORKSHOP_DEBUG
1315 _print(
"Callback_LoadDependencies_OnTimeout()");
1318 m_OnTimeout.Invoke(
this);
1323 protected void Callback_LoadScenarios_OnSuccess()
1325 #ifdef WORKSHOP_DEBUG
1326 _print(
"Callback_LoadScenarios_OnSuccess()");
1333 protected void Callback_LoadScenarios_OnError()
1335 #ifdef WORKSHOP_DEBUG
1336 _print(
"Callback_LoadScenarios_OnError()");
1339 m_OnError.Invoke(
this);
1341 CustomDebugError(
"SCR_WorkshopItem failed to load scenarios");
1345 protected void Callback_LoadScenarios_OnTimeout()
1347 #ifdef WORKSHOP_DEBUG
1348 _print(
"Callback_LoadScenarios_OnTimeout()");
1351 m_OnTimeout.Invoke(
this);
1356 protected void Callback_LoadMyReport_OnSuccess()
1358 m_OnMyReportLoaded.Invoke(
this);
1362 protected void Callback_LoadMyReport_OnError()
1364 m_OnMyReportLoadError.Invoke(
this);
1368 protected void Callback_LoadMyReport_OnTimeout()
1370 m_OnMyReportLoadError.Invoke(
this);
1374 protected void TryLoadItemFromDependency()
1377 if (!
m_Item && m_Dependency)
1379 m_Item = m_Dependency.GetCachedItem();
1383 UpdateStateFromWorkshopItem();
1386 #ifdef WORKSHOP_DEBUG
1388 _print(
string.Format(
"WorkshopItem was missing, but was loaded: %1",
m_Item.Name()));
1395 protected void TryLoadRevisions(
bool log =
true)
1400 array<Revision> revisionsTemp =
new array<Revision>;
1401 m_Item.GetRevisions(revisionsTemp);
1403 if (revisionsTemp.IsEmpty() && m_Dependency)
1404 revisionsTemp.Insert(m_Dependency.GetRevision());
1406 if (revisionsTemp.IsEmpty())
1408 #ifdef WORKSHOP_DEBUG
1410 _print(
string.Format(
"Revisions are not loaded yet. Revision array is empty."));
1418 m_aRevisions = revisionsTemp;
1422 array<ref SCR_WorkshopItem> GetLoadedDependencies()
1428 protected void TryLoadDependencies(
bool log =
true)
1430 #ifdef WORKSHOP_DEBUG
1432 _print(
"TryLoadDependencies()");
1437 Revision latestRevision = GetLatestRevision();
1438 array<Dependency> dependencies =
new array<Dependency>;
1439 latestRevision.GetDependencies(dependencies);
1446 foreach (Dependency dep : dependencies)
1450 RegisterDependency(registeredItem);
1451 registeredItem.RegisterDependent(
this);
1454 m_OnDependenciesLoaded.Invoke(
this);
1460 protected void TryLoadScenarios(
bool log =
true)
1462 #ifdef WORKSHOP_DEBUG
1464 _print(
"TryLoadScenarios()");
1468 Revision latestRevision = GetLatestRevision();
1470 m_aMissions =
new array<MissionWorkshopItem>;
1471 latestRevision.GetScenarios(m_aMissions);
1473 #ifdef WORKSHOP_DEBUG
1474 _print(
string.Format(
"TryLoadScenarios(): Received %1 scenarios", m_aMissions.Count()));
1475 _print(
"OnChanged: Callback_AskDetails_OnGetScenarios");
1480 m_OnScenariosLoaded.Invoke(
this);
1504 int id = m_aDependent.Find(item);
1506 m_aDependent.Insert(item);
1513 m_aDependent.RemoveItem(item);
1536 #ifdef WORKSHOP_DEBUG
1537 _print(
string.Format(
"Internal_StartDownload(): %1, %2", targetRevision.GetVersion(),
callback));
1543 #ifdef WORKSHOP_DEBUG
1544 _print(
"Internal_StartDownload(): UGC privileges were not checked or false!");
1550 #ifdef WORKSHOP_DEBUG
1551 _print(
"Internal_StartDownload(): Calling WorkshopItem.Download ...");
1569 bool Internal_CancelDownload()
1572 #ifdef WORKSHOP_DEBUG
1573 _print(
"Internal_CancelDownload()");
1580 m_CancelDownloadCallback.GetEventOnResponse().Insert(OnCancelDownloadResponse);
1581 m_Item.Cancel(m_CancelDownloadCallback);
1588 m_CancelDownloadCallback.GetEventOnResponse().Remove(OnCancelDownloadResponse);
1592 m_OnError.Invoke(
this);
1595 m_OnCanceled.Invoke(
this);
1650 #ifdef WORKSHOP_DEBUG
1651 _print(
string.Format(
"Internal_Report(): %1, %2, %3", eReport, sMessage,
callback));
1659 #ifdef WORKSHOP_DEBUG
1660 _print(
"OnChanged: Internal_Report()");
1672 #ifdef WORKSHOP_DEBUG
1673 _print(
string.Format(
"Internal_CancelReport(): %1",
callback));
1681 #ifdef WORKSHOP_DEBUG
1682 _print(
"OnChanged: Internal_CancelReport()");
1693 #ifdef WORKSHOP_DEBUG
1694 _print(
string.Format(
"Internal_AddAuthorBlock(): %1",
callback));
1700 WorkshopAuthor author =
m_Item.Author();
1706 #ifdef WORKSHOP_DEBUG
1707 _print(
"OnChanged: Internal_AddAuthorBlock()");
1718 #ifdef WORKSHOP_DEBUG
1719 _print(
string.Format(
"Internal_RemoveAuthorBlock(): %1",
callback));
1725 WorkshopAuthor author =
m_Item.Author();
1731 #ifdef WORKSHOP_DEBUG
1732 _print(
"OnChanged: Internal_RemoveAuthorBlock()");
1742 void Internal_Update(
float timeSlice)
1756 if (m_ActionDownload)
1760 m_ActionDownload.Internal_Update(timeSlice);
1764 newProgress =
m_Item.GetProgress();
1765 if (newProgress != m_fPrevDownloadProgress)
1773 m_fPrevDownloadProgress = newProgress;
1776 if (m_ActionDownload.IsCompleted())
1778 #ifdef WORKSHOP_DEBUG
1779 _print(
"OnChanged: Internal_Update: Download Is Completed");
1782 m_ActionDownload.Internal_Detach();
1783 m_ActionDownload =
null;
1784 m_OnDownloadComplete.Invoke(
this);
1787 else if (m_ActionDownload.IsCanceled())
1789 #ifdef WORKSHOP_DEBUG
1790 _print(
"OnChanged: Internal_Update: Download was canceled, unregistering");
1793 m_ActionDownload.Internal_Detach();
1794 m_ActionDownload =
null;
1797 else if (m_ActionDownload.IsFailed())
1799 #ifdef WORKSHOP_DEBUG
1800 _print(
"OnChanged: Internal_Update: Download has failed, unregistering");
1803 m_ActionDownload.Internal_Detach();
1804 m_ActionDownload =
null;
1811 m_ActionReport.Internal_Update(timeSlice);
1813 if (m_ActionReport.IsCompleted())
1815 m_ActionReport.Internal_Detach();
1816 m_ActionReport =
null;
1818 #ifdef WORKSHOP_DEBUG
1819 _print(
"OnChanged: Internal_Update: Report Action Was Completed");
1823 m_OnReportStateChanged.Invoke(
this,
true);
1827 if (m_ActionCancelReport)
1829 m_ActionCancelReport.Internal_Update(timeSlice);
1831 if (m_ActionCancelReport.IsCompleted())
1833 m_ActionCancelReport.Internal_Detach();
1834 m_ActionCancelReport =
null;
1836 #ifdef WORKSHOP_DEBUG
1837 _print(
"OnChanged: Internal_Update: Cancel report Action Was Completed");
1841 m_OnReportStateChanged.Invoke(
this,
false);
1845 if (m_ActionDependency)
1847 m_ActionDependency.Internal_Update(timeSlice);
1849 if (m_ActionDependency.IsCompleted())
1851 #ifdef WORKSHOP_DEBUG
1852 _print(
"OnChanged: Internal_Update: Dependency action is completed, unregistering");
1855 m_ActionDependency.Internal_Detach();
1856 m_ActionDependency =
null;
1860 else if (m_ActionDependency.IsCanceled())
1862 #ifdef WORKSHOP_DEBUG
1863 _print(
"OnChanged: Internal_Update: Dependency action is canceled, unregistering");
1866 m_ActionDependency.Internal_Detach();
1867 m_ActionDependency =
null;
1870 else if (m_ActionDependency.IsFailed())
1872 #ifdef WORKSHOP_DEBUG
1873 _print(
"OnChanged: Internal_Update: Dependency action has failed, unregistering");
1876 m_ActionDependency.Internal_Detach();
1877 m_ActionDependency =
null;
1883 UpdateAuthorBlock();
1886 bool offlineNew = GetOffline();
1887 if (offlineNew != m_bOffline)
1889 m_OnOfflineStateChanged.Invoke(
this, offlineNew);
1891 m_bOffline = offlineNew;
1896 int accessState =
m_Item.GetAccessState();
1897 if (accessState != m_iAccessState)
1899 #ifdef WORKSHOP_DEBUG
1900 _print(
"OnChanged: Internal_Update: Access state has changed");
1903 m_iAccessState = accessState;
1911 #ifdef WORKSHOP_DEBUG
1912 _print(
string.Format(
"Invoking OnChanged: ID: %1, Name: %2", GetId(), GetName()));
1919 foreach (
auto i : m_aDependent)
1923 #ifdef WORKSHOP_DEBUG
1924 _print(
string.Format(
"Invoking OnChanged: ID: %1, Name: %2, for dependent: %3, %4", GetId(), GetName(), i.GetId(), i.GetName()));
1926 i.m_OnChanged.Invoke(i);
1934 protected void UpdateAuthorBlock()
1937 if (m_ActionAddAuthorBlock)
1939 m_ActionAddAuthorBlock.Internal_Update(0);
1941 if (m_ActionAddAuthorBlock.IsCompleted())
1943 m_ActionAddAuthorBlock.Internal_Detach();
1944 m_ActionAddAuthorBlock =
null;
1946 #ifdef WORKSHOP_DEBUG
1947 _print(
"OnChanged: Internal_Update: Add author block action Was Completed");
1951 m_OnReportStateChanged.Invoke(
this,
true);
1956 if (m_ActionRemoveAuthorBlock)
1958 m_ActionRemoveAuthorBlock.Internal_Update(0);
1960 if (m_ActionRemoveAuthorBlock.IsCompleted())
1962 m_ActionRemoveAuthorBlock.Internal_Detach();
1963 m_ActionRemoveAuthorBlock =
null;
1965 #ifdef WORKSHOP_DEBUG
1966 _print(
"OnChanged: Internal_Update: Add author block action Was Completed");
1970 m_OnReportStateChanged.Invoke(
this,
false);
1977 void Internal_OnChanged()
1986 bool Internal_GetCanBeUnregistered()
1988 if (m_ActionDownload || m_ActionReport || m_ActionDependency || m_ActionCancelReport || GetOffline()
1989 || m_ActionAddAuthorBlock || m_ActionRemoveAuthorBlock)
1998 WorkshopItem Internal_GetWorkshopItem()
2001 m_Item = m_Dependency.GetCachedItem();
2006 float Internal_GetDownloadProgress()
2011 return m_Item.GetProgress();
2015 bool Internal_GetIsProcessing()
2020 return m_Item.IsProcessing();
2024 float Internal_GetProcessingProgress()
2029 return m_Item.GetProcessingProgress();
2034 void Internal_LoadDetails()
2036 if (!m_CallbackAskDetails)
2039 m_CallbackAskDetails.m_OnGetAsset.Insert(Callback_AskDetails_OnGetAsset);
2042 m_CallbackAskDetails.m_OnTimeout.Insert(Callback_AskDetails_OnTimeout);
2043 m_CallbackAskDetails.m_OnError.Insert(Callback_AskDetails_OnError);
2047 if (!m_bWaitingLoadDetails)
2051 if (
m_Item.GetStateFlags() & EWorkshopItemState.EWSTATE_ONLINE)
2053 m_Item.AskDetail(m_CallbackAskDetails);
2054 m_bWaitingLoadDetails =
true;
2057 else if (m_Dependency)
2059 m_Dependency.LoadItem(m_CallbackAskDetails);
2060 m_bWaitingLoadDetails =
true;
2066 void SetItemTargetRevision(Revision revision)
2068 m_ItemTargetRevision = revision;
2072 Revision GetItemTargetRevision()
2074 return m_ItemTargetRevision;
2078 void SetTargetRevisionPatchSize(
float size)
2080 m_fTargetRevisionPatchSize = size;
2086 float GetTargetRevisionPatchSize()
2088 return m_fTargetRevisionPatchSize;
2092 protected void SetChanged()
2119 m_Dependency = dependency;
2123 #ifdef WORKSHOP_DEBUG
2124 _print(
string.Format(
"NEW for WorkshopItem: ID: %1, Name: %2",
m_Item.Id(),
m_Item.Name()));
2127 UpdateStateFromWorkshopItem();
2132 #ifdef WORKSHOP_DEBUG
2133 _print(
string.Format(
"NEW for Dependency: ID: %1, Name: %2", m_Dependency.GetID(), m_Dependency.GetName()));
2137 if (!
m_Item && !m_Dependency)
2138 Print(
"Can't be set!");
2140 m_bOffline = GetOffline();
2142 #ifdef WORKSHOP_DEBUG
2151 #ifdef WORKSHOP_DEBUG
2152 _print(
string.Format(
"DELETE for: ID: %1, Name: %2", this.GetId(), this.GetName()));
2162 dependency.UnregisterDependent(
this);
2170 void Internal_UpdateObjects(WorkshopItem item, Dependency dependency)
2172 #ifdef WORKSHOP_DEBUG
2173 _print(
string.Format(
"Internal_UpdateObjects: %1, %2", item, dependency));
2179 UpdateStateFromWorkshopItem();
2185 m_Dependency = dependency;
2190 void Internal_OnAddonsChecked()
2192 UpdateStateFromWorkshopItem();
2196 protected bool Internal_GetUpdateAvailable()
2198 if (GetCurrentLocalRevision())
2199 return GetCurrentLocalRevision().CompareTo(GetLatestRevision()) < 0;
2213 static SCR_WorkshopItem Internal_CreateFromDependency(Dependency dependency)
2215 WorkshopItem cachedItem = dependency.GetCachedItem();
2216 #ifdef WORKSHOP_DEBUG
2217 _sprint(
string.Format(
"Internal_CreateFromDependency(): cached Workshop Item was found"));
2224 void UpdateStateFromWorkshopItem()
2228 m_bSubscribed =
m_Item.IsSubscribed();
2229 m_bMyRating =
m_Item.MyRating();
2230 m_bMyRatingSet =
m_Item.IsRatingSet();
2231 m_bFavourite =
m_Item.IsFavorite();
2237 TryLoadDependencies();
2246 static void _sprint(
string str, LogLevel logLevel = LogLevel.DEBUG)
2248 Print(
string.Format(
"[SCR_AddonManager] %1", str), logLevel);
2252 void _print(
string str, LogLevel logLevel = LogLevel.DEBUG)
2254 Print(
string.Format(
"[SCR_AddonManager] %1 %2",
this, str), logLevel);
2258 protected void CustomDebugError(
string message)
2260 string addonEnv =
"unknown due to missing item";
2262 addonEnv =
m_Item.GetBackendEnv();
2264 string CurrentEnv =
GetGame().GetBackendApi().GetBackendEnv();