/// <summary> /// The copy cef binaries to dist folder. /// </summary> /// <param name="commandLineArguments"> /// The command line arguments. /// </param> private void CopyCefBinariesToDistFolder(ChromelyCefArgument commandLineArguments) { try { this.DirectoryCopy(commandLineArguments.Destination, commandLineArguments.GetCefDistFolder); } catch (Exception) { // ignored } }
/// <summary> /// The cef binaries exist. /// </summary> /// <param name="commandLineArguments"> /// The command line arguments. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool CefBinariesExist(ChromelyCefArgument commandLineArguments) { try { return(this.CefBinariesExist(commandLineArguments.Destination, commandLineArguments.IsWin)); } catch (Exception e) { Console.WriteLine(e); } return(false); }
/// <summary> /// The copy cef binaries if exist. /// </summary> /// <param name="commandLineArguments"> /// The command line arguments. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool CopyCefBinariesIfExist(ChromelyCefArgument commandLineArguments) { try { if (!this.CefBinariesExist(commandLineArguments.GetCefDistFolder, commandLineArguments.IsWin)) { return(false); } Console.WriteLine("Copying Cef binaries from {0} to {1}", commandLineArguments.GetCefDistFolder, commandLineArguments.Destination); // Copy all files from dist folder to bin folder. this.DirectoryCopy(commandLineArguments.GetCefDistFolder, commandLineArguments.Destination); return(this.CefBinariesExist(commandLineArguments.Destination, commandLineArguments.IsWin)); } catch (Exception e) { Console.WriteLine(e); } return(false); }
/// <summary> /// The process. /// </summary> /// <param name="commandLineArguments"> /// The command line arguments. /// </param> /// <returns> /// The <see cref="bool"/>. /// </returns> public bool Process(ChromelyCefArgument commandLineArguments) { bool result = false; try { string downloadClientUrl = VersionMapper.GetUrl(commandLineArguments); Console.WriteLine($"From url: {downloadClientUrl}"); string destFolder = commandLineArguments.Destination; if (!Directory.Exists(destFolder)) { Directory.CreateDirectory(destFolder); } Console.WriteLine($"Destination: {destFolder}"); Console.WriteLine("Processing ... please wait ..."); var finalUnzippedName = this.UnzippedFolderName(downloadClientUrl); var bz2FileName = $"{finalUnzippedName}.tar.bz2"; var tarFileName = $"{finalUnzippedName}.tar"; var guid = Guid.NewGuid().ToString(); var tempFolder = Path.Combine(Path.GetTempPath(), guid); if (!Directory.Exists(tempFolder)) { Directory.CreateDirectory(tempFolder); } var downloadedBz2File = Path.Combine(tempFolder, bz2FileName); var finalUnzippedFolder = Path.Combine(tempFolder, finalUnzippedName); var webClient = new WebClient(); webClient.DownloadFile(downloadClientUrl, downloadedBz2File); var tarFile = Path.Combine(tempFolder, tarFileName); var bz2FileInfo = new FileInfo(downloadedBz2File); using (var fileToDecompressAsStream = bz2FileInfo.OpenRead()) { using (var decompressedStream = File.Create(tarFile)) { BZip2.Decompress(fileToDecompressAsStream, decompressedStream, true); } } using (var inStream = File.OpenRead(tarFile)) { TarArchive tarArchive = TarArchive.CreateInputTarArchive(inStream); tarArchive.ExtractContents(tempFolder); tarArchive.Close(); inStream.Close(); } var filesToCopyInfos = this.GetFileInfosToCopy(finalUnzippedFolder, destFolder, commandLineArguments.IsWin); this.CopyFiles(filesToCopyInfos); // Now copy all cef binaries to dist folder var copyCefBinariestoDistThread = new Thread(() => this.CopyCefBinariesToDistFolder(commandLineArguments)); copyCefBinariestoDistThread.Start(); // Delete temp folder var deleteTempFolderThread = new Thread(() => this.DeleteTempFolder(tempFolder)); deleteTempFolderThread.Start(); result = true; } catch (Exception exception) { var message = exception.GetBaseException().Message; Console.Error.WriteLine(message); // ignored result = false; } return(result); }
/// <summary> /// The run. /// </summary> /// <param name="args"> /// The args. /// </param> /// <returns> /// The <see cref="int"/>. /// </returns> private static int Run(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); var app = new CommandLineApplication(throwOnUnexpectedArg: false); app.Name = "cef"; app.HelpOption("-?|-h|--help"); string description = "chromelycef downloads cef binaries from http://opensource.spotify.com/cefbuilds/index.html, unpacks the compressed binaries and move files to a specfified location or current directory.\n\r" + "This tool only download files that are required for a Chromely app.\n\r" + "For more info please go to https://github.com/mattkol/Chromely/wiki/Cef-Binaries-Download.\n\r\n\r" + "Note that depending on your network, this might take up to 90 seconds to complete."; app.OnExecute(() => { var noCommandInfo = "Missing command.\n\r" + "To run you need the \"download\" command.\n\r" + "For more help type:\n\r\n\r" + "dotnet chromelycef.dll download -h" + "\n\r\n\r" + description; Console.WriteLine(noCommandInfo); return(0); }); app.Command( "download", (command) => { command.Description = description; command.HelpOption("-?|-h|--help"); var chromelyVersionArgument = command.Argument(Template.ChromelyVersion, Template.GetDescription(Template.ChromelyVersion)); var cefBinaryVersion = command.Option( Template.BinaryVersion, Template.GetDescription(Template.BinaryVersion), CommandOptionType.SingleValue); var platform = command.Option( Template.OS, Template.GetDescription(Template.OS), CommandOptionType.SingleValue); var cpu = command.Option( Template.Cpu, Template.GetDescription(Template.Cpu), CommandOptionType.SingleValue); var destination = command.Option( Template.Destination, Template.GetDescription(Template.Destination), CommandOptionType.SingleValue); command.OnExecute(() => { var cefArgument = new ChromelyCefArgument(); cefArgument.SetChromelyVersion(chromelyVersionArgument); cefArgument.SetOption(Template.BinaryVersion, cefBinaryVersion); cefArgument.SetOption(Template.OS, platform); cefArgument.SetOption(Template.Cpu, cpu); cefArgument.SetOption(Template.Destination, destination); DownloadService downloadService = new DownloadService(); if (downloadService.CefBinariesExist(cefArgument)) { Console.WriteLine("Cef binaries exist!"); return(0); } if (downloadService.CopyCefBinariesIfExist(cefArgument)) { Console.WriteLine("Cef binaries copied!"); return(0); } Console.WriteLine("Note that depending on your network, this might take up to 90 seconds to complete.\n\rCef binaries download started."); bool result = downloadService.Process(cefArgument); Console.WriteLine(result ? "Cef binaries download completed successfully." : "Cef binaries download completed with error."); stopwatch.Stop(); Console.WriteLine(@"Time elapsed: {0}", stopwatch.Elapsed); return(0); }); }); return(app.Execute(args)); }