Skip to content

Commit 59cf437

Browse files
committed
feat: upload progress
1 parent c11ab17 commit 59cf437

File tree

7 files changed

+114
-40
lines changed

7 files changed

+114
-40
lines changed

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<Version>35.9.4</Version>
3+
<Version>35.9.5</Version>
44
<TargetFramework>net10.0</TargetFramework>
55
<RepositoryUrl>https://github.com/dead-cells-core-modding/core</RepositoryUrl>
66
<RepositoryType>git</RepositoryType>

mdk/DCCMTool/Commands/Cdb/DiffCdbCommand.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using GameRes.Core.Cdb;
33
using GameRes.Core.Pak;
44
using Newtonsoft.Json.Linq;
5+
using Spectre.Console;
56
using Spectre.Console.Cli;
67
using System;
78
using System.Collections.Generic;
@@ -21,7 +22,7 @@ public override int Execute()
2122
var srcText = File.ReadAllText(Arguments.CDBPath);
2223
if(templateText == srcText)
2324
{
24-
Console.WriteLine("Warning: Attempt to compare two same file.");
25+
AnsiConsole.WriteLine("Warning: Attempt to compare two same file.");
2526
}
2627
var templateCDB = CdbFile.ReadFrom(templateText);
2728
var srcCDB = CdbFile.ReadFrom(srcText);
@@ -47,7 +48,7 @@ public override int Execute()
4748
diff.Add(l);
4849
if(Arguments.ShowDifference)
4950
{
50-
Console.WriteLine($"{sheet.Name}-{l.Separator.Name}-{l.Name}: {l.Value.Path}");
51+
AnsiConsole.WriteLine($"{sheet.Name}-{l.Separator.Name}-{l.Name}: {l.Value.Path}");
5152
}
5253
}
5354
}

mdk/DCCMTool/Commands/Docs/GenerateHaxeDBCommand.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using HaxeDocs;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
5+
using Spectre.Console;
56
using Spectre.Console.Cli;
67
using System;
78
using System.Buffers;
@@ -70,11 +71,11 @@ private static async Task<string> SendCommand(HaxeInstance haxe, string? stdin,
7071
{
7172
if (l[0] == 0x01)
7273
{
73-
Console.WriteLine("Haxe Print: " + l[1..]);
74+
AnsiConsole.WriteLine("Haxe Print: " + l[1..]);
7475
}
7576
else if (l[0] == 0x02)
7677
{
77-
Console.Error.WriteLine("Haxe Error: " + l[1..]);
78+
AnsiConsole.WriteLine("Haxe Error: " + l[1..]);
7879

7980
}
8081
else
@@ -231,15 +232,15 @@ async Task LoadMemberInfo(bool isStatic)
231232
catch (JsonReaderException) { }
232233
catch (HaxeCompilerException ex)
233234
{
234-
Console.Error.WriteLine(ex);
235+
AnsiConsole.WriteException(ex);
235236
}
236237
}
237238

238239
await LoadMemberInfo(true);
239240
await LoadMemberInfo(false);
240241
}
241242
haxe.Process.Kill();
242-
Console.WriteLine("Job Finished");
243+
AnsiConsole.WriteLine("Job Finished");
243244
}
244245

245246
public override async Task<int> ExecuteAsync()
@@ -250,7 +251,7 @@ public override async Task<int> ExecuteAsync()
250251
jobsCount = Environment.ProcessorCount;
251252
}
252253

253-
Console.WriteLine("Jobs Count: " + jobsCount);
254+
AnsiConsole.WriteLine("Jobs Count: " + jobsCount);
254255

255256
var td = Arguments.TempDir;
256257
if (string.IsNullOrEmpty(td))
@@ -262,7 +263,7 @@ public override async Task<int> ExecuteAsync()
262263

263264
if(Arguments.Libraries != null)
264265
{
265-
Console.WriteLine("Parsing libraries...");
266+
AnsiConsole.WriteLine("Parsing libraries...");
266267
var hxlib = Process.Start(new ProcessStartInfo("haxelib", " path " + string.Join(' ', Arguments.Libraries)){
267268
RedirectStandardOutput = true,
268269
});
@@ -278,11 +279,11 @@ public override async Task<int> ExecuteAsync()
278279
}
279280
sb.AppendLine(v);
280281
}
281-
Console.WriteLine(sb);
282+
AnsiConsole.WriteLine(sb.ToString());
282283
commonDisplayLibraryArgs = [ sb.ToString() ];
283284
}
284285

285-
Console.WriteLine("Starting haxe language server...");
286+
AnsiConsole.WriteLine("Starting haxe language server...");
286287

287288
var defHaxe = CreateHaxeInstance();
288289

@@ -292,13 +293,13 @@ public override async Task<int> ExecuteAsync()
292293
(int)initResult["haxeVersion"]["minor"],
293294
(int)initResult["haxeVersion"]["patch"]);
294295

295-
Console.WriteLine("Haxe Version: " + version);
296+
AnsiConsole.WriteLine("Haxe Version: " + version);
296297

297298

298299

299300
//Collecting class
300301

301-
Console.WriteLine("Collecting class..");
302+
AnsiConsole.WriteLine("Collecting class..");
302303

303304
var doc = new HaxeDocument();
304305
List<HaxeDocument.TypeInfo> types = doc.Types;
@@ -325,10 +326,10 @@ public override async Task<int> ExecuteAsync()
325326
}
326327
}
327328

328-
Console.WriteLine($"Loaded {types.Count} types");
329+
AnsiConsole.WriteLine($"Loaded {types.Count} types");
329330
await DisplayFunc(defHaxe, "var a: h3d.mat.Texture3D;a.");
330331

331-
Console.WriteLine("Loading class members...");
332+
AnsiConsole.WriteLine("Loading class members...");
332333

333334
List<Task> jobs = [];
334335

mdk/DCCMTool/Commands/HaxeDebugInfoCommand.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using BytecodeMapping;
2+
using Spectre.Console;
23
using Spectre.Console.Cli;
34
using System;
45
using System.Collections.Generic;
@@ -68,7 +69,7 @@ public override int Execute()
6869
}
6970
}
7071

71-
Console.WriteLine($"{fun.Name}{{IL Index: {bestFit.ILIndex}}}");
72+
AnsiConsole.WriteLine($"{fun.Name}{{IL Index: {bestFit.ILIndex}}}");
7273
return 0;
7374
}
7475

mdk/DCCMTool/Commands/Steam/SteamWorkshopMountCommand.cs

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
using Newtonsoft.Json.Linq;
3+
using Spectre.Console;
34
using Spectre.Console.Cli;
45
using Steamworks;
56
using System;
@@ -22,7 +23,7 @@ public override async Task<int> ExecuteSteamAsync()
2223
}
2324
if(string.IsNullOrEmpty(gameRoot) || !Directory.Exists(gameRoot))
2425
{
25-
Console.WriteLine("Game directory not found.");
26+
AnsiConsole.WriteLine("Game directory not found.");
2627
return -1;
2728
}
2829

@@ -32,7 +33,7 @@ public override async Task<int> ExecuteSteamAsync()
3233

3334
if (Directory.Exists(modRoot) || File.Exists(modRoot))
3435
{
35-
Console.WriteLine($"The specified mod exists in the local mods folder. If you wish to proceed, please delete \"{modRoot}\".");
36+
AnsiConsole.WriteLine($"The specified mod exists in the local mods folder. If you wish to proceed, please delete \"{modRoot}\".");
3637
return -1;
3738
}
3839

@@ -50,7 +51,7 @@ public override async Task<int> ExecuteSteamAsync()
5051

5152
if (!SteamUGC.GetQueryUGCResult(handle, 0, out var pDetails))
5253
{
53-
Console.WriteLine($"{Arguments.Name} was not found in the subscribed mods.");
54+
AnsiConsole.WriteLine($"{Arguments.Name} was not found in the subscribed mods.");
5455
}
5556
else
5657
{
@@ -72,7 +73,7 @@ public override async Task<int> ExecuteSteamAsync()
7273

7374
if (!SteamUGC.GetQueryUGCResult(handle, 0, out var pDetails))
7475
{
75-
Console.WriteLine($"{Arguments.Name} was not found in the steam workshop.");
76+
AnsiConsole.WriteLine($"{Arguments.Name} was not found in the steam workshop.");
7677
}
7778
else
7879
{
@@ -83,7 +84,7 @@ public override async Task<int> ExecuteSteamAsync()
8384
}
8485
if(modId == null)
8586
{
86-
Console.WriteLine("The specified mod cannot be found.");
87+
AnsiConsole.WriteLine("The specified mod cannot be found.");
8788
return -1;
8889
}
8990
var mod = modId.Value;
@@ -94,10 +95,10 @@ public override async Task<int> ExecuteSteamAsync()
9495
{
9596
if (!Arguments.InstallModAuto)
9697
{
97-
Console.WriteLine("The specified mod is not installed.");
98+
AnsiConsole.WriteLine("The specified mod is not installed.");
9899
return -2;
99100
}
100-
Console.WriteLine("Downloading mod...");
101+
AnsiConsole.WriteLine("Downloading mod...");
101102
SteamUGC.SubscribeItem(mod);
102103
SteamUGC.DownloadItem(mod, true);
103104
while (!((EItemState)SteamUGC.GetItemState(mod)).HasFlag(EItemState.k_EItemStateInstalled))
@@ -107,7 +108,7 @@ public override async Task<int> ExecuteSteamAsync()
107108
goto _RE_TRY;
108109
}
109110

110-
Console.WriteLine("Mod Path: " + path);
111+
AnsiConsole.WriteLine("Mod Path: " + path);
111112

112113

113114
Directory.CreateSymbolicLink(modRoot, path);

mdk/DCCMTool/Commands/Steam/UploadMAPICommand.cs

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
using Serilog.Core;
3+
using Spectre.Console;
34
using Spectre.Console.Cli;
45
using Steamworks;
56
using System;
@@ -25,7 +26,44 @@ public override async Task<int> ExecuteSteamAsync()
2526
SteamUGC.SetItemContent(updateHandle, Arguments.InputDir);
2627

2728
var ver = File.ReadAllText(Path.Combine(Arguments.InputDir, "ModCoreVersion.txt")).Trim();
28-
await SteamUGC.SubmitItemUpdate(updateHandle, $"Upload to v{ver}").Wait<RemoteStorageUpdatePublishedFileResult_t>();
29+
30+
var cb = SteamUGC.SubmitItemUpdate(updateHandle, $"Upload to v{ver}").Wait<RemoteStorageUpdatePublishedFileResult_t>();
31+
32+
await AnsiConsole.Progress()
33+
.StartAsync(async ctx =>
34+
{
35+
var task = ctx.AddTask("Uploading");
36+
while (!task.IsFinished)
37+
{
38+
var progress = SteamUGC.GetItemUpdateProgress(updateHandle, out var bytesProcessed, out var bytesTotal);
39+
40+
if (progress == EItemUpdateStatus.k_EItemUpdateStatusInvalid)
41+
{
42+
break;
43+
}
44+
else if (progress == EItemUpdateStatus.k_EItemUpdateStatusPreparingConfig ||
45+
progress == EItemUpdateStatus.k_EItemUpdateStatusPreparingContent)
46+
{
47+
task.Description = "Preparing...";
48+
}
49+
else if (progress == EItemUpdateStatus.k_EItemUpdateStatusUploadingContent)
50+
{
51+
task.Value = bytesTotal > 0 ? (double)bytesProcessed / bytesTotal * 100 : 0;
52+
task.Description = $"Uploading... ({bytesProcessed}/{bytesTotal} bytes)";
53+
}
54+
else
55+
{
56+
task.Description = "Finalizing...";
57+
task.Value = 100;
58+
}
59+
await Task.Delay(100);
60+
}
61+
});
62+
63+
var result = await cb;
64+
65+
AnsiConsole.MarkupLine("[green]Done.[/]");
66+
2967

3068
return 0;
3169
}

mdk/DCCMTool/Commands/Steam/UploadModCommnand.cs

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using DCCMTool.Commands.Cdb;
33
using Newtonsoft.Json;
44
using Newtonsoft.Json.Linq;
5+
using Spectre.Console;
56
using Spectre.Console.Cli;
67
using Steamworks;
78
using 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

Comments
 (0)