Skip to content

Commit

Permalink
auto connection
Browse files Browse the repository at this point in the history
  • Loading branch information
dfdragon committed Sep 27, 2016
1 parent cf3e495 commit c59d975
Show file tree
Hide file tree
Showing 8 changed files with 163 additions and 54 deletions.
6 changes: 6 additions & 0 deletions Interface_op.pas
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ function GetPublicVarFromXML(ParaXMLPathName: string): Integer;

PublicVar.ClientEXEDir:= VarToStr(ProgramNode.ChildNodes.FindNode('clientexedir').NodeValue);
FMain.Edit_ClientEXEDir.Text:= PublicVar.ClientEXEDir;

PublicVar.AutoConn:= StrToInt(ProgramNode.ChildNodes.FindNode('autoconn').Attributes['enable']);
PublicVar.AutoConnTime:= StrToInt(ProgramNode.ChildNodes.FindNode('autoconn').NodeValue);
FMain.SpinEdit_AutoConnTime.Value:= PublicVar.AutoConnTime;
FMain.CheckBox_AutoConn.Checked:= Boolean(PublicVar.AutoConn);
FMain.CheckBox_AutoConnClick(FMain);
except
Result:= 1;
end;
Expand Down
64 changes: 46 additions & 18 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@ object FMain: TFMain
Height = 12
Caption = 'KCPTun'#23458#25143#31471'exe'#25991#20214#65306
end
object Label_AutoConnUnit: TLabel
Left = 143
Top = 572
Width = 12
Height = 12
Caption = #31186
end
object ListView_Node: TListView
Left = 8
Top = 8
Width = 264
Height = 545
Height = 521
Columns = <
item
Caption = #23458#25143#31471#21015#34920
Expand All @@ -52,7 +59,7 @@ object FMain: TFMain
Width = 75
Height = 25
Caption = #28155#21152
TabOrder = 3
TabOrder = 4
OnClick = Btn_AddNodeClick
end
object Btn_DeleteNode: TButton
Expand All @@ -62,7 +69,7 @@ object FMain: TFMain
Height = 25
Caption = #21024#38500
Enabled = False
TabOrder = 4
TabOrder = 5
OnClick = Btn_DeleteNodeClick
end
object Btn_StartAll: TButton
Expand All @@ -71,7 +78,7 @@ object FMain: TFMain
Width = 75
Height = 25
Caption = #20840#37096#21551#21160
TabOrder = 5
TabOrder = 6
OnClick = Btn_StartAllClick
end
object Btn_StopAll: TButton
Expand All @@ -80,7 +87,7 @@ object FMain: TFMain
Width = 75
Height = 25
Caption = #20840#37096#20572#27490
TabOrder = 6
TabOrder = 7
OnClick = Btn_StopAllClick
end
object StatusBar_Status: TStatusBar
Expand Down Expand Up @@ -115,7 +122,7 @@ object FMain: TFMain
Width = 905
Height = 633
BevelInner = bvLowered
TabOrder = 9
TabOrder = 10
object Label_Remark: TLabel
Left = 14
Top = 313
Expand Down Expand Up @@ -1066,7 +1073,7 @@ object FMain: TFMain
end
object CheckBox_AutoStart: TCheckBox
Left = 8
Top = 566
Top = 542
Width = 105
Height = 17
Caption = ' '#31243#24207#24320#26426#33258#21551
Expand All @@ -1080,7 +1087,7 @@ object FMain: TFMain
Height = 20
Color = clBtnFace
ReadOnly = True
TabOrder = 7
TabOrder = 8
OnChange = Edit_ClientEXEDirChange
end
object Btn_FindClientEXE: TButton
Expand All @@ -1089,28 +1096,49 @@ object FMain: TFMain
Width = 75
Height = 25
Caption = #27983#35272
TabOrder = 8
TabOrder = 9
OnClick = Btn_FindClientEXEClick
end
object CheckBox_Minimize: TCheckBox
Left = 147
Top = 566
Top = 542
Width = 125
Height = 17
Caption = ' '#31243#24207#21551#21160#21518#26368#23567#21270
TabOrder = 2
OnClick = CheckBox_MinimizeClick
end
object CheckBox_AutoConn: TCheckBox
Left = 8
Top = 570
Width = 81
Height = 17
Caption = ' '#33258#21160#37325#36830
TabOrder = 3
OnClick = CheckBox_AutoConnClick
end
object SpinEdit_AutoConnTime: TSpinEdit
Left = 89
Top = 568
Width = 49
Height = 21
MaxLength = 3
MaxValue = 999
MinValue = 1
TabOrder = 12
Value = 0
OnChange = SpinEdit_AutoConnTimeChange
end
object OpenDialog_ClientEXE: TOpenDialog
Filter = 'KCPTun'#23458#25143#31471'|client_windows_*.exe'
Left = 48
Top = 456
Top = 344
end
object PopupMenu_Tray: TPopupMenu
AutoHotkeys = maManual
Images = ImageList_Menu
Left = 120
Top = 512
Top = 400
object Menu_Show: TMenuItem
Caption = #26174#31034'(&S)'
ImageIndex = 0
Expand Down Expand Up @@ -1144,13 +1172,13 @@ object FMain: TFMain
Visible = True
OnClick = TrayIcon_SysClick
Left = 48
Top = 512
Top = 400
end
object ImageList_Menu: TImageList
Left = 209
Top = 510
Top = 398
Bitmap = {
494C010104001800D80010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C010104001800EC0010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000002000000001002000000000000020
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Expand Down Expand Up @@ -1424,7 +1452,7 @@ object FMain: TFMain
object PopupMenu_ClientNode: TPopupMenu
AutoHotkeys = maManual
Left = 48
Top = 384
Top = 272
object Menu_Start: TMenuItem
Caption = #21551#21160'(&R)'
OnClick = Menu_StartClick
Expand Down Expand Up @@ -1459,13 +1487,13 @@ object FMain: TFMain
object OpenDialog_JSON: TOpenDialog
Filter = 'KCPTun'#37197#32622#25991#20214'|*.*'
Left = 168
Top = 456
Top = 344
end
object SaveDialog_JSON: TSaveDialog
DefaultExt = 'json'
Filter = 'JSON'#37197#32622#25991#20214'|*.json'
Options = [ofOverwritePrompt, ofHideReadOnly, ofEnableSizing]
Left = 168
Top = 384
Top = 272
end
end
40 changes: 39 additions & 1 deletion Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ interface
uses
Winapi.Windows, Winapi.ShellAPI, Winapi.Messages, System.SysUtils, System.Variants, System.Classes,
Vcl.Graphics, Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.ExtCtrls,
Xml.XMLIntf, Xml.XMLDoc, Vcl.Menus, Vcl.Buttons, Vcl.ImgList, System.JSON, System.IOUtils, PublicVar;
Xml.XMLIntf, Xml.XMLDoc, Vcl.Menus, Vcl.Buttons, Vcl.ImgList, System.JSON, System.IOUtils, PublicVar,
Vcl.Samples.Spin;

type
TFMain = class(TForm)
Expand Down Expand Up @@ -117,6 +118,9 @@ TFMain = class(TForm)
Menu_ExportToJSON: TMenuItem;
SaveDialog_JSON: TSaveDialog;
Menu_ImportFromJSON: TMenuItem;
CheckBox_AutoConn: TCheckBox;
Label_AutoConnUnit: TLabel;
SpinEdit_AutoConnTime: TSpinEdit;
procedure Btn_AddNodeClick(Sender: TObject);
procedure FormCreate(Sender: TObject);
procedure Btn_FindClientEXEClick(Sender: TObject);
Expand Down Expand Up @@ -194,6 +198,8 @@ TFMain = class(TForm)
procedure Menu_ExportToJSONClick(Sender: TObject);
procedure Menu_CopyClick(Sender: TObject);
procedure Menu_ImportFromJSONClick(Sender: TObject);
procedure CheckBox_AutoConnClick(Sender: TObject);
procedure SpinEdit_AutoConnTimeChange(Sender: TObject);
private
{ Private declarations }
procedure WMSYSCommand(var Msg: TWMSysCommand); message WM_SYSCOMMAND;
Expand Down Expand Up @@ -400,6 +406,29 @@ procedure TFMain.CheckBox_ACKNoDelayClick(Sender: TObject);
TClientNode(ListView_Node.Selected.Data).isACKNoDelay:= Integer(CheckBox_ACKNoDelay.Checked);
end;

procedure TFMain.CheckBox_AutoConnClick(Sender: TObject);
begin
PublicVar.AutoConn:= Integer(CheckBox_AutoConn.Checked);

SpinEdit_AutoConnTime.Enabled:= CheckBox_AutoConn.Checked;
Label_AutoConnUnit.Enabled:= CheckBox_AutoConn.Checked;
if CheckBox_AutoConn.Checked then
begin
SpinEdit_AutoConnTime.Color:= clWindow;
if PublicVar.CanFoucs then
SpinEdit_AutoConnTime.SetFocus;
end
else
begin
SpinEdit_AutoConnTime.Color:= clBtnFace;
end;

if not PublicVar.CanModifyXML then
Exit;
PublicVar.ProgramNode.ChildNodes['autoconn'].Attributes['enable']:= PublicVar.AutoConn;
PublicVar.XMLDocument_Para.SaveToFile;
end;

procedure TFMain.CheckBox_AutoExpireClick(Sender: TObject);
begin
Label_AutoExpire.Enabled:= CheckBox_AutoExpire.Checked;
Expand Down Expand Up @@ -1199,6 +1228,15 @@ procedure TFMain.SpeedBtn_CMDLineClick(Sender: TObject);
Memo_CMDLine.Lines.Text:= CMDLineStr;
end;

procedure TFMain.SpinEdit_AutoConnTimeChange(Sender: TObject);
begin
PublicVar.AutoConnTime:= SpinEdit_AutoConnTime.Value;
if not PublicVar.CanModifyXML then
Exit;
PublicVar.ProgramNode.ChildNodes['autoconn'].NodeValue:= SpinEdit_AutoConnTime.Text;
PublicVar.XMLDocument_Para.SaveToFile;
end;

procedure TFMain.StatusBar_StatusMouseDown(Sender: TObject;
Button: TMouseButton; Shift: TShiftState; X, Y: Integer);
var
Expand Down
21 changes: 18 additions & 3 deletions PublicFun.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ implementation
procedure CreateBlankParaXML(ParaXMLPathName: string);
var
XMLDocument_BlankPara: TXMLDocument;
Blank_ParasNode, Blank_ProgramParaNode: IXMLNode;
Blank_ParasNode, Blank_ProgramParaNode, Node: IXMLNode;
begin
XMLDocument_BlankPara:= TXMLDocument.Create(Application);
XMLDocument_BlankPara.Active:= True;
Expand All @@ -31,6 +31,10 @@ procedure CreateBlankParaXML(ParaXMLPathName: string);
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);
Expand All @@ -39,12 +43,12 @@ procedure CreateBlankParaXML(ParaXMLPathName: string);
end;
end;

//实现-c参数,Node中加入json节点
//实现-c参数,Node中加入json节点;加入自动重连节点
procedure RepairParaXML(ParaXMLPathName: string);
var
isModify: Boolean;
XMLDocument_BlankPara: TXMLDocument;
ParasNode, ClientNode, Node, JsonNode: IXMLNode;
ParasNode, ProgramParaNode, ClientNode, Node, JsonNode, AutoConnNode: IXMLNode;
i: Integer;
begin
isModify:= False;
Expand All @@ -57,6 +61,17 @@ procedure RepairParaXML(ParaXMLPathName: string);
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
Expand Down
3 changes: 3 additions & 0 deletions PublicVar.pas
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ interface
Minimize: Integer;
ClientEXEDir: string;

AutoConn: Integer;
AutoConnTime: Integer;

CanFoucs: Boolean;
ModeCanFouse: Boolean;

Expand Down
Loading

0 comments on commit c59d975

Please sign in to comment.