Пример #1
0
        /// <summary>
        /// Extracts information from a patch that can be used to determine whether the patch
        /// applies on a target system. The method returns an XML string that can be provided to
        /// <see cref="DetermineApplicablePatches(string,string[],InapplicablePatchHandler,string,UserContexts)"/>
        /// instead of the full patch file.
        /// </summary>
        /// <param name="patchPath">Full path to the patch being queried.</param>
        /// <returns>XML string containing patch data.</returns>
        /// <remarks><p>
        /// Win32 MSI API:
        /// <a href="http://msdn.microsoft.com/library/en-us/msi/setup/msiextractpatchxmldata.asp">MsiExtractPatchXMLData</a>
        /// </p></remarks>
        public static string ExtractPatchXmlData(string patchPath)
        {
            StringBuilder buf     = new StringBuilder("");
            uint          bufSize = 0;
            uint          ret     = NativeMethods.MsiExtractPatchXMLData(patchPath, 0, buf, ref bufSize);

            if (ret == (uint)NativeMethods.Error.MORE_DATA)
            {
                buf.Capacity = (int)++bufSize;
                ret          = NativeMethods.MsiExtractPatchXMLData(patchPath, 0, buf, ref bufSize);
            }

            if (ret != 0)
            {
                throw InstallerException.ExceptionFromReturnCode(ret);
            }
            return(buf.ToString());
        }