Пример #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 = StubBuilder.GetRunStub(_target, command.Name, _handler, machineWide: true);
                    }
                    catch (UnauthorizedAccessException)
                    { // Fall back to per-user stub
                        registryCommandLine = StubBuilder.GetRunStub(_target, 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));
        }