public bool GetChocolateyWebFile(string packageName, string fileFullPath, string url, string url64bit) { Debug("Calling 'ChocolateyRequest::GetChocolateyWebFile' '{0}','{1}','{2}','{3}' ", packageName, fileFullPath, url, url64bit); if (!string.IsNullOrEmpty(url64bit) && Environment.Is64BitOperatingSystem && !ForceX86) { url = url64bit; } Verbose("GetChocolateyWebFile {0} => {1}", packageName, url); var uri = new Uri(url); ProviderServices.DownloadFile(uri, fileFullPath, this); if (string.IsNullOrEmpty(fileFullPath) || !fileFullPath.FileExists()) { throw new Exception("Failed to download file {0}".format(url)); } return(true); }
internal string DownloadAndValidateFile(string name, IEnumerable <Link> links) { var failedBecauseInvalid = false; string file = null; foreach (var link in links) { var tmpFile = link.Artifact.GenerateTemporaryFilename(); file = ProviderServices.DownloadFile(link.HRef, tmpFile, -1, true, this); if (file == null || !file.FileExists()) { Debug("Failed download of '{0}'", link.HRef); file = null; continue; } Debug("Verifying the package"); var valid = ProviderServices.IsSignedAndTrusted(file, this); if (!valid) { Debug("Not Valid file '{0}' => '{1}'", link.HRef, tmpFile); Warning(Constants.Messages.FileFailedVerification, link.HRef); failedBecauseInvalid = true; #if !DEBUG tmpFile.TryHardToDelete(); continue; #endif } } if (failedBecauseInvalid) { Error(ErrorCategory.InvalidData, name, Constants.Messages.FileFailedVerification, name); return(null); } return(file); }
internal string DownLoadFileFromLinks(IEnumerable <Link> links) { string file = null; foreach (var link in links) { file = RetryDownload( // the download function takes in a uri link and download it (uri) => { var tmpFile = FilesystemExtensions.GenerateTemporaryFileOrDirectoryNameInTempDirectory(); return(ProviderServices.DownloadFile(uri, tmpFile, -1, true, this)); }, link.HRef); // got a valid file! if (file != null && file.FileExists()) { // if file is zip, unpack it and return the unpacked folder if (link.MediaType == Iso19770_2.MediaType.ZipPackage) { try { // let's extract the zipped file return(ExtractZipPackage(file)); } finally { // delete the zipped file file.TryHardToDelete(); } } return(file); } } return(file); }
internal string DownLoadFileFromLinks(string name, IEnumerable <Link> links) { string file = null; foreach (var link in links) { file = RetryDownload( // the download function takes in a uri link and download it (uri) => { var tmpFile = link.Artifact.GenerateTemporaryFilename(); return(ProviderServices.DownloadFile(uri, tmpFile, -1, true, this)); }, link.HRef); // got a valid file! if (file != null && file.FileExists()) { return(file); } } return(file); }
internal string DownLoadFileFromLinks(IEnumerable <Link> links) { string file = null; foreach (var link in links) { file = RetryDownload( // the download function takes in a uri link and download it (uri) => { var tmpFile = FilesystemExtensions.GenerateTemporaryFileOrDirectoryNameInTempDirectory(); return(ProviderServices.DownloadFile(uri, tmpFile, -1, true, this)); }, link.HRef); // got a valid file! if (file != null && file.FileExists()) { return(file); } } return(file); }
public bool InstallChocolateyVsixPackage(string packageName, string vsixUrl, string vsVersion) { Debug("Calling 'ChocolateyRequest::InstallChocolateyVsixPackage' '{0}','{1}','{2}'", packageName, vsixUrl, vsVersion); var vs = Registry.LocalMachine.OpenSubKey(@"Software\Wow6432Node\Microsoft\VisualStudio"); var versions = vs.GetSubKeyNames().Select(each => { float f; if (!float.TryParse(each, out f)) { return(null); } if (f < 10.0) { return(null); } var vsv = vs.OpenSubKey(each); if (vsv.GetValueNames().Contains("InstallDir", StringComparer.OrdinalIgnoreCase)) { return(new { Version = f, InstallDir = vsv.GetValue("InstallDir").ToString() }); } return(null); }).Where(each => each != null).OrderByDescending(each => each.Version); var reqVsVersion = versions.FirstOrDefault(); if (!string.IsNullOrEmpty(vsVersion)) { float f; if (!float.TryParse(vsVersion, out f)) { throw new Exception("Unable to parse version number"); } reqVsVersion = versions.FirstOrDefault(each => each.Version == f); } if (reqVsVersion == null) { throw new Exception("Required Visual Studio Version is not installed"); } var vsixInstller = Path.Combine(reqVsVersion.InstallDir, "VsixInstaller.exe"); if (!File.Exists(vsixInstller)) { throw new Exception("Can't find Visual Studio VSixInstaller.exe {0}".format(vsixInstller)); } var file = Path.Combine(Path.GetTempPath(), packageName.MakeSafeFileName()); ProviderServices.DownloadFile(new Uri(vsixUrl), file, this); if (string.IsNullOrEmpty(file) || !File.Exists(file)) { throw new Exception("Unable to download file {0}".format(vsixUrl)); } var process = AsyncProcess.Start(new ProcessStartInfo { FileName = vsixInstller, Arguments = @"/q ""{0}""".format(file), }); process.WaitForExit(); if (process.ExitCode > 0 && process.ExitCode != 1001) { Verbose("VsixInstall Failure {0}", file); throw new Exception("Install failure"); } return(false); }