Esempio n. 1
0
        public async Task DownloadDriver()
        {
            var client   = new GitHubClient(new ProductHeaderValue("Vulcan-Client"));
            var releases = await client.Repository.Release.GetAll("operasoftware", "operachromiumdriver");

            string operaVersion = BrowserVersion.Split(".")[0];

            foreach (var release in releases)
            {
                Match match = Regex.Match(release.Body, @"Opera Stable " + operaVersion);
                if (!match.Success)
                {
                    return;
                }
                Console.WriteLine(release.Body);
                foreach (var asset in release.Assets)
                {
                    if (asset.Name == "operadriver_win64.zip")
                    {
                        string downloadUrl = asset.BrowserDownloadUrl;
                        using (HttpClient hClient = new HttpClient())
                        {
                            using (HttpResponseMessage response = await hClient.GetAsync(downloadUrl, HttpCompletionOption.ResponseHeadersRead))
                                using (Stream streamToReadFrom = await response.Content.ReadAsStreamAsync())
                                {
                                    string currentDirectory = Directory.GetCurrentDirectory();
                                    string filePath         = $"{currentDirectory}/{ZipFileName}";
                                    using (Stream streamToWriteTo = File.Open(filePath, System.IO.FileMode.Create))
                                    {
                                        await streamToReadFrom.CopyToAsync(streamToWriteTo);

                                        Console.WriteLine("Driver pobrany");
                                    }
                                    Console.WriteLine("Rozpakowujemy drivera");
                                    await Task.Run(() =>
                                    {
                                        ZipFile.ExtractToDirectory(filePath, $"{currentDirectory}/drivers/");
                                        Console.WriteLine("Driver rozpakowany");
                                    });

                                    Console.WriteLine("Usuwamy zipa");
                                    await Task.Run(() =>
                                    {
                                        File.Delete(filePath);
                                        Console.WriteLine("Zip usuniety");
                                    });
                                }
                        }
                    }
                }
            }
        }
Esempio n. 2
0
        public override async Task DownloadZip()
        {
            string edgeVersion = BrowserVersion.Split(".")[0];

            Log.Debug("Sprawdzamy ostatnia wersje drivera do przegladrki");
            using (HttpClient client = new HttpClient())
            {
                Uri uri = new Uri($"https://msedgedriver.azureedge.net/LATEST_RELEASE_{edgeVersion}_WINDOWS");
                using (HttpResponseMessage lastestVersionResponse =
                           await client.GetAsync(uri, HttpCompletionOption.ResponseHeadersRead))
                {
                    lastestVersionResponse.EnsureSuccessStatusCode();
                    using (Stream latestVersionStream = await lastestVersionResponse.Content.ReadAsStreamAsync())
                    {
                        using (StreamReader sr = new StreamReader(latestVersionStream))
                        {
                            string latestDriverVersion = sr.ReadToEnd();
                            latestDriverVersion = String.Concat(latestDriverVersion.Where(c => !Char.IsWhiteSpace(c)));
                            Log.Debug($"Ostatnia wersja drivera {latestDriverVersion}");
                            Log.Debug("Pobieramy drivera");
                            Uri driverUri =
                                new Uri($"https://msedgedriver.azureedge.net/{latestDriverVersion}/{ZipFileName}");
                            using (HttpResponseMessage response =
                                       await client.GetAsync(driverUri, HttpCompletionOption.ResponseHeadersRead))
                            {
                                response.EnsureSuccessStatusCode();
                                using (Stream driverStream = await response.Content.ReadAsStreamAsync())
                                {
                                    using (Stream driverStreamWrite = File.Open(ZipPath, FileMode.Create))
                                    {
                                        await driverStream.CopyToAsync(driverStreamWrite);
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }