Пример #1
0
        /// <inheritdoc />
        public async Task PrepareUpdateAsync(Version version,
                                             IProgress <double> progress         = null,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            version.GuardNotNull(nameof(version));

            // Ensure that the current state is valid for this operation
            EnsureNotDisposed();
            EnsureLockFileAcquired();
            EnsureUpdaterNotLaunched();

            // Set up progress mixer
            var progressMixer = progress != null ? new ProgressMixer(progress) : null;

            // Get package file path and content directory path
            var packageFilePath       = GetPackageFilePath(version);
            var packageContentDirPath = GetPackageContentDirPath(version);

            // Ensure storage directory exists
            Directory.CreateDirectory(_storageDirPath);

            // Download package
            await _resolver.DownloadAsync(version, packageFilePath,
                                          progressMixer?.Split(0.9), // 0% -> 90%
                                          cancellationToken).ConfigureAwait(false);

            // Ensure package content directory exists and is empty
            DirectoryEx.Reset(packageContentDirPath);

            // Extract package contents
            await _extractor.ExtractAsync(packageFilePath, packageContentDirPath,
                                          progressMixer?.Split(0.1), // 90% -> 100%
                                          cancellationToken).ConfigureAwait(false);

            // Delete package
            File.Delete(packageFilePath);

            // Extract updater
            await Assembly.GetExecutingAssembly().ExtractManifestResourceAsync(UpdaterResourceName, _updaterFilePath)
            .ConfigureAwait(false);
        }
Пример #2
0
        /// <inheritdoc />
        public async Task PrepareUpdateAsync(Version version,
                                             IProgress <double> progress         = null,
                                             CancellationToken cancellationToken = default(CancellationToken))
        {
            version.GuardNotNull(nameof(version));

            // Set up progress aggregator
            var progressAggregator = progress != null ? new ProgressAggregator(progress) : null;

            // Get package file path and content directory path
            var packageFilePath       = GetPackageFilePath(version);
            var packageContentDirPath = GetPackageContentDirPath(version);

            // Create storage directory
            Directory.CreateDirectory(_storageDirPath);

            // Download package
            await _resolver.DownloadAsync(version, packageFilePath,
                                          progressAggregator?.Split(0.9), // 0% -> 90%
                                          cancellationToken).ConfigureAwait(false);

            // Create directory for package contents
            DirectoryEx.Reset(packageContentDirPath);

            // Extract package contents
            await _extractor.ExtractAsync(packageFilePath, packageContentDirPath,
                                          progressAggregator?.Split(0.1), // 90% -> 100%
                                          cancellationToken).ConfigureAwait(false);

            // Delete package
            File.Delete(packageFilePath);

            // Extract updater
            await Assembly.GetExecutingAssembly().ExtractManifestResourceAsync(UpdaterResourceName, _updaterFilePath)
            .ConfigureAwait(false);
        }