Example #1
0
        private static List <string> CreateInstallObject(int indent, PIDataArchive 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));

            // INI replacements
            if (package.IniReplacements.Count > 0)
            {
                var iniFileReplaces = PsArray.GetArrayProperty("IniFileReplaces");
                foreach (var iniReplacement in package.IniReplacements)
                {
                    var replaceObj = PsObject.GetPSObject();
                    replaceObj.AppendProperty(NewProp("default", iniReplacement.DefaultValue));
                    replaceObj.AppendProperty(NewProp("newSetting", iniReplacement.ReplaceValue));

                    iniFileReplaces.AppendObject(replaceObj.ToList(indent));
                }

                obj.AppendItem(iniFileReplaces.ToList(indent));
            }

            return(obj.ToList(indent));
        }
Example #2
0
        private static List <string> CreateCodeBlock(int indent, PowerShellCodeBlock 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));

            if (!string.IsNullOrEmpty(package.Code.Trim()))
            {
                var arguments = PsArray.GetArrayProperty("PSCodeBlock");
                // goes over each line in the arguments configured
                using (StringReader sr = new StringReader(package.Code))
                {
                    string codeLine;
                    int    lines = 0;
                    while ((codeLine = sr.ReadLine()) != null)
                    {
                        if (!string.IsNullOrWhiteSpace(codeLine))
                        {
                            lines++;
                            arguments.AppendProperty($"'{codeLine}'");
                        }
                    }
                }

                obj.AppendItem(arguments.ToList(indent));
            }

            return(obj.ToList(indent));
        }
Example #3
0
        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));
        }
Example #4
0
        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
        }