Commit 1fdc61b5 by Vasiliy Fofanov Committed by Arnaud Charlet

g-regist.ads, [...] (Set_Value): new parameter Expand...

2007-12-06  Vasiliy Fofanov  <fofanov@adacore.com>

	* g-regist.ads, g-regist.adb (Set_Value): new parameter Expand; when
	set to True this procedure will create the value of type REG_EXPAND_SZ.
	It was only possible to create REG_SZ values before.

From-SVN: r130842
parent 422ba273
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- B o d y -- -- B o d y --
-- -- -- --
-- Copyright (C) 2001-2005, Free Software Foundation, Inc. -- -- Copyright (C) 2001-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -154,7 +154,6 @@ package body GNAT.Registry is ...@@ -154,7 +154,6 @@ package body GNAT.Registry is
procedure Check_Result (Result : LONG; Message : String) is procedure Check_Result (Result : LONG; Message : String) is
use type LONG; use type LONG;
begin begin
if Result /= ERROR_SUCCESS then if Result /= ERROR_SUCCESS then
Exceptions.Raise_Exception Exceptions.Raise_Exception
...@@ -169,7 +168,6 @@ package body GNAT.Registry is ...@@ -169,7 +168,6 @@ package body GNAT.Registry is
procedure Close_Key (Key : HKEY) is procedure Close_Key (Key : HKEY) is
Result : LONG; Result : LONG;
begin begin
Result := RegCloseKey (Key); Result := RegCloseKey (Key);
Check_Result (Result, "Close_Key"); Check_Result (Result, "Close_Key");
...@@ -198,7 +196,8 @@ package body GNAT.Registry is ...@@ -198,7 +196,8 @@ package body GNAT.Registry is
Dispos : aliased DWORD; Dispos : aliased DWORD;
begin begin
Result := RegCreateKeyEx Result :=
RegCreateKeyEx
(From_Key, (From_Key,
C_Sub_Key (C_Sub_Key'First)'Address, C_Sub_Key (C_Sub_Key'First)'Address,
0, 0,
...@@ -220,7 +219,6 @@ package body GNAT.Registry is ...@@ -220,7 +219,6 @@ package body GNAT.Registry is
procedure Delete_Key (From_Key : HKEY; Sub_Key : String) is procedure Delete_Key (From_Key : HKEY; Sub_Key : String) is
C_Sub_Key : constant String := Sub_Key & ASCII.Nul; C_Sub_Key : constant String := Sub_Key & ASCII.Nul;
Result : LONG; Result : LONG;
begin begin
Result := RegDeleteKey (From_Key, C_Sub_Key (C_Sub_Key'First)'Address); Result := RegDeleteKey (From_Key, C_Sub_Key (C_Sub_Key'First)'Address);
Check_Result (Result, "Delete_Key " & Sub_Key); Check_Result (Result, "Delete_Key " & Sub_Key);
...@@ -233,7 +231,6 @@ package body GNAT.Registry is ...@@ -233,7 +231,6 @@ package body GNAT.Registry is
procedure Delete_Value (From_Key : HKEY; Sub_Key : String) is procedure Delete_Value (From_Key : HKEY; Sub_Key : String) is
C_Sub_Key : constant String := Sub_Key & ASCII.Nul; C_Sub_Key : constant String := Sub_Key & ASCII.Nul;
Result : LONG; Result : LONG;
begin begin
Result := RegDeleteValue (From_Key, C_Sub_Key (C_Sub_Key'First)'Address); Result := RegDeleteValue (From_Key, C_Sub_Key (C_Sub_Key'First)'Address);
Check_Result (Result, "Delete_Value " & Sub_Key); Check_Result (Result, "Delete_Value " & Sub_Key);
...@@ -271,7 +268,8 @@ package body GNAT.Registry is ...@@ -271,7 +268,8 @@ package body GNAT.Registry is
Size_Sub_Key := Sub_Key'Length; Size_Sub_Key := Sub_Key'Length;
Size_Value := Value'Length; Size_Value := Value'Length;
Result := RegEnumValue Result :=
RegEnumValue
(From_Key, Index, (From_Key, Index,
Sub_Key (1)'Address, Sub_Key (1)'Address,
Size_Sub_Key'Unchecked_Access, Size_Sub_Key'Unchecked_Access,
...@@ -285,7 +283,8 @@ package body GNAT.Registry is ...@@ -285,7 +283,8 @@ package body GNAT.Registry is
Quit := False; Quit := False;
if Type_Sub_Key = REG_EXPAND_SZ and then Expand then if Type_Sub_Key = REG_EXPAND_SZ and then Expand then
Action (Natural (Index) + 1, Action
(Natural (Index) + 1,
Sub_Key (1 .. Integer (Size_Sub_Key)), Sub_Key (1 .. Integer (Size_Sub_Key)),
Directory_Operations.Expand_Path Directory_Operations.Expand_Path
(Value (1 .. Integer (Size_Value) - 1), (Value (1 .. Integer (Size_Value) - 1),
...@@ -293,7 +292,8 @@ package body GNAT.Registry is ...@@ -293,7 +292,8 @@ package body GNAT.Registry is
Quit); Quit);
elsif Type_Sub_Key = REG_SZ or else Type_Sub_Key = REG_EXPAND_SZ then elsif Type_Sub_Key = REG_SZ or else Type_Sub_Key = REG_EXPAND_SZ then
Action (Natural (Index) + 1, Action
(Natural (Index) + 1,
Sub_Key (1 .. Integer (Size_Sub_Key)), Sub_Key (1 .. Integer (Size_Sub_Key)),
Value (1 .. Integer (Size_Value) - 1), Value (1 .. Integer (Size_Value) - 1),
Quit); Quit);
...@@ -349,7 +349,8 @@ package body GNAT.Registry is ...@@ -349,7 +349,8 @@ package body GNAT.Registry is
Result : LONG; Result : LONG;
begin begin
Result := RegOpenKeyEx Result :=
RegOpenKeyEx
(From_Key, (From_Key,
C_Sub_Key (C_Sub_Key'First)'Address, C_Sub_Key (C_Sub_Key'First)'Address,
0, 0,
...@@ -385,7 +386,8 @@ package body GNAT.Registry is ...@@ -385,7 +386,8 @@ package body GNAT.Registry is
begin begin
Size_Value := Value'Length; Size_Value := Value'Length;
Result := RegQueryValueEx Result :=
RegQueryValueEx
(From_Key, (From_Key,
C_Sub_Key (C_Sub_Key'First)'Address, C_Sub_Key (C_Sub_Key'First)'Address,
null, null,
...@@ -410,19 +412,28 @@ package body GNAT.Registry is ...@@ -410,19 +412,28 @@ package body GNAT.Registry is
procedure Set_Value procedure Set_Value
(From_Key : HKEY; (From_Key : HKEY;
Sub_Key : String; Sub_Key : String;
Value : String) Value : String;
Expand : Boolean := False)
is is
C_Sub_Key : constant String := Sub_Key & ASCII.Nul; C_Sub_Key : constant String := Sub_Key & ASCII.Nul;
C_Value : constant String := Value & ASCII.Nul; C_Value : constant String := Value & ASCII.Nul;
Value_Type : DWORD;
Result : LONG; Result : LONG;
begin begin
Result := RegSetValueEx if Expand then
Value_Type := REG_EXPAND_SZ;
else
Value_Type := REG_SZ;
end if;
Result :=
RegSetValueEx
(From_Key, (From_Key,
C_Sub_Key (C_Sub_Key'First)'Address, C_Sub_Key (C_Sub_Key'First)'Address,
0, 0,
REG_SZ, Value_Type,
C_Value (C_Value'First)'Address, C_Value (C_Value'First)'Address,
C_Value'Length); C_Value'Length);
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
-- -- -- --
-- S p e c -- -- S p e c --
-- -- -- --
-- Copyright (C) 2001-2005, Free Software Foundation, Inc. -- -- Copyright (C) 2001-2007, Free Software Foundation, Inc. --
-- -- -- --
-- GNAT is free software; you can redistribute it and/or modify it under -- -- GNAT is free software; you can redistribute it and/or modify it under --
-- terms of the GNU General Public License as published by the Free Soft- -- -- terms of the GNU General Public License as published by the Free Soft- --
...@@ -95,8 +95,14 @@ package GNAT.Registry is ...@@ -95,8 +95,14 @@ package GNAT.Registry is
-- REG_EXPAND_SZ the returned value will have the %name% variables -- REG_EXPAND_SZ the returned value will have the %name% variables
-- replaced by the corresponding environment variable value. -- replaced by the corresponding environment variable value.
procedure Set_Value (From_Key : HKEY; Sub_Key : String; Value : String); procedure Set_Value
-- Add the pair (Sub_Key, Value) into From_Key registry key (From_Key : HKEY;
Sub_Key : String;
Value : String;
Expand : Boolean := False);
-- Add the pair (Sub_Key, Value) into From_Key registry key.
-- By default the value created is of type REG_SZ, unless
-- Expand is True in which case it is of type REG_EXPAND_SZ
procedure Delete_Key (From_Key : HKEY; Sub_Key : String); procedure Delete_Key (From_Key : HKEY; Sub_Key : String);
-- Remove Sub_Key from the registry key From_Key -- Remove Sub_Key from the registry key From_Key
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment