Example #1
0
        public static UpdateModule RetrieveData(string updateModuleFilePath)
        {
            if (Directory.Exists(updateModuleFilePath))
            {
                throw new ArgumentException(string.Format(@"The path ""{0}"" was not a file path. It was a path to a directory.", updateModuleFilePath), nameof(updateModuleFilePath));
            }

            var module = new UpdateModule();

            try
            {
                var updateModuleFileType = DetectUpdateModuleFileType(updateModuleFilePath);
                if (updateModuleFileType == UpdateModuleFileType.Executable)
                {
                    module.ExecutableModuleProperties = new ExecutableUpdateModuleProperties(updateModuleFilePath);
                }

                var fileInfo = new FileInfo(updateModuleFilePath);
                module.UpdateModuleFileType    = updateModuleFileType;
                module.FileSize                = fileInfo.Length;
                module.LastModifiedDateTimeUtc = fileInfo.LastWriteTimeUtc;

                module.UpdateModuleFilePath = updateModuleFilePath;
                module.FielHash             = FileHashHelper.ComputeFileHash(updateModuleFilePath);
            }
            catch (Exception e)
            {
                throw new UpdateModuleDataRetrieveException(updateModuleFilePath, e);
            }

            return(module);
        }
Example #2
0
        public static UpdatePackage RetrieveData(string updatePackageFilePath)
        {
            if (Directory.Exists(updatePackageFilePath))
            {
                throw new ArgumentException(string.Format(@"The path ""{0}"" was not a file path. It was a path to a directory.", updatePackageFilePath), nameof(updatePackageFilePath));
            }

            var package           = new UpdatePackage();
            var updatePackageType = DetectUpdatePackageType(updatePackageFilePath);

            if (updatePackageType == UpdatePackageType.MSCF)
            {
                string workFolderPath = null;
                try
                {
                    workFolderPath = CreateWorkFolder();
                    ExtractMscfUpdatePackageFile(updatePackageFilePath, workFolderPath);

                    if (VerifyWsusScanCabExistence(workFolderPath))
                    {
                        // .msu package

                        var packageXmlFilePath = GetFilePathDirectlyUnderFolder(workFolderPath, "*.xml");
                        package.PropertiesFromXmlFile = new UpdatePackageMetadataFromXmlFile(packageXmlFilePath);

                        var packagePropertyFilePath = GetFilePathDirectlyUnderFolder(workFolderPath, "*-pkgProperties*.txt");
                        package.PropertiesFromPropertyFile = new UpdatePackageMetadataFromPropertyFile(packagePropertyFilePath);

                        var innerCabFilePath       = GetInnerCabFilePath(package.PropertiesFromXmlFile.InnerCabFileLocation, workFolderPath);
                        var innerCabWorkFolderPath = CreateWorkFolder(workFolderPath);
                        ExtractMscfUpdatePackageFile(innerCabFilePath, innerCabWorkFolderPath);

                        var updateMumFilePath = GetFilePathDirectlyUnderFolder(innerCabWorkFolderPath, "update.mum");
                        package.PropertiesFromUpdateMumFile = new UpdatePackageMetadataFromUpdateMumFile(updateMumFilePath);

                        package.UpdateModules = RetrieveUpdateModules(innerCabWorkFolderPath);
                    }
                    else
                    {
                        // .cab package
                        throw new NotImplementedException(string.Format(@"The CAB file type update package does not support currently. The package file path was ""{0}"".", updatePackageFilePath));
                    }
                }
                catch (Exception e)
                {
                    throw new MscfUpdatePackageDataRetrieveException(updatePackageFilePath, e);
                }
                finally
                {
                    if (workFolderPath != null && Directory.Exists(workFolderPath))
                    {
                        Directory.Delete(workFolderPath, true);
                    }
                }
            }
            else
            {
                throw new UnknownUpdatePackageTypeException(updatePackageFilePath);
            }

            package.UpdatePackageFielPath = updatePackageFilePath;
            package.FielHash          = FileHashHelper.ComputeFileHash(updatePackageFilePath);
            package.UpdatePackageType = updatePackageType;

            return(package);
        }