| 256 | } |
| 257 | |
| 258 | void ModUploader::uploadToSteam() { |
| 259 | if (!m_modDirectory) |
| 260 | return; |
| 261 | |
| 262 | QProgressDialog progress("Uploading to Steam...", "", 0, 0, this); |
| 263 | progress.setWindowModality(Qt::WindowModal); |
| 264 | progress.setCancelButton(nullptr); |
| 265 | progress.setAutoReset(false); |
| 266 | progress.show(); |
| 267 | |
| 268 | if (m_assetSource->assetPaths().empty()) { |
| 269 | QMessageBox::critical(this, "Error", "Cannot upload, mod has no content"); |
| 270 | return; |
| 271 | } |
| 272 | |
| 273 | m_steamItemCreateResult = {}; |
| 274 | m_steamItemSubmitResult = {}; |
| 275 | |
| 276 | JsonObject metadata = m_assetSource->metadata(); |
| 277 | String modIdString = metadata.value("steamContentId", "").toString(); |
| 278 | if (modIdString.empty()) { |
| 279 | CCallResult<ModUploader, CreateItemResult_t> callResultCreate; |
| 280 | callResultCreate.Set(SteamUGC()->CreateItem(SteamUtils()->GetAppID(), k_EWorkshopFileTypeCommunity), |
| 281 | this, &ModUploader::onSteamCreateItem); |
| 282 | |
| 283 | progress.setLabelText("Creating new Steam UGC Item"); |
| 284 | while (!m_steamItemCreateResult) { |
| 285 | QApplication::processEvents(); |
| 286 | SteamAPI_RunCallbacks(); |
| 287 | Thread::sleep(20); |
| 288 | } |
| 289 | |
| 290 | if (m_steamItemCreateResult->second) { |
| 291 | QMessageBox::critical(this, "Error", "There was an IO error creating a new Steam UGC item"); |
| 292 | return; |
| 293 | } |
| 294 | |
| 295 | if (m_steamItemCreateResult->first.m_bUserNeedsToAcceptWorkshopLegalAgreement) { |
| 296 | QMessageBox::critical(this, "Error", "The current Steam user has not agreed to the workshop legal agreement"); |
| 297 | return; |
| 298 | } |
| 299 | |
| 300 | if (m_steamItemCreateResult->first.m_eResult == k_EResultInsufficientPrivilege) { |
| 301 | QMessageBox::critical(this, "Error", "Insufficient privileges to create a new Steam UGC item"); |
| 302 | return; |
| 303 | } |
| 304 | |
| 305 | if (m_steamItemCreateResult->first.m_eResult != k_EResultOK) { |
| 306 | QMessageBox::critical(this, "Error", strf("Error creating new Steam UGC Item ({})", m_steamItemCreateResult->first.m_eResult).c_str()); |
| 307 | return; |
| 308 | } |
| 309 | |
| 310 | modIdString = toString(m_steamItemCreateResult->first.m_nPublishedFileId); |
| 311 | String modUrl = strf("steam://url/CommunityFilePage/{}", modIdString); |
| 312 | |
| 313 | metadata.set("steamContentId", modIdString); |
| 314 | metadata.set("link", modUrl); |
| 315 | m_assetSource->setMetadata(metadata); |
nothing calls this directly
no test coverage detected