Skip to content

Commit e564613

Browse files
committed
use runtimeidentifier for update
1 parent e59752d commit e564613

8 files changed

Lines changed: 29 additions & 21 deletions

File tree

src/Euterpe.Abstractions/IDownloadManager.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Task<bool> DownloadCpp2ILPluginAsync(
4040

4141
Task<bool> DownloadModAsync(ModDto mod, CancellationToken cancellationToken = default);
4242
Task<bool> DownloadLibAsync(LibDto lib, CancellationToken cancellationToken = default);
43-
Task DownloadReleaseByTagAsync(string tag, string osString, string updateFolder, CancellationToken cancellationToken = default);
43+
Task DownloadReleaseByTagAsync(string tag, string runtimeIdentifier, string updateFolder, CancellationToken cancellationToken = default);
4444
Task<string?> FetchReadmeAsync(string repoId, CancellationToken cancellationToken = default);
4545
IAsyncEnumerable<Mod?> GetModListAsync(CancellationToken cancellationToken = default);
4646
IAsyncEnumerable<Lib?> GetLibListAsync(CancellationToken cancellationToken = default);

src/Euterpe.Abstractions/IPlatformService.cs

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
using System.Runtime.InteropServices;
2+
13
namespace Euterpe.Abstractions;
24

35
public interface IPlatformService
46
{
57
/// <summary>
6-
/// Get OS string for download link
8+
/// Get OS string
79
/// </summary>
810
string OsString { get; }
911

@@ -12,6 +14,23 @@ public interface IPlatformService
1214
/// </summary>
1315
string UpdaterFileName { get; }
1416

17+
/// <summary>
18+
/// Get architecture string
19+
/// </summary>
20+
string ArchitectureString =>
21+
RuntimeInformation.ProcessArchitecture switch
22+
{
23+
Architecture.X64 => "x64",
24+
Architecture.X86 => "x86",
25+
Architecture.Arm64 => "arm64",
26+
_ => "unknown"
27+
};
28+
29+
/// <summary>
30+
/// Get runtime identifier
31+
/// </summary>
32+
string RuntimeIdentifier => $"{OsString}-{ArchitectureString}";
33+
1534
/// <summary>
1635
/// Get steam folder path
1736
/// </summary>

src/Euterpe.Core/Services/DownloadManager/DownloadManager.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ public async Task<bool> DownloadLibAsync(LibDto lib, CancellationToken cancellat
140140
}
141141
}
142142

143-
public async Task DownloadReleaseByTagAsync(string tag, string osString, string updateFolder, CancellationToken cancellationToken = default)
143+
public async Task DownloadReleaseByTagAsync(string tag, string runtimeIdentifier, string updateFolder, CancellationToken cancellationToken = default)
144144
{
145-
var downloadUrl = $"{ReleasesBaseUrl}{tag}/Euterpe-{osString}.zip";
145+
var downloadUrl = $"{ReleasesBaseUrl}{tag}/Euterpe-{runtimeIdentifier}.zip";
146146

147147
try
148148
{

src/Euterpe.Core/Services/PlatformServices/LinuxService/LinuxService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ internal sealed partial class LinuxService : IPlatformService
1717
}
1818
.Select(path => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path)).ToArray();
1919

20-
public string OsString => "Linux";
20+
public string OsString => "linux";
2121
public string UpdaterFileName => "Updater";
2222

2323
public bool TryGetSteamFolder([NotNullWhen(true)] out string? steamFolder)

src/Euterpe.Core/Services/PlatformServices/MacOSService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal sealed class MacOsService : IPlatformService
99
}
1010
.Select(path => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), path)).ToArray();
1111

12-
public string OsString => "MacOS";
12+
public string OsString => "osx";
1313
public string UpdaterFileName => "Updater";
1414
public bool TryGetSteamFolder([NotNullWhen(true)] out string? steamFolder) => throw new NotSupportedException();
1515
public Task<string?> GetSteamExecPathAsync() => throw new NotSupportedException();

src/Euterpe.Core/Services/PlatformServices/WindowsService/WindowsService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ internal sealed partial class WindowsService : IPlatformService
2121
}
2222
.SelectMany(path => Environment.GetLogicalDrives().Select(drive => Path.Combine(drive, path))).ToArray();
2323

24-
public string OsString => "Windows";
24+
public string OsString => "win";
2525
public string UpdaterFileName => "Updater.exe";
2626

2727
public bool TryGetSteamFolder([NotNullWhen(true)] out string? steamFolder)

src/Euterpe.Core/Services/StatisticsService.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ private async Task SendRecordVisitorAsync()
3636
var payload = new RecordVisitorRequest
3737
{
3838
Country = RegionInfo.CurrentRegion.TwoLetterISORegionName,
39-
Platform = PlatformService.OsString.ToLowerInvariant(),
40-
Arch = GetArchitecture(),
39+
Platform = PlatformService.OsString,
40+
Arch = PlatformService.ArchitectureString,
4141
AppVersion = AppVersion
4242
};
4343

@@ -64,17 +64,6 @@ private async Task SendRecordDownloadAsync(string modName, string modAuthor)
6464
using var response = await Client.SendAsync(request).ConfigureAwait(false);
6565
}
6666

67-
private static string GetArchitecture()
68-
{
69-
return RuntimeInformation.ProcessArchitecture switch
70-
{
71-
Architecture.X64 => "x64",
72-
Architecture.X86 => "x86",
73-
Architecture.Arm64 => "arm64",
74-
_ => "unknown"
75-
};
76-
}
77-
7867
private static string GenerateRequestId() => Guid.CreateVersion7().ToString();
7968

8069
#region Injections

src/Euterpe.Core/Services/UpdateService/UpdateService.Private.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private async Task StartUpdateProcessAsync(string version, CancellationToken can
4040
var updateFolder = GetUpdateTempPath();
4141
var updaterTargetPath = Path.Combine(updateFolder, PlatformService.UpdaterFileName);
4242

43-
await DownloadManager.DownloadReleaseByTagAsync(version, PlatformService.OsString, updateFolder, cancellationToken).ConfigureAwait(false);
43+
await DownloadManager.DownloadReleaseByTagAsync(version, PlatformService.RuntimeIdentifier, updateFolder, cancellationToken).ConfigureAwait(false);
4444
Logger.ZLogInformation($"Release {version} download finished");
4545

4646
File.Copy(PlatformService.UpdaterFileName, updaterTargetPath, true);

0 commit comments

Comments
 (0)