- Timestamp:
- Aug 5, 2008, 4:59:56 AM (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/ab5.0/ablib/src/Classes/ActiveBasic/Windows/Registry.ab
r573 r577 35 35 rootkeyname As String 36 36 subkeyname As String 37 edited As Boolean 37 38 38 39 Virtual Sub ~RegistryKey( ) … … 43 44 'キーの名前を取得します。 44 45 Function Name( ) As String 45 Dim name = rootkeyname + "\" + subkeyname 46 Dim name As String 47 If IsNothing(This.subkeyname) Then 48 name = This.rootkeyname 49 Else 50 name = This.rootkeyname + "\" + This.subkeyname 51 End If 46 52 Return name 47 53 End Function … … 64 70 'キーを閉じ、キーの内容が変更されている場合はディスクへフラッシュします。 65 71 Sub Close( ) 66 This.Flush()72 If This.edited Then This.Flush() 67 73 RegCloseKey( This.handle ) 68 74 End Sub … … 70 76 '新しいサブキーを作成するか、または既存のサブキーを開きます。 71 77 Function CreateSubKey( subkey As String ) As RegistryKey 78 If IsNothing(subkey) Then Return Nothing 79 Dim buf = subkey 80 '末尾の\を除去 81 If buf.EndsWith( "\" ) Then 82 buf = buf.Remove( buf.Length - 1 ) 83 End If 84 '先頭の\を除去 85 If buf.StartsWith( "\" ) Then 86 buf = buf.Remove( 0, 1 ) 87 End If 88 72 89 Dim key As Detail._System_RegistryKey 73 90 key.Root( This.rootkey ) 74 key.SubKey( subkey ) 91 If IsNothing(This.subkeyname) Then 92 key.SubKey( buf ) 93 Else 94 key.SubKey( This.subkeyname + "\" + buf ) 95 End If 75 96 key.Create( ) 76 97 Return key … … 87 108 '指定したサブキーを削除します。文字列 subkey では、大文字と小文字は区別されません。 88 109 Sub DeleteSubKey ( subkey As String ) 110 If IsNothing( subkey ) Then Exit Sub 111 This.DeleteSubKey( subkey, True ) 89 112 End Sub 90 113 Sub DeleteSubKey ( subkey As String, throwOnMissingSubKey As Boolean ) 114 If IsNothing( subkey ) Then Exit Sub 115 Dim key = This.OpenSubKey(subkey) 116 If key.SubKeyCount <> 0 Then 117 key.Close() 118 If throwOnMissingSubKey Then 119 Throw New InvalidOperationException 120 Else 121 Exit Sub 122 End If 123 End If 124 RegDeleteKey( This.handle, ToTCStr(subkey) ) 125 This.edited = True 91 126 End Sub 92 127 93 128 'サブキーとその子サブキーを再帰的に削除します。文字列 subkey では、大文字と小文字は区別されません。 94 129 Sub DeleteSubKeyTree ( subkey As String ) 130 If IsNothing( subkey ) Then Exit Sub 131 Dim key = This.OpenSubKey( subkey ) 132 If key.SubKeyCount <> 0 Then 133 Dim list = key.GetSubKeyNames() 134 Dim s As String 135 Foreach s In list 136 key.DeleteSubKeyTree( s ) 137 Next 138 End If 139 This.DeleteSubKey( subkey, False ) 95 140 End Sub 96 141 97 142 '指定した値をこのキーから削除します。 98 143 Sub DeleteValue ( name As String ) 99 RegDeleteValue( This.handle, name ) 144 If IsNothing( name ) Then Exit Sub 145 This.DeleteValue( name, True ) 100 146 End Sub 101 147 Sub DeleteValue ( name As String, throwOnMissingValue As Boolean ) 148 If IsNothing( name ) Then Exit Sub 149 RegDeleteValue( This.handle, ToTCStr(name) ) 150 This.edited = True 102 151 End Sub 103 152 … … 172 221 '指定した名前に関連付けられた値のレジストリ データ型を取得します。 173 222 Function GetValueKind ( name As String ) As RegistryValueKind 223 If IsNothing( name ) Then Exit Sub 174 224 Dim dwType As DWord 175 225 If ERROR_SUCCESS <> RegQueryValueEx( This.handle, ToTCStr(name), 0, VarPtr(dwType), NULL, NULL ) Then … … 212 262 '指定したサブキーを取得します。 213 263 Function OpenSubKey ( name As String ) As RegistryKey 264 If IsNothing(name) Then Return Nothing 265 Dim buf = name 266 '末尾の\を除去 267 If buf.EndsWith( "\" ) Then 268 buf = buf.Remove( buf.Length - 1 ) 269 End If 270 '先頭の\を除去 271 If buf.StartsWith( "\" ) Then 272 buf = buf.Remove( 0, 1 ) 273 End If 274 214 275 Dim key As Detail._System_RegistryKey 215 276 key.Root( This.rootkey ) 216 key.SubKey( name ) 277 If IsNothing(This.subkeyname) Then 278 key.SubKey( buf ) 279 Else 280 key.SubKey( This.subkeyname + "\" + buf ) 281 End If 217 282 key.Open( ) 218 283 Return key … … 273 338 274 339 Sub SubKey( subkey As String ) 340 If IsNothing(subkey) Then Exit Sub 275 341 This.subkeyname = subkey 276 If This.subkeyname.EndsWith( "\" ) Then277 This.subkeyname.Remove( This.subkeyname.Length - 1 )278 End If279 342 End Sub 280 343 281 344 Sub Create() 282 RegCreateKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ READ or KEY_WRITE, NULL, This.handle, NULL )345 RegCreateKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, NULL, REG_OPTION_NON_VOLATILE, KEY_ALL_ACCESS, NULL, This.handle, NULL ) 283 346 End Sub 284 347 ' Function Create( permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey … … 290 353 291 354 Sub Open() 292 RegOpenKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, KEY_ READ or KEY_WRITE, This.handle )355 RegOpenKeyEx( This.rootkey, ToTCStr(This.subkeyname), 0, KEY_ALL_ACCESS, This.handle ) 293 356 End Sub 294 357 ' Function Open( permissionCheck As RegistryKeyPermissionCheck ) As RegistryKey
Note:
See TracChangeset
for help on using the changeset viewer.