Skip to content

Commit

Permalink
kcptun client was aborted,but still show running state in interface
Browse files Browse the repository at this point in the history
  • Loading branch information
dfdragon committed Sep 7, 2016
1 parent d544b6a commit b8cc78a
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 12 deletions.
13 changes: 13 additions & 0 deletions Class_ClientNode.pas
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ TClientNode = class
FMemo_Log: TMemo;
FWholeLog: string;

FCorrectQuit: Boolean;

FCMDThread: TExecDOSCommand_Thread;

FXMLDocument_Para: TXMLDocument;
Expand Down Expand Up @@ -56,6 +58,8 @@ TClientNode = class

procedure SetMemo_log(const Value: TMemo);

procedure SetCorrectQuit(const Value: Boolean);

procedure SetRunState(const Value: string);
procedure SetRemark(const Value: string);

Expand Down Expand Up @@ -124,6 +128,8 @@ TClientNode = class
property Memo_Log: TMemo read FMemo_Log write SetMemo_log;
property WholeLog: string read FWholeLog write FWholeLog;

property CorrectQuit: Boolean read FCorrectQuit write SetCorrectQuit;

property XMLDocument_Para: TXMLDocument read FXMLDocument_Para write FXMLDocument_Para;
property XMLNode: IXMLNode read FXMLNode write FXMLNode;
property CanModifyXML: Boolean read FCanModifyXML write FCanModifyXML;
Expand Down Expand Up @@ -277,6 +283,13 @@ procedure TClientNode.SetMemo_log(const Value: TMemo);
FMemo_Log:= Value;
end;

procedure TClientNode.SetCorrectQuit(const Value: Boolean);
begin
if (FCMDThread <> nil) then
FCMDThread.CorrectQuit:= Value;
FCorrectQuit:= Value;
end;

function TClientNode.GetisRunCMD: Integer;
begin
Result:= 1;
Expand Down
8 changes: 4 additions & 4 deletions Main.dfm
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ object FMain: TFMain
end
item
Alignment = taCenter
Text = #21442#25968#20381#25454' '#8212#8212' KcpTun '#29256#26412#65306'20160904'
Text = #21442#25968#20381#25454' '#8212#8212' KcpTun '#29256#26412#65306'20160906'
Width = 50
end>
OnMouseDown = StatusBar_StatusMouseDown
Expand Down Expand Up @@ -1138,19 +1138,19 @@ object FMain: TFMain
OnClick = Menu_ExitClick
end
end
object TrayIcon1: TTrayIcon
object TrayIcon_Sys: TTrayIcon
Hint = 'KCPTun '#23458#25143#31471#37197#32622#31649#29702#24037#20855
PopupMenu = PopupMenu_Tray
Visible = True
OnClick = TrayIcon1Click
OnClick = TrayIcon_SysClick
Left = 48
Top = 512
end
object ImageList_Menu: TImageList
Left = 209
Top = 510
Bitmap = {
494C010104001800BC0010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
494C010104001800C00010001000FFFFFFFFFF10FFFFFFFFFFFFFFFF424D3600
0000000000003600000028000000400000002000000001002000000000000020
0000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000000000000000
Expand Down
18 changes: 13 additions & 5 deletions Main.pas
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ TFMain = class(TForm)
Menu_StopAll: TMenuItem;
N5: TMenuItem;
Menu_Exit: TMenuItem;
TrayIcon1: TTrayIcon;
TrayIcon_Sys: TTrayIcon;
CheckBox_Minimize: TCheckBox;
CheckBox_AutoExpire: TCheckBox;
Label_AutoExpire: TLabel;
Expand Down Expand Up @@ -165,7 +165,7 @@ TFMain = class(TForm)
procedure Btn_DeleteNodeClick(Sender: TObject);
procedure Menu_ShowClick(Sender: TObject);
procedure Menu_ExitClick(Sender: TObject);
procedure TrayIcon1Click(Sender: TObject);
procedure TrayIcon_SysClick(Sender: TObject);
procedure Edit_ClientEXEDirChange(Sender: TObject);
procedure Memo_CMDLineDblClick(Sender: TObject);
procedure CheckBox_MinimizeClick(Sender: TObject);
Expand Down Expand Up @@ -303,7 +303,10 @@ procedure TFMain.Btn_DeleteNodeClick(Sender: TObject);
PublicVar.XMLDocument_Para.SaveToFile;

if ClientNode.isRunCMD <> 0 then
ClientNode.StopCommand;
begin
ClientNode.CorrectQuit:= True;
ClientNode.StopCommand;
end;
ClientNode.Free;
ListView_Node.Selected.Delete;
ListView_NodeClick(Self);
Expand Down Expand Up @@ -367,6 +370,7 @@ procedure TFMain.Btn_StopAllClick(Sender: TObject);
ClientNode:= TClientNode(ListView_Node.Items[i].Data);
if (ClientNode.isRunCMD = 1) then
begin
ClientNode.CorrectQuit:= True;
ClientNode.StopCommand;
ClientNode.RunState:= '0';
end;
Expand All @@ -377,6 +381,7 @@ procedure TFMain.Btn_StopAllClick(Sender: TObject);

procedure TFMain.Btn_StopClick(Sender: TObject);
begin
TClientNode(ListView_Node.Selected.Data).CorrectQuit:= True;
TClientNode(ListView_Node.Selected.Data).StopCommand;
TClientNode(ListView_Node.Selected.Data).RunState:= '0';
ListView_Node.Repaint;
Expand Down Expand Up @@ -1057,7 +1062,10 @@ procedure TFMain.FormDestroy(Sender: TObject);
begin
ClientNode:= TClientNode(ListView_Node.Items.Item[i].Data);
if (ClientNode.isRunCMD = 1) then
ClientNode.StopCommand;
begin
ClientNode.CorrectQuit:= True;
ClientNode.StopCommand;
end;
ClientNode.Free;
end;
end;
Expand Down Expand Up @@ -1304,7 +1312,7 @@ procedure TFMain.Menu_JSONClick(Sender: TObject);
end;
end;

procedure TFMain.TrayIcon1Click(Sender: TObject);
procedure TFMain.TrayIcon_SysClick(Sender: TObject);
begin
FMain.Visible:= not FMain.Visible;
if FMain.Visible then
Expand Down
8 changes: 7 additions & 1 deletion Thread_ExecDOSCommand.pas
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ TExecDOSCommand_Thread = class(TThread)
FCommandLine: string; //待执行的命令行
FCMDHandle: THandle; //控制台程序句柄
FMemo_Log: TMemo;
FCorrectQuit: Boolean; //是否是正常的退出

procedure SetMemo_log(const Value: TMemo);

Expand All @@ -36,6 +37,7 @@ TExecDOSCommand_Thread = class(TThread)
property MainFormHandle: THandle read FMainFormHandle write FMainFormHandle;
property CMDHandle: THandle read FCMDHandle;
property Memo_Log: TMemo read FMemo_Log write SetMemo_log;
property CorrectQuit: Boolean read FCorrectQuit write FCorrectQuit;

constructor Create(CommandLine: string; CreateSuspended: Boolean);
destructor Destroy; override;
Expand Down Expand Up @@ -161,6 +163,7 @@ constructor TExecDOSCommand_Thread.Create(CommandLine: string; CreateSuspended:
FLock:= TCriticalSection.Create;
FCMDLog:= '';
FMemo_Log:= nil;
FCorrectQuit:= False;
FCommandLine:= CommandLine;
FThreadState:= 0;
end;
Expand All @@ -174,6 +177,7 @@ destructor TExecDOSCommand_Thread.Destroy;
procedure TExecDOSCommand_Thread.Execute;
begin
FThreadState:= 1;
FCorrectQuit:= False;
try
FReadFromPipeStr:= '执行命令:' + FCommandLine + #13 + #10;
AppendOutputToLog(FReadFromPipeStr);
Expand All @@ -183,7 +187,6 @@ procedure TExecDOSCommand_Thread.Execute;
FReadFromPipeStr:= '命令行字符数大于所允许的最大长度,命令中止!' + #13 + #10;
AppendOutputToLog(FReadFromPipeStr);
Synchronize(InputToMemo);
PostMessage(FMainFormHandle, WM_DOSCOMMANDSTOP, 0, LPARAM(FOwner));
end
else
begin
Expand All @@ -204,6 +207,9 @@ procedure TExecDOSCommand_Thread.Execute;
AppendOutputToLog(FReadFromPipeStr);
Synchronize(InputToMemo);

if (not FCorrectQuit) then
PostMessage(FMainFormHandle, WM_DOSCOMMANDSTOP, 0, LPARAM(FOwner));

FThreadState:= 2;
while not Terminated do
begin
Expand Down
4 changes: 2 additions & 2 deletions kcptun_gclient.dproj
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@
<DCC_DebugInformation>0</DCC_DebugInformation>
</PropertyGroup>
<PropertyGroup Condition="'$(Cfg_2_Win32)'!=''">
<VerInfo_Release>8</VerInfo_Release>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.8.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<VerInfo_Release>9</VerInfo_Release>
<VerInfo_Keys>CompanyName=;FileDescription=;FileVersion=1.0.9.0;InternalName=;LegalCopyright=;LegalTrademarks=;OriginalFilename=;ProductName=;ProductVersion=1.0.0.0;Comments=</VerInfo_Keys>
<Icon_MainIcon>k.ico</Icon_MainIcon>
<VerInfo_IncludeVerInfo>true</VerInfo_IncludeVerInfo>
<VerInfo_Locale>1033</VerInfo_Locale>
Expand Down
Binary file modified kcptun_gclient.res
Binary file not shown.

0 comments on commit b8cc78a

Please sign in to comment.