summaryrefslogtreecommitdiff
path: root/utils/fpdoc/fpde/fpdeopts.pp
blob: 8826c3d0d5d6fa58e5ef9ba64926618de4fb954a (plain)
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
{$mode objfpc}
{$H+}
unit fpdeopts;

Interface

uses SysUtils,IniFiles;

Var
  SkipEmptyNodes   : Boolean;
  ConfirmDelete    : Boolean;
  CreateBackup     : Boolean;
  MaxRecentUsed    : Integer;
  BackupExtension  : String;
  DefaultExtension : String;

Procedure LoadOptions;
Procedure SaveOptions;
Function  GetOptionFileName : String;

Implementation

Const
  DefFilename         = 'fpde.ini';
  SecPrefs            = 'Preferences';
  KeySkipEmptyNodes   = 'SkipEmptyNodes';
  KeyConfirmDelete    = 'ConfirmDelete';
  KeyCreateBackup     = 'CreateBackup';
  KeyBackupExtension  = 'BackupExtension';
  KeyDefaultExtension = 'DefaultExtension';
  KeyMaxRecentUsed    = 'MaxMRUitems';

{$ifndef win32}
Function GetOptionFileName : String;

Const
  fpdedir = '.fpde';

Var
  HomeDir : String;

begin
  HomeDir:=GetEnvironmentVariable('HOME');
  If (HomeDir<>'') then
    begin
    HomeDir:=IncludeTrailingPathDelimiter(HomeDir)+fpdedir;
    If not DirectoryExists(HomeDir) then
      If Not CreateDir(HomeDir) then
        HomeDir:=''
      else
        HomeDir:=HomeDir;
    end;
  Result:=IncludeTrailingPathDelimiter(HomeDir)+DefFileName;
end;

{$else}

Function GetOptionFileName : String;

begin
  Result:=ExtractFilePath(Paramstr(0))+DefFileName;
end;
{$endif}

Procedure LoadOptions;

begin
  With TInifile.Create(GetOptionFileName) do
    Try
      SkipEmptyNodes:=ReadBool(SecPrefs,KeySkipEmptyNodes,SkipEmptyNodes);
      ConfirmDelete:=ReadBool(SecPrefs,KeyConfirmDelete,ConfirmDelete);
      CreateBackup:=ReadBool(SecPrefs,KeyCreateBackup,CreateBackup);
      BackupExtension:=ReadString(SecPrefs,KeyBackupExtension,BackupExtension);
      DefaultExtension:=ReadString(SecPrefs,KeyDefaultExtension,DefaultExtension);
    finally
      Free;
    end;
end;

Procedure SaveOptions;

begin
  With TInifile.Create(GetOptionFileName) do
    Try
      WriteBool(SecPrefs,KeySkipEmptyNodes,SkipEmptyNodes);
      WriteBool(SecPrefs,KeyConfirmDelete,ConfirmDelete);
      WriteBool(SecPrefs,KeyCreateBackup,CreateBackup);
      WriteString(SecPrefs,KeyBackupExtension,BackupExtension);
      WriteString(SecPrefs,KeyDefaultExtension,DefaultExtension);
      UpdateFile;
    finally
      Free;
    end;
end;

Initialization
  SkipEmptyNodes   := True;
  ConfirmDelete    := True;
  CreateBackup     := True;
  BackupExtension  := '.~xml';
  DefaultExtension := '.xml';
  MaxRecentUSed    := 10;
end.