/// <summary> /// Uninstalls a package /// </summary> /// <param name="fastPackageReference"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> public void UninstallPackage(string fastPackageReference, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::UninstallPackage' '{1}'", PackageProviderName, fastPackageReference); var pkg = request.GetPackageByFastpath(fastPackageReference); request.UninstallPackage(pkg); }
/// <summary> /// </summary> /// <param name="fastPackageReference"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> public void InstallPackage(string fastPackageReference, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::InstallPackage' '{1}'", PackageProviderName, fastPackageReference); var pkgRef = request.GetPackageByFastpath(fastPackageReference); if (pkgRef == null) { request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage); return; } // need to make sure that the original package's sources list is tried first. request.OriginalSources = pkgRef.Sources; var dependencies = request.GetUninstalledPackageDependencies(pkgRef).Reverse().ToArray(); var progressId = 0; if (dependencies.Length > 0) { progressId = request.StartProgress(0, "Installing package '{0}'", pkgRef.GetCanonicalId(request)); } var n = 0; foreach (var d in dependencies) { request.Progress(progressId, (n * 100 / (dependencies.Length + 1)) + 1, "Installing dependent package '{0}'", d.GetCanonicalId(request)); if (!request.InstallSinglePackage(d)) { request.Error(ErrorCategory.InvalidResult, pkgRef.GetCanonicalId(request), Constants.Messages.DependentPackageFailedInstall, d.GetCanonicalId(request)); return; } n++; request.Progress(progressId, (n * 100 / (dependencies.Length + 1)), "Installed dependent package '{0}'", d.GetCanonicalId(request)); } // got this far, let's install the package we came here for. if (!request.InstallSinglePackage(pkgRef)) { // package itself didn't install. // roll that back out everything we did install. // and get out of here. request.Error(ErrorCategory.InvalidResult, pkgRef.GetCanonicalId(request), Constants.Messages.PackageFailedInstall, pkgRef.GetCanonicalId(request)); request.CompleteProgress(progressId, false); } request.CompleteProgress(progressId, true); }
/// <summary> /// Downloads a remote package file to a local location. /// </summary> /// <param name="fastPackageReference"></param> /// <param name="location"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> /// <returns></returns> public void DownloadPackage(string fastPackageReference, string location, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::DownloadPackage' '{1}','{2}'", PackageProviderName, fastPackageReference, location); var pkgRef = request.GetPackageByFastpath(fastPackageReference); if (pkgRef == null) { request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage); return; } // cheap and easy copy to location. using (var input = pkgRef.Package.GetStream()) { using (var output = new FileStream(location, FileMode.Create, FileAccess.Write, FileShare.Read)) { input.CopyTo(output); } } }
/// <summary> /// Uninstalls a package /// </summary> /// <param name="fastPackageReference"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> public void UninstallPackage(string fastPackageReference, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::UninstallPackage' '{1}'", PackageProviderName, fastPackageReference); var pkg = request.GetPackageByFastpath(fastPackageReference); request.UninstallPackage(pkg); }
/// <summary> /// </summary> /// <param name="fastPackageReference"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> public void InstallPackage(string fastPackageReference, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::InstallPackage' '{1}'", PackageProviderName, fastPackageReference); var pkgRef = request.GetPackageByFastpath(fastPackageReference); if (pkgRef == null) { request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage); return; } // need to make sure that the original package's sources list is tried first. request.OriginalSources = pkgRef.Sources; var dependencies = request.GetUninstalledPackageDependencies(pkgRef).Reverse().ToArray(); var progressId = 0; if (dependencies.Length > 0) { progressId = request.StartProgress(0, "Installing package '{0}'", pkgRef.GetCanonicalId(request)); } var n = 0; foreach (var d in dependencies) { request.Progress(progressId, (n*100/(dependencies.Length + 1)) + 1, "Installing dependent package '{0}'", d.GetCanonicalId(request)); if (!request.InstallSinglePackage(d)) { request.Error(ErrorCategory.InvalidResult, pkgRef.GetCanonicalId(request), Constants.Messages.DependentPackageFailedInstall, d.GetCanonicalId(request)); return; } n++; request.Progress(progressId, (n*100/(dependencies.Length + 1)), "Installed dependent package '{0}'", d.GetCanonicalId(request)); } // got this far, let's install the package we came here for. if (!request.InstallSinglePackage(pkgRef)) { // package itself didn't install. // roll that back out everything we did install. // and get out of here. request.Error(ErrorCategory.InvalidResult, pkgRef.GetCanonicalId(request), Constants.Messages.PackageFailedInstall, pkgRef.GetCanonicalId(request)); request.CompleteProgress(progressId, false); } request.CompleteProgress(progressId, true); }
/// <summary> /// Downloads a remote package file to a local location. /// </summary> /// <param name="fastPackageReference"></param> /// <param name="location"></param> /// <param name="request"> /// An object passed in from the CORE that contains functions that can be used to interact with the /// CORE and HOST /// </param> /// <returns></returns> public void DownloadPackage(string fastPackageReference, string location, ChocolateyRequest request) { // Nice-to-have put a debug message in that tells what's going on. request.Debug("Calling '{0}::DownloadPackage' '{1}','{2}'", PackageProviderName, fastPackageReference, location); var pkgRef = request.GetPackageByFastpath(fastPackageReference); if (pkgRef == null) { request.Error(ErrorCategory.InvalidArgument, fastPackageReference, Constants.Messages.UnableToResolvePackage); return; } // cheap and easy copy to location. using (var input = pkgRef.Package.GetStream()) { using (var output = new FileStream(location, FileMode.Create, FileAccess.Write, FileShare.Read)) { input.CopyTo(output); } } }