private static void FillTarget(DownloadArguments downloadArguments, bool magicMode, string targetFolder, IFileSystemProxy fileSystem) { if (targetFolder == null && !magicMode) { targetFolder = Path.GetDirectoryName(fileSystem.GetExecutingAssemblyPath()) ?? ""; } string targetPath; if (targetFolder != null) { targetPath = Path.Combine(targetFolder, "paket.exe"); } else { targetPath = GetMagicModeTarget(fileSystem); targetFolder = Path.GetDirectoryName(targetPath); } // Make sure folder exists - creates it, and parents, if it does not exist. fileSystem.CreateDirectory(targetFolder); downloadArguments.Target = targetPath; downloadArguments.Folder = targetFolder; }
public static IDownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(new WebRequestProxy(), new FileProxy()).AsCached(dlArgs.IgnoreCache); var nugetDownloadStrategy = new NugetDownloadStrategy(new WebRequestProxy(), new DirectoryProxy(), new FileProxy(), dlArgs.Folder, dlArgs.NugetSource).AsCached(dlArgs.IgnoreCache); IDownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return(effectiveStrategy); }
private static IDownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.PrepareWebRequest, BootstrapperHelper.GetDefaultWebProxyFor); var nugetDownloadStrategy = new NugetDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.GetDefaultWebProxyFor, dlArgs.Folder, dlArgs.NugetSource); IDownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return(dlArgs.IgnoreCache ? effectiveStrategy : new CacheDownloadStrategy(effectiveStrategy)); }
public BootstrapperOptions() { Verbosity = Verbosity.Normal; DownloadArguments = new DownloadArguments(); RunArgs = Enumerable.Empty<string>(); UnprocessedCommandArgs = Enumerable.Empty<string>(); }
public BootstrapperOptions() { Verbosity = Verbosity.Normal; DownloadArguments = new DownloadArguments(); RunArgs = Enumerable.Empty <string>(); UnprocessedCommandArgs = Enumerable.Empty <string>(); }
public static DownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(new WebRequestProxy(), new FileSystemProxy()).AsCached(dlArgs.IgnoreCache); var nugetDownloadStrategy = new NugetDownloadStrategy(new WebRequestProxy(), new FileSystemProxy(), dlArgs.Folder, dlArgs.NugetSource).AsCached(dlArgs.IgnoreCache); DownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return(effectiveStrategy.AsTemporarilyIgnored(dlArgs.MaxFileAgeInMinutes, dlArgs.Target)); }
private static void FillTargetToRelativeDir(DownloadArguments downloadArguments, IFileSystemProxy fileSystem) { var folder = fileSystem.GetCurrentDirectory(); var target = Path.Combine(folder, "paket.exe"); downloadArguments.Target = target; downloadArguments.Folder = Path.GetDirectoryName(target); }
private static void FillTarget(DownloadArguments downloadArguments, bool magicMode, IFileSystemProxy fileSystem) { var folder = Path.GetDirectoryName(fileSystem.GetExecutingAssemblyPath()) ?? ""; var target = magicMode ? GetMagicModeTarget(fileSystem) : Path.Combine(folder, "paket.exe"); downloadArguments.Target = target; downloadArguments.Folder = Path.GetDirectoryName(target); }
private static void FillDownloadOptionsFromArguments(DownloadArguments downloadArguments, List <string> commandArgs) { if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); downloadArguments.DoSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs.Remove(nugetSourceArg); downloadArguments.NugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); downloadArguments.IgnoreCache = true; } if (commandArgs.Contains(CommandArgs.AsTool)) { commandArgs.Remove(CommandArgs.AsTool); downloadArguments.AsTool = true; } var maxFileAgeArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.MaxFileAge, StringComparison.Ordinal)); if (maxFileAgeArg != null) { var parts = maxFileAgeArg.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var maxFileAgeInMinutesCommandArg = parts[1]; int parsedMaxFileAgeInMinutesCommandArg; if (int.TryParse(maxFileAgeInMinutesCommandArg, out parsedMaxFileAgeInMinutesCommandArg)) { downloadArguments.MaxFileAgeInMinutes = parsedMaxFileAgeInMinutesCommandArg; } } commandArgs.Remove(maxFileAgeArg); } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { downloadArguments.IgnorePrerelease = false; commandArgs.Remove(CommandArgs.Prerelease); } else { downloadArguments.LatestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } }
private static IEnumerable <string> EvaluateDownloadOptions(DownloadArguments downloadArguments, IEnumerable <string> args, NameValueCollection appSettings, IDictionary envVariables) { var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var target = Path.Combine(folder, "paket.exe"); string nugetSource = null; var latestVersion = appSettings.GetKey(AppSettingKeys.PaketVersionAppSettingsKey) ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ?? String.Empty; var ignorePrerelease = true; bool doSelfUpdate = false; var ignoreCache = false; var commandArgs = args.ToList(); if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); doSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs = commandArgs.Where(x => !x.StartsWith(CommandArgs.NugetSourceArgPrefix)).ToList(); nugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); ignoreCache = true; } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { ignorePrerelease = false; latestVersion = String.Empty; commandArgs.Remove(CommandArgs.Prerelease); } else { latestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } downloadArguments.LatestVersion = latestVersion; downloadArguments.IgnorePrerelease = ignorePrerelease; downloadArguments.IgnoreCache = ignoreCache; downloadArguments.NugetSource = nugetSource; downloadArguments.DoSelfUpdate = doSelfUpdate; downloadArguments.Target = target; downloadArguments.Folder = folder; return(commandArgs); }
private static IEnumerable<string> EvaluateDownloadOptions(DownloadArguments downloadArguments, IEnumerable<string> args, NameValueCollection appSettings, IDictionary envVariables) { var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var target = Path.Combine(folder, "paket.exe"); string nugetSource = null; var latestVersion = appSettings.GetKey(AppSettingKeys.PaketVersionAppSettingsKey) ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ?? String.Empty; var ignorePrerelease = true; bool doSelfUpdate = false; var ignoreCache = false; var commandArgs = args.ToList(); if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); doSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs = commandArgs.Where(x => !x.StartsWith(CommandArgs.NugetSourceArgPrefix)).ToList(); nugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); ignoreCache = true; } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { ignorePrerelease = false; latestVersion = String.Empty; commandArgs.Remove(CommandArgs.Prerelease); } else { latestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } downloadArguments.LatestVersion = latestVersion; downloadArguments.IgnorePrerelease = ignorePrerelease; downloadArguments.IgnoreCache = ignoreCache; downloadArguments.NugetSource = nugetSource; downloadArguments.DoSelfUpdate = doSelfUpdate; downloadArguments.Target = target; downloadArguments.Folder = folder; return commandArgs; }
private static void FillDownloadOptionsFromArguments(DownloadArguments downloadArguments, List<string> commandArgs) { if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); downloadArguments.DoSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs = commandArgs.Where(x => !x.StartsWith(CommandArgs.NugetSourceArgPrefix)).ToList(); downloadArguments.NugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); downloadArguments.IgnoreCache = true; } var maxFileAgeArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.MaxFileAge, StringComparison.Ordinal)); if (maxFileAgeArg != null) { var parts = maxFileAgeArg.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var maxFileAgeInMinutesCommandArg = parts[1]; int parsedMaxFileAgeInMinutesCommandArg; if (int.TryParse(maxFileAgeInMinutesCommandArg, out parsedMaxFileAgeInMinutesCommandArg)) { downloadArguments.MaxFileAgeInMinutes = parsedMaxFileAgeInMinutesCommandArg; } } commandArgs.Remove(maxFileAgeArg); } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { downloadArguments.IgnorePrerelease = false; commandArgs.Remove(CommandArgs.Prerelease); } else { downloadArguments.LatestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } }
public static DownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(new WebRequestProxy(), new FileSystemProxy()).AsCached(dlArgs.IgnoreCache); var nugetDownloadStrategy = new NugetDownloadStrategy(new WebRequestProxy(), new FileSystemProxy(), dlArgs.Folder, dlArgs.NugetSource).AsCached(dlArgs.IgnoreCache); DownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return effectiveStrategy.AsTemporarilyIgnored(dlArgs.MaxFileAgeInMinutes, dlArgs.Target); }
public static IDownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(new WebRequestProxy(), new FileProxy()).AsCached(dlArgs.IgnoreCache); var nugetDownloadStrategy = new NugetDownloadStrategy(new WebRequestProxy(), new DirectoryProxy(), new FileProxy(), dlArgs.Folder, dlArgs.NugetSource).AsCached(dlArgs.IgnoreCache); IDownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return effectiveStrategy; }
private static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, bool silent) { Action <Exception> handleException = exception => { if (!File.Exists(dlArgs.Target)) { Environment.ExitCode = 1; } BootstrapperHelper.WriteConsoleError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { var localVersion = BootstrapperHelper.GetLocalFileVersion(dlArgs.Target); var latestVersion = dlArgs.LatestVersion; if (latestVersion == String.Empty) { latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); } if (dlArgs.DoSelfUpdate) { if (!silent) { Console.WriteLine("Trying self update"); } downloadStrategy.SelfUpdate(latestVersion, silent); } else { var currentSemVer = String.IsNullOrEmpty(localVersion) ? new SemVer() : SemVer.Create(localVersion); var latestSemVer = SemVer.Create(latestVersion); if (currentSemVer.CompareTo(latestSemVer) != 0) { downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target, silent); if (!silent) { Console.WriteLine("Done."); } } else { if (!silent) { Console.WriteLine("Paket.exe {0} is up to date.", localVersion); } } } } catch (WebException exn) { var shouldHandleException = true; if (!File.Exists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; if (!silent) { Console.WriteLine("'{0}' download failed. If using Mono, you may need to import trusted certificates using the 'mozroots' tool as none are contained by default. Trying fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); } StartPaketBootstrapping(fallbackStrategy, dlArgs, silent); shouldHandleException = !File.Exists(dlArgs.Target); } } if (shouldHandleException) { handleException(exn); } } catch (Exception exn) { handleException(exn); } }
private static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, bool silent) { Action<Exception> handleException = exception => { if (!File.Exists(dlArgs.Target)) Environment.ExitCode = 1; BootstrapperHelper.WriteConsoleError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { var localVersion = BootstrapperHelper.GetLocalFileVersion(dlArgs.Target); var latestVersion = dlArgs.LatestVersion; if (latestVersion == String.Empty) { latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); } if (dlArgs.DoSelfUpdate) { if (!silent) Console.WriteLine("Trying self update"); downloadStrategy.SelfUpdate(latestVersion, silent); } else { if (!localVersion.StartsWith(latestVersion)) { downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target, silent); if (!silent) Console.WriteLine("Done."); } else { if (!silent) Console.WriteLine("Paket.exe {0} is up to date.", localVersion); } } } catch (WebException exn) { var shouldHandleException = true; if (!File.Exists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; if (!silent) Console.WriteLine("'{0}' download failed. Try fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); StartPaketBootstrapping(fallbackStrategy, dlArgs, silent); shouldHandleException = !File.Exists(dlArgs.Target); } } if (shouldHandleException) handleException(exn); } catch (Exception exn) { handleException(exn); } }
private static IDownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.PrepareWebRequest, BootstrapperHelper.GetDefaultWebProxyFor); var nugetDownloadStrategy = new NugetDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.GetDefaultWebProxyFor, dlArgs.Folder); IDownloadStrategy effectiveStrategy; if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return effectiveStrategy; }
private static IEnumerable<string> EvaluateDownloadOptions(DownloadArguments downloadArguments, IEnumerable<string> args, NameValueCollection appSettings, IDictionary envVariables, bool magicMode) { var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var target = magicMode ? GetMagicModeTarget() : Path.Combine(folder, "paket.exe"); string nugetSource = downloadArguments.NugetSource; var appSettingsVersion = appSettings.GetKey(AppSettingKeys.PaketVersion); var latestVersion = appSettingsVersion ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ?? downloadArguments.LatestVersion; var appSettingsRequestPrerelease = appSettings.IsTrue(AppSettingKeys.Prerelease); var prerelease = (appSettingsRequestPrerelease && string.IsNullOrEmpty(latestVersion)) || !downloadArguments.IgnorePrerelease; bool doSelfUpdate = downloadArguments.DoSelfUpdate; var ignoreCache = downloadArguments.IgnoreCache; var commandArgs = args.ToList(); int? maxFileAgeInMinutes = downloadArguments.MaxFileAgeInMinutes; if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); doSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs = commandArgs.Where(x => !x.StartsWith(CommandArgs.NugetSourceArgPrefix)).ToList(); nugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); ignoreCache = true; } var maxFileAgeArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.MaxFileAge, StringComparison.Ordinal)); if (maxFileAgeArg != null) { var parts = maxFileAgeArg.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var maxFileAgeInMinutesCommandArg = parts[1]; int parsedMaxFileAgeInMinutesCommandArg; if (int.TryParse(maxFileAgeInMinutesCommandArg, out parsedMaxFileAgeInMinutesCommandArg)) maxFileAgeInMinutes = parsedMaxFileAgeInMinutesCommandArg; } commandArgs.Remove(maxFileAgeArg); } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { prerelease = true; latestVersion = String.Empty; commandArgs.Remove(CommandArgs.Prerelease); } else { prerelease = false; latestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } downloadArguments.LatestVersion = latestVersion; downloadArguments.IgnorePrerelease = !prerelease; downloadArguments.IgnoreCache = ignoreCache; downloadArguments.NugetSource = nugetSource; downloadArguments.DoSelfUpdate = doSelfUpdate; downloadArguments.Target = target; downloadArguments.Folder = Path.GetDirectoryName(target); if (magicMode) { if (appSettingsRequestPrerelease || !String.IsNullOrWhiteSpace(appSettingsVersion)) downloadArguments.MaxFileAgeInMinutes = 0; else downloadArguments.MaxFileAgeInMinutes = 60 * 12; } else downloadArguments.MaxFileAgeInMinutes = maxFileAgeInMinutes; return commandArgs; }
public static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, IFileSystemProxy fileSystemProxy, Action onSuccess) { Action<Exception> handleException = exception => { if (!fileSystemProxy.FileExists(dlArgs.Target)) Environment.ExitCode = 1; ConsoleImpl.WriteError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { string versionRequested; if (!dlArgs.IgnorePrerelease) versionRequested = "prerelease requested"; else if (String.IsNullOrWhiteSpace(dlArgs.LatestVersion)) versionRequested = "downloading latest stable"; else versionRequested = string.Format("version {0} requested", dlArgs.LatestVersion); ConsoleImpl.WriteInfo("Checking Paket version ({0})...", versionRequested); ConsoleImpl.WriteTrace("Target path is {0}", dlArgs.Target); var localVersion = fileSystemProxy.GetLocalFileVersion(dlArgs.Target); ConsoleImpl.WriteTrace("File in target path version: v{0}", localVersion); var specificVersionRequested = true; var latestVersion = dlArgs.LatestVersion; if (latestVersion == string.Empty) { ConsoleImpl.WriteTrace("No version specified, checking online..."); var getLatestVersionWatch = Stopwatch.StartNew(); latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); getLatestVersionWatch.Stop(); ConsoleImpl.WriteTrace("Latest version check found v{0} in {1:0.##} second(s)", latestVersion, getLatestVersionWatch.Elapsed.TotalSeconds); specificVersionRequested = false; } if (dlArgs.DoSelfUpdate) { ConsoleImpl.WriteInfo("Trying self update"); downloadStrategy.SelfUpdate(latestVersion); } else { var currentSemVer = String.IsNullOrEmpty(localVersion) ? new SemVer() : SemVer.Create(localVersion); if (currentSemVer.PreRelease != null && dlArgs.IgnorePrerelease) currentSemVer = new SemVer(); var latestSemVer = SemVer.Create(latestVersion); var comparison = currentSemVer.CompareTo(latestSemVer); if ((comparison > 0 && specificVersionRequested) || comparison < 0) { ConsoleImpl.WriteTrace("Downloading v{0} ...", latestVersion); var downloadWatch = Stopwatch.StartNew(); downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target); downloadWatch.Stop(); ConsoleImpl.WriteTrace("Download took {0:0.##} second(s)", downloadWatch.Elapsed.TotalSeconds); ConsoleImpl.WriteInfo("Done in {0:0.##} second(s).", executionWatch.Elapsed.TotalSeconds); } else { ConsoleImpl.WriteInfo("Paket.exe {0} is up to date.", localVersion); } } executionWatch.Stop(); ConsoleImpl.WriteTrace("Paket Bootstrapping took {0:0.##} second(s)", executionWatch.Elapsed.TotalSeconds); onSuccess(); } catch (WebException exn) { var shouldHandleException = true; if (!fileSystemProxy.FileExists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; ConsoleImpl.WriteInfo("'{0}' download failed. If using Mono, you may need to import trusted certificates using the 'mozroots' tool as none are contained by default. Trying fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); StartPaketBootstrapping(fallbackStrategy, dlArgs, fileSystemProxy, onSuccess); shouldHandleException = !fileSystemProxy.FileExists(dlArgs.Target); } } if (shouldHandleException) handleException(exn); } catch (Exception exn) { handleException(exn); } }
private static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, bool silent) { Action <Exception> handleException = exception => { if (!File.Exists(dlArgs.Target)) { Environment.ExitCode = 1; } BootstrapperHelper.WriteConsoleError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { var localVersion = BootstrapperHelper.GetLocalFileVersion(dlArgs.Target); var latestVersion = dlArgs.LatestVersion; if (latestVersion == String.Empty) { latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); } if (dlArgs.DoSelfUpdate) { if (!silent) { Console.WriteLine("Trying self update"); } downloadStrategy.SelfUpdate(latestVersion, silent); } else { if (!localVersion.StartsWith(latestVersion)) { downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target, silent); if (!silent) { Console.WriteLine("Done."); } } else { if (!silent) { Console.WriteLine("Paket.exe {0} is up to date.", localVersion); } } } } catch (WebException exn) { var shouldHandleException = true; if (!File.Exists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; if (!silent) { Console.WriteLine("'{0}' download failed. Try fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); } StartPaketBootstrapping(fallbackStrategy, dlArgs, silent); shouldHandleException = !File.Exists(dlArgs.Target); } } if (shouldHandleException) { handleException(exn); } } catch (Exception exn) { handleException(exn); } }
private static IDownloadStrategy GetEffectiveDownloadStrategy(DownloadArguments dlArgs, bool preferNuget, bool forceNuget) { var gitHubDownloadStrategy = new GitHubDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.PrepareWebRequest, BootstrapperHelper.GetDefaultWebProxyFor); var nugetDownloadStrategy = new NugetDownloadStrategy(BootstrapperHelper.PrepareWebClient, BootstrapperHelper.GetDefaultWebProxyFor, dlArgs.Folder, dlArgs.NugetSource); IDownloadStrategy effectiveStrategy; if (forceNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = null; } else if (preferNuget) { effectiveStrategy = nugetDownloadStrategy; nugetDownloadStrategy.FallbackStrategy = gitHubDownloadStrategy; } else { effectiveStrategy = gitHubDownloadStrategy; gitHubDownloadStrategy.FallbackStrategy = nugetDownloadStrategy; } return dlArgs.IgnoreCache ? effectiveStrategy : new CacheDownloadStrategy(effectiveStrategy); }
public BootstrapperOptions() { DownloadArguments = new DownloadArguments(); }
private static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, bool silent) { Action<Exception> handleException = exception => { if (!File.Exists(dlArgs.Target)) Environment.ExitCode = 1; BootstrapperHelper.WriteConsoleError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { if (!silent) { string versionRequested; if (!dlArgs.IgnorePrerelease) versionRequested = "prerelease requested"; else if (String.IsNullOrWhiteSpace(dlArgs.LatestVersion)) versionRequested = "downloading latest stable"; else versionRequested = string.Format("version {0} requested", dlArgs.LatestVersion); Console.WriteLine("Checking Paket version ({0})...", versionRequested); } var localVersion = BootstrapperHelper.GetLocalFileVersion(dlArgs.Target); var specificVersionRequested = true; var latestVersion = dlArgs.LatestVersion; if (latestVersion == String.Empty) { latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease, silent); specificVersionRequested = false; } if (dlArgs.DoSelfUpdate) { if (!silent) Console.WriteLine("Trying self update"); downloadStrategy.SelfUpdate(latestVersion, silent); } else { var currentSemVer = String.IsNullOrEmpty(localVersion) ? new SemVer() : SemVer.Create(localVersion); var latestSemVer = SemVer.Create(latestVersion); var comparison = currentSemVer.CompareTo(latestSemVer); if ((comparison > 0 && specificVersionRequested) || comparison < 0) { downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target, silent); if (!silent) Console.WriteLine("Done."); } else { if (!silent) Console.WriteLine("Paket.exe {0} is up to date.", localVersion); } } } catch (WebException exn) { var shouldHandleException = true; if (!File.Exists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; if (!silent) Console.WriteLine("'{0}' download failed. If using Mono, you may need to import trusted certificates using the 'mozroots' tool as none are contained by default. Trying fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); StartPaketBootstrapping(fallbackStrategy, dlArgs, silent); shouldHandleException = !File.Exists(dlArgs.Target); } } if (shouldHandleException) handleException(exn); } catch (Exception exn) { handleException(exn); } }
private static IEnumerable <string> EvaluateDownloadOptions(DownloadArguments downloadArguments, IEnumerable <string> args, NameValueCollection appSettings, IDictionary envVariables) { var folder = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); var target = Path.Combine(folder, "paket.exe"); string nugetSource = null; var latestVersion = appSettings.GetKey(AppSettingKeys.PaketVersionAppSettingsKey) ?? envVariables.GetKey(EnvArgs.PaketVersionEnv) ?? String.Empty; var ignorePrerelease = true; bool doSelfUpdate = false; var ignoreCache = false; var commandArgs = args.ToList(); int? maxFileAgeInMinutes = null; if (commandArgs.Contains(CommandArgs.SelfUpdate)) { commandArgs.Remove(CommandArgs.SelfUpdate); doSelfUpdate = true; } var nugetSourceArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.NugetSourceArgPrefix)); if (nugetSourceArg != null) { commandArgs = commandArgs.Where(x => !x.StartsWith(CommandArgs.NugetSourceArgPrefix)).ToList(); nugetSource = nugetSourceArg.Substring(CommandArgs.NugetSourceArgPrefix.Length); } if (commandArgs.Contains(CommandArgs.IgnoreCache)) { commandArgs.Remove(CommandArgs.IgnoreCache); ignoreCache = true; } var maxFileAgeArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.MaxFileAge, StringComparison.Ordinal)); if (maxFileAgeArg != null) { var parts = maxFileAgeArg.Split("=".ToCharArray(), StringSplitOptions.RemoveEmptyEntries); if (parts.Length == 2) { var maxFileAgeInMinutesCommandArg = parts[1]; int parsedMaxFileAgeInMinutesCommandArg; if (int.TryParse(maxFileAgeInMinutesCommandArg, out parsedMaxFileAgeInMinutesCommandArg)) { maxFileAgeInMinutes = parsedMaxFileAgeInMinutesCommandArg; } } commandArgs.Remove(maxFileAgeArg); } if (commandArgs.Count >= 1) { if (commandArgs[0] == CommandArgs.Prerelease) { ignorePrerelease = false; latestVersion = String.Empty; commandArgs.Remove(CommandArgs.Prerelease); } else { latestVersion = commandArgs[0]; commandArgs.Remove(commandArgs[0]); } } downloadArguments.LatestVersion = latestVersion; downloadArguments.IgnorePrerelease = ignorePrerelease; downloadArguments.IgnoreCache = ignoreCache; downloadArguments.NugetSource = nugetSource; downloadArguments.DoSelfUpdate = doSelfUpdate; downloadArguments.Target = target; downloadArguments.Folder = folder; downloadArguments.MaxFileAgeInMinutes = maxFileAgeInMinutes; return(commandArgs); }
public static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, IFileSystemProxy fileSystemProxy, Action onSuccess) { Action <Exception> handleException = exception => { #if DEBUG Environment.ExitCode = 1; ConsoleImpl.WriteError(String.Format("{0} ({1})", exception.ToString(), downloadStrategy.Name)); return; #else ConsoleImpl.WriteError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); if (!fileSystemProxy.FileExists(dlArgs.Target)) { Environment.ExitCode = 1; } else { fileSystemProxy.WaitForFileFinished(dlArgs.Target); onSuccess(); } #endif }; try { string versionRequested; if (!dlArgs.IgnorePrerelease) { versionRequested = "prerelease requested"; } else if (String.IsNullOrWhiteSpace(dlArgs.LatestVersion)) { versionRequested = "downloading latest stable"; } else { versionRequested = string.Format("version {0} requested", dlArgs.LatestVersion); } ConsoleImpl.WriteInfo("Checking Paket version ({0})...", versionRequested); ConsoleImpl.WriteTrace("Target path is {0}", dlArgs.Target); var localVersion = fileSystemProxy.GetLocalFileVersion(dlArgs.Target); ConsoleImpl.WriteTrace("File in target path version: v{0}", string.IsNullOrEmpty(localVersion) ? "UNKNOWN" : localVersion); var specificVersionRequested = true; var latestVersion = dlArgs.LatestVersion; if (latestVersion == string.Empty) { ConsoleImpl.WriteTrace("No version specified, checking online..."); var getLatestVersionWatch = Stopwatch.StartNew(); latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); getLatestVersionWatch.Stop(); ConsoleImpl.WriteTrace("Latest version check found v{0} in {1:0.##} second(s)", latestVersion, getLatestVersionWatch.Elapsed.TotalSeconds); specificVersionRequested = false; } if (dlArgs.DoSelfUpdate) { ConsoleImpl.WriteInfo("Trying self update"); downloadStrategy.SelfUpdate(latestVersion); } else { var currentSemVer = String.IsNullOrEmpty(localVersion) ? new SemVer() : SemVer.Create(localVersion); if (currentSemVer.PreRelease != null && dlArgs.IgnorePrerelease) { currentSemVer = new SemVer(); } var latestSemVer = SemVer.Create(latestVersion); var comparison = currentSemVer.CompareTo(latestSemVer); if ((comparison > 0 && specificVersionRequested) || comparison < 0) { PaketHashFile hashFile = null; if (downloadStrategy.CanDownloadHashFile) { ConsoleImpl.WriteTrace("Downloading hash for v{0} ...", latestVersion); var downloadHashWatch = Stopwatch.StartNew(); hashFile = downloadStrategy.DownloadHashFile(latestVersion); downloadHashWatch.Stop(); ConsoleImpl.WriteTrace("Hash download took {0:0.##} second(s)", downloadHashWatch.Elapsed.TotalSeconds); } ConsoleImpl.WriteTrace("Downloading v{0} ...", latestVersion); var downloadWatch = Stopwatch.StartNew(); downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target, hashFile); downloadWatch.Stop(); ConsoleImpl.WriteTrace("Download took {0:0.##} second(s)", downloadWatch.Elapsed.TotalSeconds); ConsoleImpl.WriteInfo("Done in {0:0.##} second(s).", executionWatch.Elapsed.TotalSeconds); } else { ConsoleImpl.WriteInfo("Paket.exe {0} is up to date.", localVersion); } } executionWatch.Stop(); ConsoleImpl.WriteTrace("Paket Bootstrapping took {0:0.##} second(s)", executionWatch.Elapsed.TotalSeconds); onSuccess(); } catch (WebException exn) { var shouldHandleException = true; if (!fileSystemProxy.FileExists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; ConsoleImpl.WriteInfo("'{0}' download failed. If using Mono, you may need to import trusted certificates using the 'mozroots' tool as none are contained by default. Trying fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); StartPaketBootstrapping(fallbackStrategy, dlArgs, fileSystemProxy, onSuccess); shouldHandleException = !fileSystemProxy.FileExists(dlArgs.Target); } } if (shouldHandleException) { handleException(exn); } } catch (Exception exn) { handleException(exn); } }
public static void StartPaketBootstrapping(IDownloadStrategy downloadStrategy, DownloadArguments dlArgs, IFileProxy fileProxy) { Action <Exception> handleException = exception => { if (!File.Exists(dlArgs.Target)) { Environment.ExitCode = 1; } ConsoleImpl.WriteError(String.Format("{0} ({1})", exception.Message, downloadStrategy.Name)); }; try { string versionRequested; if (!dlArgs.IgnorePrerelease) { versionRequested = "prerelease requested"; } else if (String.IsNullOrWhiteSpace(dlArgs.LatestVersion)) { versionRequested = "downloading latest stable"; } else { versionRequested = string.Format("version {0} requested", dlArgs.LatestVersion); } ConsoleImpl.WriteDebug("Checking Paket version ({0})...", versionRequested); var localVersion = fileProxy.GetLocalFileVersion(dlArgs.Target); var specificVersionRequested = true; var latestVersion = dlArgs.LatestVersion; if (latestVersion == String.Empty) { latestVersion = downloadStrategy.GetLatestVersion(dlArgs.IgnorePrerelease); specificVersionRequested = false; } if (dlArgs.DoSelfUpdate) { ConsoleImpl.WriteDebug("Trying self update"); downloadStrategy.SelfUpdate(latestVersion); } else { var currentSemVer = String.IsNullOrEmpty(localVersion) ? new SemVer() : SemVer.Create(localVersion); if (currentSemVer.PreRelease != null && dlArgs.IgnorePrerelease) { currentSemVer = new SemVer(); } var latestSemVer = SemVer.Create(latestVersion); var comparison = currentSemVer.CompareTo(latestSemVer); if ((comparison > 0 && specificVersionRequested) || comparison < 0) { downloadStrategy.DownloadVersion(latestVersion, dlArgs.Target); ConsoleImpl.WriteDebug("Done."); } else { ConsoleImpl.WriteDebug("Paket.exe {0} is up to date.", localVersion); } } } catch (WebException exn) { var shouldHandleException = true; if (!File.Exists(dlArgs.Target)) { if (downloadStrategy.FallbackStrategy != null) { var fallbackStrategy = downloadStrategy.FallbackStrategy; ConsoleImpl.WriteDebug("'{0}' download failed. If using Mono, you may need to import trusted certificates using the 'mozroots' tool as none are contained by default. Trying fallback download from '{1}'.", downloadStrategy.Name, fallbackStrategy.Name); StartPaketBootstrapping(fallbackStrategy, dlArgs, fileProxy); shouldHandleException = !File.Exists(dlArgs.Target); } } if (shouldHandleException) { handleException(exn); } } catch (Exception exn) { handleException(exn); } }
private static NameValueCollection ParseBootstrapperOnlyCommandArgs(List <string> commandArgs, NameValueCollection appSettings, DownloadArguments downloadArguments, IFileSystemProxy fileSystem, bool magicMode) { var configFileArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.ConfigFile)); NameValueCollection newSettings = appSettings; if (configFileArg != null) { commandArgs.Remove(configFileArg); var configFilePath = configFileArg.Substring(CommandArgs.ConfigFile.Length); newSettings = ReadSettings(configFilePath); } // Check if output dir has been provided - commandline takes priority var outputDirArg = commandArgs.SingleOrDefault(x => x.StartsWith(CommandArgs.OutputDir)); var bootstrapperOutputDir = newSettings.GetKey(AppSettingKeys.BootstrapperOutputDir); string targetFolder = null; if (outputDirArg != null) { commandArgs.Remove(outputDirArg); targetFolder = outputDirArg.Substring(CommandArgs.OutputDir.Length); } else if (bootstrapperOutputDir != null) { targetFolder = bootstrapperOutputDir; } // Fill target - if none has been found, the default (temp folder with unique exe name) is used FillTarget(downloadArguments, magicMode, targetFolder, fileSystem); return(newSettings); }