-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathManifestGeneratorService.cs
More file actions
51 lines (47 loc) · 1.98 KB
/
Copy pathManifestGeneratorService.cs
File metadata and controls
51 lines (47 loc) · 1.98 KB
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
using System.Text.Json;
using GeneralUpdate.Tools.Models;
namespace GeneralUpdate.Tools.Services;
public static class ManifestGeneratorService
{
public static string GenerateJson(ManifestModel model)
{
var obj = new
{
mainAppName = model.MainAppName,
clientVersion = model.ClientVersion,
appType = model.AppType,
updateAppName = model.UpdateAppName,
upgradeClientVersion = model.UpgradeClientVersion,
productId = model.ProductId,
updatePath = model.UpdatePath
};
return JsonSerializer.Serialize(obj, new JsonSerializerOptions { WriteIndented = true });
}
/// <summary>
/// Builds a <see cref="ManifestModel"/> from parsed csproj data,
/// with user input overriding where a non-blank value was supplied.
/// Uses <see cref="string.IsNullOrWhiteSpace"/> so that empty strings
/// (the default for unedited UI fields) still fall back to csproj data.
/// </summary>
public static ManifestModel FromCsprojInfo(CsprojInfo client, CsprojInfo? upgrade, ManifestModel? userInput = null)
{
return new ManifestModel
{
MainAppName = !string.IsNullOrWhiteSpace(userInput?.MainAppName)
? userInput.MainAppName
: client.AssemblyName,
ClientVersion = userInput?.ClientVersion ?? "1.0.0",
AppType = !string.IsNullOrWhiteSpace(userInput?.AppType)
? userInput.AppType
: "Client",
UpdateAppName = !string.IsNullOrWhiteSpace(userInput?.UpdateAppName)
? userInput.UpdateAppName
: upgrade?.AssemblyName ?? "Update.exe",
UpgradeClientVersion = userInput?.UpgradeClientVersion ?? "1.0.0",
ProductId = userInput?.ProductId ?? "",
UpdatePath = !string.IsNullOrWhiteSpace(userInput?.UpdatePath)
? userInput.UpdatePath
: "update/"
};
}
}