File: conffile.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (86 lines) | stat: -rw-r--r-- 1,880 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86

function LoadCFGFile(AFolder: String; var AList: TStringList): Boolean;
var
  cfgfile: String;
begin
  if AList = nil then
    AList := TStringList.Create
  else
    AList.Clear;

  cfgfile := AddBackslash(AFolder) + 'lazarus.cfg';
  Result := FileExists(cfgfile);
  if not Result then
    exit;
  AList.LoadFromFile(cfgfile);
end;

procedure CreateCFGFile(APCP: String; var AList: TStringList);
var
  cfgfile: String;
begin
  if AList = nil then
    AList := TStringList.Create
  else
    AList.Clear;
  AList.add('--primary-config-path=' + APCP);
end;

function ParseCFGList(AConfig: TStringList; var APrimConfDir: String): TCfgFileState;
var
  s: String;
  i: Integer;
begin
  Result := csUnreadable;
  for i := 0 to AConfig.Count - 1 do
    if copy(AConfig[i], 1, 6) = '--pcp=' then
      s := copy(AConfig[i], 7, length(AConfig[i]))
    else
    if copy(AConfig[i], 1, 22) = '--primary-config-path=' then
      s := copy(AConfig[i], 23, length(AConfig[i]));
//  AConfig.Free;

  if s = '' then
    exit;

  if (s[1] = '"') and (s[length(s)] = '"') then
    s := copy(s, 2, length(s)-2)
  else
  if (s[1] = '''') and (s[length(s)] = '''') then
    s := copy(s, 2, length(s)-2);

  if s = '' then
    exit;

  if (not FileExists(AddBackslash(s) + 'environmentoptions.xml')) and
     (not IsDirEmpty(s))
  then begin
    Log('ParseCFGFile unreadable');
    exit;
  end;

  Result := csParsedOk;
  APrimConfDir := s;
  Log('ParseCFGFile OK');
end;

function ParseCFGFile(AFolder: String; var APrimConfDir: String): TCfgFileState;
var
  s, cfgfile: String;
  i: Integer;
  l: TStringList;
begin
  cfgfile := AddBackslash(AFolder) + 'lazarus.cfg';

  Result := csNoFile;
  if not FileExists(cfgfile) then begin
    Log('ParseCFGFile not existent');
    exit;
  end;

  l := TStringList.Create;
  l.LoadFromFile(cfgfile);
  Result := ParseCFGList(l, APrimConfDir);
  l.Free;
end;