Sha256: 0db123ee8c3295eef1fb158ca7b4fea176cd8d39544db998552651d7c8640b5e

Contents?: true

Size: 1.81 KB

Versions: 5

Compression:

Stored size: 1.81 KB

Contents

module Rake::Funnel::Support::MSDeploy
  class RegistryPatch
    KEYS = [
      'SOFTWARE\Microsoft\IIS Extensions\MSDeploy\3',
      'SOFTWARE\Wow6432Node\Microsoft\IIS Extensions\MSDeploy\3'
    ]
    VERSION_VALUE = 'Version'
    FAKE_VERSION = '99.0.0.0'

    def initialize(&block)
      begin
        patch.apply!
        yield block if block_given?
      ensure
        patch.revert!
      end
    end

    private
    def patch
      @patch ||= create_patch
    end

    def root
      Win32::Registry::HKEY_LOCAL_MACHINE
    end

    def delete_key(key)
      return nil unless key.created?

      keyname = key.keyname
      Proc.new {
        root.create(File.dirname(keyname)) do |r|
          r.delete_key(File.basename(keyname), true)
        end
      }
    end

    def delete_value(key, value)
      keyname = key.keyname
      Proc.new {
        root.create(keyname) do |r|
          r.delete_value(value)
        end
      }
    end

    def create_patch
      begin
        require 'win32/registry'
      rescue LoadError
        return Rake::Funnel::Support::Patch.new(self)
      end

      Rake::Funnel::Support::Patch.new(self) do |p|
        resets = []

        p.setup do
          resets = KEYS.map do |key|
            root.create(key) do |r|
              begin
                r[VERSION_VALUE]

                delete_version = Proc.new {}
              rescue Win32::Registry::Error
                r[VERSION_VALUE] = FAKE_VERSION

                delete_version = delete_value(r, VERSION_VALUE)
              end

              delete_key(r) || delete_version
            end
          end
        end

        p.reset do
          resets.compact.each do |reset|
            reset.call
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
rake-funnel-0.3.2.pre lib/rake/funnel/support/msdeploy/registry_patch.rb
rake-funnel-0.3.1.pre lib/rake/funnel/support/msdeploy/registry_patch.rb
rake-funnel-0.3.0.pre lib/rake/funnel/support/msdeploy/registry_patch.rb
rake-funnel-0.2.0.pre lib/rake/funnel/support/msdeploy/registry_patch.rb
rake-funnel-0.1.0.pre lib/rake/funnel/support/msdeploy/registry_patch.rb