public void save_package_information(ChocolateyPackageInformation packageInformation) { _fileSystem.create_directory_if_not_exists(ApplicationParameters.ChocolateyPackageInfoStoreLocation); _fileSystem.ensure_file_attribute_set(ApplicationParameters.ChocolateyPackageInfoStoreLocation, FileAttributes.Hidden); if (packageInformation.Package == null) { this.Log().Debug("No package information to save as package is null."); return; } var pkgStorePath = _fileSystem.combine_paths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".format_with(packageInformation.Package.Id, packageInformation.Package.Version.to_string())); _fileSystem.create_directory_if_not_exists(pkgStorePath); if (packageInformation.RegistrySnapshot != null) { _registryService.save_to_file(packageInformation.RegistrySnapshot, _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE)); } if (packageInformation.FilesSnapshot != null) { _filesService.save_to_file(packageInformation.FilesSnapshot, _fileSystem.combine_paths(pkgStorePath, FILES_SNAPSHOT_FILE)); } if (!string.IsNullOrWhiteSpace(packageInformation.Arguments)) { var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE); if (_fileSystem.file_exists(argsFile)) { _fileSystem.delete_file(argsFile); } _fileSystem.write_file(argsFile, packageInformation.Arguments); } if (packageInformation.HasSilentUninstall) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII); } if (packageInformation.IsSideBySide) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); } if (packageInformation.IsPinned) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE)); } }
public IPackage download_package(string packageId, string packageVersion, string downloadLocation, IConfigurationSettings configuration) { var version = new SemanticVersion(0, 0, 0, 0); if (!string.IsNullOrWhiteSpace(packageVersion)) { version = new SemanticVersion(packageVersion); } var packageManager = get_package_manager(downloadLocation, configuration); this.Log().Debug(() => "Searching for {0} v{1} to install from {2}.".format_with(packageId, version.to_string(), packageManager.SourceRepository.Source)); IPackage availablePackage = packageManager.SourceRepository.FindPackage(packageId, version, allowPrereleaseVersions: true, allowUnlisted: true); if (availablePackage == null) { //todo: do something here } this.Log().Debug(() => "Installing {0} v{1} from {2}.".format_with(packageId, version.to_string(), packageManager.SourceRepository.Source)); packageManager.InstallPackage(availablePackage, ignoreDependencies: true, allowPrereleaseVersions: true); var cachePackage = _fileSystem.combine_paths(Environment.GetEnvironmentVariable("LocalAppData"), "NuGet", "Cache", "{0}.{1}.nupkg".format_with(packageId, version.to_string())); if (_fileSystem.file_exists(cachePackage)) { _fileSystem.delete_file(cachePackage); } this.Log().Debug(() => "Returning {0} v{1} package.".format_with(packageId, version.to_string())); return(packageManager.LocalRepository.FindPackage(packageId, version, allowPrereleaseVersions: true, allowUnlisted: true)); }
public static IPackage BuildPackage(PackageBuilder builder, IFileSystem fileSystem, string outputPath = null) { ExcludeFiles(builder.Files); // Track if the package file was already present on disk bool isExistingPackage = fileSystem.file_exists(outputPath); try { using (Stream stream = fileSystem.create_file(outputPath)) { // Truncate if needed, as Mono fails to truncate if (stream.Length > 0) { stream.SetLength(0); } builder.Save(stream); } } catch { if (!isExistingPackage && fileSystem.file_exists(outputPath)) { fileSystem.delete_file(outputPath); } throw; } return(new OptimizedZipPackage(outputPath)); }
public void save_package_information(ChocolateyPackageInformation packageInformation) { _fileSystem.create_directory_if_not_exists(ApplicationParameters.ChocolateyPackageInfoStoreLocation); _fileSystem.ensure_file_attribute_set(ApplicationParameters.ChocolateyPackageInfoStoreLocation, FileAttributes.Hidden); var pkgStorePath = _fileSystem.combine_paths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".format_with(packageInformation.Package.Id, packageInformation.Package.Version.to_string())); _fileSystem.create_directory_if_not_exists(pkgStorePath); if (packageInformation.RegistrySnapshot != null) { _registryService.save_to_file(packageInformation.RegistrySnapshot, _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE)); } if (packageInformation.HasSilentUninstall) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII); } if (packageInformation.IsSideBySide) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); } if (packageInformation.IsPinned) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE)); } }
public static IPackage BuildPackage(PackageBuilder builder, IFileSystem fileSystem, string outputPath = null) { ExcludeFiles(builder.Files); // Track if the package file was already present on disk bool isExistingPackage = fileSystem.file_exists(outputPath); try { using (Stream stream = fileSystem.create_file(outputPath)) { builder.Save(stream); } } catch { if (!isExistingPackage && fileSystem.file_exists(outputPath)) { fileSystem.delete_file(outputPath); } throw; } return new OptimizedZipPackage(outputPath); }
public void save_package_information(ChocolateyPackageInformation packageInformation) { _fileSystem.create_directory_if_not_exists(ApplicationParameters.ChocolateyPackageInfoStoreLocation); _fileSystem.ensure_file_attribute_set(ApplicationParameters.ChocolateyPackageInfoStoreLocation, FileAttributes.Hidden); if (packageInformation.Package == null) { this.Log().Debug("No package information to save as package is null."); return; } var pkgStorePath = _fileSystem.combine_paths(ApplicationParameters.ChocolateyPackageInfoStoreLocation, "{0}.{1}".format_with(packageInformation.Package.Id, packageInformation.Package.Version.to_string())); _fileSystem.create_directory_if_not_exists(pkgStorePath); if (packageInformation.RegistrySnapshot != null) { _registryService.save_to_file(packageInformation.RegistrySnapshot, _fileSystem.combine_paths(pkgStorePath, REGISTRY_SNAPSHOT_FILE)); } if (packageInformation.FilesSnapshot != null) { FaultTolerance.try_catch_with_logging_exception( () => { _filesService.save_to_file(packageInformation.FilesSnapshot, _fileSystem.combine_paths(pkgStorePath, FILES_SNAPSHOT_FILE)); }, "Unable to save files snapshot", throwError: false, logWarningInsteadOfError: true ); } if (!string.IsNullOrWhiteSpace(packageInformation.Arguments)) { var argsFile = _fileSystem.combine_paths(pkgStorePath, ARGS_FILE); if (_fileSystem.file_exists(argsFile)) { _fileSystem.delete_file(argsFile); } _fileSystem.write_file(argsFile, packageInformation.Arguments); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, ARGS_FILE)); } if (!string.IsNullOrWhiteSpace(packageInformation.ExtraInformation)) { var extraFile = _fileSystem.combine_paths(pkgStorePath, EXTRA_FILE); if (_fileSystem.file_exists(extraFile)) { _fileSystem.delete_file(extraFile); } _fileSystem.write_file(extraFile, packageInformation.ExtraInformation); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, EXTRA_FILE)); } if (packageInformation.VersionOverride != null) { var versionOverrideFile = _fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE); if (_fileSystem.file_exists(versionOverrideFile)) { _fileSystem.delete_file(versionOverrideFile); } _fileSystem.write_file(versionOverrideFile, packageInformation.VersionOverride.to_string()); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, VERSION_OVERRIDE_FILE)); } if (packageInformation.HasSilentUninstall) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SILENT_UNINSTALLER_FILE), string.Empty, Encoding.ASCII); } if (packageInformation.IsSideBySide) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, SIDE_BY_SIDE_FILE)); } if (packageInformation.IsPinned) { _fileSystem.write_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE), string.Empty, Encoding.ASCII); } else { _fileSystem.delete_file(_fileSystem.combine_paths(pkgStorePath, PIN_FILE)); } }