Exemplo n.º 1
0
        /// <summary>
        /// Gets the full path to the designated folder on the source media or server image.
        /// </summary>
        /// <exception cref="ArgumentException">the folder was not found in the Directory table</exception>
        /// <exception cref="InvalidHandleException">the Session handle is invalid</exception>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msigetsourcepath.asp">MsiGetSourcePath</a>
        /// </p></remarks>
        public string GetSourcePath(string directory)
        {
            if (string.IsNullOrWhiteSpace(directory))
            {
                throw new ArgumentNullException("directory");
            }

            this.ValidateSessionAccess();

            StringBuilder buf     = new StringBuilder();
            uint          bufSize = 0;
            uint          ret     = RemotableNativeMethods.MsiGetSourcePath((int)this.Handle, directory, buf, ref bufSize);

            if (ret == (uint)NativeMethods.Error.MORE_DATA)
            {
                buf.Capacity = (int)++bufSize;
                ret          = ret = RemotableNativeMethods.MsiGetSourcePath((int)this.Handle, directory, buf, ref bufSize);
            }

            if (ret != 0)
            {
                if (ret == (uint)NativeMethods.Error.DIRECTORY)
                {
                    throw InstallerException.ExceptionFromReturnCode(ret, directory);
                }
                else
                {
                    throw InstallerException.ExceptionFromReturnCode(ret);
                }
            }
            return(buf.ToString());
        }