Skip to content

Commit aeb5fc2

Browse files
committed
Publicize specified assemblies. Do not carry all hashes from managed dir, only updated files
1 parent b1d1bdc commit aeb5fc2

File tree

4 files changed

+40
-16
lines changed

4 files changed

+40
-16
lines changed

src/UnturnedRedistUpdateTool/Program.cs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ private static async Task<int> Main(string[] args)
1616
#if DEBUG
1717
if (args.Length == 0)
1818
{
19-
args = [@"C:\Me\Apps\Steam\steamapps\common\Unturned", Path.Combine(AppContext.BaseDirectory, "TempRedist", "Client"), "304930", "--force"];
19+
args = [@"C:\Me\Apps\Steam\steamapps\common\Unturned", Path.Combine(AppContext.BaseDirectory, "TempRedist", "Client"), "304930", "--force", "-publicize", "Assembly-CSharp.dll"];
2020
}
2121
#endif
2222

@@ -30,6 +30,17 @@ private static async Task<int> Main(string[] args)
3030
var appId = args[2];
3131
var force = args.Any(x => x.Equals("--force", StringComparison.OrdinalIgnoreCase));
3232
var preview = args.Any(x => x.Equals("--preview", StringComparison.OrdinalIgnoreCase));
33+
List<string> publicizeAssemblies = [];
34+
var publicizeIndex = Array.FindIndex(args, x => x.Equals("-publicize", StringComparison.OrdinalIgnoreCase));
35+
if (publicizeIndex != -1)
36+
{
37+
for (var i = publicizeIndex + 1; i < args.Length; i++)
38+
{
39+
if (args[i].StartsWith("-") || args[i].StartsWith("--"))
40+
break;
41+
publicizeAssemblies.Add(args[i]);
42+
}
43+
}
3344

3445
if (string.IsNullOrWhiteSpace(appId))
3546
{
@@ -97,7 +108,7 @@ private static async Task<int> Main(string[] args)
97108

98109
Console.WriteLine($"Current Build Id: {versionInfo?.BuildId}");
99110

100-
var redistUpdater = new RedistUpdater(managedDirectory, redistPath);
111+
var redistUpdater = new RedistUpdater(managedDirectory, redistPath, publicizeAssemblies);
101112
var (updatedFiles, manifests) = await redistUpdater.UpdateAsync();
102113
if (updatedFiles.Count == 0)
103114
{
Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json;
2+
using BepInEx.AssemblyPublicizer;
23

34
namespace UnturnedRedistUpdateTool;
45

@@ -7,36 +8,49 @@ public class RedistUpdater
78
private static readonly JsonSerializerOptions ManifestJsonSerializerOptions = new() { WriteIndented = true };
89
private readonly string _managedDir;
910
private readonly string _redistPath;
11+
private readonly List<string> _publicizeAssemblies;
1012

11-
public RedistUpdater(string managedDir, string redistPath)
13+
public RedistUpdater(string managedDir, string redistPath, List<string> publicizeAssemblies)
1214
{
1315
_managedDir = managedDir;
1416
_redistPath = redistPath;
17+
_publicizeAssemblies = publicizeAssemblies;
1518
}
1619

1720
public async Task<(Dictionary<string, string> UpdatedFiles, Dictionary<string, string> Manifests)> UpdateAsync()
1821
{
1922
Dictionary<string, string> updatedFiles = [];
20-
Dictionary<string, string> manifest = [];
23+
Dictionary<string, string> manifests = [];
2124
var managedFiles = new DirectoryInfo(_managedDir).GetFiles();
2225
if (managedFiles.Length == 0)
2326
throw new InvalidOperationException($"{_managedDir} is empty");
2427
foreach (var file in managedFiles)
2528
{
2629
var managedFilePath = file.FullName;
2730
var redistFilePath = Path.Combine(_redistPath, file.Name);
28-
var managedHash = HashHelper.GetFileHash(managedFilePath);
29-
manifest[file.Name] = managedHash;
3031
if (!File.Exists(redistFilePath))
3132
continue;
32-
var redistHash = HashHelper.GetFileHash(redistFilePath);
33-
if (managedHash == redistHash)
34-
continue;
35-
file.CopyTo(redistFilePath, true);
33+
if (_publicizeAssemblies.Any(x => x == file.Name))
34+
{
35+
AssemblyPublicizer.Publicize(managedFilePath, redistFilePath);
36+
Console.WriteLine($"Publicized {redistFilePath}");
37+
var publicizedHash = HashHelper.GetFileHash(redistFilePath);
38+
manifests[file.Name] = publicizedHash;
39+
}
40+
else
41+
{
42+
var managedHash = HashHelper.GetFileHash(managedFilePath);
43+
var redistHash = HashHelper.GetFileHash(redistFilePath);
44+
if (managedHash == redistHash)
45+
continue;
46+
file.CopyTo(redistFilePath, true);
47+
var copiedHash = HashHelper.GetFileHash(redistFilePath);
48+
manifests[file.Name] = copiedHash;
49+
}
3650
updatedFiles[managedFilePath] = redistFilePath;
3751
}
3852
var manifestPath = Path.Combine(_redistPath, "manifest.sha256.json");
39-
await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(manifest, ManifestJsonSerializerOptions));
40-
return (updatedFiles, manifest);
53+
await File.WriteAllTextAsync(manifestPath, JsonSerializer.Serialize(manifests, ManifestJsonSerializerOptions));
54+
return (updatedFiles, manifests);
4155
}
4256
}

src/UnturnedRedistUpdateTool/UnturnedRedistUpdateTool.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
</ItemGroup>
1818

1919
<ItemGroup>
20+
<PackageReference Include="BepInEx.AssemblyPublicizer" Version="0.4.3" />
2021
<PackageReference Include="SharpZipLib" Version="1.4.2"/>
2122
<PackageReference Include="ValveKeyValue" Version="0.13.1.398"/>
2223
</ItemGroup>

tests/UnturnedRedistUpdateTool.Tests/RedistUpdaterTests.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
2323
File.WriteAllText(Path.Combine(source, "Unchanged.dll"), "same");
2424
File.WriteAllText(Path.Combine(target, "Unchanged.dll"), "same");
2525

26-
var updater = new RedistUpdater(source, target);
26+
var updater = new RedistUpdater(source, target, []);
2727
var (updated, manifests) = await updater.UpdateAsync();
2828

2929
updated.ShouldContainKey(Path.Combine(source, "Test.dll"));
@@ -33,14 +33,12 @@ public async Task ShouldCopyOnlyChangedFilesAndGenerateManifest()
3333

3434
// Manifest checks
3535
manifests.ShouldContainKey("Test.dll");
36-
manifests.ShouldContainKey("Unchanged.dll");
37-
manifests.Count.ShouldBe(2);
36+
manifests.Count.ShouldBe(1);
3837

3938
var manifestPath = Path.Combine(target, "manifest.sha256.json");
4039
File.Exists(manifestPath).ShouldBeTrue();
4140

4241
var manifestContent = File.ReadAllText(manifestPath);
4342
manifestContent.ShouldContain("Test.dll");
44-
manifestContent.ShouldContain("Unchanged.dll");
4543
}
4644
}

0 commit comments

Comments
 (0)