SourceInstaller.cs (1399B)
1 // Copyright (c) Microsoft Corporation. 2 // Licensed under the MIT License. 3 4 namespace WinGetSourceCreator.Model 5 { 6 public class SourceInstaller : Installer 7 { 8 public SourceInstaller(string workingDirectory, DynamicInstaller installer) 9 { 10 this.Initialize(installer); 11 this.InstallerFile = installer.Create(workingDirectory); 12 } 13 14 public SourceInstaller(string workingDirectory, LocalInstaller installer) 15 { 16 this.Initialize(installer); 17 this.InstallerFile = Path.Combine(workingDirectory, this.Name); 18 var parent = Path.GetDirectoryName(this.InstallerFile); 19 if (!string.IsNullOrEmpty(parent)) 20 { 21 Directory.CreateDirectory(parent); 22 } 23 File.Copy(installer.Input, this.InstallerFile, true); 24 } 25 26 public string InstallerFile { get; private set; } 27 28 private void Initialize(Installer installer) 29 { 30 foreach (var installerProperty in installer.GetType().GetProperties()) 31 { 32 var toProperty = this.GetType().GetProperty(installerProperty.Name); 33 if (toProperty != null) 34 { 35 toProperty.SetValue(this, installerProperty.GetValue(installer)); 36 } 37 } 38 } 39 } 40 }