Beispiel #1
0
        /// <summary>
        /// Gets a set of filter rules for registry access.
        /// </summary>
        private RegistryFilter GetRegistryFilter()
        {
            var filterRuleList = new LinkedList <RegistryFilterRule>();

            if (_mainImplementation != null)
            {
                // Create one substitution stub for each command
                foreach (var command in _mainImplementation.Commands)
                {
                    // Only handle simple commands (executable path, no arguments)
                    if (string.IsNullOrEmpty(command.Path) || command.Arguments.Count != 0)
                    {
                        continue;
                    }

                    string processCommandLine = Path.Combine(_implementationDir, command.Path);

                    string registryCommandLine;
                    try
                    { // Try to use a machine-wide stub if possible
                        registryCommandLine = _target.GetRunStub(command.Name, _handler, machineWide: true);
                    }
                    catch (UnauthorizedAccessException)
                    { // Fall back to per-user stub
                        registryCommandLine = _target.GetRunStub(command.Name, _handler);
                    }

                    // Apply filter with normal and with escaped string
                    filterRuleList.AddLast(new RegistryFilterRule(processCommandLine, registryCommandLine));
                    filterRuleList.AddLast(new RegistryFilterRule("\"" + processCommandLine + "\"", "\"" + registryCommandLine + "\""));
                }
            }

            // Redirect Windows SPAD commands to Zero Install
            foreach (var defaultProgram in _target.Feed.CapabilityLists.CompatibleCapabilities().OfType <Store.Model.Capabilities.DefaultProgram>())
            {
                if (!string.IsNullOrEmpty(defaultProgram.InstallCommands.Reinstall))
                {
                    filterRuleList.AddLast(GetInstallCommandFilter(defaultProgram.InstallCommands.Reinstall, defaultProgram.InstallCommands.ReinstallArgs, "--machine --batch --add=defaults " + _target.Uri.ToStringRfc().EscapeArgument()));
                }
                if (!string.IsNullOrEmpty(defaultProgram.InstallCommands.ShowIcons))
                {
                    filterRuleList.AddLast(GetInstallCommandFilter(defaultProgram.InstallCommands.ShowIcons, defaultProgram.InstallCommands.ShowIconsArgs, "--machine --batch --add=icons " + _target.Uri.ToStringRfc().EscapeArgument()));
                }
                if (!string.IsNullOrEmpty(defaultProgram.InstallCommands.HideIcons))
                {
                    filterRuleList.AddLast(GetInstallCommandFilter(defaultProgram.InstallCommands.HideIcons, defaultProgram.InstallCommands.HideIconsArgs, "--machine --batch --remove=icons " + _target.Uri.ToStringRfc().EscapeArgument()));
                }
            }

            return(new RegistryFilter(filterRuleList));
        }
        /// <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="handler">A callback object used when the the user is to be informed about the progress of long-running operations such as downloads.</param>
        public static void Create(AutoStart autoStart, FeedTarget target, ITaskHandler handler)
        {
            #region Sanity checks
            if (autoStart == null)
            {
                throw new ArgumentNullException("autoStart");
            }
            if (handler == null)
            {
                throw new ArgumentNullException("handler");
            }
            #endregion

            string filePath = GetStartupPath(autoStart.Name);
            Create(filePath, target.GetRunStub(autoStart.Command, handler));
        }
Beispiel #3
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 = "\"" + target.GetRunStub(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
 }