blob: 57a0c17197c66422dad52ffc120e248e5b07b2fa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
#include "StarUserGeneratedContentService_pc_steam.hpp"
#include "StarLogging.hpp"
#include "StarLexicalCast.hpp"
namespace Star {
SteamUserGeneratedContentService::SteamUserGeneratedContentService(PcPlatformServicesStatePtr)
: m_callbackDownloadResult(this, &SteamUserGeneratedContentService::onDownloadResult) {};
StringList SteamUserGeneratedContentService::subscribedContentIds() const {
List<PublishedFileId_t> contentIds(SteamUGC()->GetNumSubscribedItems(), {});
SteamUGC()->GetSubscribedItems(contentIds.ptr(), contentIds.size());
return contentIds.transformed([](PublishedFileId_t id) {
return String(toString(id));
});
}
Maybe<String> SteamUserGeneratedContentService::contentDownloadDirectory(String const& contentId) const {
PublishedFileId_t id = lexicalCast<PublishedFileId_t>(contentId);
uint32 itemState = SteamUGC()->GetItemState(id);
if (itemState & k_EItemStateInstalled) {
char path[4096];
if (SteamUGC()->GetItemInstallInfo(id, nullptr, path, sizeof(path), nullptr))
return String(path);
}
return {};
}
bool SteamUserGeneratedContentService::triggerContentDownload() {
List<PublishedFileId_t> contentIds(SteamUGC()->GetNumSubscribedItems(), {});
SteamUGC()->GetSubscribedItems(contentIds.ptr(), contentIds.size());
for (uint64 contentId : contentIds) {
if (!m_currentDownloadState.contains(contentId)) {
uint32 itemState = SteamUGC()->GetItemState(contentId);
if (!(itemState & k_EItemStateInstalled) || itemState & k_EItemStateNeedsUpdate) {
SteamUGC()->DownloadItem(contentId, true);
itemState = SteamUGC()->GetItemState(contentId);
m_currentDownloadState[contentId] = !(itemState & k_EItemStateDownloading);
} else {
m_currentDownloadState[contentId] = true;
}
}
}
bool allDownloaded = true;
for (auto const& p : m_currentDownloadState) {
if (!p.second)
allDownloaded = false;
}
return allDownloaded;
}
void SteamUserGeneratedContentService::onDownloadResult(DownloadItemResult_t* result) {
m_currentDownloadState[result->m_nPublishedFileId] = true;
}
}
|