mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-10-18 11:31:46 +02:00
* Save config strings to/from ini file
git-svn-id: trunk@41440 -
This commit is contained in:
parent
f097158802
commit
1d5877ecf0
@ -50,7 +50,8 @@ Type
|
|||||||
dioDisableSchemas, // Do not enable schemas
|
dioDisableSchemas, // Do not enable schemas
|
||||||
dioSkipWriteConnections, // Do not write connection definitions
|
dioSkipWriteConnections, // Do not write connection definitions
|
||||||
dioSkipWriteSchemas, // Do not Read schema definitions
|
dioSkipWriteSchemas, // Do not Read schema definitions
|
||||||
dioSkipBasicAuth // Do not read/write basic auth data.
|
dioSkipBasicAuth, // Do not read/write basic auth data.
|
||||||
|
dioSkipStringConfig // Do not read strings config
|
||||||
);
|
);
|
||||||
TDispatcherIniOptions = set of TDispatcherIniOption;
|
TDispatcherIniOptions = set of TDispatcherIniOption;
|
||||||
|
|
||||||
@ -73,6 +74,20 @@ Type
|
|||||||
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TDispatcherIniOptions); overload;
|
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String; aOptions : TDispatcherIniOptions); overload;
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TRestStringsConfigHelper }
|
||||||
|
|
||||||
|
TRestStringsConfigHelper = class helper for TRestStringsConfig
|
||||||
|
Public
|
||||||
|
Procedure LoadFromIni(Const aIni: TCustomIniFile); overload;
|
||||||
|
Procedure LoadFromIni(Const aIni: TCustomIniFile; ASection : String); overload;
|
||||||
|
Procedure LoadFromFile(Const aFileName : String); overload;
|
||||||
|
Procedure LoadFromFile(Const aFileName : String; Const ASection : String); overload;
|
||||||
|
Procedure SaveToFile(Const aFileName : String);overload;
|
||||||
|
Procedure SaveToFile(Const aFileName : String; Const ASection : String);overload;
|
||||||
|
Procedure SaveToIni(Const aIni: TCustomIniFile); overload;
|
||||||
|
Procedure SaveToIni(Const aIni: TCustomIniFile; ASection : String); overload;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
Function StrToOutputOptions(S : String) : TRestOutputOptions;
|
Function StrToOutputOptions(S : String) : TRestOutputOptions;
|
||||||
Function StrToDispatcherOptions(S : String) : TRestDispatcherOptions;
|
Function StrToDispatcherOptions(S : String) : TRestDispatcherOptions;
|
||||||
@ -85,6 +100,7 @@ Var
|
|||||||
TrivialEncryptKey : String = 'SQLDB';
|
TrivialEncryptKey : String = 'SQLDB';
|
||||||
DefaultConnectionSection : String = 'Connection';
|
DefaultConnectionSection : String = 'Connection';
|
||||||
DefaultDispatcherSection : String = 'Dispatcher';
|
DefaultDispatcherSection : String = 'Dispatcher';
|
||||||
|
DefaultStringsConfigSection : String = 'Dispatcher_strings';
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
|
||||||
@ -172,6 +188,86 @@ begin
|
|||||||
Result:=SetToString(PTypeInfo(TypeInfo(TConnectionIniOptions)),Integer(Options),false);
|
Result:=SetToString(PTypeInfo(TypeInfo(TConnectionIniOptions)),Integer(Options),false);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
{ TRestStringsConfigHelper }
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.LoadFromIni(const aIni: TCustomIniFile);
|
||||||
|
begin
|
||||||
|
LoadFromIni(aIni,DefaultStringsConfigSection);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.LoadFromIni(const aIni: TCustomIniFile; ASection: String);
|
||||||
|
|
||||||
|
Var
|
||||||
|
T : TRestStringProperty;
|
||||||
|
N : String;
|
||||||
|
S : UTF8String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
For T in TRestStringProperty do
|
||||||
|
begin
|
||||||
|
Str(T,N);
|
||||||
|
Delete(N,1,2);
|
||||||
|
S:=aIni.ReadString(aSection, N, GetRestString(T));
|
||||||
|
SetRestString(T,S);
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.LoadFromFile(const aFileName: String);
|
||||||
|
begin
|
||||||
|
LoadFromFile(aFileName,DefaultStringsConfigSection);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.LoadFromFile(const aFileName: String; const ASection: String);
|
||||||
|
Var
|
||||||
|
Ini : TCustomIniFile;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Ini:=TMeminiFile.Create(aFileName);
|
||||||
|
try
|
||||||
|
LoadFromIni(Ini,aSection);
|
||||||
|
finally
|
||||||
|
Ini.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.SaveToFile(const aFileName: String);
|
||||||
|
begin
|
||||||
|
SaveToFile(aFileName,DefaultStringsConfigSection);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.SaveToFile(const aFileName: String; const ASection: String);
|
||||||
|
Var
|
||||||
|
Ini : TCustomIniFile;
|
||||||
|
|
||||||
|
begin
|
||||||
|
Ini:=TMeminiFile.Create(aFileName);
|
||||||
|
try
|
||||||
|
SaveToIni(Ini,aSection);
|
||||||
|
Ini.UpdateFile;
|
||||||
|
finally
|
||||||
|
Ini.Free;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.SaveToIni(const aIni: TCustomIniFile);
|
||||||
|
begin
|
||||||
|
SaveToini(aIni,DefaultStringsConfigSection);
|
||||||
|
end;
|
||||||
|
|
||||||
|
procedure TRestStringsConfigHelper.SaveToIni(const aIni: TCustomIniFile; ASection: String);
|
||||||
|
Var
|
||||||
|
T : TRestStringProperty;
|
||||||
|
N : String;
|
||||||
|
|
||||||
|
begin
|
||||||
|
For T in TRestStringProperty do
|
||||||
|
begin
|
||||||
|
Str(T,N);
|
||||||
|
Delete(N,1,2);
|
||||||
|
aIni.WriteString(aSection, N, GetRestString(T));
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
{ TSQLDBRestDispatcherHelper }
|
{ TSQLDBRestDispatcherHelper }
|
||||||
@ -327,6 +423,8 @@ begin
|
|||||||
Self.Authenticator:=BA;
|
Self.Authenticator:=BA;
|
||||||
end;
|
end;
|
||||||
end;
|
end;
|
||||||
|
if not (dioSkipStringConfig in aOptions) then
|
||||||
|
Strings.LoadFromIni(aIni,aSection+'_strings');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure TSQLDBRestDispatcherHelper.LoadFromFile(const aFileName: String; aOptions: TDispatcherIniOptions);
|
procedure TSQLDBRestDispatcherHelper.LoadFromFile(const aFileName: String; aOptions: TDispatcherIniOptions);
|
||||||
@ -361,6 +459,7 @@ begin
|
|||||||
Ini:=TMeminiFile.Create(aFileName);
|
Ini:=TMeminiFile.Create(aFileName);
|
||||||
try
|
try
|
||||||
SaveToIni(Ini,aSection,aOptions);
|
SaveToIni(Ini,aSection,aOptions);
|
||||||
|
Ini.UpdateFile;
|
||||||
finally
|
finally
|
||||||
Ini.Free;
|
Ini.Free;
|
||||||
end;
|
end;
|
||||||
@ -396,7 +495,8 @@ begin
|
|||||||
TRestBasicAuthenticator(Authenticator).SaveToIni(aIni,BAN,[]);
|
TRestBasicAuthenticator(Authenticator).SaveToIni(aIni,BAN,[]);
|
||||||
aIni.WriteString(aSection,KeyBasicAuth,BAN);
|
aIni.WriteString(aSection,KeyBasicAuth,BAN);
|
||||||
end;
|
end;
|
||||||
Aini.UpdateFile;
|
if not (dioSkipStringConfig in aOptions) then
|
||||||
|
Strings.SaveToIni(aIni,aSection+'_strings');
|
||||||
end;
|
end;
|
||||||
|
|
||||||
{ TSQLDBRestConnectionHelper }
|
{ TSQLDBRestConnectionHelper }
|
||||||
@ -512,6 +612,7 @@ begin
|
|||||||
Ini:=TMeminiFile.Create(aFileName);
|
Ini:=TMeminiFile.Create(aFileName);
|
||||||
try
|
try
|
||||||
SaveToini(Ini,aSection,aOptions);
|
SaveToini(Ini,aSection,aOptions);
|
||||||
|
Ini.UpdateFile;
|
||||||
finally
|
finally
|
||||||
Ini.Free;
|
Ini.Free;
|
||||||
end;
|
end;
|
||||||
|
Loading…
Reference in New Issue
Block a user