Example #1
0
        public static PackageFragmentValidationResult LoadInstallXml(string zipFilename, out XElement installElement)
        {
            installElement = null;

            ZipFileSystem zipFileSystem = null;
            try
            {
                zipFileSystem = new ZipFileSystem(zipFilename);
            }
            catch (Exception ex)
            {
                return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex);
            }

            string filename = string.Format("~/{0}", PackageSystemSettings.InstallFilename);
            if (zipFileSystem.ContainsFile(filename) == false)
            {
                return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, string.Format("Installation file '{0}' is missing from the zip file", filename));
            }

            try
            {
                using (C1StreamReader streamReader = new C1StreamReader(zipFileSystem.GetFileStream(filename)))
                {
                    string fileContent = streamReader.ReadToEnd();
                    installElement = XElement.Parse(fileContent);
                }
            }
            catch (Exception ex)
            {
                return new PackageFragmentValidationResult(PackageFragmentValidationResultType.Fatal, ex);
            }

            return null;
        }
Example #2
0
        private IEnumerable<PackageFragmentValidationResult> LoadPackageFragmentInstallerBinaries(XElement packageFragmentInstallerBinariesElement)
        {
            var binaryElements = packageFragmentInstallerBinariesElement.Elements(XmlUtils.GetXName(PackageSystemSettings.XmlNamespace,
                                        PackageSystemSettings.PackageFragmentInstallerBinariesAddElementName)).ToList();

            if (!binaryElements.Any())
            {
                return new PackageFragmentValidationResult[0];
            }

            string binariesDirectory = Path.Combine(this.PackageInstallDirectory, PackageSystemSettings.BinariesDirectoryName);

            if (!C1Directory.Exists(binariesDirectory))
            {
                C1Directory.CreateDirectory(binariesDirectory);
            }

            var result = new List<PackageFragmentValidationResult>();

            foreach (XElement element in binaryElements)
            {
                XAttribute pathAttribute = element.Attribute(PackageSystemSettings.PathAttributeName);

                string sourceFilename = pathAttribute.Value;
                string targetFilename = Path.Combine(binariesDirectory, Path.GetFileName(sourceFilename));

                ZipFileSystem zipFileSystem = new ZipFileSystem(this.ZipFilename);
                if (!zipFileSystem.ContainsFile(sourceFilename))
                {
                    result.AddFatal(string.Format("The file '{0}' is missing from the zipfile", sourceFilename));
                    continue;
                }

                // Extracting dll to package temp folder
                if (C1File.Exists(targetFilename))
                {
                    bool success = false;
                    try
                    {
                        FileUtils.Delete(targetFilename);
                        success = true;
                    }
                    catch(UnauthorizedAccessException) {}

                    if(!success)
                    {
                        result.AddFatal("Access denied to file '{0}'".FormatWith(targetFilename));
                        continue;
                    }
                }

                zipFileSystem.WriteFileToDisk(sourceFilename, targetFilename);

                string newTargetFilename = Path.Combine(this.TempDirectory, Path.GetFileName(targetFilename));
                C1File.Copy(targetFilename, newTargetFilename);

                Log.LogVerbose("PackageInstaller", "Loading package uninstaller fragment assembly '{0}'", newTargetFilename);

                PackageAssemblyHandler.AddAssembly(newTargetFilename);
            }

            return result;
        }