-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGlobal.pas
105 lines (87 loc) · 2.41 KB
/
Global.pas
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
104
105
unit Global;
interface
uses
IniFiles, Classes;
const
AppMajorVersion = 0;
AppMinorVersion = 3;
AppRevision = 2;
type
TGlobal = class
private
FExePath: String;
FExeName: String;
FAppVersion: String;
FExternalApps: array[0..3] of TStringList;
FExternalAppCount: Integer;
FExcludeExtension: TStringList;
FIni: TCustomIniFile;
function GetExternalAppData(i: Integer; Name: string): String;
public
constructor Create;
destructor Destroy; override;
procedure LoadSetting;
property ExternalAppData[i: Integer;Name:string]: String read GetExternalAppData;
published
property ExePath: String read FExePath;
property ExeName: String read FExeName;
property AppVersion: String read FAppVersion;
property ExternalAppCount: Integer read FExternalAppCount;
property ExcludeExtension: TStringList read FExcludeExtension;
property Ini: TCustomIniFile read FIni;
end;
var
AppGlobal: TGlobal;
implementation
uses
SysUtils, Forms, Dialogs;
{ TGlobal }
constructor TGlobal.Create;
begin
FExePath := ExtractFilePath(Application.ExeName);
FExeName := ChangeFileExt(ExtractFileName(Application.ExeName), '');
FAppVersion := Format('ver.%d.%d.%d', [AppMajorVersion, AppMinorVersion, AppRevision]);
FIni := TMemIniFile.Create(FExePath + FExeName + '.ini');
LoadSetting;
end;
destructor TGlobal.Destroy;
var
i: integer;
begin
FIni.UpdateFile;
for i:= 0 to FExternalAppCount - 1 do
FExternalApps[i].Free;
FExcludeExtension.Free;
FIni.Free;
inherited;
end;
function TGlobal.GetExternalAppData(i: Integer; Name: string): String;
begin
if i > FExternalAppCount then Result := ''
else Result := FExternalApps[i].Values[Name];
end;
procedure TGlobal.LoadSetting;
var
i: integer;
begin
// 外部アプリ関連
i := 0;
while FIni.SectionExists('ExternalApps' + IntToStr(i)) do
begin
if Assigned(FExternalApps[i]) then FExternalApps[i].Clear
else FExternalApps[i] := TStringList.Create;
FIni.ReadSectionValues('ExternalApps' + IntToStr(i), FExternalApps[i]);
i := i + 1;
if (i >= 4) then Break;
end;
FExternalAppCount := i;
// 除外拡張子関連
if Assigned(FExcludeExtension) then FExcludeExtension.Clear
else FExcludeExtension := TStringList.Create;
FExcludeExtension.CommaText := FIni.ReadString('Filter', 'ExcludeExtension', '.txt,.exe');
end;
initialization
AppGlobal := TGlobal.Create;
finalization
AppGlobal.Free;
end.