LocalSource.cs (2563B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 4 namespace WinGetSourceCreator.Model 5 { 6 public class LocalSource 7 { 8 // Full path of the input appx manifest. 9 // Will be used to generate the package. 10 public string AppxManifest { get; set; } = string.Empty; 11 12 // The working directory where manifest will copied and referenced by the index. 13 public string WorkingDirectory { get; set; } = string.Empty; 14 15 // Input manifests. 16 // If it is a file the manifest gets copied to the input directory. 17 // If it is a directory the manifests will be copied preserving the sub dirs structure. 18 public List<string> LocalManifests { get; set; } = new(); 19 20 public List<LocalInstaller>? LocalInstallers { get; set; } 21 22 public List<DynamicInstaller>? DynamicInstallers { get; set; } 23 24 public Signature? Signature { get; set; } 25 26 public void Validate() 27 { 28 if (string.IsNullOrEmpty(this.AppxManifest)) 29 { 30 throw new ArgumentNullException(nameof(this.AppxManifest)); 31 } 32 33 if (string.IsNullOrEmpty(this.WorkingDirectory)) 34 { 35 throw new ArgumentNullException(nameof(this.WorkingDirectory)); 36 } 37 38 if (this.LocalManifests.Count == 0) 39 { 40 throw new ArgumentException(nameof(this.LocalManifests)); 41 } 42 43 if (this.LocalInstallers != null) 44 { 45 foreach (var installer in this.LocalInstallers) 46 { 47 installer.Validate(); 48 } 49 } 50 51 if (this.DynamicInstallers != null) 52 { 53 foreach (var installer in this.DynamicInstallers) 54 { 55 installer.Validate(); 56 } 57 } 58 59 if (this.Signature != null) 60 { 61 this.Signature.Validate(); 62 } 63 } 64 65 public string GetIndexName() 66 { 67 return "index.db"; 68 } 69 70 public string GetSourceName(int version) 71 { 72 switch (version) 73 { 74 case 1: 75 return "source.msix"; 76 case 2: 77 return "source2.msix"; 78 } 79 80 throw new ArgumentOutOfRangeException(nameof(version), version, "Unknown source major version"); 81 } 82 } 83 }