コード例 #1
0
        /// <inheritdoc cref="IBrowserFetcher.DownloadAsync(string)"/>
        public async Task <RevisionInfo> DownloadAsync(string revision = null)
        {
            revision ??= _preferredRevision;

            string url        = _params(_platform, revision).DownloadURL;
            string zipPath    = Path.Combine(_downloadsFolder, $"download-{_platform.ToString()}-{revision}.zip");
            string folderPath = GetFolderPath(revision);

            if (new DirectoryInfo(folderPath).Exists)
            {
                return(GetRevisionInfo(revision));
            }

            var downloadFolder = new DirectoryInfo(_downloadsFolder);

            if (!downloadFolder.Exists)
            {
                downloadFolder.Create();
            }

            if (DownloadProgressChanged != null)
            {
                _webClient.DownloadProgressChanged += DownloadProgressChanged;
            }

            await _webClient.DownloadFileTaskAsync(new Uri(url), zipPath).ConfigureAwait(false);

            if (_platform == Platform.MacOS)
            {
                // ZipFile and many others unzip libraries have issues extracting .app files
                // Until we have a clear solution we'll call the native unzip tool
                // https://github.com/dotnet/corefx/issues/15516
                NativeExtractToDirectory(zipPath, folderPath);
            }
            else
            {
                ZipFile.ExtractToDirectory(zipPath, folderPath);
            }

            new FileInfo(zipPath).Delete();

            var revisionInfo = GetRevisionInfo(revision);

            if (revisionInfo != null && GetCurrentPlatform() == Platform.Linux)
            {
                if (LinuxSysCall.Chmod(revisionInfo.ExecutablePath, LinuxSysCall.ExecutableFilePermissions) != 0)
                {
                    throw new PlaywrightSharpException($"Unable to chmod the BrowserApp ({Marshal.GetLastWin32Error()})");
                }
            }

            return(revisionInfo);
        }
コード例 #2
0
        /// <summary>
        /// Downloads the revision.
        /// </summary>
        /// <returns>Task which resolves to the completed download.</returns>
        /// <param name="revision">Revision.</param>
        public async Task <RevisionInfo> DownloadAsync(int revision)
        {
            var url        = GetDownloadURL(Platform, DownloadHost, revision);
            var zipPath    = Path.Combine(DownloadsFolder, $"download-{Platform.ToString()}-{revision}.zip");
            var folderPath = GetFolderPath(revision);

            if (new DirectoryInfo(folderPath).Exists)
            {
                return(RevisionInfo(revision));
            }

            var downloadFolder = new DirectoryInfo(DownloadsFolder);

            if (!downloadFolder.Exists)
            {
                downloadFolder.Create();
            }

            var webClient = new WebClient();

            if (DownloadProgressChanged != null)
            {
                webClient.DownloadProgressChanged += DownloadProgressChanged;
            }
            await webClient.DownloadFileTaskAsync(new Uri(url), zipPath).ConfigureAwait(false);

            if (Platform == Platform.MacOS)
            {
                //ZipFile and many others unzip libraries have issues extracting .app files
                //Until we have a clear solution we'll call the native unzip tool
                //https://github.com/dotnet/corefx/issues/15516
                NativeExtractToDirectory(zipPath, folderPath);
            }
            else
            {
                ZipFile.ExtractToDirectory(zipPath, folderPath);
            }

            new FileInfo(zipPath).Delete();

            var revisionInfo = RevisionInfo(revision);

            if (revisionInfo != null && GetCurrentPlatform() == Platform.Linux)
            {
                LinuxSysCall.Chmod(revisionInfo.ExecutablePath, LinuxSysCall.ExecutableFilePermissions);
            }
            return(revisionInfo);
        }