protected override SourcePort MergeItems(SourcePort superior, SourcePort inferior) { // Check if arguments are null if (superior is null) { throw new ArgumentNullException(nameof(superior)); } if (inferior is null) { throw new ArgumentNullException(nameof(inferior)); } // Check package IDs match if (superior.Id != inferior.Id) { throw new ArgumentException("Package IDs did not match!"); } // Determine name string name = superior.Name is null ? inferior.Name : superior.Name; // Determine author string author = superior.Author is null ? inferior.Author : superior.Author; // Determine executable string executable = superior.Executable is null ? inferior.Executable : superior.Executable; // Determine download URL string downloadUrl = superior.DownloadUrl is null ? inferior.DownloadUrl : superior.DownloadUrl; // Determine operating system SourcePort.OperatingSystem os = superior.SupportedOS == SourcePort.OperatingSystem.Unknown ? inferior.SupportedOS : superior.SupportedOS; SourcePort sourcePort = new ( id : superior.Id, downloadUrl : downloadUrl, name : name, author : author, executable : executable, os : os ); if (superior.Token.State == ProgressToken.ProgressState.Installed || inferior.Token.State == ProgressToken.ProgressState.Installed) { sourcePort.Token.State = ProgressToken.ProgressState.Installed; } return(sourcePort); }
public async Task RefreshAsync() { // Check directory exists if (!Directory.Exists(sourcePortDirPath)) { throw new DirectoryNotFoundException("Specified source port directory was not found."); } // Clear existing source port list Items.Clear(); // Load source ports by directory name await Task.Run(() => { foreach (string id in Directory.GetDirectories(sourcePortDirPath).Select(x => Path.GetFileName(x))) { SourcePort.OperatingSystem os = id.Split("-", StringSplitOptions.RemoveEmptyEntries).Last() switch { "win32" => SourcePort.OperatingSystem.Win32, "win64" => SourcePort.OperatingSystem.Win64, "linux32" => SourcePort.OperatingSystem.Linux32, "linux64" => SourcePort.OperatingSystem.Linux64, "macos" => SourcePort.OperatingSystem.MacOS, _ => SourcePort.OperatingSystem.Unknown }; SourcePort sourcePort = new SourcePort ( id: id, downloadUrl: null, name: null, author: null, executable: null, os: os ); Items.Add(sourcePort); } }); }