Skip to content

Commit 22185cc

Browse files
authored
Merge pull request #546 from ipax77/dev
Dev
2 parents 1eb70bf + d883d22 commit 22185cc

File tree

20 files changed

+154
-49
lines changed

20 files changed

+154
-49
lines changed

README.md

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,14 @@ We really like people helping us with the project. Nevertheless, take your time
3030

3131
## ChangeLog
3232

33-
<details open="open"><summary>v2.0.10</summary>
33+
<details open="open"><summary>v2.1.0</summary>
34+
35+
>- s2protocol.NET v0.9 - IronPython dependecies removed
36+
>- add dsBuild for Alarak
37+
38+
</details>
39+
40+
<details><summary>v2.0.10</summary>
3441

3542
>- DsBuilds - fix unit placement / add Abathur
3643

src/dsstats.db8services/Import/ImportService.Duplicates.cs

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ namespace dsstats.db8services.Import;
66

77
public partial class ImportService
88
{
9-
private async Task<int> HandleDuplicates(List<Replay> replays, ReplayContext context)
9+
private async Task<DupReport> HandleDuplicates(List<Replay> replays, ReplayContext context)
1010
{
1111
var replayHashes = replays.Select(s => s.ReplayHash).ToList();
1212
var dupReplays = await context.Replays
@@ -37,10 +37,29 @@ from rp in r.ReplayPlayers
3737

3838
dupReplays.AddRange(lsDupReplays);
3939
}
40+
else
41+
{
42+
var dupHashes = dupReplays
43+
.Select(s => s.ReplayHash)
44+
.ToHashSet();
45+
foreach (var replay in replays.ToArray())
46+
{
47+
if (dupHashes.Contains(replay.ReplayHash))
48+
{
49+
replays.Remove(replay);
50+
}
51+
}
52+
53+
return new()
54+
{
55+
Duplicates = dupReplays.Count,
56+
ReplayPaths = dupReplays.Select(s => s.FileName).ToHashSet()
57+
};
58+
}
4059

4160
if (dupReplays.Count == 0)
4261
{
43-
return 0;
62+
return new();
4463
}
4564

4665
int dupsHandled = 0;
@@ -74,7 +93,7 @@ from rp in r.ReplayPlayers
7493
}
7594
}
7695
await context.SaveChangesAsync();
77-
return dupsHandled;
96+
return new() { Duplicates = dupsHandled };
7897
}
7998

8099
private async Task<bool> HandleDuplicate(Replay dbReplay, Replay importReplay, ReplayContext context)
@@ -148,3 +167,9 @@ private async Task DeleteReplay(string replayHash, ReplayContext context)
148167
}
149168
}
150169
}
170+
171+
internal record DupReport
172+
{
173+
public int Duplicates { get; init; }
174+
public HashSet<string> ReplayPaths { get; init; } = [];
175+
}

src/dsstats.db8services/Import/ImportService.Import.cs

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,13 @@ public async Task<ImportResult> Import(List<ReplayDto> replayDtos, List<PlayerId
102102

103103
string? error = null;
104104
int dups = 0;
105+
HashSet<string> duplicates = [];
105106
await importSs.WaitAsync();
106107
try
107108
{
108-
dups = await HandleDuplicates(replays, context);
109-
109+
var dupResult = await HandleDuplicates(replays, context);
110+
dups = dupResult.Duplicates;
111+
duplicates = dupResult.ReplayPaths;
110112
if (replays.Count > 0)
111113
{
112114
DateTime import = DateTime.UtcNow;
@@ -132,7 +134,10 @@ public async Task<ImportResult> Import(List<ReplayDto> replayDtos, List<PlayerId
132134
{
133135
Imported = replays.Count,
134136
Duplicates = dups,
135-
Error = error
137+
Error = error,
138+
DetailErrors = duplicates
139+
.Select(s => new KeyValuePair<string, string>(s, "Duplicate replay found."))
140+
.ToDictionary(kvp => kvp.Key, kvp => kvp.Value)
136141
};
137142
}
138143
}

src/dsstats.db8services/ReplayRepository.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -73,15 +73,7 @@ public async Task SaveReplay(ReplayDto replayDto)
7373
dbReplay.Imported = DateTime.UtcNow;
7474
context.Replays.Add(dbReplay);
7575

76-
try
77-
{
78-
await context.SaveChangesAsync();
79-
}
80-
catch (Exception ex)
81-
{
82-
logger.LogError("failed saving replay: {error}", ex.Message);
83-
throw;
84-
}
76+
await context.SaveChangesAsync();
8577
}
8678

8779
private ICollection<SpawnUnit> GetMapedSpawnUnits(Spawn spawn, Commander commander)

src/dsstats.decode/DecodeService.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using pax.dsstats.parser;
55
using s2protocol.NET;
66
using System.Collections.Concurrent;
7-
using System.Reflection;
87
using System.Security.Cryptography;
98
using System.Text.RegularExpressions;
109

@@ -19,7 +18,6 @@ public partial class DecodeService(IOptions<DecodeSettings> decodeSettings,
1918
private readonly SemaphoreSlim ssRaw = new(1, 1);
2019
private readonly SemaphoreSlim fileSemaphore = new SemaphoreSlim(1, 1);
2120
private ReplayDecoder? replayDecoder;
22-
public static readonly string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
2321
private int queueCount = 0;
2422
private ConcurrentBag<string> excludeReplays = [];
2523

@@ -159,7 +157,7 @@ public async Task Decode()
159157

160158
if (replayDecoder is null)
161159
{
162-
replayDecoder = new(assemblyPath);
160+
replayDecoder = new();
163161
}
164162

165163
var options = new ReplayDecoderOptions()
@@ -264,7 +262,7 @@ public async Task DecodeRaw()
264262

265263
if (replayDecoder is null)
266264
{
267-
replayDecoder = new(assemblyPath);
265+
replayDecoder = new();
268266
}
269267

270268
var options = new ReplayDecoderOptions()

src/dsstats.decode/dsstats.decode.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@
66
<ProjectReference Include="..\dsstats.maui\dsstats.challenge\dsstats.challenge.csproj" />
77
</ItemGroup>
88

9-
<ItemGroup>
10-
<PackageReference Include="IronPython.StdLib" Version="2.7.12" />
11-
</ItemGroup>
12-
139
<PropertyGroup>
1410
<TargetFramework>net8.0</TargetFramework>
1511
<Nullable>enable</Nullable>

src/dsstats.decodecli/Program.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
using System.Diagnostics;
2-
using System.Reflection;
32
using System.Security.Cryptography;
43
using System.Text.Json;
54
using pax.dsstats.parser;
@@ -9,7 +8,6 @@ namespace dsstats.decodecli;
98

109
class Program
1110
{
12-
public static readonly string assemblyPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? "";
1311
static readonly string replayFolder = "/data/ds/decode/input";
1412
static readonly string outputFolder = "/data/ds/decode/output";
1513
static readonly string errorFolder = "/data/ds/decode/error";
@@ -37,7 +35,7 @@ static async Task Main(string[] args)
3735

3836
Stopwatch sw = Stopwatch.StartNew();
3937

40-
ReplayDecoder decoder = new(assemblyPath);
38+
ReplayDecoder decoder = new();
4139

4240
ReplayDecoderOptions options = new ReplayDecoderOptions()
4341
{

src/dsstats.decodecli/dsstats.decodecli.csproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55
<ProjectReference Include="..\dsstats.maui\pax.dsstats.parser\pax.dsstats.parser.csproj" />
66
</ItemGroup>
77

8-
<ItemGroup>
9-
<PackageReference Include="IronPython.StdLib" Version="2.7.12" />
10-
</ItemGroup>
11-
128
<PropertyGroup>
139
<OutputType>Exe</OutputType>
1410
<TargetFramework>net8.0</TargetFramework>

src/dsstats.maui/dsstats.builder/dsstats.builder/DsBuilder.cs

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,22 @@ public static void Build(DsBuildRequest buildRequest, bool dry = false)
7777
events.Add(new(InputType.KeyPress, 0, 0, 0x57, 100));
7878
foreach (var upgrade in buildRequest.Upgrades)
7979
{
80-
var upgradeChar = build.GetAbilityChar(upgrade.Upgrade.Name);
81-
if (upgradeChar is not null
82-
&& User32Wrapper.TryMapCharToKey(upgradeChar.Value, out var code, out var shift))
80+
var buildOption = build.GetAbilityBuildOption(upgrade.Upgrade.Name);
81+
if (buildOption is not null
82+
&& User32Wrapper.TryMapCharToKey(buildOption.Key, out var code, out var shift))
8383
{
84-
events.Add(new InputEvent(InputType.KeyPress, 0, 0, code, 200));
84+
if (buildOption.IsAbility)
85+
{
86+
events.Add(new(InputType.KeyPress, 0, 0, workerKey, 100));
87+
events.Add(new(InputType.KeyPress, 0, 0, 0x51, 100));
88+
events.Add(new(InputType.KeyPress, 0, 0, code, 100));
89+
events.Add(new(InputType.KeyPress, 0, 0, workerKey, 100));
90+
events.Add(new(InputType.KeyPress, 0, 0, 0x57, 100));
91+
}
92+
else
93+
{
94+
events.Add(new InputEvent(InputType.KeyPress, 0, 0, code, 200));
95+
}
8596
upgrades.Remove(upgrade);
8697
}
8798
}

src/dsstats.maui/dsstats.maui8/Platforms/Windows/Package.appxmanifest

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
66
IgnorableNamespaces="uap rescap">
77

8-
<Identity Name="29898PhilippHetzner.141231D0ED353" Publisher="CN=592AF738-4E2A-4BF3-87A7-D07953D08DE9" Version="2.0.10.0" />
8+
<Identity Name="29898PhilippHetzner.141231D0ED353" Publisher="CN=592AF738-4E2A-4BF3-87A7-D07953D08DE9" Version="2.1.0.0" />
99

1010
<Properties>
1111
<DisplayName>$placeholder$</DisplayName>

0 commit comments

Comments
 (0)