public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
        {
            IEngine engine = new Engine(pEngine);
            IBootstrapperCommand bootstrapperCommand = command.GetBootstrapperCommand();

            return(this.Create(engine, bootstrapperCommand));
        }
예제 #2
0
        /// <summary>
        /// Loads the bootstrapper application assembly and creates an instance of the IBootstrapperApplication.
        /// </summary>
        /// <param name="pEngine">IBootstrapperEngine provided for the bootstrapper application.</param>
        /// <param name="command">Command line for the bootstrapper application.</param>
        /// <returns>Bootstrapper application via <see cref="IBootstrapperApplication"/> interface.</returns>
        /// <exception cref="MissingAttributeException">The bootstrapper application assembly
        /// does not define the <see cref="BootstrapperApplicationAttribute"/>.</exception>
        public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
        {
            // Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host.
            HostSection section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection;
            if (null == section)
            {
                throw new MissingAttributeException(); // TODO: throw a more specific exception than this.
            }

            // Load the BA and make sure it extends BootstrapperApplication.
            Type baType = BootstrapperApplicationFactory.GetBootstrapperApplicationTypeFromAssembly(section.AssemblyName);
            BootstrapperApplication ba = Activator.CreateInstance(baType) as BootstrapperApplication;
            if (null == ba)
            {
                throw new InvalidBootstrapperApplicationException();
            }

            ba.Engine = new Engine(pEngine);
            ba.Command = command;
            return ba;
        }
        /// <summary>
        /// Loads the bootstrapper application assembly and creates an instance of the IBootstrapperApplication.
        /// </summary>
        /// <param name="pEngine">IBootstrapperEngine provided for the bootstrapper application.</param>
        /// <param name="command">Command line for the bootstrapper application.</param>
        /// <returns>Bootstrapper application via <see cref="IBootstrapperApplication"/> interface.</returns>
        /// <exception cref="MissingAttributeException">The bootstrapper application assembly
        /// does not define the <see cref="BootstrapperApplicationAttribute"/>.</exception>
        public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
        {
            // Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host.
            HostSection section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection;

            if (null == section)
            {
                throw new MissingAttributeException(); // TODO: throw a more specific exception than this.
            }

            // Load the BA and make sure it extends BootstrapperApplication.
            Type baType = BootstrapperApplicationFactory.GetBootstrapperApplicationTypeFromAssembly(section.AssemblyName);
            BootstrapperApplication ba = Activator.CreateInstance(baType) as BootstrapperApplication;

            if (null == ba)
            {
                throw new InvalidBootstrapperApplicationException();
            }

            ba.Engine  = new Engine(pEngine);
            ba.Command = command;
            return(ba);
        }
예제 #4
0
        /// <summary>
        /// Loads the bootstrapper application assembly and creates an instance of the IBootstrapperApplication.
        /// </summary>
        /// <param name="pEngine">IBootstrapperEngine provided for the bootstrapper application.</param>
        /// <param name="command">Command line for the bootstrapper application.</param>
        /// <returns>Bootstrapper application via <see cref="IBootstrapperApplication"/> interface.</returns>
        /// <exception cref="MissingAttributeException">The bootstrapper application assembly
        /// does not define the <see cref="BootstrapperApplicationFactoryAttribute"/>.</exception>
        public IBootstrapperApplication Create(IBootstrapperEngine pEngine, ref Command command)
        {
            // Get the wix.boostrapper section group to get the name of the bootstrapper application assembly to host.
            var section = ConfigurationManager.GetSection("wix.bootstrapper/host") as HostSection;

            if (null == section)
            {
                throw new MissingAttributeException(); // TODO: throw a more specific exception than this.
            }

            // Load the BA's IBootstrapperApplicationFactory.
            var baFactoryType = BootstrapperApplicationFactory.GetBAFactoryTypeFromAssembly(section.AssemblyName);
            var baFactory     = (IBootstrapperApplicationFactory)Activator.CreateInstance(baFactoryType);

            if (null == baFactory)
            {
                throw new InvalidBootstrapperApplicationFactoryException();
            }

            var ba = baFactory.Create(pEngine, ref command);

            return(ba);
        }
예제 #5
0
파일: BalUtil.cs 프로젝트: wixtoolset/wix4
 internal static extern bool BalVariableExistsFromEngine(
     [MarshalAs(UnmanagedType.Interface)] IBootstrapperEngine pEngine,
     [MarshalAs(UnmanagedType.LPWStr)] string wzVariable
     );
예제 #6
0
파일: BalUtil.cs 프로젝트: wixtoolset/wix4
 internal static extern int BalGetVersionVariableFromEngine(
     [MarshalAs(UnmanagedType.Interface)] IBootstrapperEngine pEngine,
     [MarshalAs(UnmanagedType.LPWStr)] string wzVariable,
     ref StrUtil.StrHandle psczOut
     );
예제 #7
0
파일: BalUtil.cs 프로젝트: wixtoolset/wix4
 internal static extern int BalFormatStringFromEngine(
     [MarshalAs(UnmanagedType.Interface)] IBootstrapperEngine pEngine,
     [MarshalAs(UnmanagedType.LPWStr)] string wzFormat,
     ref StrUtil.StrHandle psczOut
     );
예제 #8
0
        /// <summary>
        /// Creates a new instance of the <see cref="Engine"/> container class.
        /// </summary>
        /// <param name="engine">The <see cref="IBootstrapperEngine"/> to contain.</param>
        internal Engine(IBootstrapperEngine engine)
        {
            this.engine = engine;

            // Wrap the calls to get and set numeric variables.
            this.numericVariables = new Variables <long>(
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableNumeric(name, out value);
                if (NativeMethods.S_OK != ret)
                {
                    throw new Win32Exception(ret);
                }

                return(value);
            },
                delegate(string name, long value)
            {
                this.engine.SetVariableNumeric(name, value);
            },
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableNumeric(name, out value);

                return(NativeMethods.E_NOTFOUND != ret);
            }
                );

            // Wrap the calls to get and set string variables using SecureStrings.
            this.secureStringVariables = new Variables <SecureString>(
                delegate(string name)
            {
                int length;
                IntPtr pUniString = getStringVariable(name, out length);
                try
                {
                    return(convertToSecureString(pUniString, length));
                }
                finally
                {
                    if (IntPtr.Zero != pUniString)
                    {
                        Marshal.FreeCoTaskMem(pUniString);
                    }
                }
            },
                delegate(string name, SecureString value)
            {
                IntPtr pValue = Marshal.SecureStringToCoTaskMemUnicode(value);
                try
                {
                    this.engine.SetVariableString(name, pValue);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(pValue);
                }
            },
                delegate(string name)
            {
                return(containsVariable(name));
            }
                );

            // Wrap the calls to get and set string variables.
            this.stringVariables = new Variables <string>(
                delegate(string name)
            {
                int length;
                IntPtr pUniString = getStringVariable(name, out length);
                try
                {
                    return(Marshal.PtrToStringUni(pUniString, length));
                }
                finally
                {
                    if (IntPtr.Zero != pUniString)
                    {
                        Marshal.FreeCoTaskMem(pUniString);
                    }
                }
            },
                delegate(string name, string value)
            {
                IntPtr pValue = Marshal.StringToCoTaskMemUni(value);
                try
                {
                    this.engine.SetVariableString(name, pValue);
                }
                finally
                {
                    Marshal.FreeCoTaskMem(pValue);
                }
            },
                delegate(string name)
            {
                return(containsVariable(name));
            }
                );

            // Wrap the calls to get and set version variables.
            this.versionVariables = new Variables <Version>(
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableVersion(name, out value);
                if (NativeMethods.S_OK != ret)
                {
                    throw new Win32Exception(ret);
                }

                return(LongToVersion(value));
            },
                delegate(string name, Version value)
            {
                long version = VersionToLong(value);
                this.engine.SetVariableVersion(name, version);
            },
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableVersion(name, out value);

                return(NativeMethods.E_NOTFOUND != ret);
            }
                );
        }
예제 #9
0
파일: Engine.cs 프로젝트: jchoover/balutil

        
예제 #10
0
파일: Engine.cs 프로젝트: fyisa/wix3
        /// <summary>
        /// Creates a new instance of the <see cref="Engine"/> container class.
        /// </summary>
        /// <param name="engine">The <see cref="IBootstrapperEngine"/> to contain.</param>
        internal Engine(IBootstrapperEngine engine)
        {
            this.engine = engine;

            // Wrap the calls to get and set numeric variables.
            this.numericVariables = new Variables <long>(
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableNumeric(name, out value);
                if (NativeMethods.S_OK != ret)
                {
                    throw new Win32Exception(ret);
                }

                return(value);
            },
                delegate(string name, long value)
            {
                this.engine.SetVariableNumeric(name, value);
            },
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableNumeric(name, out value);

                return(NativeMethods.E_NOTFOUND != ret);
            }
                );

            // Wrap the calls to get and set string variables.
            this.stringVariables = new Variables <string>(
                delegate(string name)
            {
                int capacity     = InitialBufferSize;
                StringBuilder sb = new StringBuilder(capacity);

                // Get the size of the buffer.
                int ret = this.engine.GetVariableString(name, sb, ref capacity);
                if (NativeMethods.E_INSUFFICIENT_BUFFER == ret || NativeMethods.E_MOREDATA == ret)
                {
                    sb.Capacity = ++capacity;     // Add one for the null terminator.
                    ret         = this.engine.GetVariableString(name, sb, ref capacity);
                }

                if (NativeMethods.S_OK != ret)
                {
                    throw new Win32Exception(ret);
                }

                return(sb.ToString());
            },
                delegate(string name, string value)
            {
                this.engine.SetVariableString(name, value);
            },
                delegate(string name)
            {
                int capacity     = InitialBufferSize;
                StringBuilder sb = new StringBuilder(capacity);
                int ret          = this.engine.GetVariableString(name, sb, ref capacity);

                return(NativeMethods.E_NOTFOUND != ret);
            }
                );

            // Wrap the calls to get and set version variables.
            this.versionVariables = new Variables <Version>(
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableVersion(name, out value);
                if (NativeMethods.S_OK != ret)
                {
                    throw new Win32Exception(ret);
                }

                int major    = (int)((value & ((long)0xffff << 48)) >> 48);
                int minor    = (int)((value & ((long)0xffff << 32)) >> 32);
                int build    = (int)((value & ((long)0xffff << 16)) >> 16);
                int revision = (int)(value & 0xffff);

                return(new Version(major, minor, build, revision));
            },
                delegate(string name, Version value)
            {
                // In Windows, each version component has a max value of 65535,
                // so we truncate the version before shifting it, which will overflow if invalid.
                long major    = (long)(ushort)value.Major << 48;
                long minor    = (long)(ushort)value.Minor << 32;
                long build    = (long)(ushort)value.Build << 16;
                long revision = (long)(ushort)value.Revision;

                long version = major | minor | build | revision;
                this.engine.SetVariableVersion(name, version);
            },
                delegate(string name)
            {
                long value;
                int ret = this.engine.GetVariableVersion(name, out value);

                return(NativeMethods.E_NOTFOUND != ret);
            }
                );
        }