From 14d65f7a58dceb1dd0782a31e421289988d87e10 Mon Sep 17 00:00:00 2001 From: Bastian Eicher Date: Wed, 2 Oct 2024 09:57:26 +0200 Subject: [PATCH] Removed OneGet support --- src/OneGet.Bootstrap/0install.psd1 | 19 - .../BootstrapPackageProvider.cs | 19 - src/OneGet.Bootstrap/OneGet.Bootstrap.csproj | 38 -- .../OneGet.Bootstrap.csproj.DotSettings | 2 - .../OneGetBootstrapHandler.cs | 21 -- .../OneGetContextInterceptor.cs | 101 ------ src/OneGet.Bootstrap/PowerShell.nuspec | 30 -- src/OneGet/IOneGetContext.cs | 23 -- src/OneGet/OneGet.csproj | 16 - src/OneGet/OneGetContext.cs | 332 ------------------ src/OneGet/OneGetHandler.cs | 58 --- src/OneGet/OneGetProgress.cs | 50 --- src/OneGet/PackageProvider.cs | 17 - src/OneGet/PackageProviderBase.cs | 198 ----------- src/OneGet/Sdk/Constants.cs | 106 ------ src/OneGet/Sdk/ErrorCategory.cs | 52 --- src/OneGet/Sdk/Request.cs | 308 ---------------- src/OneGet/Sdk/_Namespace.md | 5 - src/OneGet/_Namespace.md | 5 - src/OneGet/provider.manifest | 8 - src/ZeroInstall.Windows.sln | 4 - src/ZeroInstall.Windows.sln.DotSettings | 4 +- 22 files changed, 1 insertion(+), 1415 deletions(-) delete mode 100644 src/OneGet.Bootstrap/0install.psd1 delete mode 100644 src/OneGet.Bootstrap/BootstrapPackageProvider.cs delete mode 100644 src/OneGet.Bootstrap/OneGet.Bootstrap.csproj delete mode 100644 src/OneGet.Bootstrap/OneGet.Bootstrap.csproj.DotSettings delete mode 100644 src/OneGet.Bootstrap/OneGetBootstrapHandler.cs delete mode 100644 src/OneGet.Bootstrap/OneGetContextInterceptor.cs delete mode 100644 src/OneGet.Bootstrap/PowerShell.nuspec delete mode 100644 src/OneGet/IOneGetContext.cs delete mode 100644 src/OneGet/OneGet.csproj delete mode 100644 src/OneGet/OneGetContext.cs delete mode 100644 src/OneGet/OneGetHandler.cs delete mode 100644 src/OneGet/OneGetProgress.cs delete mode 100644 src/OneGet/PackageProvider.cs delete mode 100644 src/OneGet/PackageProviderBase.cs delete mode 100644 src/OneGet/Sdk/Constants.cs delete mode 100644 src/OneGet/Sdk/ErrorCategory.cs delete mode 100644 src/OneGet/Sdk/Request.cs delete mode 100644 src/OneGet/Sdk/_Namespace.md delete mode 100644 src/OneGet/_Namespace.md delete mode 100644 src/OneGet/provider.manifest diff --git a/src/OneGet.Bootstrap/0install.psd1 b/src/OneGet.Bootstrap/0install.psd1 deleted file mode 100644 index 3ed390b41f..0000000000 --- a/src/OneGet.Bootstrap/0install.psd1 +++ /dev/null @@ -1,19 +0,0 @@ -@{ - ModuleVersion = '1.0.0' - GUID = '89e16ee9-f9dd-4efd-b7a2-e0374958f6c0' - Author = 'Bastian Eicher' - CompanyName = '0install.net' - Copyright = 'Copyright Bastian Eicher et al.' - Description = 'Zero Install is a decentralized cross-platform software-installation system.' - PowerShellVersion = '3.0' - FunctionsToExport = @() - #RequiredModules = @('PackageManagement') - FileList = @('0install.dll') - PrivateData = @{ - PackageManagementProviders = '0install.dll' - PSData = @{ - Tags = @("PackageManagement","Provider") - ProjectUri = 'https://0install.net' - } - } -} diff --git a/src/OneGet.Bootstrap/BootstrapPackageProvider.cs b/src/OneGet.Bootstrap/BootstrapPackageProvider.cs deleted file mode 100644 index 9c06ccc992..0000000000 --- a/src/OneGet.Bootstrap/BootstrapPackageProvider.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using LinFu.DynamicProxy; -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// A OneGet package provider that bootstraps/deploys Zero Install. -/// -public class BootstrapPackageProvider : PackageProviderBase -{ - public override string PackageProviderName => "0install"; - - /// - protected override IOneGetContext BuildContext(Request request) => - new ProxyFactory().CreateProxy(new OneGetContextInterceptor(request)); -} diff --git a/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj b/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj deleted file mode 100644 index 67f7974774..0000000000 --- a/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - ZeroInstall.OneGet - ZeroInstall.OneGet.Bootstrap - Downloads and proxies to the Zero Install OneGet Provider. - Library - bin\$(Configuration)\ - - - - - - - - - - - - - - - - - - - - - - - pushd "$(OutDir)" -"$(ILRepack)" /targetplatform:v4 /ndebug /union /noRepackRes /wildcards /out:"$(TargetDir)0install.dll" "$(TargetPath)" 0install.exe ZeroInstall.*.dll Generator.Equals.Runtime.dll NanoByte.Common.dll System.Buffers.dll System.Memory.dll System.Runtime.*.dll System.Threading.*.dll Microsoft.Bcl.HashCode.dll Newtonsoft.Json.dll INIFileParser.dll BouncyCastle.OpenPgp.dll ICSharpCode.SharpZipLib.dll NDesk.Options.dll LinFu.DynamicProxy.dll -popd - - - diff --git a/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj.DotSettings b/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj.DotSettings deleted file mode 100644 index 392ac44b72..0000000000 --- a/src/OneGet.Bootstrap/OneGet.Bootstrap.csproj.DotSettings +++ /dev/null @@ -1,2 +0,0 @@ - - True \ No newline at end of file diff --git a/src/OneGet.Bootstrap/OneGetBootstrapHandler.cs b/src/OneGet.Bootstrap/OneGetBootstrapHandler.cs deleted file mode 100644 index de25bd77a1..0000000000 --- a/src/OneGet.Bootstrap/OneGetBootstrapHandler.cs +++ /dev/null @@ -1,21 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Manages communication between s and a OneGet during the bootstrap process. -/// -public class OneGetBootstrapHandler(Request request) : OneGetHandler(request), IBootstrapHandler -{ - /// - public bool IsGui => false; - - /// - public bool Background { get => false; set {} } - - /// - public string? GetCustomStorePath(bool machineWide, string? currentPath) => currentPath; -} diff --git a/src/OneGet.Bootstrap/OneGetContextInterceptor.cs b/src/OneGet.Bootstrap/OneGetContextInterceptor.cs deleted file mode 100644 index c3ee6b2e07..0000000000 --- a/src/OneGet.Bootstrap/OneGetContextInterceptor.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using System.Reflection; -using LinFu.DynamicProxy; -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Forwards requests to an implementation from a deployed or cached Zero Install instance. -/// -/// The OneGet request interface to pass to the constructor of the target implementation. -public class OneGetContextInterceptor(Request request) : IInterceptor -{ - private object? _context; - - // NOTE: Static/shared lock, to avoid multiple deployments being started in parallel - private static readonly object _initLock = new(); - - public object Intercept(InvocationInfo info) - { - #region Sanity checks - if (info == null) throw new ArgumentNullException(nameof(info)); - #endregion - - // Double-checked locking - if (_context == null) - { - lock (_initLock) - { - _context ??= InitExternalContext(); - } - } - - request.Debug("Forwarding to other Zero Install instance: {0}", info.TargetMethod.Name); - return DuckType(_context, info); - } - - /// - /// Initializes an loaded from an external OneGet provider assembly. - /// - private object InitExternalContext() - { - string providerDirectory = GetProviderDirectory(); - request.Verbose("Loading Zero Install OneGet provider from {0}", providerDirectory); - - var assembly = Assembly.LoadFrom(Path.Combine(providerDirectory, "ZeroInstall.OneGet.dll")); - var requestType = assembly.GetType("PackageManagement.Sdk.Request", throwOnError: true); - var requestProxy = new ProxyFactory().CreateProxy(requestType, new RequestInterceptor(request)); - var contextType = assembly.GetType("ZeroInstall.OneGet.OneGetContext", throwOnError: true); - return Activator.CreateInstance(contextType, requestProxy); - } - - /// - /// Gets the path of the directory to load the Zero Install OneGet provider assembly from. - /// - /// The full path of the directory containing the provider assembly. - private string GetProviderDirectory() - { - using var handler = new OneGetBootstrapHandler(request); - var bootstrap = new BootstrapProcess(handler); - var startInfo = bootstrap.ZeroInstallDeployed([]) ?? bootstrap.ZeroInstallCached([]); - return Path.GetDirectoryName(startInfo.FileName)!; - } - - /// - /// Duck-types from to an external type with the same method signatures. - /// - private class RequestInterceptor : IInterceptor - { - private readonly Request _request; - - public RequestInterceptor(Request request) - { - _request = request; - } - - public object Intercept(InvocationInfo info) => DuckType(_request, info); - } - - /// - /// Forwards a method invocation to a using duck-typing. - /// - private static object DuckType(object target, InvocationInfo info) - { - var method = target.GetType().GetMethod( - info.TargetMethod.Name, - info.TargetMethod.GetParameters().Select(x => x.ParameterType).ToArray()); - if (method == null) throw new InvalidOperationException("Unable to find suitable method for duck-typing: " + info.TargetMethod.Name); - - try - { - return method.Invoke(target, info.Arguments); - } - catch (TargetInvocationException ex) when (ex.InnerException != null) - { - throw ex.InnerException.Rethrow(); - } - } -} diff --git a/src/OneGet.Bootstrap/PowerShell.nuspec b/src/OneGet.Bootstrap/PowerShell.nuspec deleted file mode 100644 index 0c61f53aad..0000000000 --- a/src/OneGet.Bootstrap/PowerShell.nuspec +++ /dev/null @@ -1,30 +0,0 @@ - - - - 0install - Zero Install OneGet Provider - $version$ - Bastian Eicher - bastian.eicher - false - LGPL-3.0-or-later - https://0install.net/ - icon.png - https://raw.githubusercontent.com/0install/0install-win/master/icon.png - OneGet Package Provider for Zero Install - This installs the OneGet Package Provider for Zero Install, a decentralized cross-distribution software installation system. - -Zero Install is a decentralized cross-platform software-installation system available under the LGPL. It allows software developers to publish programs directly from their own web-sites, while supporting features familiar from centralized distribution repositories such as shared libraries, automatic updates and digital signatures. It is intended to complement, rather than replace, the operating system’s package management. 0install packages never interfere with those provided by the distribution. - -Zero Install does not define a new packaging format; unmodified tarballs or zip archives can be used. Instead, it defines an [XML metadata format](https://docs.0install.net/specifications/feed/) to describe these packages and the dependencies between them. A single metadata file can be used on multiple platforms (e.g. Windows, Ubuntu, Debian, Fedora, FreeBSD and Mac OS X). - -Zero Install also has some interesting features not often found in traditional package managers. For example, while it will share libraries whenever possible, it can always install multiple versions of a package in parallel when there are conflicting requirements. Installation is always side-effect-free (each package is unpacked to its own directory and will not touch shared directories), making it ideal for use with sandboxing technologies and virtualization. - Copyright Bastian Eicher et al. - PackageManagement Provider PSModule - - - - - - - diff --git a/src/OneGet/IOneGetContext.cs b/src/OneGet/IOneGetContext.cs deleted file mode 100644 index c04d5de28e..0000000000 --- a/src/OneGet/IOneGetContext.cs +++ /dev/null @@ -1,23 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Provides an execution context for handling a single OneGet . -/// -public interface IOneGetContext : IDisposable -{ - void AddPackageSource(string uri); - void RemovePackageSource(string uri); - void ResolvePackageSources(); - void FindPackage(string? name, string? requiredVersion, string? minimumVersion, string? maximumVersion); - void FindPackageBy(string identifier); - void GetInstalledPackages(string? name); - void DownloadPackage(string fastPackageReference, string location); - void InstallPackage(string fastPackageReference); - void UninstallPackage(string fastPackageReference); - void GetPackageDetails(string fastPackageReference); -} diff --git a/src/OneGet/OneGet.csproj b/src/OneGet/OneGet.csproj deleted file mode 100644 index 7780f83d3a..0000000000 --- a/src/OneGet/OneGet.csproj +++ /dev/null @@ -1,16 +0,0 @@ - - - - - ZeroInstall.OneGet - ZeroInstall.OneGet - Implements a OneGet Provider for Zero Install, exposing package installation functionality. - Library - ..\..\artifacts\$(Configuration)\ - - - - - - - diff --git a/src/OneGet/OneGetContext.cs b/src/OneGet/OneGetContext.cs deleted file mode 100644 index 429714be0d..0000000000 --- a/src/OneGet/OneGetContext.cs +++ /dev/null @@ -1,332 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using NanoByte.Common.Native; -using PackageManagement.Sdk; -using ZeroInstall.Commands; -using ZeroInstall.Commands.Basic.Exporters; -using ZeroInstall.Commands.Desktop; -using ZeroInstall.Commands.Properties; -using ZeroInstall.DesktopIntegration; -using ZeroInstall.Model.Preferences; -using ZeroInstall.Model.Selection; -using ZeroInstall.Services; -using ZeroInstall.Services.Feeds; -using ZeroInstall.Services.Solvers; -using ZeroInstall.Store.Feeds; - -namespace ZeroInstall.OneGet; - -/// -/// Provides an execution context for handling a single OneGet . -/// -/// The OneGet request callback object. -public sealed class OneGetContext(Request request) : ScopedOperation(new OneGetHandler(request)), IOneGetContext -{ - /// - public void Dispose() => Handler.Dispose(); - - private bool Refresh => request.OptionKeys.Contains("Refresh"); - private bool AllVersions => request.OptionKeys.Contains("AllVersions"); - private bool GlobalSearch => request.OptionKeys.Contains("GlobalSearch"); - private bool DeferDownload => request.OptionKeys.Contains("DeferDownload"); - private bool MachineWide => StringUtils.EqualsIgnoreCase(request.GetOptionValue("Scope"), "AllUsers"); - - public void AddPackageSource(string uri) - { - var feedUri = new FeedUri(uri); - - CatalogManager.DownloadCatalog(feedUri); - - if (CatalogManager.AddSource(feedUri)) - CatalogManager.TryGetOnline(); - else - Log.Warn(string.Format(Resources.CatalogAlreadyRegistered, feedUri.ToStringRfc())); - } - - public void RemovePackageSource(string uri) - { - var feedUri = new FeedUri(uri); - - if (!CatalogManager.RemoveSource(feedUri)) - Log.Warn(string.Format(Resources.CatalogNotRegistered, feedUri.ToStringRfc())); - } - - public void ResolvePackageSources() - { - var registeredSources = CatalogManager.GetSources(); - - if (request.Sources.Any()) - { - foreach (var uri in request.Sources.TrySelect(x => new FeedUri(x), (UriFormatException _) => {})) - { - bool isRegistered = registeredSources.Contains(uri); - request.YieldPackageSource(uri.ToStringRfc(), uri.ToStringRfc(), isTrusted: isRegistered, isRegistered: isRegistered, isValidated: false); - } - } - else - { - foreach (var uri in registeredSources) - request.YieldPackageSource(uri.ToStringRfc(), uri.ToStringRfc(), isTrusted: true, isRegistered: true, isValidated: false); - } - } - - public void FindPackage(string? name, string? requiredVersion, string? minimumVersion, string? maximumVersion) - { - FeedManager.Refresh = Refresh; - - VersionRange versionRange; - if (requiredVersion != null) versionRange = new VersionRange(requiredVersion); - else if (minimumVersion != null || maximumVersion != null) - { - var constraint = new Constraint(); - if (minimumVersion != null) constraint.NotBefore = new ImplementationVersion(minimumVersion); - if (maximumVersion != null) constraint.Before = new ImplementationVersion(maximumVersion); - versionRange = constraint; - } - else versionRange = null; - - if (GlobalSearch) MirrorSearch(name, versionRange); - else CatalogSearch(name, versionRange); - } - - private void MirrorSearch(string? name, VersionRange? versionRange) - { - foreach (var result in SearchResults.Query(Config, name)) - { - var requirements = new Requirements(result.Uri); - if (versionRange != null) requirements.ExtraRestrictions[requirements.InterfaceUri] = versionRange; - Yield(requirements, result.ToPseudoFeed()); - } - } - - private void CatalogSearch(string? name, VersionRange? versionRange) - { - foreach (var feed in GetCatalogResults(name)) - { - if (AllVersions) - { - foreach (var implementation in FeedManager.GetFresh(feed.Uri).Implementations) - { - var requirements = new Requirements(feed.Uri) {ExtraRestrictions = {{feed.Uri, implementation.Version}}}; - Yield(requirements, feed, implementation); - } - } - else - { - var requirements = new Requirements(feed.Uri); - if (versionRange != null) requirements.ExtraRestrictions[requirements.InterfaceUri] = versionRange; - Yield(requirements, feed); - } - } - } - - private IEnumerable GetCatalogResults(string? query) - { - if (string.IsNullOrEmpty(query)) - { - Log.Info("Returning entire catalog"); - return CatalogManager.Get().Feeds; - } - - Log.Info("Searching for short-name match in Catalog: " + query); - if (FindByShortName(query) is {} feed) return [feed]; - - Log.Info("Searching for partial match in Catalog: " + query); - return CatalogManager.Get().Search(query); - } - - public void FindPackageBy(string identifier) - { - FeedManager.Refresh = Refresh; - Yield(new Requirements(GetCanonicalUri(identifier))); - } - - public void GetInstalledPackages(string name) - { - var appList = AppList.LoadSafe(MachineWide); - foreach (var entry in appList.Search(name)) - Yield(entry.EffectiveRequirements); - } - - public void DownloadPackage(string fastPackageReference, string location) - { - var requirements = ParseReference(fastPackageReference); - var selections = Solve(requirements); - foreach (var implementation in SelectionsManager.GetUncachedImplementations(selections)) - Fetcher.Fetch(implementation); - - var exporter = new Exporter(selections, requirements.Architecture, location); - exporter.ExportFeeds(FeedCache, OpenPgp); - exporter.ExportImplementations(ImplementationStore, Handler); - if (FeedCache.GetFeed(requirements.InterfaceUri) is {} feed) - { - exporter.ExportIcons( - [..feed.Icons, ..feed.SplashScreens], - IconStores.DesktopIntegration(Config, Handler, machineWide: false)); - } - exporter.DeployImportScript(); - - Yield(requirements); - - BackgroundSelfUpdate(); - } - - public void InstallPackage(string fastPackageReference) - { - var requirements = ParseReference(fastPackageReference); - try - { - Install(requirements); - BackgroundSelfUpdate(); - } - catch (UnsuitableInstallBaseException ex) - { - string installLocation = ZeroInstallDeployment.FindOther(ex.NeedsMachineWide) - ?? DeployInstance(ex.NeedsMachineWide); - - // Since we cannot another copy of Zero Install from a different location into the same AppDomain, simply pretend we are running from a different source - Locations.OverrideInstallBase(installLocation); - Install(requirements); - } - } - - private void Install(Requirements requirements) - { - if (MachineWide && !WindowsUtils.IsAdministrator) throw new NotAdminException(Resources.MustBeAdminForMachineWide); - if (MachineWide && !ZeroInstallInstance.IsMachineWide) throw new UnsuitableInstallBaseException(Resources.NoMachineWideIntegrationFromPerUser, MachineWide); - if (!ZeroInstallInstance.IsDeployed) throw new UnsuitableInstallBaseException(Resources.NoIntegrationDeployRequired, MachineWide); - - FeedManager.Refresh = Refresh || !DeferDownload; - - var selections = Solve(requirements); - - ApplyIntegration(requirements); - ApplyVersionRestrictions(requirements, selections); - if (!DeferDownload) - { - foreach (var implementation in SelectionsManager.GetUncachedImplementations(selections)) - Fetcher.Fetch(implementation); - } - Yield(requirements); - } - - private Selections Solve(Requirements requirements) - { - var selections = Solver.Solve(requirements); - - if (FeedManager.ShouldRefresh || SelectionsManager.GetUncached(selections.Implementations).Any()) - { - FeedManager.Stale = false; - FeedManager.Refresh = true; - selections = Solver.Solve(requirements); - FeedManager.Refresh = false; - } - - try - { - selections.Name = FeedCache.GetFeed(selections.InterfaceUri).Name; - } - #region Error handling - catch (KeyNotFoundException) - { - // Fall back to using feed file name - selections.Name = selections.InterfaceUri.ToString().GetRightPartAtLastOccurrence('/'); - } - #endregion - - return selections; - } - - private void ApplyIntegration(Requirements requirements) - { - Log.Info(Resources.DesktopIntegrationApply); - var feed = FeedManager[requirements.InterfaceUri]; - using var integrationManager = new CategoryIntegrationManager(Config, Handler, MachineWide); - var appEntry = integrationManager.AddApp(new(requirements.InterfaceUri, feed)); - integrationManager.AddAccessPointCategories(appEntry, feed, CategoryIntegrationManager.StandardCategories); - } - - private static void ApplyVersionRestrictions(Requirements requirements, Selections selections) - { - if (requirements.ExtraRestrictions.Count == 0) return; - - // TODO - Log.Warn($"You have applied a version restriction to this app. Zero Install will continue to apply this restriction to any future updates. You will need to run '0install select --customize {requirements.InterfaceUri}' to undo this."); - - foreach (var (feedUri, _) in requirements.ExtraRestrictions) - { - var selection = selections.GetImplementation(feedUri); - if (selection != null) - { - var pref = FeedPreferences.LoadForSafe(feedUri); - pref.Implementations.Clear(); - pref[selection.ID].UserStability = Stability.Preferred; - pref.SaveFor(feedUri); - } - } - } - - /// - /// Deploys a Zero Install instance to this machine. - /// - /// true to deploy to a location for all users; false to deploy to a location for the current user only. - /// The director Zero Install was deployed to. - private string DeployInstance(bool machineWide) - { - string programFiles = machineWide - ? WindowsUtils.GetFolderPath(Environment.SpecialFolder.ProgramFiles) - : Path.Combine(WindowsUtils.GetFolderPath(Environment.SpecialFolder.ApplicationData), "Programs"); - string installLocation = Path.Combine(programFiles, "Zero Install"); - - Log.Info("Deploying Zero Install to " + installLocation); - using (var manager = new SelfManager(installLocation, Handler, machineWide)) - manager.Deploy(libraryMode: true); - - return installLocation; - } - - public void UninstallPackage(string fastPackageReference) - { - if (MachineWide && !WindowsUtils.IsAdministrator) throw new NotAdminException(Resources.MustBeAdminForMachineWide); - - var requirements = ParseReference(fastPackageReference); - - using var integrationManager = new IntegrationManager(Config, Handler, MachineWide); - integrationManager.RemoveApp(integrationManager.AppList[requirements.InterfaceUri]); - } - - public void GetPackageDetails(string fastPackageReference) - { - FeedManager.Refresh = true; - - var requirements = ParseReference(fastPackageReference); - Yield(requirements); - } - - private static Requirements ParseReference(string fastPackageReference) => JsonStorage.FromJsonString(fastPackageReference); - - private void Yield(Requirements requirements, Feed? feed = null, ImplementationBase? implementation = null) - { - EnsureAllowed(requirements.InterfaceUri); - - if (implementation == null) - { - var selections = Solver.TrySolve(requirements); - if (selections != null) implementation = selections.MainImplementation; - } - feed ??= FeedManager[requirements.InterfaceUri]; - - var sourceUri = feed.CatalogUri ?? feed.Uri; - request.YieldSoftwareIdentity( - fastPath: requirements.ToJsonString(), - name: feed.Name, - version: implementation?.Version?.ToString(), - versionScheme: null, - summary: feed.Summaries.GetBestLanguage(CultureInfo.CurrentUICulture), - source: sourceUri?.ToStringRfc(), - searchKey: feed.Name, - fullPath: null, - packageFileName: feed.Name); - } -} diff --git a/src/OneGet/OneGetHandler.cs b/src/OneGet/OneGetHandler.cs deleted file mode 100644 index bb5a280fe9..0000000000 --- a/src/OneGet/OneGetHandler.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Manages communication between s and a OneGet . -/// -public class OneGetHandler : CliTaskHandler -{ - private readonly Request _request; - - public OneGetHandler(Request request) - { - _request = request; - - Verbosity = _request.IsInteractive ? Verbosity.Normal : Verbosity.Batch; - } - - /// - /// Displays entries using the OneGet object. - /// - protected override void DisplayLogEntry(LogSeverity severity, string message) - { - switch (severity) - { - case LogSeverity.Debug: - _request.Debug(message); - break; - case LogSeverity.Info: - _request.Verbose(message); - break; - case LogSeverity.Warn: - case LogSeverity.Error: - _request.Warning(message); - break; - } - } - - /// - public override void RunTask(ITask task) - { - #region Sanity checks - if (task == null) throw new ArgumentNullException(nameof(task)); - #endregion - - task.Run(CancellationToken, CredentialProvider, new OneGetProgress(task.Name, _request, CancellationTokenSource)); - } - - /// - protected override bool AskInteractive(string question, bool defaultAnswer) - => _request.OptionKeys.Contains("Force") || _request.ShouldContinue(question, "Zero Install"); - - /// - public override void Error(Exception exception) => _request.Warning(exception.Message); -} diff --git a/src/OneGet/OneGetProgress.cs b/src/OneGet/OneGetProgress.cs deleted file mode 100644 index 6a430c7cb3..0000000000 --- a/src/OneGet/OneGetProgress.cs +++ /dev/null @@ -1,50 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Represents a single progress bar provided by OneGet. -/// -public class OneGetProgress : MarshalByRefObject, IProgress -{ - private readonly string _name; - private readonly Request _request; - private readonly CancellationTokenSource _cancellationTokenSource; - private readonly int _activityId; - - public OneGetProgress(string name, Request request, CancellationTokenSource cancellationTokenSource) - { - _name = name ?? throw new ArgumentNullException(nameof(name)); - _request = request ?? throw new ArgumentNullException(nameof(request)); - _cancellationTokenSource = cancellationTokenSource ?? throw new ArgumentNullException(nameof(cancellationTokenSource)); - - _request.Debug(name); - _activityId = _request.StartProgress(0, name); - } - - public void Report(TaskSnapshot value) - { - if (_request.IsCanceled) _cancellationTokenSource.Cancel(); - - switch (value.State) - { - case TaskState.Canceled: - case TaskState.IOError: - case TaskState.WebError: - _request.CompleteProgress(_activityId, false); - break; - - case TaskState.Header: - case TaskState.Data: - _request.Progress(_activityId, (int)(value.Value * 100), _name); - break; - - case TaskState.Complete: - _request.CompleteProgress(_activityId, true); - break; - } - } -} diff --git a/src/OneGet/PackageProvider.cs b/src/OneGet/PackageProvider.cs deleted file mode 100644 index 0f3555ec66..0000000000 --- a/src/OneGet/PackageProvider.cs +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// A OneGet package provider for Zero Install. -/// -public class PackageProvider : PackageProviderBase -{ - public override string PackageProviderName => "0install"; - - /// - protected override IOneGetContext BuildContext(Request request) => new OneGetContext(request); -} diff --git a/src/OneGet/PackageProviderBase.cs b/src/OneGet/PackageProviderBase.cs deleted file mode 100644 index a037d86298..0000000000 --- a/src/OneGet/PackageProviderBase.cs +++ /dev/null @@ -1,198 +0,0 @@ -// Copyright Bastian Eicher et al. -// Licensed under the GNU Lesser Public License - -using System.Security; -using NanoByte.Common.Info; -using PackageManagement.Sdk; - -namespace ZeroInstall.OneGet; - -/// -/// Common base for OneGet package providers. Implements OneGet duck-typing interface. -/// -public abstract class PackageProviderBase -{ - public abstract string PackageProviderName { get; } - - public string ProviderVersion => AppInfo.CurrentLibrary.Version ?? "1.0.0-pre"; - - public void OnUnhandledException(string methodName, Exception exception) - { - Log.Error($"Unexpected exception thrown in {PackageProviderName}::{methodName}", exception); - } - - public void InitializeProvider(Request request) => request.Debug("Calling '{0}::InitializeProvider'", PackageProviderName); - - public void GetFeatures(Request request) - { - request.Debug("Calling '{0}::GetFeatures'", PackageProviderName); - request.Yield(new Dictionary - { - [Constants.Features.SupportedExtensions] = ["xml"], - [Constants.Features.SupportedSchemes] = ["http", "https", "file"] - }); - } - - public void GetDynamicOptions(string? category, Request request) - { - request.Debug("Calling '{0}::GetDynamicOptions'", PackageProviderName); - switch ((category ?? "").ToLowerInvariant()) - { - case "package": - request.YieldDynamicOption("Refresh", Constants.OptionType.Switch, isRequired: false); - request.YieldDynamicOption("AllVersions", Constants.OptionType.Switch, isRequired: false); - request.YieldDynamicOption("GlobalSearch", Constants.OptionType.Switch, isRequired: false); - break; - - case "install": - request.YieldDynamicOption("Refresh", Constants.OptionType.Switch, isRequired: false); - request.YieldDynamicOption("DeferDownload", Constants.OptionType.Switch, isRequired: false); - request.YieldDynamicOption("Scope", Constants.OptionType.String, isRequired: false, permittedValues: new[] {"CurrentUser", "AllUsers"}); - break; - - case "source": - break; - } - } - - /// - /// Creates a instance and executes a delegate on it, handling common exception types. - /// - private void Do(Request request, Action action) - { - try - { - using var context = BuildContext(request); - action(context); - } - #region Error handling - catch (OperationCanceledException) - {} - catch (FormatException ex) - { - request.Error(ErrorCategory.InvalidArgument, "", ex.Message); - } - catch (WebException ex) - { - request.Error(ErrorCategory.ConnectionError, "", ex.Message); - } - catch (NotSupportedException ex) - { - request.Error(ErrorCategory.NotImplemented, "", ex.Message); - } - catch (IOException ex) - { - request.Error(ErrorCategory.OpenError, "", ex.Message); - } - catch (Exception ex) when (ex is UnauthorizedAccessException or SecurityException) - { - request.Error(ErrorCategory.PermissionDenied, "", ex.Message); - } - catch (InvalidDataException ex) - { - request.Error(ErrorCategory.InvalidData, "", ex.Message); - } - catch (Exception ex) - { - request.Error(ErrorCategory.MetadataError, "", ex.Message); - } - #endregion - } - - /// - /// Creates a for a given . - /// - protected abstract IOneGetContext BuildContext(Request request); - - public void ResolvePackageSources(Request request) - { - request.Debug("Calling '{0}::ResolvePackageSources'", PackageProviderName); - Do(request, x => x.ResolvePackageSources()); - } - - public void AddPackageSource(string name, string location, bool trusted, Request request) - { - request.Debug("Calling '{0}::AddPackageSource'", PackageProviderName); - if (string.IsNullOrEmpty(location)) - { - request.Error(ErrorCategory.InvalidArgument, "location", "Location parameter missing"); - return; - } - Do(request, x => x.AddPackageSource(location)); - } - - public void RemovePackageSource(string name, Request request) - { - request.Debug("Calling '{0}::RemovePackageSource'", PackageProviderName); - if (string.IsNullOrEmpty(name)) - { - request.Error(ErrorCategory.InvalidArgument, "name", "Name parameter missing"); - return; - } - - Do(request, x => x.RemovePackageSource(name)); - } - - public void FindPackage(string name, string requiredVersion, string minimumVersion, string maximumVersion, int id, Request request) - { - request.Debug("Calling '{0}::FindPackage'", PackageProviderName); - Do(request, x => x.FindPackage(name, requiredVersion, minimumVersion, maximumVersion)); - } - - public void FindPackageByFile(string file, int id, Request request) - { - request.Debug("Calling '{0}::FindPackageByFile'", PackageProviderName); - if (string.IsNullOrEmpty(file)) - { - request.Error(ErrorCategory.InvalidArgument, "file", "File parameter missing"); - return; - } - Do(request, x => x.FindPackageBy(file)); - } - - public void FindPackageByUri(Uri uri, int id, Request request) - { - request.Debug("Calling '{0}::FindPackageByUri'", PackageProviderName); - if (uri == null) - { - request.Error(ErrorCategory.InvalidArgument, "uri", "Uri parameter missing"); - return; - } - Do(request, x => x.FindPackageBy(uri.OriginalString)); - } - - public void DownloadPackage(string fastPackageReference, string location, Request request) - { - request.Debug("Calling '{0}::DownloadPackage'", PackageProviderName); - if (string.IsNullOrEmpty(location)) - { - request.Error(ErrorCategory.InvalidArgument, "location", "Location parameter missing"); - return; - } - Do(request, x => x.DownloadPackage(fastPackageReference, location)); - } - - public void InstallPackage(string fastPackageReference, Request request) - { - request.Debug("Calling '{0}::InstallPackage'", PackageProviderName); - Do(request, x => x.InstallPackage(fastPackageReference)); - } - - public void UninstallPackage(string fastPackageReference, Request request) - { - request.Debug("Calling '{0}::UninstallPackage'", PackageProviderName); - Do(request, x => x.UninstallPackage(fastPackageReference)); - } - - public void GetInstalledPackages(string name, string requiredVersion, string minimumVersion, string maximumVersion, Request request) - { - request.Debug("Calling '{0}::GetInstalledPackages'", PackageProviderName); - Do(request, x => x.GetInstalledPackages(name)); - } - - public void GetPackageDetails(string fastPackageReference, Request request) - { - request.Debug("Calling '{0}::GetPackageDetails'", PackageProviderName); - Do(request, x => x.GetPackageDetails(fastPackageReference)); - } -} \ No newline at end of file diff --git a/src/OneGet/Sdk/Constants.cs b/src/OneGet/Sdk/Constants.cs deleted file mode 100644 index e514f1e5ae..0000000000 --- a/src/OneGet/Sdk/Constants.cs +++ /dev/null @@ -1,106 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -namespace PackageManagement.Sdk { - public static partial class Constants { - #region copy common-constants-implementation /internal/public - - public const string MinVersion = "0.0.0.1"; - public const string MSGPrefix = "MSG:"; - public static string[] FeaturePresent = new string[0]; - public static string[] Empty = new string[0]; - - public static partial class Features { - public const string AutomationOnly = "automation-only"; - public const string MagicSignatures = "magic-signatures"; - public const string SupportedExtensions = "file-extensions"; - public const string SupportedSchemes = "uri-schemes"; - public const string SupportsPowerShellModules = "supports-powershell-modules"; - public const string SupportsRegexSearch = "supports-regex-search"; - public const string SupportsSubstringSearch = "supports-substring-search"; - public const string SupportsWildcardSearch = "supports-wildcard-search"; - } - - public static partial class Messages { - public const string CreatefolderFailed = "MSG:CreatefolderFailed"; - public const string DependencyResolutionError = "MSG:UnableToResolveDependency_dependencyPackage"; - public const string DependentPackageFailedInstall = "MSG:DependentPackageFailedInstall_dependency"; - public const string DestinationPathNotSet = "MSG:DestinationPathNotSet"; - public const string FailedProviderBootstrap = "MSG:FailedProviderBootstrap"; - public const string FileFailedVerification = "MSG:FileFailedVerification"; - public const string InvalidFilename = "MSG:InvalidFilename"; - public const string MissingRequiredParameter = "MSG:MissingRequiredParameter"; - public const string PackageFailedInstall = "MSG:UnableToInstallPackage_package_reason"; - public const string PackageSourceExists = "MSG:PackageSourceExists"; - public const string ProtocolNotSupported = "MSG:ProtocolNotSupported"; - public const string ProviderPluginLoadFailure = "MSG:ProviderPluginLoadFailure"; - public const string ProviderSwidtagUnavailable = "MSG:ProviderSwidtagUnavailable"; - public const string RemoveEnvironmentVariableRequiresElevation = "MSG:RemoveEnvironmentVariableRequiresElevation"; - public const string SchemeNotSupported = "MSG:SchemeNotSupported"; - public const string SourceLocationNotValid = "MSG:SourceLocationNotValid_Location"; - public const string UnableToCopyFileTo = "MSG:UnableToCopyFileTo"; - public const string UnableToCreateShortcutTargetDoesNotExist = "MSG:UnableToCreateShortcutTargetDoesNotExist"; - public const string UnableToDownload = "MSG:UnableToDownload"; - public const string UnableToOverwriteExistingFile = "MSG:UnableToOverwriteExistingFile"; - public const string UnableToRemoveFile = "MSG:UnableToRemoveFile"; - public const string UnableToResolvePackage = "MSG:UnableToResolvePackage"; - public const string UnableToResolveSource = "MSG:UnableToResolveSource_NameOrLocation"; - public const string UnableToUninstallPackage = "MSG:UnableToUninstallPackage"; - public const string UnknownFolderId = "MSG:UnknownFolderId"; - public const string UnknownProvider = "MSG:UnknownProvider"; - public const string UnsupportedArchive = "MSG:UnsupportedArchive"; - public const string UnsupportedProviderType = "MSG:UnsupportedProviderType"; - public const string UriSchemeNotSupported = "MSG:UriSchemeNotSupported_Scheme"; - public const string UserDeclinedUntrustedPackageInstall = "MSG:UserDeclinedUntrustedPackageInstall"; - } - - public static partial class OptionType { - public const string String = "String"; - public const string StringArray = "StringArray"; - public const string Int = "Int"; - public const string Switch = "Switch"; - public const string Folder = "Folder"; - public const string File = "File"; - public const string Path = "Path"; - public const string Uri = "Uri"; - public const string SecureString = "SecureString"; - } - - public static partial class PackageStatus { - public const string Available = "Available"; - public const string Dependency = "Dependency"; - public const string Installed = "Installed"; - public const string Uninstalled = "Uninstalled"; - } - - public static partial class Parameters { - public const string IsUpdate = "IsUpdatePackageSource"; - public const string Name = "Name"; - public const string Location = "Location"; - } - - public static partial class Signatures { - public const string Cab = "4D534346"; - public const string OleCompoundDocument = "D0CF11E0A1B11AE1"; - public const string Zip = "504b0304"; - public static string[] ZipVariants = [Zip /* should have EXEs? */]; - } - - public static partial class SwidTag { - public const string SoftwareIdentity = "SoftwareIdentity"; - } - - #endregion - } -} diff --git a/src/OneGet/Sdk/ErrorCategory.cs b/src/OneGet/Sdk/ErrorCategory.cs deleted file mode 100644 index ef0aa7cde0..0000000000 --- a/src/OneGet/Sdk/ErrorCategory.cs +++ /dev/null @@ -1,52 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -namespace PackageManagement.Sdk -{ - public enum ErrorCategory - { - NotSpecified, - OpenError, - CloseError, - DeviceError, - DeadlockDetected, - InvalidArgument, - InvalidData, - InvalidOperation, - InvalidResult, - InvalidType, - MetadataError, - NotImplemented, - NotInstalled, - ObjectNotFound, - OperationStopped, - OperationTimeout, - SyntaxError, - ParserError, - PermissionDenied, - ResourceBusy, - ResourceExists, - ResourceUnavailable, - ReadError, - WriteError, - FromStdErr, - SecurityError, - ProtocolError, - ConnectionError, - AuthenticationError, - LimitsExceeded, - QuotaExceeded, - NotEnabled, - } -} diff --git a/src/OneGet/Sdk/Request.cs b/src/OneGet/Sdk/Request.cs deleted file mode 100644 index 389adee228..0000000000 --- a/src/OneGet/Sdk/Request.cs +++ /dev/null @@ -1,308 +0,0 @@ -// -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// - -namespace PackageManagement.Sdk { - using System; - using System.Collections.Generic; - using System.Globalization; - using System.Linq; - using System.Security; - - public abstract class Request { - private Dictionary _options; - private string[] _packageSources; - - #region PackageMangaement Interfaces - public interface IProviderServices { - bool IsElevated { get; } - - IEnumerable FindPackageByCanonicalId(string canonicalId, Request requestObject); - - string GetCanonicalPackageId(string providerName, string packageName, string version, string source); - - string ParseProviderName(string canonicalPackageId); - - string ParsePackageName(string canonicalPackageId); - - string ParsePackageVersion(string canonicalPackageId); - - string ParsePackageSource(string canonicalPackageId); - - void DownloadFile(Uri remoteLocation, string localFilename, Request requestObject); - - bool IsSupportedArchive(string localFilename, Request requestObject); - - IEnumerable UnpackArchive(string localFilename, string destinationFolder, Request requestObject); - - bool Install(string fileName, string additionalArgs, Request requestObject); - - bool IsSignedAndTrusted(string filename, Request requestObject); - } - - public interface IPackageProvider { - - } - - public interface IPackageManagementService { - int Version { get; } - - IEnumerable ProviderNames { get; } - - IEnumerable AllProviderNames { get; } - - IEnumerable PackageProviders { get; } - - IEnumerable SelectProvidersWithFeature(string featureName); - - IEnumerable SelectProvidersWithFeature(string featureName, string value); - - IEnumerable SelectProviders(string providerName, Request requestObject); - - bool RequirePackageProvider(string requestor, string packageProviderName, string minimumVersion, Request requestObject); - } - #endregion - - #region core-apis - - public abstract object PackageManagementService {get;} - - public abstract IProviderServices ProviderServices {get;} - - #endregion - - #region copy host-apis - - /* Synced/Generated code =================================================== */ - public abstract bool IsCanceled {get;} - - public abstract string GetMessageString(string messageText, string defaultText); - - public abstract bool Warning(string messageText); - - public abstract bool Error(string id, string category, string targetObjectValue, string messageText); - - public abstract bool Message(string messageText); - - public abstract bool Verbose(string messageText); - - public abstract bool Debug(string messageText); - - public abstract int StartProgress(int parentActivityId, string messageText); - - public abstract bool Progress(int activityId, int progressPercentage, string messageText); - - public abstract bool CompleteProgress(int activityId, bool isSuccessful); - - /// - /// Used by a provider to request what metadata keys were passed from the user - /// - /// - public abstract IEnumerable OptionKeys {get;} - - /// - /// - /// - /// - public abstract IEnumerable GetOptionValues(string key); - - public abstract IEnumerable Sources {get;} - - public abstract string CredentialUsername {get;} - - public abstract SecureString CredentialPassword {get;} - - public abstract bool ShouldBootstrapProvider(string requestor, string providerName, string providerVersion, string providerType, string location, string destination); - - public abstract bool ShouldContinueWithUntrustedPackageSource(string package, string packageSource); - - public abstract bool ShouldContinue(string query, string caption, ref bool yesToAll, ref bool noToAll); - - public abstract bool ShouldContinue(string query, string caption); - - public abstract bool AskPermission(string permission); - - public abstract bool IsInteractive {get;} - - public abstract int CallCount {get;} - - #endregion - - #region copy response-apis - - /* Synced/Generated code =================================================== */ - - /// - /// Used by a provider to return fields for a SoftwareIdentity. - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - /// - public abstract string YieldSoftwareIdentity(string fastPath, string name, string version, string versionScheme, string summary, string source, string searchKey, string fullPath, string packageFileName); - - public abstract string AddMetadata(string name, string value); - - public abstract string AddMetadata(string elementPath, string name, string value); - - public abstract string AddMetadata(string elementPath, Uri @namespace, string name, string value); - - public abstract string AddMeta(string elementPath); - - public abstract string AddEntity(string name, string regid, string role, string thumbprint); - - public abstract string AddLink(Uri referenceUri, string relationship, string mediaType, string ownership, string use, string appliesToMedia, string artifact); - - public abstract string AddDependency(string providerName, string packageName, string version, string source, string appliesTo); - - public abstract string AddPayload(); - - public abstract string AddEvidence(DateTime date, string deviceId); - - public abstract string AddDirectory(string elementPath, string directoryName, string location, string root, bool isKey); - - public abstract string AddFile(string elementPath, string fileName, string location, string root, bool isKey, long size, string version); - - public abstract string AddProcess(string elementPath, string processName, int pid); - - public abstract string AddResource(string elementPath, string type); - - /// - /// Used by a provider to return fields for a package source (repository) - /// - /// - /// - /// - /// - /// - /// - public abstract bool YieldPackageSource(string name, string location, bool isTrusted, bool isRegistered, bool isValidated); - - /// - /// Used by a provider to return the fields for a Metadata Definition - /// The cmdlets can use this to supply tab-completion for metadata to the user. - /// - /// the provider-defined name of the option - /// one of ['string','int','path','switch'] - /// if the parameter is mandatory - /// - public abstract bool YieldDynamicOption(string name, string expectedType, bool isRequired); - - public abstract bool YieldKeyValuePair(string key, string value); - - public abstract bool YieldValue(string value); - - #endregion - /// - /// Yield values in a dictionary as key/value pairs. (one pair for each value in each key) - /// - /// - /// - public bool Yield(Dictionary dictionary) { - return dictionary.All(Yield); - } - - public bool Yield(KeyValuePair pair) { - if (pair.Value.Length == 0) { - return YieldKeyValuePair(pair.Key, null); - } - return pair.Value.All(each => YieldKeyValuePair(pair.Key, each)); - } - - public bool Error(ErrorCategory category, string targetObjectValue, string messageText, params object[] args) { - return Error(messageText, category.ToString(), targetObjectValue, FormatMessageString(messageText, args)); - } - - public bool Warning(string messageText, params object[] args) { - return Warning(FormatMessageString(messageText, args)); - } - - public bool Message(string messageText, params object[] args) { - return Message(FormatMessageString(messageText, args)); - } - - public bool Verbose(string messageText, params object[] args) { - return Verbose(FormatMessageString(messageText, args)); - } - - public bool Debug(string messageText, params object[] args) { - return Debug(FormatMessageString(messageText, args)); - } - - public int StartProgress(int parentActivityId, string messageText, params object[] args) { - return StartProgress(parentActivityId, FormatMessageString(messageText, args)); - } - - public bool Progress(int activityId, int progressPercentage, string messageText, params object[] args) { - return Progress(activityId, progressPercentage, FormatMessageString(messageText, args)); - } - - public string GetOptionValue(string name) { - // get the value from the request - return (GetOptionValues(name) ?? Enumerable.Empty()).LastOrDefault(); - } - - private static string FixMeFormat(string formatString, object[] args) { - if (args == null || args.Length == 0) { - // not really any args, and not really expectng any - return formatString.Replace('{', '\u00ab').Replace('}', '\u00bb'); - } - return args.Aggregate(formatString.Replace('{', '\u00ab').Replace('}', '\u00bb'), (current, arg) => current + string.Format(CultureInfo.CurrentCulture, " \u00ab{0}\u00bb", arg)); - } - - internal string GetMessageStringInternal(string messageText) { - return messageText; - } - - internal string FormatMessageString(string messageText, params object[] args) { - if (string.IsNullOrEmpty(messageText)) { - return string.Empty; - } - - if (args == null) { - return messageText; - } - - if (messageText.StartsWith(Constants.MSGPrefix, true, CultureInfo.CurrentCulture)) { - // check with the caller first, then with the local resources, and fallback to using the messageText itself. - messageText = GetMessageString(messageText.Substring(Constants.MSGPrefix.Length), GetMessageStringInternal(messageText) ?? messageText) ?? GetMessageStringInternal(messageText) ?? messageText; - } - - // if it doesn't look like we have the correct number of parameters - // let's return a fix-me-format string. - var c = messageText.ToCharArray().Where(each => each == '{').Count(); - if (c < args.Length) { - return FixMeFormat(messageText, args); - } - return string.Format(CultureInfo.CurrentCulture, messageText, args); - } - - public bool YieldDynamicOption(string name, string expectedType, bool isRequired, IEnumerable permittedValues) { - return YieldDynamicOption(name, expectedType, isRequired) && (permittedValues ?? Enumerable.Empty()).All(each => YieldKeyValuePair(name, each)); - } - - public Dictionary Options { - get { - return _options ?? (_options = OptionKeys.Where(each => !string.IsNullOrEmpty(each)).ToDictionary(k => k, (k) => (GetOptionValues(k) ?? new string[0]).ToArray())); - } - } - - public IEnumerable PackageSources => _packageSources ?? (_packageSources = (Sources ?? new string[0]).ToArray()); - } -} diff --git a/src/OneGet/Sdk/_Namespace.md b/src/OneGet/Sdk/_Namespace.md deleted file mode 100644 index a34664c40f..0000000000 --- a/src/OneGet/Sdk/_Namespace.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -uid: PackageManagement.Sdk -summary: *content ---- -Embedded OneGet SDK classes. diff --git a/src/OneGet/_Namespace.md b/src/OneGet/_Namespace.md deleted file mode 100644 index 669f245fae..0000000000 --- a/src/OneGet/_Namespace.md +++ /dev/null @@ -1,5 +0,0 @@ ---- -uid: ZeroInstall.OneGet -summary: *content ---- -Implements the OneGet package provider interface for Zero Install. diff --git a/src/OneGet/provider.manifest b/src/OneGet/provider.manifest deleted file mode 100644 index 16d9c14524..0000000000 --- a/src/OneGet/provider.manifest +++ /dev/null @@ -1,8 +0,0 @@ - - - - diff --git a/src/ZeroInstall.Windows.sln b/src/ZeroInstall.Windows.sln index e5ddbb6d46..463d41c26e 100644 --- a/src/ZeroInstall.Windows.sln +++ b/src/ZeroInstall.Windows.sln @@ -15,14 +15,10 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store.Management.Cli", "Sto EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Store.Service", "Store.Service\Store.Service.csproj", "{7334A4AA-B517-4102-8D4D-9B4B3A94C5FA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneGet", "OneGet\OneGet.csproj", "{2FCB7FA5-41A2-42B6-8825-F3A8194DB306}" -EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap", "Bootstrap\Bootstrap.csproj", "{4B47068C-73D3-4F2F-BC96-8FE2B8FA4A7D}" EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Bootstrap.WinForms", "Bootstrap.WinForms\Bootstrap.WinForms.csproj", "{C2FAC835-333A-4219-9872-50B1172167E5}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OneGet.Bootstrap", "OneGet.Bootstrap\OneGet.Bootstrap.csproj", "{187CD9C1-DD75-49E8-AEBB-F73D8E4F9BE3}" -EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Shared", "Shared", "{FF4B5DDF-618F-4D5A-82CF-A41C13740BEB}" ProjectSection(SolutionItems) = preProject Directory.Build.props = Directory.Build.props diff --git a/src/ZeroInstall.Windows.sln.DotSettings b/src/ZeroInstall.Windows.sln.DotSettings index 99cad2c38c..a849060f4d 100644 --- a/src/ZeroInstall.Windows.sln.DotSettings +++ b/src/ZeroInstall.Windows.sln.DotSettings @@ -1,7 +1,5 @@  Inherit - OneGet\Sdk - OneGet.Bootstrap\Sdk AssemblyInfo.cs GlobalAssemblyInfo.cs GlobalSuppressions.cs @@ -32,4 +30,4 @@ Licensed under the GNU Lesser Public License True True True - True \ No newline at end of file + True