コード例 #1
0
        /// <summary>
        /// Harvest the cab file.
        /// </summary>
        /// <param name="fragment">The property name of the bindings property.</param>
        /// <param name="argument">The path to the cab file.</param>
        /// <returns>The harvested cab binaries.</returns>
        private Wix.Fragment HarvestCab(Wix.Fragment fragment, String argument)
        {
            // crack the cab file into a temp directory.
            String cabDir = System.IO.Path.GetTempPath() + Guid.NewGuid().ToString();

            // should this be in a try...catch?
            System.IO.Directory.CreateDirectory(cabDir);

            using (WixExtractCab extractCab = new WixExtractCab())
            {
                try
                {
                    extractCab.Extract(argument, cabDir);
                }
                catch (FileNotFoundException)
                {
                    throw new WixException(WixErrors.CabExtractionFailed(argument, cabDir));
                }
            }

            // Process the folder
            //
            DirectoryHarvester ds = new DirectoryHarvester();

            fragment = ds.Harvest(cabDir);

            return(fragment);
        }
コード例 #2
0
        private void ExtractFilesFromMergeModule(IMsmMerge2 merge, WixMergeRow wixMergeRow)
        {
            bool  moduleOpen = false;
            short mergeLanguage;

            try
            {
                mergeLanguage = Convert.ToInt16(wixMergeRow.Language, CultureInfo.InvariantCulture);
            }
            catch (System.FormatException)
            {
                Messaging.Instance.OnMessage(WixErrors.InvalidMergeLanguage(wixMergeRow.SourceLineNumbers, wixMergeRow.Id, wixMergeRow.Language));
                return;
            }

            try
            {
                merge.OpenModule(wixMergeRow.SourceFile, mergeLanguage);
                moduleOpen = true;

                string safeMergeId = wixMergeRow.Number.ToString(CultureInfo.InvariantCulture.NumberFormat);

                // extract the module cabinet, then explode all of the files to a temp directory
                string moduleCabPath = String.Concat(this.TempFilesLocation, Path.DirectorySeparatorChar, safeMergeId, ".module.cab");
                merge.ExtractCAB(moduleCabPath);

                string mergeIdPath = String.Concat(this.TempFilesLocation, Path.DirectorySeparatorChar, "MergeId.", safeMergeId);
                Directory.CreateDirectory(mergeIdPath);

                using (WixExtractCab extractCab = new WixExtractCab())
                {
                    try
                    {
                        extractCab.Extract(moduleCabPath, mergeIdPath);
                    }
                    catch (FileNotFoundException)
                    {
                        throw new WixException(WixErrors.CabFileDoesNotExist(moduleCabPath, wixMergeRow.SourceFile, mergeIdPath));
                    }
                    catch
                    {
                        throw new WixException(WixErrors.CabExtractionFailed(moduleCabPath, wixMergeRow.SourceFile, mergeIdPath));
                    }
                }
            }
            catch (COMException ce)
            {
                throw new WixException(WixErrors.UnableToOpenModule(wixMergeRow.SourceLineNumbers, wixMergeRow.SourceFile, ce.Message));
            }
            finally
            {
                if (moduleOpen)
                {
                    merge.CloseModule();
                }
            }
        }