Skip to content

Commit c4b1a8f

Browse files
committed
.NET 9 AOT + random codebase fixes
1 parent fbeccaf commit c4b1a8f

17 files changed

Lines changed: 124 additions & 63 deletions

File tree

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
custom: [ 'https://boosty.to/theairblow' ]
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
name: .NET Core Desktop
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
7+
jobs:
8+
build-windows:
9+
name: Windows Build
10+
runs-on: windows-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
16+
- name: Install .NET 9.0
17+
uses: actions/setup-dotnet@v4
18+
with:
19+
dotnet-version: '9.0.x'
20+
- name: Build Thor
21+
run: dotnet publish Thor.sln -c Release -r win-x64
22+
- uses: actions/upload-artifact@v4
23+
with:
24+
name: Thor-Windows.exe
25+
path: TheAirBlow.Thor.Shell/bin/Release/net9.0/win-x64/publish/Thor.exe
26+
build-linux:
27+
name: Linux Build
28+
runs-on: ubuntu-latest
29+
steps:
30+
- name: Checkout
31+
uses: actions/checkout@v4
32+
with:
33+
fetch-depth: 0
34+
- name: Install .NET 9.0
35+
uses: actions/setup-dotnet@v4
36+
with:
37+
dotnet-version: '9.0.x'
38+
- name: Build Thor
39+
run: dotnet publish Thor.sln -c Release -r linux-x64
40+
- uses: actions/upload-artifact@v4
41+
with:
42+
name: Thor-Linux
43+
path: TheAirBlow.Thor.Shell/bin/Release/net9.0/linux-x64/publish/Thor
44+
build-macos:
45+
name: MacOS Build
46+
runs-on: macos-latest
47+
steps:
48+
- name: Checkout
49+
uses: actions/checkout@v4
50+
with:
51+
fetch-depth: 0
52+
- name: Install .NET 9.0
53+
uses: actions/setup-dotnet@v4
54+
with:
55+
dotnet-version: '9.0.x'
56+
- name: Build Thor
57+
run: dotnet publish Thor.sln -c Release -r osx-x64
58+
- uses: actions/upload-artifact@v4
59+
with:
60+
name: Thor-MacOS
61+
path: TheAirBlow.Thor.Shell/bin/Release/net9.0/osx-x64/publish/Thor
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
namespace TheAirBlow.Thor.Library.Communication;
22

33
public class DeviceInfo {
4-
public string DisplayName;
5-
public string Identifier;
4+
public string DisplayName { get; set; } = "";
5+
public string Identifier { get; set; } = "";
66
}

TheAirBlow.Thor.Library/Communication/IHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ namespace TheAirBlow.Thor.Library.Communication;
22

33
public interface IHandler {
44
public string GetNotes();
5-
public Task<List<DeviceInfo>> GetDevices();
5+
public List<DeviceInfo> GetDevices();
66
public void Initialize(string? id, byte[]? direct = null);
77
public bool IsConnected();
88
public void Disconnect();

TheAirBlow.Thor.Library/Lookup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,12 @@ public static async Task<InitState> Initialize() {
2222
await File.WriteAllTextAsync("usb.ids", usbIds2);
2323
_split = usbIds2.Split("\n");
2424
return InitState.Cache;
25-
} catch (Exception e) {
25+
} catch {
2626
return InitState.Failed;
2727
}
2828
}
2929

30-
public static async Task<string> GetDisplayName(int vendorId, int productId) {
30+
public static string GetDisplayName(int vendorId, int productId) {
3131
if (_split == null)
3232
return "Failed to load device name database";
3333

TheAirBlow.Thor.Library/PIT/PitData.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
namespace TheAirBlow.Thor.Library.PIT;
22

33
public class PitData {
4-
public List<PitEntry> Entries = new();
5-
public FieldMapper.Mapper Mapper;
6-
public bool IsNewVersion;
7-
public string Unknown;
8-
public string Project;
9-
public int Reserved;
4+
public readonly List<PitEntry> Entries = [];
5+
public FieldMapper.Mapper Mapper { get; set; } = null!;
6+
public bool IsNewVersion { get; set; }
7+
public string Unknown { get; set; } = "";
8+
public string Project { get; set; } = "";
9+
public int Reserved { get; set; }
1010

1111
public PitData(byte[] content)
1212
=> Parse(new MemoryStream(content));
@@ -29,7 +29,7 @@ private void Parse(Stream stream) {
2929
var entry = new PitEntry {
3030
BinaryType = reader.ReadInt32(),
3131
DeviceType = reader.ReadInt32(),
32-
PartitionID = reader.ReadInt32(),
32+
PartitionId = reader.ReadInt32(),
3333
Attributes = reader.ReadInt32(),
3434
UpdateAttributes = reader.ReadInt32(),
3535
BlockSize = reader.ReadInt32(),
Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
namespace TheAirBlow.Thor.Library.PIT;
22

33
public class PitEntry {
4-
public int BinaryType;
5-
public int DeviceType;
6-
public int PartitionID;
7-
public int Attributes; // Or Partition Type
8-
public int UpdateAttributes; // Or File System
9-
public int BlockSize;
10-
public int BlockCount;
11-
public int FileOffset;
12-
public int FileSize;
13-
public string Partition;
14-
public string FileName;
15-
public string DeltaName;
4+
public int BinaryType { get; set; }
5+
public int DeviceType { get; set; }
6+
public int PartitionId { get; set; }
7+
public int Attributes { get; set; }
8+
public int UpdateAttributes { get; set; }
9+
public int BlockSize { get; set; }
10+
public int BlockCount { get; set; }
11+
public int FileOffset { get; set; }
12+
public int FileSize { get; set; }
13+
public string Partition { get; set; } = "";
14+
public string FileName { get; set; } = "";
15+
public string DeltaName { get; set; } = "";
1616
}

TheAirBlow.Thor.Library/Platform/Linux.cs

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using System.Diagnostics.CodeAnalysis;
12
using System.Reflection.Metadata;
23
using System.Runtime.InteropServices;
34
using Serilog;
@@ -14,7 +15,7 @@ public string GetNotes()
1415
"1) To temporarily unload, run \"sudo modprobe -r cdc_acm\"\n" +
1516
"2) To disable it, run \"echo 'blacklist cdc_acm' | sudo tee -a /etc/modprobe.d/cdc_acm-blacklist.conf\"";
1617

17-
public async Task<List<DeviceInfo>> GetDevices() {
18+
public List<DeviceInfo> GetDevices() {
1819
var list = new List<DeviceInfo>();
1920
foreach (var bus in Directory.EnumerateDirectories("/dev/bus/usb/"))
2021
foreach (var device in Directory.EnumerateFiles(bus)) {
@@ -31,7 +32,7 @@ public async Task<List<DeviceInfo>> GetDevices() {
3132
if (vendor == USB.Vendor) {
3233
var product = reader.ReadInt16();
3334
list.Add(new DeviceInfo {
34-
DisplayName = await Lookup.GetDisplayName(vendor, product),
35+
DisplayName = Lookup.GetDisplayName(vendor, product),
3536
Identifier = device[13..].Replace("/", ":")
3637
});
3738
}
@@ -276,6 +277,8 @@ public void Dispose() {
276277
_detached = false;
277278
}
278279

280+
[SuppressMessage("ReSharper", "InconsistentNaming")]
281+
[SuppressMessage("ReSharper", "ShiftExpressionZeroLeftOperand")]
279282
public static unsafe class Interop {
280283
private const int _IOC_NRBITS = 8;
281284
private const int _IOC_TYPEBITS = 8;
@@ -296,15 +299,15 @@ private static uint _IOR(uint type, uint nr, uint size)
296299
private static uint _IOW(uint type, uint nr, uint size)
297300
=> (1U << _IOC_DIRSHIFT) | (type << _IOC_TYPESHIFT)
298301
| (nr << _IOC_NRSHIFT) | (size << _IOC_SIZESHIFT);
299-
public static uint USBDEVFS_SETINTERFACE = _IOR('U', 4, (uint)sizeof(SetInterface));
300-
public static uint USBDEVFS_GETDRIVER = _IOW('U', 8, (uint)sizeof(GetDriver));
301-
public static uint USBDEVFS_BULK = _IOWR('U', 2, (uint)sizeof(BulkTransfer));
302-
public static uint USBDEVFS_IOCTL = _IOWR('U', 18, (uint)sizeof(UsbIoCtl));
303-
public static uint USBDEVFS_RELEASEINTERFACE = _IOR('U', 16, sizeof(uint));
304-
public static uint USBDEVFS_CLAIMINTERFACE = _IOR('U', 15, sizeof(uint));
305-
public static uint USBDEVFS_DISCONNECT = _IO('U', 22);
306-
public static uint USBDEVFS_CONNECT = _IO('U', 23);
307-
public static uint USBDEVFS_RESET = _IO('U', 20);
302+
public static readonly uint USBDEVFS_SETINTERFACE = _IOR('U', 4, (uint)Marshal.SizeOf<SetInterface>());
303+
public static readonly uint USBDEVFS_GETDRIVER = _IOW('U', 8, (uint)Marshal.SizeOf<GetDriver>());
304+
public static readonly uint USBDEVFS_BULK = _IOWR('U', 2, (uint)Marshal.SizeOf<BulkTransfer>());
305+
public static readonly uint USBDEVFS_IOCTL = _IOWR('U', 18, (uint)Marshal.SizeOf<UsbIoCtl>());
306+
public static readonly uint USBDEVFS_RELEASEINTERFACE = _IOR('U', 16, sizeof(uint));
307+
public static readonly uint USBDEVFS_CLAIMINTERFACE = _IOR('U', 15, sizeof(uint));
308+
public static readonly uint USBDEVFS_DISCONNECT = _IO('U', 22);
309+
public static readonly uint USBDEVFS_CONNECT = _IO('U', 23);
310+
public static readonly uint USBDEVFS_RESET = _IO('U', 20);
308311

309312
public struct BulkTransfer {
310313
public uint Endpoint;

TheAirBlow.Thor.Library/Protocols/Odin.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ public byte[] DumpPIT() {
223223
buf = _handler.BulkRead(500, out _);
224224
Array.Copy(buf, 0, pitBuf,
225225
i*500, buf.Length);
226-
} catch (Exception e) {
226+
} catch {
227227
Log.Debug("Failed to read block {0}", i);
228228
throw;
229229
}
@@ -389,7 +389,7 @@ public void FlashPartition(Stream? stream, PitEntry entry, Action<FlashProgressI
389389
buf.WriteInt(realSize, 12);
390390
buf.WriteInt(entry.BinaryType, 16);
391391
buf.WriteInt(entry.DeviceType, 20);
392-
buf.WriteInt(entry.PartitionID, 24);
392+
buf.WriteInt(entry.PartitionId, 24);
393393
buf.WriteInt(last ? 1 : 0, 28);
394394
buf.WriteInt(EfsClear ? 1 : 0, 32);
395395
buf.WriteInt(BootloaderUpdate ? 1 : 0, 36);
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
<Project Sdk="Microsoft.NET.Sdk">
2-
32
<PropertyGroup>
4-
<TargetFramework>net7.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
54
<ImplicitUsings>enable</ImplicitUsings>
65
<Nullable>enable</Nullable>
76
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
7+
<IsAotCompatible>true</IsAotCompatible>
88
<Version>1.0.4</Version>
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.5" />
13-
<PackageReference Include="Serilog" Version="3.0.0-dev-02022" />
12+
<PackageReference Include="K4os.Compression.LZ4.Streams" Version="1.3.8" />
13+
<PackageReference Include="Serilog" Version="4.3.0" />
1414
<PackageReference Include="Serilog.Exceptions" Version="8.4.0" />
15-
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.1-dev-00910" />
15+
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
1616
</ItemGroup>
17-
1817
</Project>

0 commit comments

Comments
 (0)