Exemple #1
0
        public void ProductManifestTest()
        {
            FileInfo _fi = new FileInfo(FileNames.ManifestFileName);

            Assert.IsFalse(_fi.Exists, FileNames.ManifestFileName);
            FileNames.UnloadProductManifest();
            DeployManifest _manifest = FileNames.ProductManifest();

            Assert.IsNull(_manifest);
            FileInfo _testManifest = new FileInfo(Path.Combine(@"TestingData\", "CAS.Product.xml"));

            Assert.IsTrue(_testManifest.Exists);
            _testManifest.CopyTo(FileNames.ManifestFileName);
            FileInfo _manifestFileInfo = new FileInfo(FileNames.ManifestFileName);

            Assert.IsTrue(_manifestFileInfo.Exists);
            _manifest = FileNames.ProductManifest();
            Assert.IsNotNull(_manifest);
            _manifestFileInfo.Delete();
            _manifestFileInfo.Refresh();
            Assert.IsFalse(_manifestFileInfo.Exists);
            _manifest = FileNames.ProductManifest();
            Assert.IsNotNull(_manifest);
            Assert.AreEqual(@"TestApplicationDataPath\0D42ACCD-BBE0-4F79-9307-B746E6E09937", FileNames.ApplicationDataPath);
            FileNames.UnloadProductManifest();
            _manifest = FileNames.ProductManifest();
            Assert.IsNull(_manifest);
        }
 private bool BuildResolvedSettings(DeployManifest manifest)
 {
     if (this.Product != null)
     {
         manifest.Product = this.Product;
     }
     else if (string.IsNullOrEmpty(manifest.Product))
     {
         manifest.Product = Path.GetFileNameWithoutExtension(manifest.AssemblyIdentity.Name);
     }
     if (this.Publisher != null)
     {
         manifest.Publisher = this.Publisher;
     }
     else if (string.IsNullOrEmpty(manifest.Publisher))
     {
         string registeredOrganization = Util.GetRegisteredOrganization();
         if (!string.IsNullOrEmpty(registeredOrganization))
         {
             manifest.Publisher = registeredOrganization;
         }
         else
         {
             manifest.Publisher = manifest.Product;
         }
     }
     return(true);
 }
Exemple #3
0
        /// <summary>
        /// Writes the deploy manifest.
        /// </summary>
        /// <param name="name">The name of the deployment.</param>
        /// <param name="type">The type <see cref="ProductType"/> of the deployment.</param>
        /// <param name="publisher">The publisher name - used to create the application data folder.</param>
        /// <param name="supportUrl">The support URL.</param>
        /// <param name="deploymentUrl">The deployment URL.</param>
        /// <param name="appData">The path for the application data folder.</param>
        private static void WriteDeployManifest(AssemblyName name, ProductType type, string publisher, Uri supportUrl, Uri deploymentUrl, string appData)
        {
            if (File.Exists(FileNames.ManifestFileName))
            {
                File.SetAttributes(FileNames.ManifestFileName, 0);
            }
            string hex = BitConverter.ToString(name.GetPublicKeyToken());

            hex = hex.Replace("-", "");
            DeployManifest _deployManifest = new DeployManifest()
            {
                AssemblyIdentity = new AssemblyIdentity(name.FullName, name.Version.ToString())
                {
                    PublicKeyToken = hex,
                    Type           = type.ToString(),
                },
                Product       = name.Name,
                Publisher     = publisher,
                SupportUrl    = supportUrl.ToString(),
                DeploymentUrl = deploymentUrl.ToString(),
            };
            FileReference fr = new FileReference()
            {
                TargetPath = appData,
                IsDataFile = true,
                IsOptional = false,
                Group      = "license"
            };

            _deployManifest.FileReferences.Add(fr);
            ManifestWriter.WriteManifest(_deployManifest, FileNames.ManifestFileName);
            File.SetAttributes(FileNames.ManifestFileName, FileAttributes.ReadOnly | FileAttributes.Hidden);
        }
        private bool BuildResolvedSettings(DeployManifest manifest)
        {
            // Note: if changing the logic in this function, please update the logic in
            //  GenerateApplicationManifest.BuildResolvedSettings as well.
            if (Product != null)
            {
                manifest.Product = Product;
            }
            else if (String.IsNullOrEmpty(manifest.Product))
            {
                manifest.Product = Path.GetFileNameWithoutExtension(manifest.AssemblyIdentity.Name);
            }
            Debug.Assert(!String.IsNullOrEmpty(manifest.Product));

            if (Publisher != null)
            {
                manifest.Publisher = Publisher;
            }
            else if (String.IsNullOrEmpty(manifest.Publisher))
            {
                string org = Util.GetRegisteredOrganization();
                if (!String.IsNullOrEmpty(org))
                {
                    manifest.Publisher = org;
                }
                else
                {
                    manifest.Publisher = manifest.Product;
                }
            }
            Debug.Assert(!String.IsNullOrEmpty(manifest.Publisher));

            return(true);
        }
Exemple #5
0
 internal void SetProduct(DeployManifest product)
 {
     this.FullName   = product.AssemblyIdentity.Name;
     this.ShortName  = product.Product;
     this.Version    = product.AssemblyIdentity.Version;
     this.IsModified = true;
 }
        /// <summary>
        /// Sets the codebase of the application manifest reference in the given deployment manifest.
        /// </summary>
        /// <param name="deploymentManifest">DeploymentManifest object</param>
        /// <param name="appCodeBase">Codebase</param>
        private static void SetApplicationCodeBase(DeployManifest deploymentManifest, string appCodeBase)
        {
            if (deploymentManifest == null)
            {
                return;
            }

            AssemblyReferenceCollection collection = deploymentManifest.AssemblyReferences;

            AssemblyReference ar;

            if (collection.Count > 0)
            {
                ar            = collection[0];
                ar.TargetPath = appCodeBase;
            }
            else
            {
                ar = new AssemblyReference(appCodeBase)
                {
                    TargetPath = appCodeBase
                };
                collection.Add(ar);
            }
        }
        /// <summary>
        /// Add application manifest details to a deployment manifest
        /// </summary>
        /// <param name="deploymentManifest">DeploymentManifest object</param>
        /// <param name="deploymentManifestPath">Deployment manifest path</param>
        /// <param name="applicationManifest">ApplicationManifest object</param>
        /// <param name="applicationManifestPath">Application manifest path</param>
        /// <param name="targetFrameworkVersion">Target Framework version</param>
        private static void SetApplicationManifestReference(
            DeployManifest deploymentManifest,
            string deploymentManifestPath,
            ApplicationManifest applicationManifest,
            string applicationManifestPath,
            string targetFrameworkVersion)
        {
            // Validate parameters
            if ((deploymentManifest == null) || (applicationManifest == null) ||
                (deploymentManifestPath == null) || (applicationManifestPath == null))
            {
                Application.PrintErrorMessage(ErrorMessages.InternalError);
                return;
            }

            // Get absolute directory paths for both path parameters
            if (!Path.IsPathRooted(deploymentManifestPath))
            {
                deploymentManifestPath = Path.Combine(Environment.CurrentDirectory, deploymentManifestPath);
            }

            if (!Path.IsPathRooted(applicationManifestPath))
            {
                applicationManifestPath = Path.Combine(Environment.CurrentDirectory, applicationManifestPath);
            }

            string deploymentManifestDir  = Path.GetDirectoryName(deploymentManifestPath);
            string applicationManifestDir = Path.GetDirectoryName(applicationManifestPath);

            // Codebase defaults to a canonical string from the application manifest identity
            string codebase = applicationManifest.AssemblyIdentity.Version + "\\" + applicationManifest.AssemblyIdentity.Name + ".manifest";

            // Use relative codebase if possible
            if (applicationManifestDir.StartsWith(deploymentManifestDir, StringComparison.OrdinalIgnoreCase))
            {
                codebase = applicationManifestPath.Substring(deploymentManifestDir.Length);

                if (codebase.StartsWith("\\"))
                {
                    codebase = codebase.Substring(1);
                }
            }

            // Create a new assembly reference for the application manifest
            AssemblyReference ar = new AssemblyReference(applicationManifestPath)
            {
                AssemblyIdentity = applicationManifest.AssemblyIdentity
            };

            // Update the deployment manifest
            deploymentManifest.AssemblyReferences.Clear();
            deploymentManifest.AssemblyReferences.Add(ar);
            deploymentManifest.EntryPoint = ar;
            deploymentManifest.ResolveFiles();
            deploymentManifest.UpdateFileInfo(targetFrameworkVersion);

            // Update the codebase so the canonical one gets used even if the application manifest
            // happens to live somewhere else at the moment.
            ar.TargetPath = codebase;
        }
        /// <summary>
        /// Generates Deployment manifest
        /// </summary>
        /// <param name="deploymentManifestPath">Path of generated deployment manifest</param>
        /// <param name="appName">Application name</param>
        /// <param name="version">Version</param>
        /// <param name="processor">Processor type</param>
        /// <param name="applicationManifest">Application manifest from which to extract deployment details</param>
        /// <param name="applicationManifestPath">Path to application manifest</param>
        /// <param name="appCodeBase">Application codebase</param>
        /// <param name="appProviderUrl">Application provider URL</param>
        /// <param name="minVersion">Minimum version</param>
        /// <param name="install">Install state</param>
        /// <param name="includeDeploymentProviderUrl"></param>
        /// <param name="publisherName">Publisher name</param>
        /// <param name="supportUrl">Support URL</param>
        /// <param name="targetFrameworkVersion">Target Framework version</param>
        /// <returns>DeploymentManifest object</returns>
        public static DeployManifest GenerateDeploymentManifest(string deploymentManifestPath,
                                                                string appName, Version version, Processors processor,
                                                                ApplicationManifest applicationManifest, string applicationManifestPath, string appCodeBase,
                                                                string appProviderUrl, string minVersion, TriStateBool install, TriStateBool includeDeploymentProviderUrl,
                                                                string publisherName, string supportUrl, string targetFrameworkVersion)
        {
            /*
             * Mage running on Core cannot obtain .NET FX version for targeting.
             * Set default minimum version to v4.5, that Launcher targets,
             * which is a good default for .NET FX Mage as well.
             *
             * As always, version can be modified in deployment manifest, if needed.
             */
            Version shortVersion        = new Version(4, 5);
            string  frameworkIdentifier = ".NETFramework";

            DeployManifest manifest = new DeployManifest((new FrameworkName(frameworkIdentifier, shortVersion)).FullName);

            // Set default manifest publish options
            if (install == TriStateBool.True)
            {
                manifest.Install       = true;
                manifest.UpdateEnabled = true;
                manifest.UpdateMode    = UpdateMode.Background;
            }
            else
            {
                manifest.Install = false;
            }

            // Use default application name if none was specified
            if (appName == null)
            {
                appName = Application.Resources.GetString("DefaultAppName");
            }

            // Use default version if none was specified
            if (version == null)
            {
                version = defaultVersion;
            }

            // Use default processor if none was specified
            if (processor == Processors.Undefined)
            {
                processor = Processors.msil;
            }

            // Use default provider URL if none was specified
            if (appProviderUrl == null)
            {
                appProviderUrl = "";
            }

            UpdateDeploymentManifest(manifest, deploymentManifestPath, appName, version, processor,
                                     applicationManifest, applicationManifestPath, appCodeBase,
                                     appProviderUrl, minVersion, install, includeDeploymentProviderUrl, publisherName, supportUrl, targetFrameworkVersion);

            return(manifest);
        }
Exemple #9
0
 private static void Initialization()
 {
     //This is called in static creator.
     //It is possible that this might be called before creation of valid manifest,
     //that’s why it is worth to call Initialization again when the DeployManifest is null.
     //see property "DeployManifest"
     mDeployManifest = ManifestManagement.ReadDeployManifest();
     ApplicationData = GetApplicationData();
 }
Exemple #10
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Product"/> class.
 /// </summary>
 /// <param name="Manifest">The manifest.</param>
 public Product(DeployManifest Manifest)
 {
     SetProduct(Manifest);
     this.IsInGAC     = false;
     this.Developer   = string.Empty;
     this.Description = string.Empty;
     this.isLicensed  = false;
     this.IsModified  = false;
 }
 public ManifestSigningDialog(DeployManifest deployManifest, ApplicationManifest appManifest)
 {
     m_DeployManifest = deployManifest;
     m_AppManifest    = appManifest;
     InitializeComponent();
     if (!string.IsNullOrEmpty(Settings.Default.LastSelectedCertificate) &&
         File.Exists(Settings.Default.LastSelectedCertificate))
     {
         m_PathTextBox.Text = Settings.Default.LastSelectedCertificate;
     }
 }
Exemple #12
0
        private DeployManifest CreateDeployManifest(ApplicationManifest applicationManifest, string applicationManifestPath,
                                                    string applicationManifestName, string url, string entryPointFilePath)
        {
            DeployManifest manifest = new DeployManifest(TargetFramework);

            if (!string.IsNullOrWhiteSpace(url))
            {
                manifest.DeploymentUrl = url;
            }

            manifest.MapFileExtensions      = true;
            manifest.Publisher              = Publisher;
            manifest.Product                = GetProductName(entryPointFilePath);
            manifest.TrustUrlParameters     = UrlParameters;
            manifest.Install                = Install;
            manifest.MinimumRequiredVersion = MinimumRequiredVersion;
            manifest.CreateDesktopShortcut  = CreateDesktopShortcut;

            if (RequireLatestVersion)
            {
                manifest.MinimumRequiredVersion = Version;
            }
            if (AutoUpdate && Install)
            {
                manifest.UpdateEnabled = true;
                manifest.UpdateMode    = UpdateMode.Foreground;
            }


            AssemblyReference assembly = new AssemblyReference(applicationManifestPath);
            AssemblyIdentity  identity = new AssemblyIdentity(applicationManifest.AssemblyIdentity);

            if (UseConfigName)
            {
                identity.Name = string.Format(CultureInfo.InvariantCulture, "{0}_{1}.app", Path.GetFileNameWithoutExtension(identity.Name), this.ConfigName);
            }
            else
            {
                identity.Name = string.Format(CultureInfo.InvariantCulture, "{0}.app", Path.GetFileNameWithoutExtension(identity.Name));
            }

            identity.Type = string.Empty;

            manifest.AssemblyIdentity = identity;
            manifest.AssemblyReferences.Add(assembly);
            manifest.EntryPoint = assembly;
            manifest.ResolveFiles();
            manifest.UpdateFileInfo();
            assembly.TargetPath = applicationManifestName;

            manifest.ResolveFiles();
            manifest.UpdateFileInfo();
            return(manifest);
        }
Exemple #13
0
        /// <summary>
        /// Reads important information from <see cref="DeployManifest"/>.
        /// </summary>
        /// <param name="deploy"><see cref="DeployManifest"/> instance.</param>
        /// <returns><see cref="InfoData"/> items.</returns>
        private static IEnumerable <InfoData> GetDeployInfoData(DeployManifest deploy)
        {
            if (deploy == null)
            {
                yield break;
            }

            var fileName    = Path.GetFileName(deploy.SourcePath);
            var urlFileName = GetUrlFileName(deploy.DeploymentUrl);

            if (!string.Equals(fileName, urlFileName, StringComparison.OrdinalIgnoreCase))
            {
                yield return
                    (new InfoData(
                         nameof(deploy.SourcePath),
                         "SourcePath application file name is not equals to DeploymentUrl file name.",
                         true));
            }

            yield return
                (new InfoData(
                     nameof(deploy.DeploymentUrl),
                     $"Your application hosting service must publishing your folder: \"{Path.GetDirectoryName(deploy.SourcePath)}\" and clients will try to activate your application from URI: {deploy.DeploymentUrl}"));


            yield return
                (new InfoData(
                     nameof(deploy.MapFileExtensions),
                     deploy.MapFileExtensions
                        ? "All application files will be renamed from [file.ext] to [file.ext.deploy]. Its useful if your publishing service have download files restrictions."
                        : "Be sure that your publishing service have not file restrictions for your files."));

            if (deploy.TrustUrlParameters)
            {
                yield return
                    (new InfoData(
                         nameof(deploy.TrustUrlParameters),
                         "Any URL activation parameters will be passed to your application entry point as command line arguments."));
            }

            if (!deploy.UpdateEnabled)
            {
                yield return(new InfoData(nameof(deploy.UpdateEnabled), "Your application will not be updatable.", true));
            }

            yield return
                (new InfoData(
                     nameof(deploy.UpdateMode),
                     deploy.UpdateMode == UpdateMode.Foreground
                        ? "Your application updating before launch."
                        : "Your application starts with a current copy and downloading new copy while works."));
        }
        /// <summary>
        /// Updates the application reference in a deployment manifest to point to a specific application manifest
        /// </summary>
        /// <param name="depManifest">The deployment manifest to update</param>
        /// <param name="appManifest">The app manifest to refer to </param>
        public static void UpdateDeployManifestAppReference(DeployManifest depManifest, ApplicationManifest appManifest)
        {
            string deployManifestPath = Path.GetDirectoryName(depManifest.SourcePath);
            string relPath            = ManifestHelper.GetRelativeFolderPath(appManifest.SourcePath, deployManifestPath);

            depManifest.AssemblyReferences.Clear();
            AssemblyReference assemRef = depManifest.AssemblyReferences.Add(appManifest.SourcePath);

            assemRef.TargetPath    = Path.Combine(relPath, assemRef.TargetPath);
            depManifest.EntryPoint = assemRef;
            depManifest.EntryPoint.ReferenceType = AssemblyReferenceType.ClickOnceManifest;
            depManifest.ResolveFiles();
            depManifest.UpdateFileInfo();
        }
        private DeployManifest DownloadDeployManifest(string url, out string urlRedirect)
        {
            var            result   = CrawlContent(url, out urlRedirect);
            DeployManifest manifest = null;

            using (var ms = new MemoryStream())
            {
                byte[] buffer = System.Text.Encoding.Default.GetBytes(result);
                ms.Write(buffer, 0, buffer.Length);
                ms.Seek(0, SeekOrigin.Begin);

                manifest = (DeployManifest)ManifestReader.ReadManifest(ms, false);
                ms.Close();
            }
            return(manifest);
        }
Exemple #16
0
        private bool CreateManifests(string entryPoint, string baseUrl, List <PackageFileInfo> additionalFiles, List <string> filesToDelete)
        {
            string configFileName;
            string entryPointFilePath;
            ApplicationManifest appManifest;

            try
            {
                appManifest = CreateApplicationManifest(entryPoint, out configFileName, out entryPointFilePath);
            }
            catch (DuplicateAssemblyReferenceException ex)
            {
                Log.LogError("ClickOnce: {0}", ex.Message);
                return(false);
            }

            string appManifestFileName        = Path.GetFileName(appManifest.EntryPoint.SourcePath) + ".manifest";
            string deployManifestFileName     = Path.GetFileName(appManifest.EntryPoint.SourcePath) + ".application";
            string deployManifestTempFileName = Path.GetTempFileName();
            string appManifestTempFileName    = Path.GetTempFileName();

            ManifestWriter.WriteManifest(appManifest, appManifestTempFileName);
            SecurityUtilities.SignFile(Certificate.ItemSpec, GetCertPassword(), null, appManifestTempFileName);
            string         deploymentUrl  = BuildDeploymentUrl(deployManifestFileName, baseUrl);
            DeployManifest deployManifest = CreateDeployManifest(
                appManifest,
                appManifestTempFileName,
                appManifestFileName,
                deploymentUrl,
                entryPointFilePath);


            ManifestWriter.WriteManifest(deployManifest, deployManifestTempFileName);
            SecurityUtilities.SignFile(Certificate.ItemSpec, GetCertPassword(), null, deployManifestTempFileName);

            additionalFiles.Add(new PackageFileInfo(appManifestTempFileName, appManifestFileName));
            additionalFiles.Add(new PackageFileInfo(deployManifestTempFileName, deployManifestFileName));

            filesToDelete.Add(appManifestTempFileName);
            filesToDelete.Add(deployManifestTempFileName);
            if (ConfigFile != null && !string.IsNullOrEmpty(configFileName))
            {
                additionalFiles.Add(new PackageFileInfo(ConfigFile.ItemSpec, CombineWithWebsite ? AddDeploySuffix(configFileName) : configFileName));
            }

            return(true);
        }
 public void InstallLicenseFromContainerDefaultParametersTest()
 {
     try
     {
         LibInstaller.InstallLicense(true);
         Assert.Fail();
     }
     catch (Exception ex)
     {
         DeployManifest _manifest = FileNames.ProductManifest();
         Assert.IsNotNull(_manifest);
         Assert.AreEqual <string>("CAS.CodeProtect.UnitTests", _manifest.Product);
         Assert.IsFalse(ex.Message.Contains("CAS.CodeProtect.UnitTests"));
         Assert.IsTrue(ex.Message.Contains("CodeProtect.UnitTests"));
         ManifestManagement.DeleteDeployManifest();
     }
 }
 public void InstallLicenseFromContainerAllParametersTest()
 {
     try
     {
         LibInstaller.InstallLicense("user", "company", "email", true, "", "", Assembly.GetExecutingAssembly());
         Assert.Fail();
     }
     catch (Exception ex)
     {
         DeployManifest _manifest = FileNames.ProductManifest();
         Assert.IsNotNull(_manifest);
         Assert.AreEqual <string>("CAS.CodeProtect.UnitTests", _manifest.Product);
         Assert.IsFalse(ex.Message.Contains("CAS.CodeProtect.UnitTests"));
         Assert.IsTrue(ex.Message.Contains("CodeProtect.UnitTests"));
         ManifestManagement.DeleteDeployManifest();
     }
 }
Exemple #19
0
        /// <inheritdoc/>
        public override bool Execute(Container container, out string errorString)
        {
            ApplicationManifest application = container.Application;
            DeployManifest      deploy      = container.Deploy;

            errorString = null;

            if (application == null)
            {
                throw new ArgumentNullException(nameof(application));
            }

            if (deploy == null)
            {
                throw new ArgumentNullException(nameof(deploy));
            }

            return(UpdateManifestUtils.RecreateReferences(container, out errorString));
        }
        /// <summary>
        /// Loads the deployment manifest and referenced app manifest data into the manifest variables passed in
        /// </summary>
        /// <param name="fileName">Deployment manifest to load</param>
        /// <param name="deployManifest">Deployment manifest to populate</param>
        /// <param name="appManifest">Application manifest to populate</param>
        public static void LoadDeploymentManifestData(string fileName, out DeployManifest deployManifest, out ApplicationManifest appManifest)
        {
            Manifest manifest = ManifestReader.ReadManifest(fileName, false);

            deployManifest = manifest as DeployManifest;
            //This is the part that doesn't work if the deployment manifest is for a project targeting .NET 4.0.
            //If you put a breakpoint here and check the contents of the deployManifest, you will find that
            //  the CompatibleFrameworks collection has a count of 0, but that section does exist in the manifest.
            //  This has been filed as a Connect bug. When they fix it, you can run this utility for a .NET 4.0 application.
            //  Until then, it will only work for applications targeting .NET 2.0, .NET 3.0, and .NET 3.5.
            if (deployManifest == null)
            {
                throw new ArgumentException("Not a valid deployment manifest");
            }

            //If the user used mage at all, it will replace the space in "Application Files" with a %20.
            //Check for it and replace it if found. RobinDotNet 4/7/2010
            string assemManifestPath = deployManifest.EntryPoint.TargetPath.Replace("%20", " ");

            assemManifestPath = Path.Combine(Path.GetDirectoryName(deployManifest.SourcePath), assemManifestPath);
            appManifest       = LoadAppManifest(assemManifestPath);
        }
Exemple #21
0
        public void ManifestFromAssemblyManagementWriteReadTestMethod()
        {
            FileInfo _fi = new FileInfo(FileNames.ManifestFileName);

            Assert.IsFalse(_fi.Exists);
            Assembly _thisAssembly = Assembly.GetExecutingAssembly();

            ManifestManagement.WriteDeployManifest(_thisAssembly, CommonDefinitions.AssemblyProduct);
            _fi.Refresh();
            Assert.IsTrue(_fi.Exists);
            DeployManifest _manifest = ManifestManagement.ReadDeployManifest();

            ManifestManagement.DeleteDeployManifest();
            _fi.Refresh();
            Assert.IsFalse(_fi.Exists);
            //test the content
            Assert.IsNotNull(_manifest);
            Assert.IsTrue(_manifest.Install);
            Assert.AreEqual <string>("CodeProtectTests", _manifest.Product);
            Assert.AreEqual <string>("CAS", _manifest.Publisher); //Only in test environment
            Assert.AreEqual <string>("http://www.commsvr.eu/", _manifest.SupportUrl);
            Assert.AreEqual <string>("http://www.commsvr.eu/", _manifest.DeploymentUrl);
            AssemblyIdentity _id = _manifest.AssemblyIdentity;

            Assert.IsNotNull(_id);
            AssemblyName _thisName = _thisAssembly.GetName();

            Assert.AreEqual <string>(_thisName.Version.ToString(), _id.Version);
            //FileReferences
            Assert.IsNotNull(_manifest.FileReferences);
            Assert.AreEqual <int>(1, _manifest.FileReferences.Count);
            FileReference _FileReference = _manifest.FileReferences[0];

            Assert.AreEqual <string>(FileNames.TargetDir, _FileReference.TargetPath);
            Assert.AreEqual <string>("license", _FileReference.Group);
            Assert.IsFalse(_FileReference.IsOptional);
            Assert.IsTrue(_FileReference.IsDataFile);
        }
        private static bool CreateDeployFile(Container container, out string errorString)
        {
            DeployManifest deploy = container.Deploy;

            // Set deploy entry point identity
            SetDeployEntrypointIdentity(container);

            // Set AssemblyReferences
            AddManifestReference(container);

            // Set global important settings
            FlowUtils.SetGlobals(container.Deploy, container);

            if (!InfoUtils.IsValidManifest(deploy, out errorString))
            {
                return(false);
            }

            // Writing to file
            ManifestWriter.WriteManifest(deploy, deploy.SourcePath, FlowUtils.GetTargetFramework(container));

            ProcessAfterSave(deploy, container.Application.TargetFrameworkVersion);
            return(true);
        }
        private Manifest DownloadManifest(DeployManifest deployManifest, string url, out string urlRedirect)
        {
            url = url.Split('?')[0];             // Remove all parameters
            string file        = System.IO.Path.GetFileName(url);
            var    rootUrl     = url.Replace(file, "").TrimEnd('/').ToLower();
            string manifestUrl = string.Format("{0}/{1}", rootUrl, deployManifest.EntryPoint);

            manifestUrl = Uri.EscapeUriString(manifestUrl.Replace("\\", "/"));
            string manifestContent = CrawlContent(manifestUrl, out urlRedirect);

            Manifest manifest;

            using (var ms = new MemoryStream())
            {
                byte[] buffer = System.Text.Encoding.Default.GetBytes(manifestContent);
                ms.Write(buffer, 0, buffer.Length);
                ms.Seek(0, SeekOrigin.Begin);

                manifest = (AssemblyManifest)ManifestReader.ReadManifest(ms, false);
                ms.Close();
            }

            return(manifest);
        }
        public int IsLatestVersion(Models.ClickonceSettings settings)
        {
            if (settings == null)
            {
                return(-1);
            }
            if (!settings.LastRunSuccess)
            {
                return(-1);
            }
            if (settings.FullExeFileName == null)
            {
                return(-1);
            }
            if (!System.IO.File.Exists(settings.FullExeFileName))
            {
                return(-1);
            }
            DeployManifest deployManifest = null;

            try
            {
                string urlRedirect = null;
                deployManifest = DownloadDeployManifest(settings.ClickonceUrl, out urlRedirect);
                if (urlRedirect != settings.ClickonceUrl)
                {
                    settings.ClickonceUrl = urlRedirect;
                }
            }
            catch (Exception ex)
            {
                return(-2);
            }

            return(deployManifest.AssemblyIdentity.Version == settings.Version ? 0 : -1);
        }
        private bool BuildDeployManifest(DeployManifest manifest)
        {
            if (manifest.EntryPoint == null)
            {
                Log.LogErrorWithCodeFromResources("GenerateManifest.NoEntryPoint");
                return(false);
            }

            if (SupportUrl != null)
            {
                manifest.SupportUrl = SupportUrl;
            }

            if (DeploymentUrl != null)
            {
                manifest.DeploymentUrl = DeploymentUrl;
            }

            if (_install.HasValue)
            {
                manifest.Install = (bool)_install;
            }

            if (_updateEnabled.HasValue)
            {
                manifest.UpdateEnabled = (bool)_updateEnabled;
            }

            if (_updateInterval.HasValue)
            {
                manifest.UpdateInterval = (int)_updateInterval;
            }

            if (_updateMode.HasValue)
            {
                manifest.UpdateMode = (UpdateMode)_updateMode;
            }

            if (_updateUnit.HasValue)
            {
                manifest.UpdateUnit = (UpdateUnit)_updateUnit;
            }

            if (MinimumRequiredVersion != null)
            {
                manifest.MinimumRequiredVersion = MinimumRequiredVersion;
            }

            if (manifest.Install) // Ignore DisallowUrlActivation flag for online-only apps
            {
                if (_disallowUrlActivation.HasValue)
                {
                    manifest.DisallowUrlActivation = (bool)_disallowUrlActivation;
                }
            }

            if (_mapFileExtensions.HasValue)
            {
                manifest.MapFileExtensions = (bool)_mapFileExtensions;
            }

            if (_trustUrlParameters.HasValue)
            {
                manifest.TrustUrlParameters = (bool)_trustUrlParameters;
            }

            if (_createDesktopShortcut.HasValue)
            {
                manifest.CreateDesktopShortcut = CreateDesktopShortcut;
            }

            if (SuiteName != null)
            {
                manifest.SuiteName = SuiteName;
            }

            if (ErrorReportUrl != null)
            {
                manifest.ErrorReportUrl = ErrorReportUrl;
            }

            return(true);
        }
        /// <summary>
        /// Saves manifest values into the respective manifest
        /// </summary>
        /// <param name="name">Application deployment name</param>
        /// <param name="version">Version number</param>
        /// <param name="deploymentProvider">Deployment provider URL</param>
        /// <param name="deployManifest">Deployment manifest reference</param>
        /// <param name="appManifest">Application manifest reference</param>
        /// <param name="appFiles">List of files to populate app manifest</param>
        /// <param name="preReqs">List of prerequisites to add</param>
        public static void SaveManifestValues(string name, string version, string deploymentProvider, DeployManifest deployManifest, ApplicationManifest appManifest, IList <ApplicationFile> appFiles, IList <AssemblyReference> preReqs)
        {
            // Populate discrete values
            deployManifest.AssemblyIdentity.Name    = name;
            deployManifest.AssemblyIdentity.Version = version;
            deployManifest.DeploymentUrl            = deploymentProvider;
            appManifest.AssemblyIdentity.Version    = version;

            // Refresh app manifest file lists
            appManifest.AssemblyReferences.Clear();
            appManifest.FileReferences.Clear();

            // Populate prerequisites
            foreach (AssemblyReference assemRef in preReqs)
            {
                appManifest.AssemblyReferences.Add(assemRef);
            }

            // Populate assembly and file references
            foreach (ApplicationFile appFile in appFiles)
            {
                string           appFilePath       = Path.Combine(appFile.RelativePath, appFile.FileName);
                string           appManifestFolder = Path.GetDirectoryName(appManifest.SourcePath);
                string           appFileFullPath   = Path.Combine(appManifestFolder, appFilePath) + ".deploy";
                AssemblyIdentity assemId           = AssemblyIdentity.FromFile(appFileFullPath);
                if (assemId != null)                 // valid assembly
                {
                    AssemblyReference assemRef = appManifest.AssemblyReferences.Add(appFileFullPath);
                    assemRef.TargetPath = appFilePath;
                    if (appFile.EntryPoint)
                    {
                        appManifest.EntryPoint = assemRef;
                    }
                }
                else
                {
                    FileReference fref = appManifest.FileReferences.Add(appFileFullPath);
                    fref.TargetPath = appFilePath;
                    if (appFile.DataFile)
                    {
                        fref.IsDataFile = true;
                    }
                }
            }
        }
        private void DownloadAll(DeployManifest deployManifest, Manifest manifest, string url, string directory)
        {
            string[] exetoken      = deployManifest.EntryPoint.ToString().Split('\\');
            string   versionFolder = deployManifest.AssemblyIdentity.Version;
            string   folderPath    = System.IO.Path.Combine(directory, versionFolder);

            System.IO.Directory.CreateDirectory(folderPath);

            var exeFileName = deployManifest.EntryPoint;

            Settings.Version = versionFolder;

            var    token = url.Split('/');
            string path  = url.Replace(token[token.Length - 1], "");

            string rootUrl = url;
            var    total   = manifest.AssemblyReferences.Count + manifest.FileReferences.Count;

            m_BgWorker.ReportProgress(0, string.Format(PCResource.TotalFileCountMessage, total));
            var i = 1;

            foreach (AssemblyReference ar in manifest.AssemblyReferences)
            {
                if (m_BgWorker.CancellationPending)
                {
                    break;
                }

                if (ar.AssemblyIdentity.Name.Equals(deployManifest.EntryPoint.AssemblyIdentity.Name, StringComparison.CurrentCultureIgnoreCase))
                {
                    var mainExeFileName = ((Microsoft.Build.Tasks.Deployment.ManifestUtilities.BaseReference)(ar)).TargetPath;
                    Settings.ExeFileName = System.IO.Path.Combine(folderPath, mainExeFileName);
                }

                int progress = Convert.ToInt32(i * 100.0 / (total * 1.0));
                m_BgWorker.ReportProgress(0, string.Format(PCResource.FileDownloadMessage, ar.TargetPath));
                m_BgWorker.ReportProgress(-1, progress);
                i++;
                if (string.IsNullOrEmpty(ar.TargetPath))
                {
                    continue;
                }

                CreateDirectory(folderPath, ar.TargetPath);

                string fileName            = System.IO.Path.Combine(folderPath, ar.TargetPath);
                var    applicationFileName = System.IO.Path.GetFileName(url);
                rootUrl = url.Replace(applicationFileName, "").Trim('/');
                rootUrl = string.Format("{0}/{1}.deploy", rootUrl, ar.TargetPath);
                rootUrl = rootUrl.Replace(@"\", "/");
                using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write))
                {
                    while (true)
                    {
                        if (m_BgWorker.CancellationPending)
                        {
                            break;
                        }
                        try
                        {
                            CrawlFile(rootUrl, fs, null, null);
                            fs.Flush();
                            fs.Close();
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            if (rootUrl.IndexOf(".deploy") == -1)
                            {
                                break;
                            }
                            rootUrl = rootUrl.Replace(".deploy", "");
                        }
                    }
                }
            }

            foreach (FileReference file in manifest.FileReferences)
            {
                if (m_BgWorker.CancellationPending)
                {
                    break;
                }

                int progress = Convert.ToInt32(i * 100.0 / (total * 1.0));
                m_BgWorker.ReportProgress(0, string.Format(PCResource.FileDownloadMessage, file.TargetPath));
                m_BgWorker.ReportProgress(-1, progress);
                i++;
                if (string.IsNullOrEmpty(file.TargetPath))
                {
                    continue;
                }

                CreateDirectory(folderPath, file.TargetPath);

                string fileName            = System.IO.Path.Combine(folderPath, file.TargetPath);
                var    applicationFileName = System.IO.Path.GetFileName(url);
                rootUrl = url.Replace(applicationFileName, "").Trim('/');
                rootUrl = string.Format("{0}/{1}.deploy", rootUrl, file.TargetPath);
                rootUrl = rootUrl.Replace(@"\", "/");
                using (var fs = new System.IO.FileStream(fileName, System.IO.FileMode.Create, System.IO.FileAccess.Write, System.IO.FileShare.Write))
                {
                    while (true)
                    {
                        if (m_BgWorker.CancellationPending)
                        {
                            break;
                        }
                        try
                        {
                            CrawlFile(rootUrl, fs, null, null);
                            fs.Flush();
                            fs.Close();
                            break;
                        }
                        catch (Exception ex)
                        {
                            Console.WriteLine(ex.Message);
                            if (rootUrl.IndexOf(".deploy") == -1)
                            {
                                break;
                            }
                            rootUrl = rootUrl.Replace(".deploy", "");
                        }
                    }
                }
            }
        }
Exemple #28
0
 /// <summary>
 /// Reads ClickOnce application version.
 /// </summary>
 /// <param name="deploy"><see cref="DeployManifest"/> file instance.</param>
 /// <returns>Version inside <see cref="DeployManifest"/>.</returns>
 public static string ReadApplicationVersion(DeployManifest deploy)
 {
     return(deploy.AssemblyIdentity.Version);
 }
        public int CreateManifestDocument(string path)
        {
            int r = ERROR_ROOTPATH_NOT_SPECIFIED;

            if (!string.IsNullOrEmpty(rootPath))
            {
                r = ERROR_PROCUCT_NOT_SPECIFIED;
                if (!string.IsNullOrEmpty(applicationId))
                {
                    r = ERROR_PUBLISHER_NOT_SPECIFIED;
                    if (!string.IsNullOrEmpty(publisherId))
                    {
                        r = ERROR_NEWVERSION_NOT_SPECIFIED;
                        if (newApplicationVersion != null)
                        {
                            r = ERROR_UPDATELOCATION_NOT_SPECIFIED;
                            if (!string.IsNullOrEmpty(globalUpdateLocation))
                            {
                                r = ERROR_ROOTPATH_NOT_FOUND;
                                if (Directory.Exists(rootPath))
                                {
                                    r = ERROR_SUCCESS;
                                    DeployManifest appMan = new DeployManifest();
                                    if (!string.IsNullOrEmpty(description))
                                    {
                                        appMan.Description = description;
                                    }
                                    appMan.Product               = applicationId;
                                    appMan.Publisher             = publisherId;
                                    appMan.AssemblyIdentity.Name = applicationId;
                                    appMan.AssemblyIdentity.ProcessorArchitecture = platform.ToString();
                                    if (targetApplicationVersion != null)
                                    {
                                        appMan.MinimumRequiredVersion = targetApplicationVersion.ToString();
                                    }
                                    appMan.AssemblyIdentity.Version = newApplicationVersion.ToString();
                                    string s1 = globalUpdateLocation;
                                    if ((copyMethod == FileCopyMethod.http) || (copyMethod == FileCopyMethod.ftp))
                                    {
                                        s1 = s1.Replace("\\", "/");
                                    }
                                    if (!s1.StartsWith(FileCopyMethod.file.ToString() + "://", StringComparison.CurrentCultureIgnoreCase) && !s1.StartsWith(FileCopyMethod.http.ToString() + "://", StringComparison.CurrentCultureIgnoreCase) && !s1.StartsWith(FileCopyMethod.ftp.ToString() + "://", StringComparison.CurrentCultureIgnoreCase))
                                    {
                                        if ((copyMethod == FileCopyMethod.http) || (copyMethod == FileCopyMethod.ftp))
                                        {
                                            s1 = copyMethod.ToString() + "://" + s1;
                                        }
                                    }
                                    appMan.DeploymentUrl = s1;
                                    if ((postUpdateCommand != null) && !string.IsNullOrEmpty(postUpdateCommand.executable))
                                    {
                                        appMan.SupportUrl = postUpdateCommand.executable + ";" + ((postUpdateCommand.targetpath == null) ? string.Empty : postUpdateCommand.targetpath) + ";" + ((postUpdateCommand.arguments == null) ? string.Empty : postUpdateCommand.arguments) + ";" + postUpdateCommand.delete.ToString();
                                        if (GetFileReferenceIndex(postUpdateCommand.executable) < 0)
                                        {
                                            AddFileReference(postUpdateCommand.executable, postUpdateCommand.targetpath);
                                        }
                                    }
                                    if (GetListCount(files) > 0)
                                    {
                                        foreach (Object obj in files)
                                        {
                                            appMan.FileReferences.Add(obj as FileReference);
                                        }
                                    }
                                    if (GetListCount(assemblies) > 0)
                                    {
                                        foreach (Object obj in assemblies)
                                        {
                                            appMan.AssemblyReferences.Add(obj as AssemblyReference);
                                        }
                                    }
                                    s1 = manifestFileName;
                                    if (string.IsNullOrEmpty(s1))
                                    {
                                        s1 = Path.Combine(rootPath, DEFAULT_MANIFEST_FILENAME);
                                    }
                                    else
                                    if (!s1.Contains(Path.DirectorySeparatorChar.ToString()) && !s1.Contains(Path.AltDirectorySeparatorChar.ToString()))
                                    {
                                        s1 = Path.Combine(rootPath, s1);
                                    }
                                    appMan.SourcePath = s1;
                                    appMan.ResolveFiles(new string[] { rootPath });
                                    if (useValidation)
                                    {
                                        appMan.UpdateFileInfo();
                                    }
                                    if (string.IsNullOrEmpty(path))
                                    {
                                        ManifestWriter.WriteManifest(appMan);
                                    }
                                    else
                                    {
                                        ManifestWriter.WriteManifest(appMan, path);
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(r);
        }
 private bool BuildDeployManifest(DeployManifest manifest)
 {
     if (manifest.EntryPoint == null)
     {
         base.Log.LogErrorWithCodeFromResources("GenerateManifest.NoEntryPoint", new object[0]);
         return(false);
     }
     if (this.SupportUrl != null)
     {
         manifest.SupportUrl = this.SupportUrl;
     }
     if (this.DeploymentUrl != null)
     {
         manifest.DeploymentUrl = this.DeploymentUrl;
     }
     if (this.install.HasValue)
     {
         manifest.Install = this.install.Value;
     }
     if (this.updateEnabled.HasValue)
     {
         manifest.UpdateEnabled = this.updateEnabled.Value;
     }
     if (this.updateInterval.HasValue)
     {
         manifest.UpdateInterval = this.updateInterval.Value;
     }
     if (this.updateMode.HasValue)
     {
         manifest.UpdateMode = this.updateMode.Value;
     }
     if (this.updateUnit.HasValue)
     {
         manifest.UpdateUnit = this.updateUnit.Value;
     }
     if (this.MinimumRequiredVersion != null)
     {
         manifest.MinimumRequiredVersion = this.MinimumRequiredVersion;
     }
     if (manifest.Install && this.disallowUrlActivation.HasValue)
     {
         manifest.DisallowUrlActivation = this.disallowUrlActivation.Value;
     }
     if (this.mapFileExtensions.HasValue)
     {
         manifest.MapFileExtensions = this.mapFileExtensions.Value;
     }
     if (this.trustUrlParameters.HasValue)
     {
         manifest.TrustUrlParameters = this.trustUrlParameters.Value;
     }
     if (this.createDesktopShortcut.HasValue)
     {
         manifest.CreateDesktopShortcut = this.CreateDesktopShortcut;
     }
     if (this.SuiteName != null)
     {
         manifest.SuiteName = this.SuiteName;
     }
     if (this.ErrorReportUrl != null)
     {
         manifest.ErrorReportUrl = this.ErrorReportUrl;
     }
     return(true);
 }