Ejemplo n.º 1
0
    /// <summary>
    /// Runs the deployment process.
    /// </summary>
    /// <param name="libraryMode">Deploy Zero Install as a library for use by other applications without its own desktop integration.</param>
    /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
    /// <exception cref="IOException">An IO operation failed.</exception>
    public void Deploy(bool libraryMode = false)
    {
        if (Portable && libraryMode)
        {
            throw new ArgumentException(string.Format(Resources.CannotUseOptionsTogether, "--portable", "--library"), nameof(libraryMode));
        }

        var newManifest = LoadManifest(Locations.InstallBase);
        var oldManifest = LoadManifest(TargetDir);

        try
        {
            MutexAcquire();

            if (!FileUtils.PathEquals(TargetDir, Locations.InstallBase))
            {
                if (MachineWide)
                {
                    ServiceStop();
                }

                using var clearDir  = new ClearDirectory(TargetDir, oldManifest, Handler);
                using var deployDir = new DeployDirectory(Locations.InstallBase, newManifest, TargetDir, Handler);
                deployDir.Stage();
                clearDir.Stage();
                if (Portable)
                {
                    FileUtils.Touch(Path.Combine(TargetDir, Locations.PortableFlagName));
                }
                deployDir.Commit();
                clearDir.Commit();
            }

            if (!Portable)
            {
                if (!libraryMode)
                {
                    DesktopIntegrationApply(newManifest.TotalSize);
                }
                ZeroInstallInstance.RegisterLocation(TargetDir, MachineWide, libraryMode);
                RemoveOneGetBootstrap();
            }

            MutexRelease();

            if (MachineWide)
            {
                NgenApply();
                if (ServiceInstall())
                {
                    ServiceStart();
                }
                TaskSchedulerApply(libraryMode);
            }
        }
        catch
        {
            MutexRelease();
            throw;
        }
    }
Ejemplo n.º 2
0
        /// <summary>
        /// Runs the deployment process.
        /// </summary>
        /// <exception cref="UnauthorizedAccessException">Access to a resource was denied.</exception>
        /// <exception cref="IOException">An IO operation failed.</exception>
        public void Deploy()
        {
            if (TargetDir == Locations.InstallBase)
            {
                throw new InvalidOperationException(string.Format(Resources.SourceAndTargetSame, TargetDir));
            }

            var newManifest = LoadManifest(Locations.InstallBase);

            if (newManifest == null)
            {
                throw new IOException(Resources.MaintenanceMissingManifest);
            }
            var oldManifest = LoadManifest(TargetDir) ?? LegacyManifest;

            if (WindowsUtils.IsWindows && MachineWide)
            {
                ServiceStop();
            }

            try
            {
                TargetMutexAquire();

                using (var clearDir = new ClearDirectory(TargetDir, oldManifest, Handler))
                    using (var deployDir = new DeployDirectory(Locations.InstallBase, newManifest, TargetDir, Handler))
                    {
                        deployDir.Stage();
                        clearDir.Stage();
                        if (Portable)
                        {
                            FileUtils.Touch(Path.Combine(TargetDir, Locations.PortableFlagName));
                        }
                        deployDir.Commit();
                        clearDir.Commit();
                    }

                if (!Portable)
                {
                    DesktopIntegrationApply();

                    if (WindowsUtils.IsWindows)
                    {
                        RegistryApply();
                        WindowsUtils.BroadcastMessage(PerformedWindowMessageID);
                        RemoveOneGetBootstrap();
                    }
                }

                TargetMutexRelease();

                if (WindowsUtils.IsWindows && MachineWide)
                {
                    NgenApply();
                    ServiceInstall();
                    ServiceStart();
                }
            }
            catch
            {
                TargetMutexRelease();
                throw;
            }
        }