Sha256: 8c365edff05b510af62618f9a598995a3573a46f893c91f97d384f5f03bb4fb4

Contents?: true

Size: 1.55 KB

Versions: 101

Compression:

Stored size: 1.55 KB

Contents

class Knj::Win::Registry
  def self.const(type)
    if type == :cur_user
      return Win32::Registry::HKEY_CURRENT_USER
    elsif type == :local_machine
      return Win32::Registry::HKEY_LOCAL_MACHINE
    else
      raise "Unknown type: " + type.to_s
    end
  end
  
  def self.type(in_type)
    return Win32::Registry::REG_SZ if in_type == :sz
    return Win32::Registry::REG_DWORD if in_type == :dword
    return Win32::Registry::REG_BINARY if in_type == :bin
    return nil if in_type == nil
    
    raise "Unknown type: #{in_type}"
  end
  
  def self.get(type, regpath, key, in_type = nil)
    hkey = self.const(type)
    hkey.open(regpath, Win32::Registry::KEY_ALL_ACCESS) do |reg|
      return reg[key, self.type(in_type)].to_s
      
      #reg.each_key do |k, v|
      #  puts k, v
      #end
      #reg.each_value do |k, v|
      #  puts k, v
      #end
      
      #reg_typ, reg_val = reg.read('')
      #return {
      #  :type => reg_typ,
      #  :value => reg_val
      #}
    end
  end
  
  def self.set(type, regpath, key, content = nil, in_type = nil)
    if key.is_a?(Array)
      key.each do |v|
        if v.is_a?(Array)
          self.set(type, regpath, v[0], v[1], v[2])
        elsif v.is_a?(Hash)
          self.set(type, regpath, k, v[:val], v[:type])
        else
          raise "Unknown type: #{v.class.to_s}"
        end
      end
    else
      hkey = self.const(type)
      hkey.create(regpath)
      hkey.open(regpath, Win32::Registry::KEY_ALL_ACCESS) do |reg|
        reg[key.to_s, self.type(in_type)] = content.to_s
      end
    end
  end
end

Version data entries

101 entries across 101 versions & 1 rubygems

Version Path
knjrbfw-0.0.116 lib/knj/win_registry.rb
knjrbfw-0.0.115 lib/knj/win_registry.rb
knjrbfw-0.0.114 lib/knj/win_registry.rb
knjrbfw-0.0.113 lib/knj/win_registry.rb
knjrbfw-0.0.111 lib/knj/win_registry.rb
knjrbfw-0.0.110 lib/knj/win_registry.rb
knjrbfw-0.0.109 lib/knj/win_registry.rb
knjrbfw-0.0.108 lib/knj/win_registry.rb
knjrbfw-0.0.107 lib/knj/win_registry.rb
knjrbfw-0.0.105 lib/knj/win_registry.rb
knjrbfw-0.0.104 lib/knj/win_registry.rb
knjrbfw-0.0.103 lib/knj/win_registry.rb
knjrbfw-0.0.102 lib/knj/win_registry.rb
knjrbfw-0.0.101 lib/knj/win_registry.rb
knjrbfw-0.0.100 lib/knj/win_registry.rb
knjrbfw-0.0.99 lib/knj/win_registry.rb
knjrbfw-0.0.98 lib/knj/win_registry.rb
knjrbfw-0.0.97 lib/knj/win_registry.rb
knjrbfw-0.0.96 lib/knj/win_registry.rb
knjrbfw-0.0.95 lib/knj/win_registry.rb