Utility class for building stub EXEs that execute "0install" commands. Provides persistent local paths.
        /// <summary>
        /// Generates a command-line string for launching a <see cref="Verb"/>.
        /// </summary>
        /// <param name="target">The application being integrated.</param>
        /// <param name="verb">The verb to get to launch command for.</param>
        /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param>
        /// <param name="machineWide">Store the stub in a machine-wide directory instead of just for the current user.</param>
        /// <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>
        internal static string GetLaunchCommandLine(FeedTarget target, Verb verb, IIconStore iconStore, bool machineWide)
        {
            string GetRunStub()
            {
                try
                {
                    return(StubBuilder.GetRunStub(target, verb.Command, iconStore, machineWide));
                }
                #region Error handling
                catch (InvalidOperationException ex)
                {
                    // Wrap exception since only certain exception types are allowed
                    throw new IOException(ex.Message, ex);
                }
                #endregion
            }

            if (verb.Arguments.Count == 0)
            {
                string arguments = string.IsNullOrEmpty(verb.ArgumentsLiteral) ? "\"%V\"" : verb.ArgumentsLiteral;
                return(GetRunStub().EscapeArgument() + " " + arguments);
            }

            return(verb.Arguments.Select(x => x.Value)
                   .Prepend(GetRunStub())
                   .JoinEscapeArguments()
                   .Replace("${item}", "\"%V\""));
        }
示例#2
0
        /// <summary>
        /// Creates an application alias in the current system.
        /// </summary>
        /// <param name="target">The application being integrated.</param>
        /// <param name="command">The command within <paramref name="target"/> the alias shall point to; can be <c>null</c>.</param>
        /// <param name="aliasName">The name of the alias to be created.</param>
        /// <param name="machineWide">Create the alias machine-wide instead of just for the current user.</param>
        /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
        /// <exception cref="OperationCanceledException">The user canceled the task.</exception>
        /// <exception cref="IOException">A problem occurs while writing to the filesystem or registry.</exception>
        /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception>
        /// <exception cref="UnauthorizedAccessException">Write access to the filesystem or registry is not permitted.</exception>
        public static void Create(FeedTarget target, [CanBeNull] string command, [NotNull] string aliasName, bool machineWide, [NotNull] ITaskHandler handler)
        {
            #region Sanity checks
            if (string.IsNullOrEmpty(aliasName))
            {
                throw new ArgumentNullException(nameof(aliasName));
            }
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }
            #endregion

            if (string.IsNullOrEmpty(aliasName) || aliasName.IndexOfAny(Path.GetInvalidFileNameChars()) != -1)
            {
                throw new IOException(string.Format(Resources.NameInvalidChars, aliasName));
            }

            string stubDirPath = GetStubDir(machineWide);
            PathEnv.AddDir(stubDirPath, machineWide);

            string stubFilePath = Path.Combine(stubDirPath, aliasName + ".exe");
            StubBuilder.BuildRunStub(target, stubFilePath, handler, needsTerminal: true, command: command);
            AddToAppPaths(aliasName + ".exe", stubFilePath, machineWide);
        }
        public void TestBuildStubNeedsTerminal()
        {
            Skip.IfNot(WindowsUtils.IsWindows, "StubBuilder is only used on Windows");

            var target = new FeedTarget(FeedTest.Test1Uri, FeedTest.CreateTestFeed());

            using var tempFile = new TemporaryFile("0install-unit-tests");
            StubBuilder.BuildRunStub(target, tempFile, _iconStoreMock.Object, needsTerminal: true);
        }
示例#4
0
        public void TestBuildStubNeedsTerminal()
        {
            if (!WindowsUtils.IsWindows)
            {
                Assert.Ignore("StubBuilder is only used on Windows");
            }

            var target = new FeedTarget(FeedTest.Test1Uri, FeedTest.CreateTestFeed());

            using (var tempFile = new TemporaryFile("0install-unit-tests"))
                StubBuilder.BuildRunStub(target, tempFile, new SilentTaskHandler(), needsTerminal: true);
        }
示例#5
0
        /// <summary>
        /// Creates a new Windows shortcut in the "Startup" menu.
        /// </summary>
        /// <param name="autoStart">Information about the shortcut to be created.</param>
        /// <param name="target">The target the shortcut shall point to.</param>
        /// <param name="iconStore">Stores icon files downloaded from the web as local files.</param>
        /// <param name="machineWide">Create the shortcut machine-wide instead of just for the current user.</param>
        public static void Create(AutoStart autoStart, FeedTarget target, IIconStore iconStore, bool machineWide)
        {
            #region Sanity checks
            if (autoStart == null)
            {
                throw new ArgumentNullException(nameof(autoStart));
            }
            if (iconStore == null)
            {
                throw new ArgumentNullException(nameof(iconStore));
            }
            #endregion

            string filePath = GetStartupPath(autoStart.Name, machineWide);
            Create(filePath, targetPath: StubBuilder.GetRunStub(target, autoStart.Command, iconStore));
        }
示例#6
0
 /// <summary>
 /// Generates a command-line string for launching a <see cref="Store.Model.Capabilities.Verb"/>.
 /// </summary>
 /// <param name="target">The application being integrated.</param>
 /// <param name="verb">The verb to get to launch command for.</param>
 /// <param name="machineWide">Store the stub in a machine-wide directory instead of just for the current user.</param>
 /// <param name="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
 /// <exception cref="IOException">A problem occurs while writing to the filesystem.</exception>
 /// <exception cref="WebException">A problem occured while downloading additional data (such as icons).</exception>
 /// <exception cref="InvalidOperationException">Write access to the filesystem is not permitted.</exception>
 internal static string GetLaunchCommandLine(FeedTarget target, Store.Model.Capabilities.Verb verb, bool machineWide, ITaskHandler handler)
 {
     try
     {
         string launchCommand = "\"" + StubBuilder.GetRunStub(target, verb.Command, handler, machineWide) + "\"";
         if (!string.IsNullOrEmpty(verb.Arguments))
         {
             launchCommand += " " + verb.Arguments;
         }
         return(launchCommand);
     }
     #region Error handling
     catch (InvalidOperationException ex)
     {
         // Wrap exception since only certain exception types are allowed
         throw new IOException(ex.Message, ex);
     }
     #endregion
 }