/// <exclude /> public override void Uninstall() { Verify.IsNotNull(_filesToDelete as object ?? _filesToCopy, "{0} has not been validated", this.GetType().Name); foreach (string filename in _filesToDelete) { Log.LogVerbose(LogTitle, "Uninstalling the file '{0}'", filename); FileUtils.Delete(filename); } foreach (var fileToCopy in _filesToCopy) { string targetFile = fileToCopy.Item2; Log.LogVerbose(LogTitle, "Restoring file from a backup copy'{0}'", targetFile); if ((C1File.GetAttributes(targetFile) & FileAttributes.ReadOnly) > 0) { FileUtils.RemoveReadOnly(targetFile); } C1File.Copy(fileToCopy.Item1, targetFile, true); } }
public IEnumerable <ElementAction> Provide(EntityToken entityToken) { var websiteFileEntityToken = (WebsiteFileElementProviderEntityToken)entityToken; var attr = C1File.GetAttributes(websiteFileEntityToken.Path); if ((attr & FileAttributes.Directory) == FileAttributes.Directory) { var root = PathUtil.Resolve("~"); var relativePath = websiteFileEntityToken.Path.Remove(0, root.Length); var actionToken = new DownloadActionToken("File", "/" + relativePath); yield return(Actions.CreateElementAction(actionToken)); } }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneFilesElement, this.ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); _filesToCopy = new List <FileToCopy>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File")) { XAttribute sourceFilenameAttribute = fileElement.Attribute("sourceFilename"); XAttribute targetFilenameAttribute = fileElement.Attribute("targetFilename"); if (sourceFilenameAttribute == null) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_MissingAttribute("sourceFilename"), fileElement); continue; } if (targetFilenameAttribute == null) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_MissingAttribute("targetFilename"), fileElement); continue; } XAttribute allowOverwriteAttribute = fileElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = fileElement.Attribute("assemblyLoad"); XAttribute onlyUpdateAttribute = fileElement.Attribute("onlyUpdate"); XAttribute addAssemblyBindingAttribute = fileElement.Attribute("addAssemblyBinding"); bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool loadAssembly = false; if (!ParseBoolAttribute(assemblyLoadAttribute, validationResult, ref loadAssembly)) { continue; } bool onlyUpdate = false; if (!ParseBoolAttribute(onlyUpdateAttribute, validationResult, ref onlyUpdate)) { continue; } bool addAssemblyBinding = false; if (!ParseBoolAttribute(addAssemblyBindingAttribute, validationResult, ref addAssemblyBinding)) { continue; } string sourceFilename = sourceFilenameAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsFile(sourceFilename)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingFile(sourceFilename), sourceFilenameAttribute); continue; } if (loadAssembly && onlyUpdate) { validationResult.AddFatal( Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowedWithLoadAssemlby, onlyUpdateAttribute); continue; } string targetFilename = PathUtil.Resolve(targetFilenameAttribute.Value); if (C1File.Exists(targetFilename)) { if (!allowOverwrite && !onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetFilenameAttribute); continue; } if (((C1File.GetAttributes(targetFilename) & FileAttributes.ReadOnly) > 0) && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileReadOnly(targetFilename), targetFilenameAttribute); continue; } } else if (onlyUpdate) { Log.LogVerbose(LogTitle, "Skipping updating of the file '{0}' because it does not exist", targetFilename); continue; // Target file does not, so skip this } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = targetFilenameAttribute.Value, TargetFilePath = targetFilename, Overwrite = allowOverwrite || onlyUpdate, AddAssemblyBinding = addAssemblyBinding }; _filesToCopy.Add(fileToCopy); if (loadAssembly) { string tempFilename = Path.Combine(this.InstallerContext.TempDirectory, Path.GetFileName(targetFilename)); this.InstallerContext.ZipFileSystem.WriteFileToDisk(sourceFilename, tempFilename); PackageAssemblyHandler.AddAssembly(tempFilename); } } } if (validationResult.Count > 0) { _filesToCopy = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <XElement> Install() { Verify.IsNotNull(_filesToCopy, "{0} has not been validated", this.GetType().Name); var dependencies = new List <Pair <string, Version> >(); var asmBindingsToAdd = new List <AssemblyBindingInfo>(); var fileElements = new List <XElement>(); foreach (FileToCopy fileToCopy in _filesToCopy) { Log.LogVerbose(LogTitle, "Installing the file '{0}' to the target filename '{1}'", fileToCopy.SourceFilename, fileToCopy.TargetFilePath); // Extracting the dll file so version can be checked string tempFileName = Path.Combine(InstallerContext.TempDirectory, Path.GetRandomFileName()); this.InstallerContext.ZipFileSystem.WriteFileToDisk(fileToCopy.SourceFilename, tempFileName); // Checking for dll version here: var sourceFileVersionInfo = FileVersionInfo.GetVersionInfo(tempFileName); var sourceFileVersion = GetDllProductVersion(tempFileName); dependencies.Add(new Pair <string, Version>(fileToCopy.TargetRelativeFilePath, sourceFileVersion)); string targetDirectory = Path.GetDirectoryName(fileToCopy.TargetFilePath); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } string backupFileName = null; bool addAssemblyBinding = fileToCopy.AddAssemblyBinding; if (C1File.Exists(fileToCopy.TargetFilePath) && fileToCopy.Overwrite) { var existingFileVersion = GetDllProductVersion(fileToCopy.TargetFilePath); if (existingFileVersion == sourceFileVersion) { Log.LogInformation(LogTitle, "Skipping installation for file '{0}' version '{1}'. A file with the same version already exists.", fileToCopy.TargetRelativeFilePath, sourceFileVersion); continue; } if (existingFileVersion > sourceFileVersion) { Log.LogInformation(LogTitle, "Skipping installation for file '{0}' version '{1}', as a file with a newer version '{2}' already exists.", fileToCopy.TargetRelativeFilePath, sourceFileVersion, existingFileVersion); continue; } addAssemblyBinding = true; if ((C1File.GetAttributes(fileToCopy.TargetFilePath) & FileAttributes.ReadOnly) > 0) { FileUtils.RemoveReadOnly(fileToCopy.TargetFilePath); } if (InstallerContext.PackageInformation.CanBeUninstalled) { backupFileName = GetBackupFileName(fileToCopy.TargetFilePath); string backupFilesFolder = this.InstallerContext.PackageDirectory + "\\FileBackup"; C1Directory.CreateDirectory(backupFilesFolder); C1File.Copy(fileToCopy.TargetFilePath, backupFilesFolder + "\\" + backupFileName); } Log.LogInformation(LogTitle, "Overwriting existing file '{0}' version '{2}', new version is '{1}'", fileToCopy.TargetRelativeFilePath, sourceFileVersion, existingFileVersion); } if (addAssemblyBinding) { asmBindingsToAdd.Add(new AssemblyBindingInfo { FilePath = fileToCopy.TargetFilePath, FileVersionInfo = sourceFileVersionInfo, VersionInfo = sourceFileVersion }); } File.Delete(fileToCopy.TargetFilePath); File.Move(tempFileName, fileToCopy.TargetFilePath); var fileElement = new XElement("File", new XAttribute("filename", fileToCopy.TargetRelativeFilePath), new XAttribute("version", sourceFileVersion)); if (backupFileName != null) { fileElement.Add(new XAttribute("backupFile", backupFileName)); } fileElements.Add(fileElement); } UpdateBindingRedirects(asmBindingsToAdd); yield return(new XElement("Files", fileElements)); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { var validationResult = new List <PackageFragmentValidationResult>(); if (this.Configuration.Count(f => f.Name == "Files") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneFilesElement, this.ConfigurationParent); return(validationResult); } if (this.Configuration.Count(f => f.Name == "Directories") > 1) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyOneDirectoriesElement, this.ConfigurationParent); return(validationResult); } XElement filesElement = this.Configuration.SingleOrDefault(f => f.Name == "Files"); XElement directoriesElement = this.Configuration.SingleOrDefault(f => f.Name == "Directories"); _filesToCopy = new List <FileToCopy>(); _directoriesToDelete = new List <string>(); if (filesElement != null) { foreach (XElement fileElement in filesElement.Elements("File")) { XAttribute sourceFilenameAttribute = fileElement.Attribute("sourceFilename"); XAttribute targetFilenameAttribute = fileElement.Attribute("targetFilename"); if (sourceFilenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("sourceFilename"), fileElement); continue; } if (targetFilenameAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("targetFilename"), fileElement); continue; } XAttribute allowOverwriteAttribute = fileElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = fileElement.Attribute("assemblyLoad"); XAttribute deleteTargetDirectoryAttribute = fileElement.Attribute("deleteTargetDirectory"); XAttribute onlyUpdateAttribute = fileElement.Attribute("onlyUpdate"); XAttribute onlyAddAttribute = fileElement.Attribute("onlyAdd"); if (deleteTargetDirectoryAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_DeleteTargetDirectoryNotAllowed, fileElement); continue; } bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool loadAssembly = false; if (!ParseBoolAttribute(assemblyLoadAttribute, validationResult, ref loadAssembly)) { continue; } bool onlyUpdate = false; if (!ParseBoolAttribute(onlyUpdateAttribute, validationResult, ref onlyUpdate)) { continue; } bool onlyAdd = false; if (!ParseBoolAttribute(onlyAddAttribute, validationResult, ref onlyAdd)) { continue; } string sourceFilename = sourceFilenameAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsFile(sourceFilename)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingFile(sourceFilename), sourceFilenameAttribute); continue; } if (loadAssembly && onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowedWithLoadAssemlby, onlyUpdateAttribute); continue; } if (onlyAdd && onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateAndOnlyAddNotAllowed, onlyUpdateAttribute); continue; } if (onlyAdd && allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyAddAndAllowOverwriteNotAllowed, onlyAddAttribute); continue; } string targetFilename = PathUtil.Resolve(targetFilenameAttribute.Value); if (C1File.Exists(targetFilename)) { if (onlyAdd) { Log.LogVerbose(LogTitle, "Skipping adding of the file '{0}' because it already exist and is marked 'onlyAdd'", targetFilename); continue; // Target file does not, so skip this } if (!allowOverwrite && !onlyUpdate) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetFilenameAttribute); continue; } if (((C1File.GetAttributes(targetFilename) & FileAttributes.ReadOnly) > 0) && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileReadOnly(targetFilename), targetFilenameAttribute); continue; } } else if (onlyUpdate) { Log.LogVerbose(LogTitle, "Skipping updating of the file '{0}' because it does not exist", targetFilename); continue; // Target file does not, so skip this } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = targetFilenameAttribute.Value, TargetFilePath = targetFilename, Overwrite = allowOverwrite || onlyUpdate }; _filesToCopy.Add(fileToCopy); if (loadAssembly) { string tempFilename = Path.Combine(this.InstallerContext.TempDirectory, Path.GetFileName(targetFilename)); this.InstallerContext.ZipFileSystem.WriteFileToDisk(sourceFilename, tempFilename); PackageAssemblyHandler.AddAssembly(tempFilename); } } } if (directoriesElement != null) { foreach (XElement directoryElement in directoriesElement.Elements("Directory")) { XAttribute sourceDirectoryAttribute = directoryElement.Attribute("sourceDirectory"); XAttribute targetDirectoryAttribute = directoryElement.Attribute("targetDirectory"); if (sourceDirectoryAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("sourceDirectory"), directoryElement); continue; } if (targetDirectoryAttribute == null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingAttribute("targetDirectory"), directoryElement); continue; } XAttribute allowOverwriteAttribute = directoryElement.Attribute("allowOverwrite"); XAttribute assemblyLoadAttribute = directoryElement.Attribute("assemblyLoad"); XAttribute deleteTargetDirectoryAttribute = directoryElement.Attribute("deleteTargetDirectory"); XAttribute onlyUpdateAttribute = directoryElement.Attribute("onlyUpdate"); if (assemblyLoadAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_AssemblyLoadNotAllowed, directoryElement); continue; } if (onlyUpdateAttribute != null) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_OnlyUpdateNotAllowed, directoryElement); continue; } bool allowOverwrite = false; if (!ParseBoolAttribute(allowOverwriteAttribute, validationResult, ref allowOverwrite)) { continue; } bool deleteTargetDirectory = false; if (!ParseBoolAttribute(deleteTargetDirectoryAttribute, validationResult, ref deleteTargetDirectory)) { continue; } string sourceDirectory = sourceDirectoryAttribute.Value; if (!this.InstallerContext.ZipFileSystem.ContainsDirectory(sourceDirectory)) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_MissingDirectory(sourceDirectory), sourceDirectoryAttribute); continue; } string targetDirectory = PathUtil.Resolve(targetDirectoryAttribute.Value); if (deleteTargetDirectory) { if (C1Directory.Exists(targetDirectory)) { _directoriesToDelete.Add(targetDirectory); } } foreach (string sourceFilename in this.InstallerContext.ZipFileSystem.GetFilenames(sourceDirectory)) { string resolvedSourceFilename = sourceFilename.Remove(0, sourceDirectory.Length); if (resolvedSourceFilename.StartsWith("/")) { resolvedSourceFilename = resolvedSourceFilename.Remove(0, 1); } string targetFilename = Path.Combine(targetDirectory, resolvedSourceFilename); if (C1File.Exists(targetFilename) && !deleteTargetDirectory && !allowOverwrite) { validationResult.AddFatal(Texts.FilePackageFragmentInstaller_FileExists(targetFilename), targetDirectoryAttribute); continue; } var fileToCopy = new FileToCopy { SourceFilename = sourceFilename, TargetRelativeFilePath = Path.Combine(targetDirectoryAttribute.Value, resolvedSourceFilename), TargetFilePath = targetFilename, Overwrite = allowOverwrite }; _filesToCopy.Add(fileToCopy); } } } if (validationResult.Count > 0) { _filesToCopy = null; _directoriesToDelete = null; } return(validationResult); }
/// <exclude /> public override IEnumerable <XElement> Install() { Verify.IsNotNull(_filesToCopy, "{0} has not been validated", this.GetType().Name); foreach (string directoryToDelete in _directoriesToDelete) { Directory.Delete(directoryToDelete, true); } var fileElements = new List <XElement>(); foreach (FileToCopy fileToCopy in _filesToCopy) { Log.LogVerbose(LogTitle, "Installing the file '{0}' to the target filename '{1}'", fileToCopy.SourceFilename, fileToCopy.TargetFilePath); string targetDirectory = Path.GetDirectoryName(fileToCopy.TargetFilePath); if (!Directory.Exists(targetDirectory)) { Directory.CreateDirectory(targetDirectory); } string backupFileName = null; if (C1File.Exists(fileToCopy.TargetFilePath) && fileToCopy.Overwrite) { if ((C1File.GetAttributes(fileToCopy.TargetFilePath) & FileAttributes.ReadOnly) > 0) { FileUtils.RemoveReadOnly(fileToCopy.TargetFilePath); } if (InstallerContext.PackageInformation.CanBeUninstalled) { backupFileName = GetBackupFileName(fileToCopy.TargetFilePath); string backupFilesFolder = this.InstallerContext.PackageDirectory + "\\FileBackup"; C1Directory.CreateDirectory(backupFilesFolder); C1File.Copy(fileToCopy.TargetFilePath, backupFilesFolder + "\\" + backupFileName); } } this.InstallerContext.ZipFileSystem.WriteFileToDisk(fileToCopy.SourceFilename, fileToCopy.TargetFilePath); // Searching for static IData interfaces string targetFilePath = fileToCopy.TargetFilePath; if (targetFilePath.StartsWith(Path.Combine(PathUtil.BaseDirectory, "Bin"), StringComparison.InvariantCultureIgnoreCase) && targetFilePath.EndsWith(".dll", StringComparison.InvariantCultureIgnoreCase)) { string fileName = Path.GetFileName(targetFilePath); if (!DllsNotToLoad.Any(fileName.StartsWith)) { Assembly assembly; try { assembly = Assembly.LoadFrom(targetFilePath); } catch (Exception) { continue; } DataTypeTypesManager.AddNewAssembly(assembly, false); } } var fileElement = new XElement("File", new XAttribute("filename", fileToCopy.TargetRelativeFilePath)); if (backupFileName != null) { fileElement.Add(new XAttribute("backupFile", backupFileName)); } fileElements.Add(fileElement); } yield return(new XElement("Files", fileElements)); }
/// <exclude /> public override IEnumerable <PackageFragmentValidationResult> Validate() { _xslTransformations = new List <XslTransformation>(); var validationResult = new List <PackageFragmentValidationResult>(); var filesElement = this.ConfigurationParent.GetSingleConfigurationElement("XslFiles", validationResult, false); if (filesElement == null) { return(validationResult); } foreach (XElement fileElement in filesElement.GetConfigurationElements("XslFile", validationResult)) { XAttribute pathXMLAttribute = fileElement.Attribute(TargetXmlAttributeName); XAttribute inputXMLAttribute = fileElement.Attribute(InputXmlAttributeName); XAttribute outputXMLAttribute = fileElement.Attribute(OutputXmlAttributeName); XAttribute pathXSLAttribute = fileElement.Attribute(TargetXslAttributeName); XAttribute installXSLAttribute = fileElement.Attribute(InstallXslAttributeName); XAttribute uninstallXSLAttribute = fileElement.Attribute(UninstallXslAttributeName); XAttribute overrideReadOnlyAttribute = fileElement.Attribute(OverrideReadOnlyAttributeName); XAttribute skipIfNotExistAttribute = fileElement.Attribute(SkipIfNotExistAttributeName); bool skipIfNotExist = skipIfNotExistAttribute != null && skipIfNotExistAttribute.Value.ToLower() == "true"; if (pathXSLAttribute == null && installXSLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } if (outputXMLAttribute != null && uninstallXSLAttribute != null) { validationResult.AddFatal("Xsl installer does not suppurt simultaneous usage of attributes '{0}' and '{1}'" .FormatWith(OutputXmlAttributeName, UninstallXslAttributeName), fileElement); continue; } string xslFilePath = (pathXSLAttribute ?? installXSLAttribute).Value; XslTransformation xslFile; if (inputXMLAttribute != null) { if (outputXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute("outputFilename"), fileElement); continue; } xslFile = new XslTransformation { XslPath = xslFilePath, InputXmlPath = inputXMLAttribute.Value, OutputXmlPath = outputXMLAttribute.Value }; } else { if (pathXMLAttribute == null) { validationResult.AddFatal(Texts.PackageFragmentInstaller_MissingAttribute(TargetXmlAttributeName), fileElement); continue; } string pathToXmlFile = pathXMLAttribute.Value; xslFile = new XslTransformation { XslPath = xslFilePath, // UninstallXslPath = uninstallXSLAttribute != null ? uninstallXSLAttribute.Value : null, InputXmlPath = pathToXmlFile, OutputXmlPath = pathToXmlFile }; } if (!C1File.Exists(PathUtil.Resolve(xslFile.InputXmlPath))) { if (skipIfNotExist) { continue; } validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileNotFound(xslFile.InputXmlPath), fileElement); continue; } string outputXmlFullPath = PathUtil.Resolve(xslFile.OutputXmlPath); if (C1File.Exists(outputXmlFullPath) && (C1File.GetAttributes(outputXmlFullPath) & FileAttributes.ReadOnly) > 0) { if (overrideReadOnlyAttribute == null || overrideReadOnlyAttribute.Value != "true") { validationResult.AddFatal(Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnly(xslFile.OutputXmlPath), fileElement); continue; } FileUtils.RemoveReadOnly(outputXmlFullPath); Log.LogWarning(LogTitle, Texts.FileXslTransformationPackageFragmentInstaller_FileReadOnlyOverride(xslFile.OutputXmlPath)); } if (!PathUtil.WritePermissionGranted(outputXmlFullPath)) { validationResult.AddFatal(Texts.NotEnoughNtfsPermissions(xslFile.OutputXmlPath), fileElement); continue; } _xslTransformations.Add(xslFile); } if (validationResult.Count > 0) { _xslTransformations = null; } return(validationResult); }