Module: Wine
- Defined in:
- documented/wine.rb
Overview
Module for interacting with WINE registry This module provides methods to get and set values in the WINE registry.
Constant Summary collapse
- BIN =
The path to the WINE binary
$wine_bin- PREFIX =
The path to the WINE prefix
$wine_prefix
Class Method Summary collapse
-
.registry_gets(key) ⇒ String, false
Retrieves a value from the WINE registry.
-
.registry_puts(key, value) ⇒ Boolean
Sets a value in the WINE registry.
Class Method Details
.registry_gets(key) ⇒ String, false
Retrieves a value from the WINE registry
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'documented/wine.rb', line 42 def Wine.registry_gets(key) hkey, subkey, thingie = /(HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER)\\(.+)\\([^\\]*)/.match(key).captures # fixme: stupid highlights ]/ if File.exist?(PREFIX + '/system.reg') if hkey == 'HKEY_LOCAL_MACHINE' subkey = "[#{subkey.gsub('\\', '\\\\\\')}]" if thingie.nil? or thingie.empty? thingie = '@' else thingie = "\"#{thingie}\"" end lookin = result = false File.open(PREFIX + '/system.reg') { |f| f.readlines }.each { |line| if line[0...subkey.length] == subkey lookin = true elsif line =~ /^\[/ lookin = false elsif lookin and line =~ /^#{thingie}="(.*)"$/i result = $1.split('\\"').join('"').split('\\\\').join('\\').sub(/\\0$/, '') break end } return result else return false end else return false end end |
.registry_puts(key, value) ⇒ Boolean
Sets a value in the WINE registry
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'documented/wine.rb', line 79 def Wine.registry_puts(key, value) hkey, subkey, thingie = /(HKEY_LOCAL_MACHINE|HKEY_CURRENT_USER)\\(.+)\\([^\\]*)/.match(key).captures # fixme ]/ if File.exist?(PREFIX) if thingie.nil? or thingie.empty? thingie = '@' else thingie = "\"#{thingie}\"" end # gsub sucks for this.. value = value.split('\\').join('\\\\') value = value.split('"').join('\"') begin regedit_data = "REGEDIT4\n\n[#{hkey}\\#{subkey}]\n#{thingie}=\"#{value}\"\n\n" filename = "#{TEMP_DIR}/wine-#{Time.now.to_i}.reg" File.open(filename, 'w') { |f| f.write(regedit_data) } system("#{BIN} regedit #{filename}") sleep 0.2 File.delete(filename) rescue return false end return true end end |