diff --git a/starsky/starsky.feature.externaldependencies/ExternalDependenciesService.cs b/starsky/starsky.feature.externaldependencies/ExternalDependenciesService.cs index 67eee7f799..b4edcd19cd 100644 --- a/starsky/starsky.feature.externaldependencies/ExternalDependenciesService.cs +++ b/starsky/starsky.feature.externaldependencies/ExternalDependenciesService.cs @@ -31,18 +31,29 @@ public ExternalDependenciesService(IExifToolDownload exifToolDownload, _geoFileDownload = geoFileDownload; } - public async Task SetupAsync(List args) + public async Task SetupAsync(string[] args) { await SetupAsync(ArgsHelper.GetRuntime(args)); } - public async Task SetupAsync(OSPlatform? currentPlatform = null, - Architecture? architecture = null) + public async Task SetupAsync(List<(OSPlatform?, Architecture?)> currentPlatforms) { - currentPlatform ??= PlatformParser.GetCurrentOsPlatform(); - await RunMigrations.Run(_dbContext, _logger, _appSettings); - await _exifToolDownload.DownloadExifTool(currentPlatform == OSPlatform.Windows); + + + if ( currentPlatforms.Count == 0 ) + { + currentPlatforms = + [ + ( PlatformParser.GetCurrentOsPlatform(), + PlatformParser.GetCurrentArchitecture() ) + ]; + } + + foreach ( var (osPlatform, _) in currentPlatforms ) + { + await _exifToolDownload.DownloadExifTool(osPlatform == OSPlatform.Windows); + } await _geoFileDownload.DownloadAsync(); } diff --git a/starsky/starsky.feature.externaldependencies/Interfaces/IExternalDependenciesService.cs b/starsky/starsky.feature.externaldependencies/Interfaces/IExternalDependenciesService.cs index 2e44d64eac..da6308a8c4 100644 --- a/starsky/starsky.feature.externaldependencies/Interfaces/IExternalDependenciesService.cs +++ b/starsky/starsky.feature.externaldependencies/Interfaces/IExternalDependenciesService.cs @@ -1,8 +1,6 @@ -using System.Runtime.InteropServices; - namespace starsky.feature.externaldependencies.Interfaces; public interface IExternalDependenciesService { - Task SetupAsync(OSPlatform? currentPlatform = null, Architecture? architecture = null); + Task SetupAsync(string[] args); } diff --git a/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs b/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs index 36e7c51f69..5d974568dc 100644 --- a/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs +++ b/starsky/starsky.foundation.platform/Helpers/ArgsHelper.cs @@ -642,23 +642,25 @@ public static ConsoleOutputMode GetConsoleOutputMode(IReadOnlyList args) /// /// arg list /// path - public static OSPlatform? GetRuntime(IReadOnlyList args) + public static List<(OSPlatform?, Architecture?)> GetRuntime(IReadOnlyList args) { - OSPlatform? outputMode = null; + var outputModeList = new List<(OSPlatform?, Architecture?)>(); for ( var arg = 0; arg < args.Count; arg++ ) { if ( args[arg]? - .Equals("--runtime", StringComparison.CurrentCultureIgnoreCase) != true || - ( arg + 1 ) == args.Count ) + .Equals("--runtime", + StringComparison.CurrentCultureIgnoreCase) != true || + arg + 1 == args.Count ) { continue; } var runtimeItem = args[arg + 1]; - outputMode = PlatformParser.RuntimeIdentifier(runtimeItem); + var parsedRuntimeList = PlatformParser.RuntimeIdentifier(runtimeItem); + outputModeList.AddRange(parsedRuntimeList); } - return outputMode; + return outputModeList; } /// diff --git a/starsky/starsky.foundation.platform/Helpers/PlatformParser.cs b/starsky/starsky.foundation.platform/Helpers/PlatformParser.cs index a6c31c58eb..be979cd8ee 100644 --- a/starsky/starsky.foundation.platform/Helpers/PlatformParser.cs +++ b/starsky/starsky.foundation.platform/Helpers/PlatformParser.cs @@ -20,23 +20,57 @@ public static class PlatformParser return currentPlatform; } - public static OSPlatform? RuntimeIdentifier(string? runtimeIdentifier) + public static List<(OSPlatform?, Architecture?)> RuntimeIdentifier(string? runtimeIdentifiers) { - if ( runtimeIdentifier == null ) + var result = new List<(OSPlatform?, Architecture?)>(); + if ( runtimeIdentifiers == null ) { - return null; + return []; } - if ( runtimeIdentifier.StartsWith("win-") ) + var runtimes = runtimeIdentifiers.Split(",").Where(x => !string.IsNullOrEmpty(x)).ToList(); + foreach ( var runtime in runtimes ) + { + var singleRuntimeIdentifier = SingleRuntimeIdentifier(runtime); + if ( singleRuntimeIdentifier is { Item1: not null, Item2: not null } ) + { + result.Add(singleRuntimeIdentifier); + } + } + + return result; + } + + private static (OSPlatform?, Architecture?) SingleRuntimeIdentifier(string? runtimeIdentifier) + { + if ( runtimeIdentifier == null ) { - return OSPlatform.Windows; + return ( null, null ); } - if ( runtimeIdentifier.StartsWith("linux-") ) + switch ( runtimeIdentifier ) { - return OSPlatform.Linux; + case "win-x64": + return ( OSPlatform.Windows, Architecture.X64 ); + case "win-arm64": + return ( OSPlatform.Windows, Architecture.Arm64 ); + case "linux-arm": + return ( OSPlatform.Linux, Architecture.Arm ); + case "linux-arm64": + return ( OSPlatform.Linux, Architecture.Arm64 ); + case "linux-x64": + return ( OSPlatform.Linux, Architecture.X64 ); + case "osx-x64": + return ( OSPlatform.OSX, Architecture.X64 ); + case "osx-arm64": + return ( OSPlatform.OSX, Architecture.Arm64 ); + default: + return ( null, null ); } + } - return runtimeIdentifier.StartsWith("osx-") ? OSPlatform.OSX : null; + public static Architecture GetCurrentArchitecture() + { + return Architecture.Wasm; } } diff --git a/starsky/starskydependenciescli/Program.cs b/starsky/starskydependenciescli/Program.cs index 56f3abfbac..fa012c4703 100644 --- a/starsky/starskydependenciescli/Program.cs +++ b/starsky/starskydependenciescli/Program.cs @@ -38,7 +38,7 @@ public static async Task Main(string[] args) var dependenciesService = serviceProvider.GetRequiredService(); - await dependenciesService.SetupAsync(); + await dependenciesService.SetupAsync(args); } } } diff --git a/starsky/starskytest/starsky.feature.externaldependencies/ExternalDependenciesServiceTest.cs b/starsky/starskytest/starsky.feature.externaldependencies/ExternalDependenciesServiceTest.cs index b96ae8c272..b24955f6a8 100644 --- a/starsky/starskytest/starsky.feature.externaldependencies/ExternalDependenciesServiceTest.cs +++ b/starsky/starskytest/starsky.feature.externaldependencies/ExternalDependenciesServiceTest.cs @@ -1,3 +1,4 @@ +using System.Collections.Generic; using System.Threading.Tasks; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.DependencyInjection; @@ -34,9 +35,13 @@ public ExternalDependenciesServiceTest() public async Task ExternalDependenciesServiceTest_ExifTool_Default() { var fakeExifToolDownload = new FakeExifToolDownload(); + var appSettings = new AppSettings + { + DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase + }; var externalDependenciesService = new ExternalDependenciesService(fakeExifToolDownload, - _dbContext, new FakeIWebLogger(), new AppSettings(), new FakeIGeoFileDownload()); - await externalDependenciesService.SetupAsync([]); + _dbContext, new FakeIWebLogger(), appSettings, new FakeIGeoFileDownload()); + await externalDependenciesService.SetupAsync(new List().ToArray()); Assert.AreEqual(new AppSettings().IsWindows, fakeExifToolDownload.Called[0]); } @@ -45,14 +50,40 @@ public async Task ExternalDependenciesServiceTest_ExifTool_Default() [DataRow("osx-arm64", false)] [DataRow("linux-x64", false)] [DataRow("win-x64", true)] - public async Task ExternalDependenciesServiceTest_ExifTool_DataTestMethod(string input, bool expected) + public async Task ExternalDependenciesServiceTest_ExifTool_Single_DataTestMethod(string input, + bool expected) { var fakeExifToolDownload = new FakeExifToolDownload(); + var appSettings = new AppSettings + { + DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase + }; var externalDependenciesService = new ExternalDependenciesService(fakeExifToolDownload, - _dbContext, new FakeIWebLogger(), new AppSettings(), new FakeIGeoFileDownload()); - + _dbContext, new FakeIWebLogger(), appSettings, new FakeIGeoFileDownload()); + await externalDependenciesService.SetupAsync(["--runtime", input]); Assert.AreEqual(expected, fakeExifToolDownload.Called[0]); } + + [DataTestMethod] + [DataRow("osx-arm64,osx-x64", false, false)] + [DataRow("linux-x64,osx-x64", false, false)] + [DataRow("win-x64,osx-x64", true, false)] + public async Task ExternalDependenciesServiceTest_ExifTool_Multiple_DataTestMethod(string input, + bool expected1, bool expected2) + { + var appSettings = new AppSettings + { + DatabaseType = AppSettings.DatabaseTypeList.InMemoryDatabase + }; + var fakeExifToolDownload = new FakeExifToolDownload(); + var externalDependenciesService = new ExternalDependenciesService(fakeExifToolDownload, + _dbContext, new FakeIWebLogger(), appSettings, new FakeIGeoFileDownload()); + + await externalDependenciesService.SetupAsync(["--runtime", input]); + + Assert.AreEqual(expected1, fakeExifToolDownload.Called[0]); + Assert.AreEqual(expected2, fakeExifToolDownload.Called[1]); + } } diff --git a/starsky/starskytest/starsky.foundation.platform/Helpers/ArgsHelperTest.cs b/starsky/starskytest/starsky.foundation.platform/Helpers/ArgsHelperTest.cs index cd0d5fe542..42656a606d 100644 --- a/starsky/starskytest/starsky.foundation.platform/Helpers/ArgsHelperTest.cs +++ b/starsky/starskytest/starsky.foundation.platform/Helpers/ArgsHelperTest.cs @@ -644,7 +644,7 @@ public void Name() public void GetRuntimeTest(string input, string expected) { var args = new List { "--runtime", input }.ToArray(); - Assert.AreEqual(expected, ArgsHelper.GetRuntime(args).ToString()); + Assert.AreEqual(expected, ArgsHelper.GetRuntime(args)[0].Item1.ToString()); } } } diff --git a/starsky/starskytest/starsky.foundation.platform/Helpers/PlatformParserTest.cs b/starsky/starskytest/starsky.foundation.platform/Helpers/PlatformParserTest.cs index e836675c6a..69a68b57a2 100644 --- a/starsky/starskytest/starsky.foundation.platform/Helpers/PlatformParserTest.cs +++ b/starsky/starskytest/starsky.foundation.platform/Helpers/PlatformParserTest.cs @@ -22,18 +22,20 @@ public void GetCurrentOsPlatformTest() } [DataTestMethod] - [DataRow("osx-arm64", "OSX")] - [DataRow("osx-x64", "OSX")] - [DataRow("linux-x64", "LINUX")] - [DataRow("linux-arm", "LINUX")] - [DataRow("linux-arm64", "LINUX")] - [DataRow("win-x64", "WINDOWS")] - [DataRow("win-x86", "WINDOWS")] - [DataRow("win-arm64", "WINDOWS")] - [DataRow("test", "")] - [DataRow(null, "")] - public void RuntimeIdentifierTest(string input, string expected) + [DataRow("osx-arm64", "OSX", "Arm64")] + [DataRow("osx-x64", "OSX", "X64")] + [DataRow("linux-x64", "LINUX", "X64")] + [DataRow("linux-arm", "LINUX", "Arm")] + [DataRow("linux-arm64", "LINUX", "Arm64")] + [DataRow("win-x64", "WINDOWS", "X64")] + [DataRow("win-x86", "WINDOWS", "X86")] + [DataRow("win-arm64", "WINDOWS", "Arm64")] + [DataRow("test", "", "")] + [DataRow(null, "", "")] + public void RuntimeIdentifierTest(string input, string expectedOs, string expectedArch) { - Assert.AreEqual(expected, PlatformParser.RuntimeIdentifier(input).ToString()); + var result = PlatformParser.RuntimeIdentifier(input); + Assert.AreEqual(expectedOs, result[0].Item1.ToString()); + Assert.AreEqual(expectedArch, result[0].Item2.ToString()); } }