Xregistry

Check-in [e0ac02449c]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix implementation of deleteSection under Windows.
Timelines: family | ancestors | descendants | both | trunk | version-1.3.4
Files: files | file ages | folders
SHA1:e0ac02449c27371be10dc717de6d250537f238cc
User & Date: wbp 2016-02-14 03:44:03
Context
2016-02-15
22:59
Correct homepage and eliminate dependency on cat(1) in gemspec. check-in: 009e45c5ff user: wbp tags: trunk, version-1.3.5
2016-02-14
03:44
Fix implementation of deleteSection under Windows. check-in: e0ac02449c user: wbp tags: trunk, version-1.3.4
2016-02-06
22:12
Add tests. check-in: d1ec4fbec8 user: wbp tags: trunk, version-1.3.3
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Rakefile.

1
2
3
4
5
6
7
8
9
10
11
12
13
14

15
16
17
18
19
20
21
# Rakefile for xregistry gem.
# Last modified:  06-Feb-2016  Wm. Parsons

require 'rake/testtask'

name    = 'xregistry'
version = %x[cat VERSION].chomp
package = "#{name}-#{version}"

distfiles = %w[
  LICENSE
  Rakefile
  VERSION
  lib/xregistry.rb

  xregistry.gemspec
]

task :default => [:build]

desc "Build #{name} gem"
task :build do

|












>







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Rakefile for xregistry gem.
# Last modified:  13-Feb-2016  Wm. Parsons

require 'rake/testtask'

name    = 'xregistry'
version = %x[cat VERSION].chomp
package = "#{name}-#{version}"

distfiles = %w[
  LICENSE
  Rakefile
  VERSION
  lib/xregistry.rb
  test/test_xregistry.rb
  xregistry.gemspec
]

task :default => [:build]

desc "Build #{name} gem"
task :build do

Changes to VERSION.

1
1.3.3
|
1
1.3.4

Changes to lib/xregistry.rb.

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
38
39
40
41
42
43
44










45

46
47
48
49
50
51
52
#  registry, but without needing the FOX toolkit.
#
#  The original FOX registry uses the Windows registry if running under Windows,
#  and an .INI type file if running under Unix-type systems.  This class also
#  uses the Windows registry if running under Windows, but uses an SQLite3
#  database if running under a Unix-type system.
#
#  Last revised:  20-Jan-2016  Wm. Parsons
################################################################################


class Registry
  # Construct registry object; app_key and vendor_key must be string constants.
  # Regular applications SHOULD set a vendor key!
  def initialize(app_key = '', vendor_key = '')
................................................................................

      @db = SQLite3::Database.new("#{regdir}/#{app_key}.db3")
    end
  end

  # Delete a specified section from the registry.
  def deleteSection(section)










    @db.execute "drop table if exists \"#{section}\""

  end
  alias delete_section deleteSection

  # Read a boolean registry entry from the specified section and key.  If no
  # value is found, the default value is returned.
  def readBoolEntry(section, key, default = false)
    readEntry(section, key, default ? 1 : 0) == 0 ? false : true







|







 







>
>
>
>
>
>
>
>
>
>
|
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
..
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#  registry, but without needing the FOX toolkit.
#
#  The original FOX registry uses the Windows registry if running under Windows,
#  and an .INI type file if running under Unix-type systems.  This class also
#  uses the Windows registry if running under Windows, but uses an SQLite3
#  database if running under a Unix-type system.
#
#  Last revised:  13-Feb-2016  Wm. Parsons
################################################################################


class Registry
  # Construct registry object; app_key and vendor_key must be string constants.
  # Regular applications SHOULD set a vendor key!
  def initialize(app_key = '', vendor_key = '')
................................................................................

      @db = SQLite3::Database.new("#{regdir}/#{app_key}.db3")
    end
  end

  # Delete a specified section from the registry.
  def deleteSection(section)
    if @on_windows
      begin
        pkey = [@root_key, section].join('\\')
        access = Win32::Registry::KEY_ALL_ACCESS
        Win32::Registry::HKEY_CURRENT_USER.open(@root_key, access) do |reg|
          reg.delete_key(section, true)
        end
      rescue Win32::Registry::Error
      end
    else
      @db.execute "drop table if exists \"#{section}\""
    end
  end
  alias delete_section deleteSection

  # Read a boolean registry entry from the specified section and key.  If no
  # value is found, the default value is returned.
  def readBoolEntry(section, key, default = false)
    readEntry(section, key, default ? 1 : 0) == 0 ? false : true

Changes to test/test_xregistry.rb.

1
2
3
4
5
6
7
8
9
..
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
# test program for wregistry gem
# Last modified:  06-Feb-2016

require 'xregistry'
require 'test/unit'

class TestWregistry < Test::Unit::TestCase
  def setup
    @@reg ||= Registry.new('testxreg', 'Wikareia')
................................................................................
    @@reg.writeStringEntry('Settings', 'string_key2', 'test value')
    string = @@reg.readStringEntry('Settings', 'string_key2', nil)
    assert_equal('test value', string)
  end

  # test of deleteSection
  def test_delete_section

    @@reg.deleteSection('Settings')
    string = @@reg.readStringEntry('Settings', 'section', 'no value')
    assert_equal('no value', string)

    # test of deleteSection when section doesn't exist
    @@reg.deleteSection('Settings')
    string = @@reg.readStringEntry('Settings', 'section', 'no value')
    assert_equal('no value', string)
  end
end

|







 







>

|




|



1
2
3
4
5
6
7
8
9
..
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# test program for wregistry gem
# Last modified:  13-Feb-2016

require 'xregistry'
require 'test/unit'

class TestWregistry < Test::Unit::TestCase
  def setup
    @@reg ||= Registry.new('testxreg', 'Wikareia')
................................................................................
    @@reg.writeStringEntry('Settings', 'string_key2', 'test value')
    string = @@reg.readStringEntry('Settings', 'string_key2', nil)
    assert_equal('test value', string)
  end

  # test of deleteSection
  def test_delete_section
    @@reg.writeStringEntry('Settings', 'key', 'dummy value')
    @@reg.deleteSection('Settings')
    string = @@reg.readStringEntry('Settings', 'key', 'no value')
    assert_equal('no value', string)

    # test of deleteSection when section doesn't exist
    @@reg.deleteSection('Settings')
    string = @@reg.readStringEntry('Settings', 'key', 'no value')
    assert_equal('no value', string)
  end
end