22using DCCMTool . Commands . Cdb ;
33using Newtonsoft . Json ;
44using Newtonsoft . Json . Linq ;
5+ using Spectre . Console ;
56using Spectre . Console . Cli ;
67using Steamworks ;
78using System ;
@@ -21,7 +22,7 @@ public override async Task<int> ExecuteSteamAsync()
2122 var modname = modinfo [ "name" ] ! . ToString ( ) ;
2223 var ver = modinfo [ "version" ] ! . ToString ( ) ;
2324
24- Console . WriteLine ( $ "Finding mod { modname } in workshop...") ;
25+ AnsiConsole . WriteLine ( $ "Finding mod { modname } in workshop...") ;
2526
2627 var handle = SteamUGC . CreateQueryUserUGCRequest ( SteamUser . GetSteamID ( ) . GetAccountID ( ) , EUserUGCList . k_EUserUGCList_Published ,
2728 EUGCMatchingUGCType . k_EUGCMatchingUGCType_All , EUserUGCListSortOrder . k_EUserUGCListSortOrder_LastUpdatedDesc ,
@@ -38,14 +39,14 @@ public override async Task<int> ExecuteSteamAsync()
3839 if ( resultCount > 1 )
3940 {
4041 SteamUGC . ReleaseQueryUGCRequest ( handle ) ;
41- Console . Error . WriteLine ( " You appear to have uploaded multiple mods with the same name.") ;
42+ AnsiConsole . MarkupLine ( "[red] You appear to have uploaded multiple mods with the same name.[/] ") ;
4243 return - 1 ;
4344 }
4445 else if ( resultCount == 1 )
4546 {
4647 if ( ! SteamUGC . GetQueryUGCResult ( handle , 0 , out var details ) )
4748 {
48- Console . Error . WriteLine ( "Failed to GetQueryUGCResult" ) ;
49+ AnsiConsole . WriteLine ( "[red] Failed to GetQueryUGCResult[/] " ) ;
4950 SteamUGC . ReleaseQueryUGCRequest ( handle ) ;
5051 return - 2 ;
5152 }
@@ -56,11 +57,11 @@ public override async Task<int> ExecuteSteamAsync()
5657 else if ( resultCount == 0 )
5758 {
5859 SteamUGC . ReleaseQueryUGCRequest ( handle ) ;
59- Console . WriteLine ( "Creating new item..." ) ;
60+ AnsiConsole . WriteLine ( "Creating new item..." ) ;
6061 var r = await SteamUGC . CreateItem ( APPID , EWorkshopFileType . k_EWorkshopFileTypeCommunity ) . Wait < CreateItemResult_t > ( ) ;
6162 if ( r . m_eResult != EResult . k_EResultOK )
6263 {
63- Console . WriteLine ( "Failed to create new item: " + r . m_eResult . ToString ( ) ) ;
64+ AnsiConsole . WriteLine ( "Failed to create new item: " + r . m_eResult . ToString ( ) ) ;
6465 return - 3 ;
6566 }
6667 updateHandle = SteamUGC . StartItemUpdate ( APPID , r . m_nPublishedFileId ) ;
@@ -80,7 +81,7 @@ public override async Task<int> ExecuteSteamAsync()
8081 var rp = previewPath + v ;
8182 if ( File . Exists ( rp ) )
8283 {
83- Console . WriteLine ( "Found preview: " + rp ) ;
84+ AnsiConsole . WriteLine ( "Found preview: " + rp ) ;
8485 SteamUGC . SetItemPreview ( updateHandle , Path . GetFullPath ( rp ) ) ;
8586 break ;
8687 }
@@ -98,20 +99,51 @@ public override async Task<int> ExecuteSteamAsync()
9899 Arguments . UpdateText = "Update to v" + ver ;
99100 }
100101
101- Console . WriteLine ( "Uploading..." ) ;
102+ var sresultTask = SteamUGC . SubmitItemUpdate ( updateHandle , Arguments . UpdateText ) . Wait < SubmitItemUpdateResult_t > ( ) ;
102103
103- var sresult = await SteamUGC . SubmitItemUpdate ( updateHandle , Arguments . UpdateText ) . Wait < SubmitItemUpdateResult_t > ( ) ;
104-
105- if ( sresult . m_eResult != EResult . k_EResultOK )
104+ await AnsiConsole . Progress ( ) . StartAsync ( async ctx =>
106105 {
107- Console . WriteLine ( "Unable to upload mod: " + sresult . m_eResult ) ;
108- Console . WriteLine ( "Please visit https://partner.steamgames.com/doc/api/ISteamUGC#SubmitItemUpdateResult_t for more information." ) ;
106+ var task = ctx . AddTask ( "Uploading" ) ;
107+ while ( ! task . IsFinished )
108+ {
109+ var progress = SteamUGC . GetItemUpdateProgress ( updateHandle , out var bytesProcessed , out var bytesTotal ) ;
110+
111+ if ( progress == EItemUpdateStatus . k_EItemUpdateStatusInvalid )
112+ {
113+ task . Description ( "Upload" ) ;
114+ break ;
115+ }
116+ else if ( progress == EItemUpdateStatus . k_EItemUpdateStatusPreparingConfig ||
117+ progress == EItemUpdateStatus . k_EItemUpdateStatusPreparingContent )
118+ {
119+ task . Description = "Preparing..." ;
120+ }
121+ else if ( progress == EItemUpdateStatus . k_EItemUpdateStatusUploadingContent )
122+ {
123+ task . Value = bytesTotal > 0 ? ( double ) bytesProcessed / bytesTotal * 100 : 0 ;
124+ task . Description = $ "Uploading... ({ bytesProcessed } /{ bytesTotal } bytes)";
125+ }
126+ else
127+ {
128+ task . Description = "Finalizing..." ;
129+ task . Value = 100 ;
130+ }
131+ await Task . Delay ( 100 ) ;
132+ }
133+ } ) ;
134+
135+ var sresult = await sresultTask ;
136+
137+ if ( sresult . m_eResult != EResult . k_EResultOK )
138+ {
139+ AnsiConsole . MarkupLine ( "[red]Unable to upload mod:{0}[/]" , sresult . m_eResult ) ;
140+ AnsiConsole . MarkupLine ( "Please visit https://partner.steamgames.com/doc/api/ISteamUGC#SubmitItemUpdateResult_t for more information." ) ;
109141 return - 1 ;
110142 }
111143
112- Console . WriteLine ( "Mod Workshop Id: " + publishId . m_PublishedFileId ) ;
113- Console . WriteLine ( "You can access your mod here.: https://steamcommunity.com/sharedfiles/filedetails/?id=" + publishId . m_PublishedFileId ) ;
114- Console . WriteLine ( "Finished. ") ;
144+ AnsiConsole . MarkupLine ( "Mod Workshop Id: " + publishId . m_PublishedFileId ) ;
145+ AnsiConsole . MarkupLine ( "You can access your mod here: [green] https://steamcommunity.com/sharedfiles/filedetails/?id={0}[/]" , publishId . m_PublishedFileId ) ;
146+ AnsiConsole . MarkupLine ( "[green]Done.[/] ") ;
115147
116148 return 0 ;
117149 }
0 commit comments