diff options
author | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
---|---|---|
committer | Kae <80987908+Novaenia@users.noreply.github.com> | 2023-06-20 14:33:09 +1000 |
commit | 6352e8e3196f78388b6c771073f9e03eaa612673 (patch) | |
tree | e23772f79a7fbc41bc9108951e9e136857484bf4 /source/application/StarUserGeneratedContentService_pc_steam.cpp | |
parent | 6741a057e5639280d85d0f88ba26f000baa58f61 (diff) |
everything everywhere
all at once
Diffstat (limited to 'source/application/StarUserGeneratedContentService_pc_steam.cpp')
-rw-r--r-- | source/application/StarUserGeneratedContentService_pc_steam.cpp | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/source/application/StarUserGeneratedContentService_pc_steam.cpp b/source/application/StarUserGeneratedContentService_pc_steam.cpp new file mode 100644 index 0000000..57a0c17 --- /dev/null +++ b/source/application/StarUserGeneratedContentService_pc_steam.cpp @@ -0,0 +1,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; +} + + +} |