/// <summary> /// Returns a command-line for executing the "0install run" command. /// Generates and returns a stub EXE if possible, falls back to directly pointing to the "0install" EXE otherwise. /// </summary> /// <param name="target">The application to be launched.</param> /// <param name="command">The command argument to be passed to the the "0install run" command; can be <c>null</c>.</param> /// <param name="machineWide"><c>true</c> place the generated stub in a machine-wide location; <c>false</c> to place it in the current user profile.</param> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="InvalidOperationException">There was a compilation error while generating the stub EXE.</exception> /// <exception cref="IOException">A problem occurred while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> public IReadOnlyList <string> GetRunCommandLine(FeedTarget target, string?command = null, bool machineWide = false) { string targetKey = target.Uri + "#" + command; var entryPoint = target.Feed.GetEntryPoint(command); bool gui = entryPoint is not { NeedsTerminal : true }; string targetHash = targetKey.Hash(SHA256.Create()); string exeName = (entryPoint == null) ? FeedUri.Escape(target.Feed.Name) : entryPoint.BinaryName ?? entryPoint.Command; string path = Path.Combine( IntegrationManager.GetDir(machineWide, "stubs", targetHash), exeName + ".exe"); #if !DEBUG try #endif { CreateOrUpdateRunStub(path, target, gui, command); return(new[] { path }); } #if !DEBUG catch (Exception ex) { var exe = GetExe(gui); Log.Error($"Failed to generate stub EXE for {targetKey}. Falling back to using '{exe}' directly.", ex); return(GetArguments(target.Uri, command, gui) .Prepend(Path.Combine(Locations.InstallBase, exe)) .ToList()); } #endif }
/// <summary> /// Returns a command-line for executing the "0install run" command. Generates and returns a stub EXE if possible, falls back to directly pointing to the "0install" binary otherwise. /// </summary> /// <param name="target">The application to be launched.</param> /// <param name="command">The command argument to be passed to the the "0install run" command; can be <c>null</c>.</param> /// <param name="machineWide"><c>true</c> place the generated stub in a machine-wide location; <c>false</c> to place it in the current user profile.</param> /// <returns></returns> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="InvalidOperationException">There was a compilation error while generating the stub EXE.</exception> /// <exception cref="IOException">A problem occurred while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception> /// <exception cref="UnauthorizedAccessException">Write access to the filesystem is not permitted.</exception> public IReadOnlyList <string> GetRunCommandLine(FeedTarget target, string?command = null, bool machineWide = false) { var entryPoint = target.Feed.GetEntryPoint(command); bool gui = entryPoint is not { NeedsTerminal : true }; try { #if NETFRAMEWORK string hash = (target.Uri + "#" + command).Hash(SHA256.Create()); string exeName = (entryPoint == null) ? FeedUri.Escape(target.Feed.Name) : entryPoint.BinaryName ?? entryPoint.Command; string path = Path.Combine( IntegrationManager.GetDir(machineWide, "stubs", hash), exeName + ".exe"); CreateOrUpdateRunStub(path, target, gui, command); return(new[] { path }); #else return(GetArguments(target.Uri, command, gui) .Prepend(GetBinary(gui)) .ToList()); #endif } #region Error handling catch (InvalidOperationException ex) { // Wrap exception since only certain exception types are allowed throw new IOException(ex.Message, ex); } #endregion }
/// <summary> /// Builds a stub EXE in a well-known location. Future calls with the same arguments will return the same EXE. /// </summary> /// <param name="target">The application to be launched via the stub.</param> /// <param name="command">The command argument to be passed to the the "0install run" command; can be <c>null</c>.</param> /// <param name="machineWide">Store the stub in a machine-wide directory instead of just for the current user.</param> /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param> /// <returns>The path to the generated stub EXE.</returns> /// <exception cref="OperationCanceledException">The user canceled the task.</exception> /// <exception cref="InvalidOperationException">There was a compilation error while generating the stub EXE.</exception> /// <exception cref="IOException">A problem occurred while writing to the filesystem.</exception> /// <exception cref="WebException">A problem occurred while downloading additional data (such as icons).</exception> /// <exception cref="InvalidOperationException">Write access to the filesystem is not permitted.</exception> public static string GetRunStub(FeedTarget target, string?command, IIconStore iconStore, bool machineWide = false) { #region Sanity checks if (iconStore == null) { throw new ArgumentNullException(nameof(iconStore)); } #endregion var entryPoint = target.Feed.GetEntryPoint(command); string exeName = (entryPoint != null) ? entryPoint.BinaryName ?? entryPoint.Command : FeedUri.Escape(target.Feed.Name); bool needsTerminal = (entryPoint != null && entryPoint.NeedsTerminal); string hash = (target.Uri + "#" + command).Hash(SHA256.Create()); string path = Path.Combine( IntegrationManager.GetDir(machineWide, "stubs", hash), exeName + ".exe"); CreateOrUpdateRunStub(target, path, command, needsTerminal, iconStore); return(path); }
/// <summary> /// Returns the path of the directory used to store alias stub EXEs. /// </summary> /// <param name="machineWide"><c>true</c> for a machine-wide directory; <c>false</c> for a directory just for the current user.</param> public static string GetStubDir(bool machineWide) => IntegrationManager.GetDir(machineWide, "aliases");
/// <summary> /// Provides icon files for use with desktop integration. Files will remain persisted. /// </summary> public static IIconStore DesktopIntegration(Config config, ITaskHandler handler, bool machineWide) => new IconStore( IntegrationManager.GetDir(machineWide, "icons"), config, handler);