248 lines
6.2 KiB
Plaintext
248 lines
6.2 KiB
Plaintext
unit DMptMonMain;
|
||
|
||
interface
|
||
|
||
uses
|
||
Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
|
||
Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Vcl.StdCtrls, Vcl.ComCtrls, Vcl.Menus,
|
||
Vcl.ExtCtrls, VirtualTrees, ThdMtpMon;
|
||
|
||
type
|
||
TDlgMptMonMain = class(TForm)
|
||
pcMain: TPageControl;
|
||
tabMtpList: TTabSheet;
|
||
tabMtpMon: TTabSheet;
|
||
popFun: TPopupMenu;
|
||
miRemoveDev: TMenuItem;
|
||
pnTop: TPanel;
|
||
btnRefresh: TButton;
|
||
vtList: TVirtualStringTree;
|
||
Panel1: TPanel;
|
||
btnMtpMon: TButton;
|
||
chPreventMtp: TCheckBox;
|
||
Label1: TLabel;
|
||
mmExcp: TMemo;
|
||
procedure miRemoveDevClick(Sender: TObject);
|
||
procedure btnRefreshClick(Sender: TObject);
|
||
procedure vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
||
var NodeDataSize: Integer);
|
||
procedure vtListFreeNode(Sender: TBaseVirtualTree; Node: PVirtualNode);
|
||
procedure vtListGetText(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
||
Column: TColumnIndex; TextType: TVSTTextType; var CellText: string);
|
||
procedure vtListGetHint(Sender: TBaseVirtualTree; Node: PVirtualNode;
|
||
Column: TColumnIndex; var LineBreakStyle: TVTTooltipLineBreakStyle;
|
||
var HintText: string);
|
||
procedure vtListContextPopup(Sender: TObject; MousePos: TPoint;
|
||
var Handled: Boolean);
|
||
procedure btnMtpMonClick(Sender: TObject);
|
||
private
|
||
{ Private declarations }
|
||
ThdMtpMon_: TThdMtpMon;
|
||
public
|
||
{ Public declarations }
|
||
Constructor Create(aOwner: TComponent); override;
|
||
Destructor Destroy; override;
|
||
|
||
procedure RefreshList;
|
||
|
||
procedure process_WM_MTP_NOTIFY(var msg: TMessage); Message WM_MTP_NOTIFY;
|
||
end;
|
||
|
||
var
|
||
DlgMptMonMain: TDlgMptMonMain;
|
||
|
||
implementation
|
||
|
||
uses
|
||
Define, Tocsg.Driver, Tocsg.MTP, Tocsg.Safe, Tocsg.VirtualTreeViewUtil,
|
||
superobject, GlobalDefine, DNotice, Tocsg.Strings;
|
||
|
||
{$R *.dfm}
|
||
|
||
Constructor TDlgMptMonMain.Create(aOwner: TComponent);
|
||
begin
|
||
Inherited Create(aOwner);
|
||
ThdMtpMon_ := nil;
|
||
Caption := APP_TITLE;
|
||
pcMain.ActivePageIndex := 0;
|
||
RefreshList;
|
||
end;
|
||
|
||
Destructor TDlgMptMonMain.Destroy;
|
||
begin
|
||
if ThdMtpMon_ <> nil then
|
||
FreeAndNil(ThdMtpMon_);
|
||
Inherited;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.btnMtpMonClick(Sender: TObject);
|
||
var
|
||
PreventMtp: TPreventMtp;
|
||
MgMtp: TManagerMtpDev;
|
||
IgrDevList: TStringList;
|
||
i: Integer;
|
||
bPrevent: Boolean;
|
||
msg: TMessage;
|
||
bRetray: Boolean;
|
||
Label
|
||
LB_Prevent;
|
||
begin
|
||
if ThdMtpMon_ = nil then
|
||
begin
|
||
PreventMtp.bPrevent := chPreventMtp.Checked;
|
||
PreventMtp.sIgrDevId := Trim(mmExcp.Text);
|
||
|
||
Guard(IgrDevList, TStringList.Create);
|
||
SplitString(PreventMtp.sIgrDevId, ';', IgrDevList);
|
||
Guard(MgMtp, TManagerMtpDev.Create);
|
||
MgMtp.RefreshMptDev;
|
||
for i := 0 to MgMtp.MtpEntList.Count - 1 do
|
||
begin
|
||
bPrevent := false;
|
||
if PreventMtp.bPrevent then
|
||
begin
|
||
if IgrDevList.IndexOf(MgMtp.MtpEntList[i].sDevId) = -1 then
|
||
begin
|
||
bRetray := false;
|
||
LB_Prevent :
|
||
bPrevent := RemoveUsbDevEnableByDevPath(MgMtp.MtpEntList[i].sDevId);
|
||
if not bPrevent and not bRetray then
|
||
begin
|
||
Sleep(2000);
|
||
bRetray := true;
|
||
goto LB_Prevent;
|
||
end;
|
||
end;
|
||
end;
|
||
|
||
msg.Msg := WM_MTP_NOTIFY;
|
||
msg.WParam := Integer(bPrevent);
|
||
msg.LParam := NativeUInt(MgMtp.MtpEntList[i]);
|
||
process_WM_MTP_NOTIFY(msg);
|
||
end;
|
||
|
||
ThdMtpMon_ := TThdMtpMon.Create(Handle, PreventMtp);
|
||
ThdMtpMon_.StartThread;
|
||
end else begin
|
||
FreeAndNil(ThdMtpMon_);
|
||
btnMtpMon.Caption := '<27><><EFBFBD><EFBFBD>/<2F><><EFBFBD><EFBFBD>';
|
||
end;
|
||
|
||
chPreventMtp.Enabled := ThdMtpMon_ = nil;
|
||
tabMtpList.Visible := chPreventMtp.Enabled;
|
||
mmExcp.Enabled := chPreventMtp.Enabled;
|
||
|
||
Application.ProcessMessages;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.btnRefreshClick(Sender: TObject);
|
||
begin
|
||
RefreshList;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.miRemoveDevClick(Sender: TObject);
|
||
var
|
||
pNode: PVirtualNode;
|
||
pData: PMtpEnt;
|
||
begin
|
||
pNode := vtList.GetFirstSelected;
|
||
if pNode = nil then
|
||
exit;
|
||
|
||
if MessageBox(Handle, PChar('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD> <20>Ͻðڽ<C3B0><DABD>ϱ<EFBFBD>?'),
|
||
PChar(Caption), MB_ICONQUESTION or MB_YESNO) = IDNO then exit;
|
||
|
||
pData := vtList.GetNodeData(pNode);
|
||
if RemoveUsbDevEnableByDevPath(pData.sDevId) then
|
||
begin
|
||
vtList.DeleteNode(pNode);
|
||
MessageBox(Handle, PChar('<27><><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>߽<EFBFBD><DFBD>ϴ<EFBFBD>.'), PChar(Caption), MB_ICONINFORMATION or MB_OK);
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.RefreshList;
|
||
var
|
||
MtpDev: TManagerMtpDev;
|
||
i: Integer;
|
||
pData: PMtpEnt;
|
||
begin
|
||
Guard(MtpDev, TManagerMtpDev.Create);
|
||
MtpDev.RefreshMptDev;
|
||
|
||
vtList.BeginUpdate;
|
||
try
|
||
vtList.Clear;
|
||
for i := 0 to MtpDev.MtpEntList.Count - 1 do
|
||
begin
|
||
pData := VT_AddChildData(vtList);
|
||
pData^ := MtpDev.MtpEntList[i]^;
|
||
end;
|
||
finally
|
||
vtList.EndUpdate;
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.vtListContextPopup(Sender: TObject; MousePos: TPoint;
|
||
var Handled: Boolean);
|
||
begin
|
||
Handled := vtList.GetNodeAt(MousePos) = nil;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.vtListFreeNode(Sender: TBaseVirtualTree;
|
||
Node: PVirtualNode);
|
||
var
|
||
pData: PMtpEnt;
|
||
begin
|
||
pData := Sender.GetNodeData(Node);
|
||
Finalize(pData^);
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.vtListGetHint(Sender: TBaseVirtualTree;
|
||
Node: PVirtualNode; Column: TColumnIndex;
|
||
var LineBreakStyle: TVTTooltipLineBreakStyle; var HintText: string);
|
||
begin
|
||
HintText := vtList.Text[Node, Column];
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.vtListGetNodeDataSize(Sender: TBaseVirtualTree;
|
||
var NodeDataSize: Integer);
|
||
begin
|
||
NodeDataSize := SizeOf(TMtpEnt);
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.vtListGetText(Sender: TBaseVirtualTree;
|
||
Node: PVirtualNode; Column: TColumnIndex; TextType: TVSTTextType;
|
||
var CellText: string);
|
||
var
|
||
pData: PMtpEnt;
|
||
begin
|
||
pData := Sender.GetNodeData(Node);
|
||
|
||
case Column of
|
||
0 : CellText := IntToStr(Node.Index + 1);
|
||
1 : CellText := pData.sName;
|
||
2 : CellText := pData.sDesc;
|
||
3 : CellText := pData.sMfg;
|
||
4 : CellText := pData.sDevId;
|
||
end;
|
||
end;
|
||
|
||
procedure TDlgMptMonMain.process_WM_MTP_NOTIFY(var msg: TMessage);
|
||
var
|
||
pEnt: PMtpEnt;
|
||
O: ISuperObject;
|
||
sData: String;
|
||
begin
|
||
pEnt := PMtpEnt(msg.LParam);
|
||
|
||
O := SO;
|
||
O.I['T'] := TYPE_MSG_PREVENT_MTP;
|
||
sData := pEnt.sName + '|' + pEnt.sDesc + '|' + pEnt.sDevId;
|
||
if msg.WParam <> 0 then
|
||
sData := sData + '|PV';
|
||
O.S['D'] := sData;
|
||
TDlgNotice.Create(nil).PopupMessage(O.AsString);
|
||
end;
|
||
|
||
end.
|