forked from dfdragon/kcptun_xclient
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PublicFun.pas
181 lines (157 loc) · 5.07 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
unit PublicFun;
interface
//** Converted with Mida BASIC 275 http://www.midaconverter.com
uses
System.SysUtils,
System.Types,
System.UITypes,
System.Classes,
System.Variants,
System.IniFiles,
Data.DB,
FMX.Types,
FMX.Controls,
FMX.Forms,
FMX.Dialogs,
FMX.Objects,
FMX.Menus,
FMX.Grid,
FMX.ExtCtrls,
FMX.ListBox,
FMX.TreeView,
FMX.Memo,
FMX.TabControl,
FMX.Layouts,
FMX.Edit,
FMX.Platform,
FMX.Bind.DBEngExt,
FMX.Bind.Editors,
FMX.Bind.DBLinks,
FMX.Bind.Navigator,
Data.Bind.EngExt,
Data.Bind.Components,
Data.Bind.DBScope,
Data.Bind.DBLinks,
Datasnap.DBClient,
Fmx.Bind.Grid,
System.Rtti,
System.Bindings.Outputs,
Data.Bind.Grid,
Fmx.StdCtrls,
FMX.Header,
FMX.Graphics,
Macapi.Foundation, Macapi.Helpers,
Xml.XMLIntf, Xml.XMLDoc, Macapi.CoreFoundation;
//** Original VCL Uses section :
//** Xml.XMLIntf, Xml.XMLDoc, Winapi.Windows, Vcl.Forms, System.Win.Registry;
procedure CreateBlankParaXML(ParaXMLPathName: string);
procedure RepaireParaXML(ParaXMLPathName: string);
//procedure WriteREGAutoRun(AutoStart: Integer; FileFullName: string);
function GetAppVersionStr: string;
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:= 'utf-8';
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节点;加入自动重连节点
procedure RepaireParaXML(ParaXMLPathName: string);
var
isModify: Boolean;
XMLDocument_BlankPara: TXMLDocument;
ParasNode, ProgramParaNode, ClientNode, Node, LocalPortNode, JsonNode, AutoConnNode: 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;
end;
if isModify then
XMLDocument_BlankPara.SaveToFile(ParaXMLPathName);
finally
XMLDocument_BlankPara.Free;
end;
end;
function GetAppVersionStr: string;
var
CFStr: CFStringRef;
Range: CFRange;
begin
CFStr:= CFBundleGetValueForInfoDictionaryKey(CFBundleGetMainBundle, kCFBundleVersionKey);
Range.location:= 0;
Range.length:= CFStringGetLength(CFStr);
SetLength(Result, Range.length);
CFStringGetCharacters(CFStr, Range, PChar(Result));
end;
//procedure WriteREGAutoRun(AutoStart: Integer; FileFullName: string);
//var
// loginItems: LSSharedFileListRef;
// url: string;
// item: LSSharedFileListItemRef;
//begin
// loginItems:= LSSharedFileListCreate(NULL, kLSSharedFileListSessionLoginItems, NULL);
// //url为app所在的目录
// url:= TNSBundle.Wrap(TNSBundle.OCClass.mainBundle).bundlePath.UTF8String;
// item = LSSharedFileListInsertItemURL(loginItems, kLSSharedFileListItemLast, NULL, NULL, StrToNSStr(url), NULL, NULL);
// CFRelease(item);
// CFRelease(loginItems);
//end;
end.