protected override string GetLatestVersionCore(bool ignorePrerelease) { IEnumerable <string> allVersions = null; if (FileSystemProxy.DirectoryExists(NugetSource)) { var paketPrefix = "paket."; allVersions = FileSystemProxy. EnumerateFiles(NugetSource, "paket.*.nupkg", SearchOption.TopDirectoryOnly). Select(x => Path.GetFileNameWithoutExtension(x)). // If the specified character isn't a digit, then the file // likely contains the bootstrapper or paket.core Where(x => x.Length > paketPrefix.Length && Char.IsDigit(x[paketPrefix.Length])). Select(x => x.Substring(paketPrefix.Length)); } else { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); var versionRequestUrl = apiHelper.GetAllPackageVersions(!ignorePrerelease); var versions = WebRequestProxy.DownloadString(versionRequestUrl); allVersions = versions. Trim('[', ']'). Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries). Select(x => x.Trim('"')); } var latestVersion = allVersions. Select(SemVer.Create). Where(x => !ignorePrerelease || (x.PreRelease == null)). OrderBy(x => x). LastOrDefault(x => !String.IsNullOrWhiteSpace(x.Original)); return(latestVersion != null ? latestVersion.Original : String.Empty); }
protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile) { var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteInfo("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paket"); WebRequestProxy.DownloadFile(url, tmpFile); if (!BootstrapperHelper.ValidateHash(FileSystemProxy, hashfile, latestVersion, tmpFile)) { ConsoleImpl.WriteWarning("Hash of downloaded paket.exe is invalid, retrying once"); WebRequestProxy.DownloadFile(url, tmpFile); if (!BootstrapperHelper.ValidateHash(FileSystemProxy, hashfile, latestVersion, tmpFile)) { ConsoleImpl.WriteWarning("Hash of downloaded paket.exe still invalid (Using the file anyway)"); } else { ConsoleImpl.WriteTrace("Hash of downloaded file successfully found in {0}", hashfile); } } else { ConsoleImpl.WriteTrace("Hash of downloaded file successfully found in {0}", hashfile); } FileSystemProxy.CopyFile(tmpFile, target, true); FileSystemProxy.DeleteFile(tmpFile); }
protected override void DownloadVersionCore(string latestVersion, string target, PaketHashFile hashfile) { string url = String.Format(Constants.PaketNupkgDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteInfo("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paketnupkg"); WebRequestProxy.DownloadFile(url, tmpFile); string packageName = Path.GetFileName(url); var randomFullPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); FileSystemProxy.CreateDirectory(randomFullPath); string packagePath = Path.Combine(randomFullPath, packageName); FileSystemProxy.CopyFile(tmpFile, packagePath, true); FileSystemProxy.DeleteFile(tmpFile); var installAsTool = new InstallKind.InstallAsTool(FileSystemProxy); installAsTool.Run(randomFullPath, target, latestVersion); FileSystemProxy.DeleteDirectory(randomFullPath, true); }
public void SelfUpdate(string latestVersion) { var executingAssembly = Assembly.GetExecutingAssembly(); string exePath = executingAssembly.Location; var localVersion = FileSystemProxy.GetLocalFileVersion(exePath); if (localVersion.StartsWith(latestVersion)) { ConsoleImpl.WriteDebug("Bootstrapper is up to date. Nothing to do."); return; } var url = String.Format("https://github.com/fsprojects/Paket/releases/download/{0}/paket.bootstrapper.exe", latestVersion); ConsoleImpl.WriteDebug("Starting download of bootstrapper from {0}", url); string renamedPath = BootstrapperHelper.GetTempFile("oldBootstrapper"); string tmpDownloadPath = BootstrapperHelper.GetTempFile("newBootstrapper"); WebRequestProxy.DownloadFile(url, tmpDownloadPath); try { FileSystemProxy.MoveFile(exePath, renamedPath); FileSystemProxy.MoveFile(tmpDownloadPath, exePath); ConsoleImpl.WriteDebug("Self update of bootstrapper was successful."); } catch (Exception) { ConsoleImpl.WriteDebug("Self update failed. Resetting bootstrapper."); FileSystemProxy.MoveFile(renamedPath, exePath); throw; } }
internal static string GetLocalFileVersion(string target, FileSystemProxy fileSystemProxy) { if (!File.Exists(target)) { ConsoleImpl.WriteTrace("File doesn't exists, no version information: {0}", target); return(""); } try { var bytes = new MemoryStream(); using (var stream = fileSystemProxy.OpenRead(target)) { stream.CopyTo(bytes); } var attr = Assembly.Load(bytes.ToArray()).GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).Cast <AssemblyInformationalVersionAttribute>().FirstOrDefault(); if (attr == null) { ConsoleImpl.WriteWarning("No assembly version found in {0}", target); return(""); } return(attr.InformationalVersion); } catch (Exception exception) { ConsoleImpl.WriteWarning("Unable to get file version from {0}: {1}", target, exception); return(""); } }
static void Main(string[] args) { Console.CancelKeyPress += CancelKeyPressed; var fileProxy = new FileSystemProxy(); var argumentsFromDependenciesFile = WindowsProcessArguments.Parse( PaketDependencies.GetBootstrapperArgsForFolder(Environment.CurrentDirectory)); var options = ArgumentParser.ParseArgumentsAndConfigurations(args, ConfigurationManager.AppSettings, Environment.GetEnvironmentVariables(), fileProxy, argumentsFromDependenciesFile); if (options.ShowHelp) { ConsoleImpl.WriteDebug(BootstrapperHelper.HelpText); return; } ConsoleImpl.Silent = options.Silent; if (options.UnprocessedCommandArgs.Any()) { ConsoleImpl.WriteInfo("Ignoring the following unknown argument(s): {0}", String.Join(", ", options.UnprocessedCommandArgs)); } var effectiveStrategy = GetEffectiveDownloadStrategy(options.DownloadArguments, options.PreferNuget, options.ForceNuget); StartPaketBootstrapping(effectiveStrategy, options.DownloadArguments, fileProxy, () => OnSuccessfulDownload(options)); }
static void Main(string[] args) { executionWatch.Start(); Console.CancelKeyPress += CancelKeyPressed; var fileProxy = new FileSystemProxy(); var optionsBeforeDependenciesFile = ArgumentParser.ParseArgumentsAndConfigurations(args, ConfigurationManager.AppSettings, Environment.GetEnvironmentVariables(), fileProxy, Enumerable.Empty <string>()); ConsoleImpl.Verbosity = optionsBeforeDependenciesFile.Verbosity; var argumentsFromDependenciesFile = WindowsProcessArguments.Parse( PaketDependencies.GetBootstrapperArgsForFolder(fileProxy)); var options = ArgumentParser.ParseArgumentsAndConfigurations(args, ConfigurationManager.AppSettings, Environment.GetEnvironmentVariables(), fileProxy, argumentsFromDependenciesFile); if (options.ShowHelp) { ConsoleImpl.WriteAlways(BootstrapperHelper.HelpText); return; } ConsoleImpl.Verbosity = options.Verbosity; if (options.UnprocessedCommandArgs.Any()) { ConsoleImpl.WriteWarning("Ignoring the following unknown argument(s): {0}", String.Join(", ", options.UnprocessedCommandArgs)); } var effectiveStrategy = GetEffectiveDownloadStrategy(options.DownloadArguments, options.PreferNuget, options.ForceNuget); ConsoleImpl.WriteTrace("Using strategy: " + effectiveStrategy.Name); StartPaketBootstrapping(effectiveStrategy, options.DownloadArguments, fileProxy, () => OnSuccessfulDownload(options)); }
public IntegrationTests() { var fileSystem = new FileSystemProxy(); _sut = new App.Services.Marchive(new Archiver(fileSystem), fileSystem, A.Fake <ILogger <App.Services.Marchive> >(), new MArchiveSettings()); }
public TrinketProxyEgg() { streamFactory = new StreamFactory(); processProxy = new ProcessProxy(); var pofContext = new PofContext().With(x => { x.MergeContext(new DspPofContext()); x.MergeContext(new TrinketsApiPofContext()); x.MergeContext(new TrinketsImplPofContext()); }); ICollectionFactory collectionFactory = new CollectionFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); IThreadingProxy threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory()); var dnsProxy = new DnsProxy(); INetworkingProxy networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(dnsProxy), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(dnsProxy)); pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); ProxyGenerator proxyGenerator = new ProxyGenerator(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); // construct libdsp local service node ClusteringConfiguration clusteringConfiguration = new ClientClusteringConfiguration(); ServiceClient localServiceClient = serviceClientFactory.Construct(clusteringConfiguration); keepaliveObjects.Add(localServiceClient); temporaryFileService = localServiceClient.GetService<TemporaryFileService>(); var processInjector = new ProcessInjectorImpl(); ProcessInjectionConfiguration processInjectionConfiguration = new ProcessInjectionConfigurationImpl(injectionAttempts: 10, injectionAttemptsDelay: 200); processInjectionService = new ProcessInjectionServiceImpl(processInjector, processInjectionConfiguration); IDtpNodeFactory transportNodeFactory = new DefaultDtpNodeFactory(); BootstrapConfigurationGenerator bootstrapConfigurationGenerator = new BootstrapConfigurationGeneratorImpl(); trinketInternalUtilities = new TrinketInternalUtilitiesImpl(fileSystemProxy); trinketDtpServerFactory = new TrinketDtpServerFactoryImpl(streamFactory, transportNodeFactory, bootstrapConfigurationGenerator); }
public void Create() { var log = A.Fake <ILog>(); var proxy = new FileSystemProxy(log); Assert.NotNull(proxy); }
public void CombineTest() { var p1 = "c:/1"; var p2 = "a.txt"; var p = new FileSystemProxy(); var res = p.Combine(p1, p2); Assert.AreEqual(res, "c:/1\\a.txt"); }
public void CreateTempDirectoryTest() { var p = new FileSystemProxy(); var s = p.CreateTempEmptyFolder(); var b = Directory.Exists(s); Assert.IsTrue(b); Directory.Delete(s); }
internal async Task <Dictionary <string, TValue> > GetArchiveContentAsync <TValue>(string archivePath) { var fileText = await FileSystemProxy.ReadTextFromFileAsync(archivePath); var archiveFile = JsonConvert.DeserializeObject <ArchiveFile <TValue> >(fileText); var archiveContent = archiveFile.Content; return(archiveContent); }
public void ImportingTaskStart() { var temporaryDirectory = TemporaryFileService.AllocateTemporaryDirectory(TimeSpan.FromHours(1)); DirectoryHelpers.DirectoryCopy(Modification.RepositoryPath, temporaryDirectory, true); Directory.Move(temporaryDirectory, finalRepositoryPath); Modification = ModificationLoader.FromPath(finalRepositoryPath); PhaseFactory.SetModification(Modification); ViewModel.SetModification(Modification); var enabledComponent = Modification.GetComponent <EnabledComponent>(); enabledComponent.IsEnabled = true; var thumbnailDirectory = Path.Combine(finalRepositoryPath, "thumbnails"); FileSystemProxy.PrepareDirectory(thumbnailDirectory); var thumbnailGenerationTask = Task.Factory.StartNew(() => { using (var ms = new MemoryStream()) using (var writer = new BinaryWriter(ms)) { PofSerializer.Serialize(writer, new ThumbnailGenerationParameters { DestinationDirectory = thumbnailDirectory, SourceDirectory = importedDirectoryPath, ThumbnailsToGenerate = 3 }); ExeggutorService.SpawnHatchling( "thumbnail-generator", new SpawnConfiguration { InstanceName = "thumbnail-generator-" + DateTime.UtcNow.GetUnixTime(), Arguments = ms.GetBuffer() }); var thumbnailComponent = Modification.GetComponent <ThumbnailComponent>(); thumbnailComponent.SelectThumbnailIfUnselected(); } }, TaskCreationOptions.LongRunning); var contentDirectory = Path.Combine(finalRepositoryPath, "content"); FileSystemProxy.PrepareDirectory(contentDirectory); for (var i = 0; i < relativeImportedFilePaths.Length; i++) { var sourceFile = Path.Combine(importedDirectoryPath, relativeImportedFilePaths[i]); var destinationFile = Path.Combine(contentDirectory, relativeImportedFilePaths[i]); FileSystemProxy.PrepareParentDirectory(destinationFile); FileSystemProxy.CopyFile(sourceFile, destinationFile); UpdateProgress(0.333 * ((double)i / relativeImportedFilePaths.Length)); } LeagueBuildUtilities.ResolveModification(Modification, CancellationToken.None); UpdateProgress(0.666); LeagueBuildUtilities.CompileModification(Modification, CancellationToken.None); UpdateProgress(1); thumbnailGenerationTask.Wait(); PhaseManager.Transition(PhaseFactory.Idle()); }
public void DeleteDirTest() { var p = new FileSystemProxy(); var s = p.CreateTempEmptyFolder(); var b = Directory.Exists(s); Assert.IsTrue(b); p.DeleteDirectory(s); b = Directory.Exists(s); Assert.IsFalse(b); }
internal async Task <Dictionary <string, TValue> > GetLatestArchiveAsync <TValue>(string archiveNamePrefix) { var archiveFilesName = FileSystemProxy.EnumerateFiles(_archiveFolderPath, archiveNamePrefix + "*", SearchOption.AllDirectories) .OrderByDescending(x => ExtractDateTime(x, archiveNamePrefix)) .First(); var archiveContent = await GetArchiveContentAsync <TValue>(archiveFilesName); return(archiveContent); }
public CommonIOBaseClass() { fileSystem = FileSystemProxy.GetFileSystem( ConfigurationManager.AppSettings["FileSystemType"] == "AzureBlob" ? FileSystemTypes.AzureBlob : FileSystemTypes.SystemIO, AzureBlobConfiguration.GetAzureBlobSettings()); File = fileSystem.File; Directory = fileSystem.Directory; Path = fileSystem.Path; DriveInfo = fileSystem.DriveInfo; }
public void DownloadVersion(string latestVersion, string target) { var url = String.Format(Constants.PaketExeDownloadUrlTemplate, latestVersion); ConsoleImpl.WriteDebug("Starting download from {0}", url); var tmpFile = BootstrapperHelper.GetTempFile("paket"); WebRequestProxy.DownloadFile(url, tmpFile); FileSystemProxy.CopyFile(tmpFile, target, true); FileSystemProxy.DeleteFile(tmpFile); }
public void DeleteFileTest() { var p = new FileSystemProxy(); var s = p.CreateTempEmptyFolder(); var fname = p + "1.txt"; using (var f = File.CreateText(fname)) { } var b = File.Exists(fname); Assert.IsTrue(b); p.DeleteFile(fname); b = File.Exists(fname); Assert.IsFalse(b); Directory.Delete(s, true); }
/// <summary> /// Creates a new <see cref="FileSystemServer"/> and registers its services using the provided HOS client. /// </summary> /// <param name="horizonClient">The <see cref="HorizonClient"/> that will be used by this server.</param> /// <param name="config">The configuration for the created <see cref="FileSystemServer"/>.</param> public FileSystemServer(HorizonClient horizonClient, FileSystemServerConfig config) { if (config.FsCreators == null) { throw new ArgumentException("FsCreators must not be null"); } if (config.DeviceOperator == null) { throw new ArgumentException("DeviceOperator must not be null"); } Hos = horizonClient; IsDebugMode = false; ExternalKeySet externalKeySet = config.ExternalKeySet ?? new ExternalKeySet(); Timer = config.TimeSpanGenerator ?? new StopWatchTimeSpanGenerator(); var fspConfig = new FileSystemProxyConfiguration { FsCreatorInterfaces = config.FsCreators, ProgramRegistryServiceImpl = new ProgramRegistryServiceImpl(this) }; FsProxyCore = new FileSystemProxyCore(fspConfig, externalKeySet, config.DeviceOperator); FsProxyCore.SetSaveDataIndexerManager(new SaveDataIndexerManager(Hos.Fs, SaveIndexerId, new ArrayPoolMemoryResource(), new SdHandleManager(), false)); FileSystemProxy fsProxy = GetFileSystemProxyServiceObject(); fsProxy.SetCurrentProcess(Hos.Os.GetCurrentProcessId().Value).IgnoreResult(); fsProxy.CleanUpTemporaryStorage().IgnoreResult(); Hos.Sm.RegisterService(new FileSystemProxyService(this), "fsp-srv").IgnoreResult(); Hos.Sm.RegisterService(new FileSystemProxyForLoaderService(this), "fsp-ldr").IgnoreResult(); Hos.Sm.RegisterService(new ProgramRegistryService(this), "fsp-pr").IgnoreResult(); // NS usually takes care of this if (Hos.Fs.IsSdCardInserted()) { Hos.Fs.SetSdCardAccessibility(true); } }
internal void CreateArchive <TValue>(string archiveName, Dictionary <string, TValue> archive) { var archiveFile = new ArchiveFile <TValue> { Date = DateTime.UtcNow, TrainingProviderName = TrainingProviderName, Content = archive }; var fileName = Path.Combine(_archiveCurrentSaveDirectory, archiveName); var enumConverter = new StringEnumConverter { AllowIntegerValues = false, CamelCaseText = false }; FileSystemProxy.WriteTextToNewFile(fileName, JsonConvert.SerializeObject(archiveFile, Formatting.Indented, enumConverter)); }
public static void Main(string[] args) { Console.WindowWidth = Console.BufferWidth = 120; var streamFactory = new StreamFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); DargonNodeFactory dargonNodeFactory = new DargonNodeFactoryImpl(); var dispatcher = new DispatcherCommand("root"); dispatcher.RegisterCommand(new ExitCommand()); dispatcher.RegisterCommand(new LoadSolutionCommand(streamFactory, dargonNodeFactory)); dispatcher.RegisterCommand(new ChangeDirectoryCommand()); dispatcher.RegisterCommand(new ListDirectoryCommand()); dispatcher.RegisterCommand(new PrintWorkingDirectoryCommand()); dispatcher.RegisterCommand(new AliasCommand("dir", new ListDirectoryCommand())); dispatcher.RegisterCommand(new DumpCommand(fileSystemProxy)); dispatcher.RegisterCommand(new SetWindowWidthCommand()); dispatcher.Eval(LoadSolutionCommand.kLoadSolutionCommand + " " + (ConfigurationManager.AppSettings?["radsPath"] ?? "")); new ReplCore(dispatcher).Run(); }
internal async Task <Dictionary <string, TValue> > MergeArchivesAsync <TValue>(string archiveNamePrefix) { var archiveFilesNames = FileSystemProxy.EnumerateFiles(_archiveFolderPath, archiveNamePrefix + "*", SearchOption.AllDirectories) .OrderBy(x => ExtractDateTime(x, archiveNamePrefix)); var mergedArchivesContent = new Dictionary <string, TValue>(); foreach (var filesName in archiveFilesNames) { var archiveContent = await GetArchiveContentAsync <TValue>(filesName); foreach (var item in archiveContent) { mergedArchivesContent[item.Key] = item.Value; } } return(mergedArchivesContent); }
public void FindFilesInSubDirTest() { var p = new FileSystemProxy(); var dir = p.CreateTempEmptyFolder(); CreateFiles(dir); var subdir = Path.Combine(dir, "1"); Directory.CreateDirectory(subdir); CreateFiles(subdir+ "\\"); var result = p.FindFiles(dir, "*.txt", true).ToList(); Assert.AreEqual(result.Count, 4); var i1 = p.Combine(dir, "1.txt"); var i2 = p.Combine(dir, "2.txt"); var i3 = p.Combine(subdir, "1.txt"); var i4 = p.Combine(subdir, "2.txt"); Assert.IsTrue(result.Contains(i1)); Assert.IsTrue(result.Contains(i2)); Assert.IsTrue(result.Contains(i3)); Assert.IsTrue(result.Contains(i4)); Directory.Delete(dir, true); }
public void FindFilesNoSubDirTest() { var p = new FileSystemProxy(); var dir = p.CreateTempEmptyFolder(); CreateFiles(dir); var subdir = Path.Combine(dir, "1"); Directory.CreateDirectory(subdir); CreateFiles(subdir + "\\"); var result = p.FindFiles(dir, "*.txt", false).ToList(); Assert.AreEqual(result.Count, 2); var i1 = p.Combine(dir, "1.txt"); var i2 = p.Combine(dir, "2.txt"); Assert.IsTrue(result.Contains(i1)); Assert.IsTrue(result.Contains(i2)); Directory.Delete(dir, true); }
public TrinketProxyEgg() { streamFactory = new StreamFactory(); processProxy = new ProcessProxy(); var pofContext = new PofContext().With(x => { x.MergeContext(new DspPofContext()); x.MergeContext(new TrinketsApiPofContext()); x.MergeContext(new TrinketsImplPofContext()); }); ICollectionFactory collectionFactory = new CollectionFactory(); IFileSystemProxy fileSystemProxy = new FileSystemProxy(streamFactory); IThreadingProxy threadingProxy = new ThreadingProxy(new ThreadingFactory(), new SynchronizationFactory()); var dnsProxy = new DnsProxy(); INetworkingProxy networkingProxy = new NetworkingProxy(new SocketFactory(new TcpEndPointFactory(dnsProxy), new NetworkingInternalFactory(threadingProxy, streamFactory)), new TcpEndPointFactory(dnsProxy)); pofSerializer = new PofSerializer(pofContext); PofStreamsFactory pofStreamsFactory = new PofStreamsFactoryImpl(threadingProxy, streamFactory, pofSerializer); ProxyGenerator proxyGenerator = new ProxyGenerator(); var serviceClientFactory = new ServiceClientFactoryImpl(proxyGenerator, streamFactory, collectionFactory, threadingProxy, networkingProxy, pofSerializer, pofStreamsFactory); // construct libdsp local service node ClusteringConfiguration clusteringConfiguration = new ClientClusteringConfiguration(); ServiceClient localServiceClient = serviceClientFactory.Construct(clusteringConfiguration); keepaliveObjects.Add(localServiceClient); temporaryFileService = localServiceClient.GetService <TemporaryFileService>(); var processInjector = new ProcessInjectorImpl(); ProcessInjectionConfiguration processInjectionConfiguration = new ProcessInjectionConfigurationImpl(injectionAttempts: 10, injectionAttemptsDelay: 200); processInjectionService = new ProcessInjectionServiceImpl(processInjector, processInjectionConfiguration); IDtpNodeFactory transportNodeFactory = new DefaultDtpNodeFactory(); BootstrapConfigurationGenerator bootstrapConfigurationGenerator = new BootstrapConfigurationGeneratorImpl(); trinketInternalUtilities = new TrinketInternalUtilitiesImpl(fileSystemProxy); trinketDtpServerFactory = new TrinketDtpServerFactoryImpl(streamFactory, transportNodeFactory, bootstrapConfigurationGenerator); }
public MainWindow() { InitializeComponent(); fs = new Microsoft.VisualBasic.Devices.Computer().FileSystem; }
protected override void SelfUpdateCore(string latestVersion) { string target = Assembly.GetExecutingAssembly().Location; var localVersion = FileSystemProxy.GetLocalFileVersion(target); if (localVersion.StartsWith(latestVersion)) { ConsoleImpl.WriteInfo("Bootstrapper is up to date. Nothing to do."); return; } var apiHelper = new NugetApiHelper(PaketBootstrapperNugetPackageName, NugetSource); const string paketNupkgFile = "paket.bootstrapper.latest.nupkg"; const string paketNupkgFileTemplate = "paket.bootstrapper.{0}.nupkg"; var getLatestFromNugetUrl = apiHelper.GetLatestPackage(); var paketDownloadUrl = getLatestFromNugetUrl; var paketFile = paketNupkgFile; if (!String.IsNullOrWhiteSpace(latestVersion)) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); FileSystemProxy.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (FileSystemProxy.DirectoryExists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) { latestVersion = GetLatestVersion(false); } var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); ConsoleImpl.WriteInfo("Starting download from {0}", sourcePath); FileSystemProxy.CopyFile(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteInfo("Starting download from {0}", paketDownloadUrl); WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.bootstrapper.exe"); var renamedPath = BootstrapperHelper.GetTempFile("oldBootstrapper"); try { FileSystemProxy.MoveFile(target, renamedPath); FileSystemProxy.MoveFile(paketSourceFile, target); ConsoleImpl.WriteInfo("Self update of bootstrapper was successful."); } catch (Exception) { ConsoleImpl.WriteInfo("Self update failed. Resetting bootstrapper."); FileSystemProxy.MoveFile(renamedPath, target); throw; } FileSystemProxy.DeleteDirectory(randomFullPath, true); }
protected override void DownloadVersionCore(string latestVersion, string target) { var apiHelper = new NugetApiHelper(PaketNugetPackageName, NugetSource); const string paketNupkgFile = "paket.latest.nupkg"; const string paketNupkgFileTemplate = "paket.{0}.nupkg"; var paketDownloadUrl = apiHelper.GetLatestPackage(); var paketFile = paketNupkgFile; if (!String.IsNullOrWhiteSpace(latestVersion)) { paketDownloadUrl = apiHelper.GetSpecificPackageVersion(latestVersion); paketFile = String.Format(paketNupkgFileTemplate, latestVersion); } var randomFullPath = Path.Combine(Folder, Path.GetRandomFileName()); FileSystemProxy.CreateDirectory(randomFullPath); var paketPackageFile = Path.Combine(randomFullPath, paketFile); if (FileSystemProxy.DirectoryExists(NugetSource)) { if (String.IsNullOrWhiteSpace(latestVersion)) { latestVersion = GetLatestVersion(false); } var sourcePath = Path.Combine(NugetSource, String.Format(paketNupkgFileTemplate, latestVersion)); ConsoleImpl.WriteInfo("Starting download from {0}", sourcePath); FileSystemProxy.CopyFile(sourcePath, paketPackageFile); } else { ConsoleImpl.WriteInfo("Starting download from {0}", paketDownloadUrl); try { WebRequestProxy.DownloadFile(paketDownloadUrl, paketPackageFile); } catch (WebException webException) { if (webException.Status == WebExceptionStatus.ProtocolError && !string.IsNullOrEmpty(latestVersion)) { var response = (HttpWebResponse)webException.Response; if (response.StatusCode == HttpStatusCode.NotFound) { throw new WebException(String.Format("Version {0} wasn't found (404)", latestVersion), webException); } if (response.StatusCode == HttpStatusCode.BadRequest) { // For cases like "The package version is not a valid semantic version" throw new WebException(String.Format("Unable to get version '{0}': {1}", latestVersion, response.StatusDescription), webException); } } Console.WriteLine(webException.ToString()); throw; } } FileSystemProxy.ExtractToDirectory(paketPackageFile, randomFullPath); var paketSourceFile = Path.Combine(randomFullPath, "tools", "paket.exe"); FileSystemProxy.CopyFile(paketSourceFile, target, true); FileSystemProxy.DeleteDirectory(randomFullPath, true); }
public MultiCommitManager(FileSystemProxy fsProxy) { FsProxy = fsProxy; }
public DefaultProxyProvider() { FileSystemProxy = new FileSystemProxy(); EnvProxy = new EnvProxy(); WebRequestProxy = new WebRequestProxy(EnvProxy); }
static void Main(string[] args) { AppContext.SetSwitch("Switch.System.Net.DontEnableSystemDefaultTlsVersions", false); executionWatch.Start(); Console.CancelKeyPress += CancelKeyPressed; var fileProxy = new FileSystemProxy(); var appSettings = ConfigurationManager.AppSettings; var appConfigInWorkingDir = Path.Combine(Environment.CurrentDirectory, "paket.bootstrapper.exe.config"); if (File.Exists(appConfigInWorkingDir)) { var exeInWorkingDir = Path.Combine(Environment.CurrentDirectory, "paket.bootstrapper.exe"); var exeConf = ConfigurationManager.OpenExeConfiguration(null); if (exeConf != null) { var nv = new System.Collections.Specialized.NameValueCollection(); foreach (KeyValueConfigurationElement kv in exeConf.AppSettings.Settings) { nv.Add(kv.Key, kv.Value); } appSettings = nv; } } var optionsBeforeDependenciesFile = ArgumentParser.ParseArgumentsAndConfigurations(args, appSettings, Environment.GetEnvironmentVariables(), fileProxy, Enumerable.Empty <string>()); ConsoleImpl.Verbosity = optionsBeforeDependenciesFile.Verbosity; var argumentsFromDependenciesFile = WindowsProcessArguments.Parse( PaketDependencies.GetBootstrapperArgsForFolder(fileProxy)); var options = ArgumentParser.ParseArgumentsAndConfigurations(args, appSettings, Environment.GetEnvironmentVariables(), fileProxy, argumentsFromDependenciesFile); if (options.ShowHelp) { ConsoleImpl.WriteAlways(BootstrapperHelper.HelpText); return; } ConsoleImpl.Verbosity = options.Verbosity; if (options.UnprocessedCommandArgs.Any()) { ConsoleImpl.WriteWarning("Ignoring the following unknown argument(s): {0}", String.Join(", ", options.UnprocessedCommandArgs)); } #if PAKET_BOOTSTRAP_NO_CACHE ConsoleImpl.WriteTrace("Force ignore cache, because not implemented."); options.DownloadArguments.IgnoreCache = true; #endif var effectiveStrategy = GetEffectiveDownloadStrategy(options.DownloadArguments, options.PreferNuget, options.ForceNuget); ConsoleImpl.WriteTrace("Using strategy: " + effectiveStrategy.Name); ConsoleImpl.WriteTrace("Using install kind: " + (options.DownloadArguments.AsTool? "tool": "exe")); StartPaketBootstrapping(effectiveStrategy, options.DownloadArguments, fileProxy, () => OnSuccessfulDownload(options)); }