Changeset 392 for Registry


Ignore:
Timestamp:
Jul 25, 2012, 4:09:33 PM (12 years ago)
Author:
chronos
Message:
Location:
Registry
Files:
9 added
2 edited

Legend:

Unmodified
Added
Removed
  • Registry/UGeneralRegistry.pas

    r391 r392  
    2525  end;
    2626
    27   TRegValueType = (vtUnknown, vtInteger, vtString, vtBinary, vtFloat, vtBoolean);
     27  TRegValueType = (vtUnknown, vtInteger, vtString, vtBinary, vtFloat, vtBoolean,
     28    vtText);
    2829
    2930  TRegValueInfo = record
    3031    ValueType: TRegValueType;
    3132    Size: Integer;
     33  end;
     34
     35  TRegKey = record
     36    Root: NativeInt;
     37    Path: string;
    3238  end;
    3339
     
    4450    function KeyExists(const Name: string): Boolean; virtual; abstract;
    4551    function ValueExists(const Name: string): Boolean; virtual; abstract;
     52    function GetKeyInfo(var Value: TRegKeyInfo): Boolean; virtual; abstract;
     53    function GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean; virtual; abstract;
     54    function GetValueType(const Name: string): TRegValueType; virtual; abstract;
     55    function GetValueSize(const Name: string): Integer; virtual; abstract;
    4656    function OpenKey(const Key: string; CreateNew: Boolean): Boolean; virtual; abstract;
    4757    procedure CloseKey; virtual; abstract;
     
    90100    function DeleteValue(const Name: string): Boolean;
    91101    function RenameValue(const OldName, NewName: string): Boolean;
     102    function GetKeyInfo(out Value: TRegKeyInfo): Boolean;
     103    function GetValueInfo(const Name: string; out Value: TRegValueInfo): Boolean;
     104    function GetValueType(const Name: string): TRegValueType;
     105    function GetValueSize(const Name: string): Integer;
    92106    function OpenKey(const Key: string; CreateNew: Boolean): Boolean;
    93107    function ReadBool(const Name: string): Boolean;
     
    97111    function ReadString(const Name: string): string;
    98112    function ReadBinaryData(const Name: string; var Buffer; BufSize: Integer): Integer;
     113    function ReadBoolDefault(const Name: string; const DefaultValue: Boolean): Boolean;
     114    function ReadDateTimeDefault(const Name: string; const DefaultValue: TDateTime): TDateTime;
     115    function ReadFloatDefault(const Name: string; const DefaultValue: Double): Double;
     116    function ReadIntegerDefault(const Name: string; const DefaultValue: Integer): Integer;
     117    function ReadStringDefault(const Name: string; const DefaultValue: string): string;
    99118    procedure WriteBool(const Name: string; Value: Boolean);
    100119    procedure WriteDateTime(const Name: string; Value: TDateTime);
     
    144163    function KeyExists(const Name: string): Boolean; override;
    145164    function ValueExists(const Name: string): Boolean; override;
     165    function GetKeyInfo(var Value: TRegKeyInfo): Boolean; override;
     166    function GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean; override;
     167    function GetValueType(const Name: string): TRegValueType; override;
     168    function GetValueSize(const Name: string): Integer; override;
    146169    function OpenKey(const Key: string; CreateNew: Boolean): Boolean; override;
    147170    procedure CloseKey; override;
     
    169192  {$ENDIF}
    170193
     194const
     195  RegValueTypeName: array[TRegValueType] of string = ('Unknown', 'Integer', 'String',
     196    'Binary', 'Float', 'Boolean', 'Text');
     197
    171198procedure Register;
    172199
     
    215242begin
    216243  Result := Registry.ValueExists(Name);
     244end;
     245
     246function TWinRegistry.GetKeyInfo(var Value: TRegKeyInfo): Boolean;
     247var
     248  KeyInfo: WinRegistry.TRegKeyInfo;
     249begin
     250  Result := Registry.GetKeyInfo(KeyInfo);
     251  if Result then begin
     252    Value.CreationTime := KeyInfo.FileTime;
     253    Value.ModificationTime := KeyInfo.FileTime;
     254    Value.MaxDataLength := KeyInfo.MaxDataLen;
     255    Value.MaxSubKeyLength := KeyInfo.MaxSubKeyLen;
     256    Value.MaxValueLength := KeyInfo.MaxValueLen;
     257    Value.NumberSubKeys := KeyInfo.NumSubKeys;
     258    Value.NumberValues := KeyInfo.NumValues;
     259  end;
     260end;
     261
     262function TWinRegistry.GetValueInfo(const Name: string; var Value: TRegValueInfo): Boolean;
     263var
     264  ValueInfo: WinRegistry.TRegDataInfo;
     265begin
     266  Result := Registry.GetDataInfo(Name, ValueInfo);
     267  if Result then begin
     268    Value.Size := ValueInfo.DataSize;
     269    case ValueInfo.RegData of
     270      rdUnknown: Value.ValueType := vtUnknown;
     271      rdString: Value.ValueType := vtString;
     272      rdExpandString: Value.ValueType := vtText;
     273      rdBinary: Value.ValueType := vtBinary;
     274      rdInteger: Value.ValueType := vtInteger;
     275    end;
     276  end;
     277end;
     278
     279function TWinRegistry.GetValueType(const Name: string): TRegValueType;
     280var
     281  ValueInfo: TRegValueInfo;
     282begin
     283  if GetValueInfo(Name, ValueInfo) then
     284    Result := ValueInfo.ValueType else Result := vtUnknown;
     285end;
     286
     287function TWinRegistry.GetValueSize(const Name: string): Integer;
     288begin
     289  Result := Registry.GetDataSize(Name);
    217290end;
    218291
     
    447520end;
    448521
     522function TGeneralRegistry.GetKeyInfo(out Value: TRegKeyInfo): Boolean;
     523begin
     524  CheckBackend;
     525  Result := Backend.GetKeyInfo(Value);
     526end;
     527
     528function TGeneralRegistry.GetValueInfo(const Name: string; out Value: TRegValueInfo): Boolean;
     529begin
     530  CheckBackend;
     531  Result := Backend.GetValueInfo(Name, Value);
     532end;
     533
     534function TGeneralRegistry.GetValueType(const Name: string): TRegValueType;
     535begin
     536  CheckBackend;
     537  Result := Backend.GetValueType(Name);
     538end;
     539
     540function TGeneralRegistry.GetValueSize(const Name: string): Integer;
     541begin
     542  CheckBackend;
     543  Result := Backend.GetValueSize(Name);
     544end;
     545
    449546function TGeneralRegistry.DeleteKey(const Name: string; Recursive: Boolean = False): Boolean;
    450547begin
     
    494591  CheckBackend;
    495592  Result := Backend.ReadBinaryData(Name, Buffer, BufSize);
     593end;
     594
     595function TGeneralRegistry.ReadBoolDefault(const Name: string;
     596  const DefaultValue: Boolean): Boolean;
     597begin
     598  if ValueExists(Name) then Result := ReadBool(Name)
     599    else Result := DefaultValue;
     600end;
     601
     602function TGeneralRegistry.ReadDateTimeDefault(const Name: string;
     603  const DefaultValue: TDateTime): TDateTime;
     604begin
     605  if ValueExists(Name) then Result := ReadDateTime(Name)
     606    else Result := DefaultValue;
     607end;
     608
     609function TGeneralRegistry.ReadFloatDefault(const Name: string;
     610  const DefaultValue: Double): Double;
     611begin
     612  if ValueExists(Name) then Result := ReadFloat(Name)
     613    else Result := DefaultValue;
     614end;
     615
     616function TGeneralRegistry.ReadIntegerDefault(const Name: string;
     617  const DefaultValue: Integer): Integer;
     618begin
     619  if ValueExists(Name) then Result := ReadInteger(Name)
     620    else Result := DefaultValue;
     621end;
     622
     623function TGeneralRegistry.ReadStringDefault(const Name: string;
     624  const DefaultValue: string): string;
     625begin
     626  if ValueExists(Name) then Result := ReadString(Name)
     627    else Result := DefaultValue;
    496628end;
    497629
  • Registry/WinRegistry.pas

    r390 r392  
     1// FPC windows registry implementation with removed linux xmlregistry imitation
     2
    13unit WinRegistry;
    24
Note: See TracChangeset for help on using the changeset viewer.