mirror of
https://gitlab.com/freepascal.org/fpc/source.git
synced 2025-08-17 03:59:13 +02:00
* First search for a user-specific configuration file, if that does not exist,
search for a system-wide configuration file. If this one also does not exist, create a system-wide configuration if the user is a super-user. Else create a user-specific configuration file git-svn-id: trunk@15161 -
This commit is contained in:
parent
e235d71cb7
commit
3295cd8370
@ -37,7 +37,6 @@ Type
|
|||||||
Public
|
Public
|
||||||
Constructor Create;
|
Constructor Create;
|
||||||
Destructor Destroy;override;
|
Destructor Destroy;override;
|
||||||
Function GetConfigFileName : String;
|
|
||||||
Procedure LoadGlobalDefaults;
|
Procedure LoadGlobalDefaults;
|
||||||
Procedure LoadCompilerDefaults;
|
Procedure LoadCompilerDefaults;
|
||||||
Procedure ProcessCommandLine;
|
Procedure ProcessCommandLine;
|
||||||
@ -49,20 +48,12 @@ Type
|
|||||||
|
|
||||||
{ TMakeTool }
|
{ TMakeTool }
|
||||||
|
|
||||||
function TMakeTool.GetConfigFileName: String;
|
|
||||||
begin
|
|
||||||
if HasOption('C','config-file') then
|
|
||||||
Result:=GetOptionValue('C','config-file')
|
|
||||||
else
|
|
||||||
Result:=GetAppConfigFile(IsSuperUser,False);
|
|
||||||
end;
|
|
||||||
|
|
||||||
|
|
||||||
procedure TMakeTool.LoadGlobalDefaults;
|
procedure TMakeTool.LoadGlobalDefaults;
|
||||||
var
|
var
|
||||||
i : integer;
|
i : integer;
|
||||||
cfgfile : String;
|
cfgfile : String;
|
||||||
GeneratedConfig : boolean;
|
GeneratedConfig,
|
||||||
|
UseGlobalConfig : boolean;
|
||||||
begin
|
begin
|
||||||
// Default verbosity
|
// Default verbosity
|
||||||
LogLevels:=DefaultLogLevels;
|
LogLevels:=DefaultLogLevels;
|
||||||
@ -72,21 +63,43 @@ begin
|
|||||||
LogLevels:=AllLogLevels+[vlDebug];
|
LogLevels:=AllLogLevels+[vlDebug];
|
||||||
break;
|
break;
|
||||||
end;
|
end;
|
||||||
// Load file or create new default configuration
|
|
||||||
cfgfile:=GetConfigFileName;
|
|
||||||
GeneratedConfig:=false;
|
GeneratedConfig:=false;
|
||||||
if FileExists(cfgfile) then
|
UseGlobalConfig:=false;
|
||||||
|
// First try config file from command line
|
||||||
|
if HasOption('C','config-file') then
|
||||||
begin
|
begin
|
||||||
GlobalOptions.LoadGlobalFromFile(cfgfile);
|
cfgfile:=GetOptionValue('C','config-file');
|
||||||
if GlobalOptions.Dirty then
|
if not FileExists(cfgfile) then
|
||||||
GlobalOptions.SaveGlobalToFile(cfgfile);
|
Error(SErrNoSuchFile,[cfgfile]);
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
begin
|
begin
|
||||||
|
// Now try if a local config-file exists
|
||||||
|
cfgfile:=GetAppConfigFile(False,False);
|
||||||
|
if not FileExists(cfgfile) then
|
||||||
|
begin
|
||||||
|
// If not, try to find a global configuration file
|
||||||
|
cfgfile:=GetAppConfigFile(True,False);
|
||||||
|
if FileExists(cfgfile) then
|
||||||
|
UseGlobalConfig := true
|
||||||
|
else
|
||||||
|
begin
|
||||||
|
// Create a new configuration file
|
||||||
|
if not IsSuperUser then // Make a local, not global, configuration file
|
||||||
|
cfgfile:=GetAppConfigFile(False,False);
|
||||||
ForceDirectories(ExtractFilePath(cfgfile));
|
ForceDirectories(ExtractFilePath(cfgfile));
|
||||||
GlobalOptions.SaveGlobalToFile(cfgfile);
|
GlobalOptions.SaveGlobalToFile(cfgfile);
|
||||||
GeneratedConfig:=true;
|
GeneratedConfig:=true;
|
||||||
end;
|
end;
|
||||||
|
end;
|
||||||
|
end;
|
||||||
|
// Load file or create new default configuration
|
||||||
|
if not GeneratedConfig then
|
||||||
|
begin
|
||||||
|
GlobalOptions.LoadGlobalFromFile(cfgfile);
|
||||||
|
if GlobalOptions.Dirty and (not UseGlobalConfig or IsSuperUser) then
|
||||||
|
GlobalOptions.SaveGlobalToFile(cfgfile);
|
||||||
|
end;
|
||||||
GlobalOptions.CompilerConfig:=GlobalOptions.DefaultCompilerConfig;
|
GlobalOptions.CompilerConfig:=GlobalOptions.DefaultCompilerConfig;
|
||||||
// Tracing of what we've done above, need to be done after the verbosity is set
|
// Tracing of what we've done above, need to be done after the verbosity is set
|
||||||
if GeneratedConfig then
|
if GeneratedConfig then
|
||||||
|
Loading…
Reference in New Issue
Block a user