forked from dfdragon/kcptun_gclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PublicFun.pas
164 lines (146 loc) · 4.85 KB
/
PublicFun.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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
unit PublicFun;
interface
uses
Xml.XMLIntf, Xml.XMLDoc, Winapi.Windows, Vcl.Forms, System.Win.Registry;
procedure CreateBlankParaXML(ParaXMLPathName: string);
procedure RepairParaXML(ParaXMLPathName: string);
procedure WriteREGAutoRun(AutoStart: Integer; FileFullName: string);
function CheckREGAutoRunExist(): Boolean;
implementation
procedure CreateBlankParaXML(ParaXMLPathName: string);
var
XMLDocument_BlankPara: TXMLDocument;
Blank_ParasNode, Blank_ProgramParaNode, Node: IXMLNode;
begin
XMLDocument_BlankPara:= TXMLDocument.Create(Application);
XMLDocument_BlankPara.Active:= True;
XMLDocument_BlankPara.Version:='1.0';
XMLDocument_BlankPara.Encoding:= 'gbk';
XMLDocument_BlankPara.NodeIndentStr:= #9;
XMLDocument_BlankPara.Options:= XMLDocument_BlankPara.Options + [doNodeAutoIndent];
try
Blank_ParasNode:= XMLDocument_BlankPara.AddChild('paras');
Blank_ParasNode.Attributes['author']:= 'badcat';
Blank_ProgramParaNode:= Blank_ParasNode.AddChild('programpara');
Blank_ProgramParaNode.AddChild('autostart').NodeValue:= 0;
Blank_ProgramParaNode.AddChild('minimize').NodeValue:= 0;
Blank_ProgramParaNode.AddChild('clientexedir');
Node:= Blank_ProgramParaNode.AddChild('autoconn');
Node.NodeValue:= 5;
Node.Attributes['enable']:= 0;
Blank_ParasNode.AddChild('clientnodes');
XMLDocument_BlankPara.SaveToFile(ParaXMLPathName);
finally
XMLDocument_BlankPara.Free;
end;
end;
//实现-c参数,Node中加入json节点;加入自动重连节点;加入ScavengeTTL节点;加入Quiet节点
procedure RepairParaXML(ParaXMLPathName: string);
var
isModify: Boolean;
XMLDocument_BlankPara: TXMLDocument;
ParasNode, ProgramParaNode, ClientNode, Node, LocalPortNode, JsonNode, AutoConnNode, ScavengeTTLNode, QuietNode: IXMLNode;
i: Integer;
begin
isModify:= False;
XMLDocument_BlankPara:= TXMLDocument.Create(Application);
XMLDocument_BlankPara.Active:= True;
XMLDocument_BlankPara.Version:='1.0';
XMLDocument_BlankPara.Encoding:= 'gbk';
XMLDocument_BlankPara.NodeIndentStr:= #9;
XMLDocument_BlankPara.Options:= XMLDocument_BlankPara.Options + [doNodeAutoIndent];
XMLDocument_BlankPara.LoadFromFile(ParaXMLPathName);
try
ParasNode:= XMLDocument_BlankPara.DocumentElement;
ProgramParaNode:= ParasNode.ChildNodes.FindNode('programpara');
AutoConnNode:= ProgramParaNode.ChildNodes.FindNode('autoconn');
if AutoConnNode = nil then
begin
isModify:= True;
AutoConnNode:= ProgramParaNode.AddChild('autoconn');
AutoConnNode.NodeValue:= 5;
AutoConnNode.Attributes['enable']:= 0;
end;
ClientNode:= ParasNode.ChildNodes.FindNode('clientnodes');
for i := 0 to (ClientNode.ChildNodes.Count - 1) do
begin
Node:= ClientNode.ChildNodes[i];
LocalPortNode:= Node.ChildNodes.FindNode('localport');
if LocalPortNode <> nil then
begin
if (LocalPortNode.AttributeNodes.FindNode('allowonlylocal') = nil) then
begin
isModify:= True;
LocalPortNode.Attributes['allowonlylocal']:= 0;
end;
end;
JsonNode:= Node.ChildNodes.FindNode('json');
if JsonNode = nil then
begin
isModify:= True;
JsonNode:= Node.AddChild('json');
JsonNode.Attributes['enable']:= 0;
end;
ScavengeTTLNode:= Node.ChildNodes.FindNode('scavengettl');
if ScavengeTTLNode = nil then
begin
isModify:= True;
ScavengeTTLNode:= Node.AddChild('scavengettl');
ScavengeTTLNode.Attributes['enable']:= 0;
end;
QuietNode:= Node.ChildNodes.FindNode('quiet');
if QuietNode = nil then
begin
isModify:= True;
QuietNode:= Node.AddChild('quiet');
QuietNode.Attributes['enable']:= 0;
end;
end;
if isModify then
XMLDocument_BlankPara.SaveToFile(ParaXMLPathName);
finally
XMLDocument_BlankPara.Free;
end;
end;
procedure WriteREGAutoRun(AutoStart: Integer; FileFullName: string);
var
Reg: TRegistry;
begin
Reg:= TRegistry.Create;
try
Reg.RootKey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
try
if AutoStart = 0 then
begin
Reg.DeleteValue('KCPTun 客户端配置管理工具');
end
else
begin
Reg.WriteString('KCPTun 客户端配置管理工具', FileFullName);
end;
finally
Reg.CloseKey;
end;//try
finally
Reg.Free;
end;//try
end;
function CheckREGAutoRunExist(): Boolean;
var
Reg: TRegistry;
begin
Reg:= TRegistry.Create;
try
Reg.RootKey:= HKEY_LOCAL_MACHINE;
Reg.OpenKey('SOFTWARE\Microsoft\Windows\CurrentVersion\Run', True);
try
Result:= Reg.ValueExists('KCPTun 客户端配置管理工具');
finally
Reg.CloseKey;
end;//try
finally
Reg.Free;
end;//try
end;
end.