Browse Source

* Patch from Bart Broersma to fix bug ID #35022

git-svn-id: trunk@44477 -
michael 5 years ago
parent
commit
25b7e1352b

+ 11 - 11
packages/fcl-registry/src/regini.inc

@@ -300,18 +300,18 @@ begin
   S:=Section;
   S:=Section;
   If (S<>'') and (S[1] = '\') then
   If (S<>'') and (S[1] = '\') then
     Delete(S,1,1);
     Delete(S,1,1);
-  if CreateSection then
-    CreateKey('\'+FPath+S);
-  if Section <> '' then
+  if CreateSection and (S<>'') then
+    CreateKey('\'+CurrentPath+'\'+S);
+  if S <> '' then
+    k:=GetKey('\'+CurrentPath+'\'+S)
+  else
+    k:=GetKey('\'+CurrentPath);
+  if k = 0 then
     begin
     begin
-    k:=GetKey('\'+FPath+S);
-    if k = 0 then
-      begin
-      Result:=False;
-      exit;
-      end;
-    SetCurrentKey(k);
-  end;
+    Result:=False;
+    exit;
+    end;
+  SetCurrentKey(k);
   Result:=True;
   Result:=True;
 end;
 end;
 
 

+ 14 - 0
packages/fcl-registry/src/registry.pp

@@ -57,6 +57,7 @@ type
     fRootKey: HKEY;
     fRootKey: HKEY;
     fLazyWrite: Boolean;
     fLazyWrite: Boolean;
     fCurrentPath: UnicodeString;
     fCurrentPath: UnicodeString;
+    function FixPath(APath: UnicodeString): UnicodeString;
     function GetLastErrorMsg: string;
     function GetLastErrorMsg: string;
     function RegMultiSzDataToUnicodeStringArray(U: UnicodeString): TUnicodeStringArray;
     function RegMultiSzDataToUnicodeStringArray(U: UnicodeString): TUnicodeStringArray;
     function ListToArray(List: TStrings; IsUtf8: Boolean): TUnicodeStringArray;
     function ListToArray(List: TStrings; IsUtf8: Boolean): TUnicodeStringArray;
@@ -632,6 +633,19 @@ begin
   ReadStringList(UnicodeString(Name), AList);
   ReadStringList(UnicodeString(Name), AList);
 end;
 end;
 
 
+function TRegistry.FixPath(APath: UnicodeString): UnicodeString;
+const
+  Delim={$ifdef XMLREG}'/'{$else}'\'{$endif};
+begin
+  //At this point we know the path is valid, since this is only called after OpenKey succeeded
+  //Just sanitize it
+  while (Pos(Delim+Delim,APath) > 0) do
+    APath := UnicodeStringReplace(APath, Delim+Delim,Delim,[rfReplaceAll]);
+  if (Length(APath) > 1) and (APath[Length(APath)] = Delim) then
+    System.Delete(APath, Length(APath), 1);
+  Result := APath;
+end;
+
 function TRegistry.RegMultiSzDataToUnicodeStringArray(U: UnicodeString): TUnicodeStringArray;
 function TRegistry.RegMultiSzDataToUnicodeStringArray(U: UnicodeString): TUnicodeStringArray;
 var
 var
   Len, i, p: Integer;
   Len, i, p: Integer;

+ 7 - 3
packages/fcl-registry/src/winreg.inc

@@ -227,8 +227,12 @@ begin
     end;                     
     end;                     
   If Result then begin
   If Result then begin
     if RelativeKey(Key) then
     if RelativeKey(Key) then
-      S:=CurrentPath + Key
-    else
+        begin
+          if (Key>'') and (CurrentPath>'') and (CurrentPath[Length(CurrentPath)]<>'\') then
+            S:=CurrentPath + '\' + Key
+          else
+            S:=CurrentPath + Key;
+        end  else
       S:=u;
       S:=u;
     ChangeKey(Handle, S);
     ChangeKey(Handle, S);
   end;
   end;
@@ -325,7 +329,7 @@ procedure TRegistry.ChangeKey(Value: HKey; const Path: UnicodeString);
 begin
 begin
   CloseKey;
   CloseKey;
   FCurrentKey:=Value;
   FCurrentKey:=Value;
-  FCurrentPath:=Path;
+  FCurrentPath:=FixPath(Path);
 end;
 end;
 
 
 
 

+ 1 - 0
packages/fcl-registry/src/xmlreg.pp

@@ -81,6 +81,7 @@ Type
     // These interpret the Data buffer as unicode data
     // These interpret the Data buffer as unicode data
     Function GetValueDataUnicode(Name : UnicodeString; Out DataType : TDataType; Var Data; Var DataSize : Integer) : Boolean;
     Function GetValueDataUnicode(Name : UnicodeString; Out DataType : TDataType; Var Data; Var DataSize : Integer) : Boolean;
     Function SetValueDataUnicode(Name : UnicodeString; DataType : TDataType; Const Data; DataSize : Integer) : Boolean;
     Function SetValueDataUnicode(Name : UnicodeString; DataType : TDataType; Const Data; DataSize : Integer) : Boolean;
+    Property CurrentKey: UnicodeString read FCurrentKey; //used by TRegistry
     Property FileName : String Read FFileName Write SetFileName;
     Property FileName : String Read FFileName Write SetFileName;
     Property RootKey : UnicodeString Read FRootKey Write SetRootkey;
     Property RootKey : UnicodeString Read FRootKey Write SetRootkey;
     Property AutoFlush : Boolean Read FAutoFlush Write FAutoFlush;
     Property AutoFlush : Boolean Read FAutoFlush Write FAutoFlush;

+ 14 - 1
packages/fcl-registry/src/xregreg.inc

@@ -223,9 +223,22 @@ end;
 
 
 function TRegistry.OpenKey(const Key: UnicodeString; CanCreate: Boolean): Boolean;
 function TRegistry.OpenKey(const Key: UnicodeString; CanCreate: Boolean): Boolean;
 
 
+var
+  S: UnicodeString;
+  P: SizeInt;
 begin
 begin
   Result:=TXmlRegistry(FSysData).SetKey(Key,CanCreate);
   Result:=TXmlRegistry(FSysData).SetKey(Key,CanCreate);
   FCurrentKey:=1;
   FCurrentKey:=1;
+  If Result then begin
+    S:=TXmlRegistry(FSysData).CurrentKey;
+    if (S>'') then begin
+      //S starts with RootKey+'/'
+      P:=Pos('/',S);
+      if (P>0) then
+        System.Delete(S,1,P);
+    end;
+    ChangeKey(FCurrentKey, S);
+  end;
 end;
 end;
 
 
 function TRegistry.OpenKeyReadOnly(const Key: UnicodeString): Boolean;
 function TRegistry.OpenKeyReadOnly(const Key: UnicodeString): Boolean;
@@ -266,7 +279,7 @@ end;
 
 
 procedure TRegistry.ChangeKey(Value: HKey; const Path: UnicodeString);
 procedure TRegistry.ChangeKey(Value: HKey; const Path: UnicodeString);
 begin
 begin
-
+  FCurrentPath:=FixPath(Path);
 end;
 end;
 
 
 function TRegistry.GetKeyNames: TUnicodeStringArray;
 function TRegistry.GetKeyNames: TUnicodeStringArray;