private static List <string> CreateInstallObject(int indent, Executable package) { var obj = PsObject.GetPSObject(); obj.AppendProperty(NewProp("install", package.Install.ToString())); obj.AppendProperty(NewProp("type", package.Type.ToString())); obj.AppendProperty(NewProp("displayName", package.DisplayName)); obj.AppendProperty(NewProp("package", package.FileInfo.FileName)); //arguments if (!string.IsNullOrEmpty(package.Arguments.Trim())) { var arguments = PsArray.GetArrayProperty("arguments"); // goes over each line in the arguments configured using (StringReader sr = new StringReader(package.Arguments)) { string arg; int argsCount = 0; while ((arg = sr.ReadLine()) != null) { if (!string.IsNullOrWhiteSpace(arg)) { argsCount++; arguments.AppendProperty($"'{arg}'"); } } } obj.AppendItem(arguments.ToList(indent)); } return(obj.ToList(indent)); }
public static void CreateInstallConfigFromObjects(IEnumerable <IInstallationStep> packages, string outputFolder) { var version = GetCurrentExeVersion(); // Generate headers var config = new List <string>(); config.Add($"# {UserSettings.Default.PackGenConfigFileName}"); config.Add($"# Generated on {DateTime.Now} from the silent package builder v {version}"); config.Add("# "); config.Add("# "); config.Add("# "); var rootObject = PsObject.GetPSObject(); rootObject.AppendProperty(NewProp("sourcePackagesDir", "SetupPackages")); rootObject.AppendProperty(NewProp("extractedPackagesDir", "ExtractedPackages")); var installPackagesArray = PsArray.GetArrayProperty("installPackages"); // packages foreach (var package in packages) { if (package is PowerShellCodeBlock) { installPackagesArray.AppendObject(CreateCodeBlock(0, (PowerShellCodeBlock)package)); } if (package is PIDataArchive) { installPackagesArray.AppendObject(CreateInstallObject(0, (PIDataArchive)package)); } if (package is OSIAutoExtractSetupPackage) { installPackagesArray.AppendObject(CreateInstallObject(0, (OSIAutoExtractSetupPackage)package)); } if (package is Executable) { installPackagesArray.AppendObject(CreateInstallObject(0, (Executable)package)); } } rootObject.AppendItem(installPackagesArray.ToList(0)); config.AddRange(rootObject.ToList(0)); File.WriteAllLines(Path.Combine(outputFolder, UserSettings.Default.PackGenConfigFileName), config); // check space for packages in the target dir }