⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.pas

📁 最好的局域网搜索软件
💻 PAS
📖 第 1 页 / 共 5 页
字号:
  ScanPort_IP1, ScanPort_IP2    : string;
  Ping_IP1, Ping_IP2            : string;
  Nbt_IP1, Nbt_IP2              : string;

  CopyFileList: TStringList;

procedure ParseFtpUrl(url: string; var FtpSvr, FtpDir: string);

implementation
uses GetDomainThreadUnit,SearchGroupThreadUnit,SearchHostThreadUnit,
     SearchDirThreadunit,ConFig,CopyTo,Tools,About,ItemProp,
     SearchHosts, FtpBrowse, FtpSubDir, HttpGet;
{$R *.DFM}

function GetImgIndex(s:string):integer;
var
  //i:integer;
  extn:string;
begin
  result:=1;
  extn:=lowercase(ExtractFileExt(s));
  if (extn='.txt')or(extn='.log') then result:= 48 else
  if extn='.bmp' then result:= 49 else
  if (extn='.exe')or(extn='.com') then result:= 74 else
  if (extn='.htm')or(extn='.html')or(extn='.shtml')or(extn='.plg') then result:= 53 else
  if (extn='.jpg')or(extn='.jpeg') then result:= 55 else
  if extn='.pdf' then result:= 57 else
  if extn='.ppt' then result:= 58 else
  if (extn='.dll')or(extn='.sys') then result:= 59 else
  if (extn='.doc')or(extn='.rtf') then result:= 61 else
  if (extn='.zip')or(extn='.gz')or(extn='.tar')or(extn='.z')or(extn='.tgz') then result:= 62 else
  if (extn='.rar')or(extn='.iso')or(extn='.cab') then result:= 66 else
  if (extn='.mp3')or(extn='.wsz')or(extn='.wma')or(extn='.m3u') then result:= 35 else
  if (extn='.mpg')or(extn='.mpeg')or(extn='.avi')or(extn='.asx') then result:= 78 else
  if (extn='.rm')or(extn='.rmvb')or(extn='.ram')or(extn='.ra') then result:= 79 else
  if (extn='.dsw')or(extn='.dsp') then result:= 67 else
  if extn='.chm' then result:= 68 else
  if extn='.ps' then result:= 63 else
  if extn='.hlp' then result:= 65 else
  if extn='.bat' then result:= 60 else
  if (extn='.ini')or(extn='.inf') then result:= 54 else
  if extn='.c' then result:= 69 else
  if extn='.gif' then result:= 70 else
  if extn='.h' then result:= 71 else
  if extn='.dpr' then result:= 72 else
  if extn='.cpp' then result:= 50 else
  if extn='.dcu' then result:= 51 else
  if extn='.pas' then result:= 56 else
  if (extn='.obj')or(extn='.ilk')or(extn='.pch')or(extn='.pdb')or(extn='.idb') then result:= 73 else
  if extn='.mid' then result:= 75 else
  if extn='.wav' then result:= 76 else
  if extn='.m' then result:= 64 else
  if (extn='.wmv')or(extn='.asf') then result:= 80 else
  if extn='.swf' then result:= 81 else
  if extn='.mht' then result:= 82 else
  if extn='.sch' then result:= 83 else
  if extn='.pcb' then result:= 84 else
  if extn='.ddb' then result:= 85 else
  if extn='.prj' then result:= 86 else
  if extn='.pps' then result:= 87 else
  if extn='.xml' then result:= 88 else
  if extn='.dsn' then result:= 89 else
  if extn='.pot' then result:= 90 else
  if extn='.wpj' then result:= 91 else
  if extn='.pr' then result:= 92 else
  if extn='.wsp' then result:= 93 else
  if extn='.java' then result:= 94 else
  if extn='.mdl' then result:= 95 else
  if extn='.rc' then result:= 96 else
  if extn='.dot' then result:= 97 else
  if extn='.vhd' then result:= 102 else
  if (extn='.v')or(extn='.tf') then result:= 103 else
  if extn='.xls' then result:= 104 else
  if extn='.psd' then result:= 108 else
  if extn='.tif' then result:= 112 else
end;

procedure TMainForm.ShowToolsForm(index: integer);
begin
  with ToolsForm do
  begin
    Show;
    if WindowState = wsMinimized then ShowWindow(Handle, SW_RESTORE);
    PageCtrl.ActivePageIndex := index;
  end;
end;

function TMainForm.GroupFunc(s:string):string;
begin
  if ((s<>'')and(s[1]='\'))or(s='查找')or(s='收藏')or(s='搜索IP地址段') then result:='未知'
  else result:=s;
end;

{
in: url: 'ftp://x.x.x.x/aabb/ccdd/'
out: FptSvr: x.x.x.x
out: FtpDir: aabb/ccdd/
}
procedure ParseFtpUrl(url: string; var FtpSvr, FtpDir: string);
var
  s: string;
  i: integer;
begin
  s := url;
  delete(s, 1, 6);
  i := pos('/', s);
  if i = 0 then
  begin
    FtpSvr := s;
    FtpDir := '/';
  end
  else
  begin
    FtpSvr := copy(s, 1, i-1);
    delete(s, 1, i-1);
    FtpDir := s;
  end;
end;

{
in: url: 'ftp://x.x.x.x/aabb/c.txt'
return: c.txt
}
function GetFileNameFromFtpUrl(url: string): string;
var
  i, len: integer;
begin
  len := length(url);
  for i := len downto 1 do if url[i] = '/' then break;
  result := copy(url, i+1, len-i); 
end;

{
in: url: 'ftp://x.x.x.x/aabb/c.txt'
return: ftp://x.x.x.x/aabb/
}
function GetDirNameFromFtpUrl(url: string): string;
var
  i, len: integer;
begin
  len := length(url);
  for i := len downto 1 do if url[i] = '/' then break;
  result := copy(url, 1, i); 
end;

{
  目前有点问题,同一个目录中只能用一次。
}
function GetFtpFileSize(FtpHandle: HINTERNET; FileName: string): integer;
{var
  FileSize: DWORD;
  FileHandle: HINTERNET;}
begin
  {
  FileHandle := FtpOpenFile(FtpHandle, pchar(FileName),
        GENERIC_READ, FTP_TRANSFER_TYPE_BINARY, 0);
  FileSize := FtpGetFileSize(FileHandle, @FileSize);
  InternetCloseHandle(FileHandle);
  }
  //ShowMessage(FileName);
  result := ZwFtpGetFileSize(FileName);
end;

procedure TMainForm.AddCap(group: string; dir: string);
//var
//  RItem: TListItem;
begin
  if (group = '')and(dir = '') then
  begin
    pnlHeader.Caption := '';
    ShowMessage('dir name is null!');
    exit;
  end;

  IsFtp := (dir[1] = 'f');
  if IsFtp then // ftp
  begin
    pnlHeader.Caption := ' 地址:'+dir;
    StatusBar.Panels[2].Text := pnlHeader.Caption;
    CurDirName := dir;
    ParseFtpUrl(CurDirName, CurFtpSvr, CurFtpDir);
    exit;
  end
  else
  begin
    group := trim(group);
    pnlHeader.Caption := ' 地址:'+dir+' (工作组:'+GroupFunc(group)+')';
    CurDirName := dir + '\';
  end;

  StatusBar.Panels[2].Text := pnlHeader.Caption;


end;

procedure TExecuteThread.Execute;
begin
  ExecuteFile(exefile, '', exedir, SW_SHOW);
end;

procedure TMainForm.PageControlWndProc1(var Message: TMessage);  //Client
begin
  FOriginalPageControlWndProc1(Message);
  with Message do
    if (Msg = TCM_ADJUSTRECT) and (Message.WParam = 0) then
    begin
      PRect(LParam)^.Top := PRect(LParam)^.Top-5;
      PRect(LParam)^.Bottom := PRect(LParam)^.Bottom-2;
      PRect(LParam)^.left := PRect(LParam)^.left;
      PRect(LParam)^.Right := PRect(LParam)^.Right+1;
      InflateRect(PRect(LParam)^, 5, 3);
    end;
end;

procedure TMainForm.PageControlWndProc3(var Message: TMessage); //left
begin
  FOriginalPageControlWndProc3(Message);
  with Message do
    if (Msg = TCM_ADJUSTRECT) and (Message.WParam = 0) then
    begin
      PRect(LParam)^.Top := PRect(LParam)^.Top;
      PRect(LParam)^.Bottom := PRect(LParam)^.Bottom +3;
      PRect(LParam)^.left := PRect(LParam)^.left-1;
      PRect(LParam)^.Right := PRect(LParam)^.Right;
      InflateRect(PRect(LParam)^, 5, 3);
    end;
end;

procedure TMainForm.PageControlWndProc4(var Message: TMessage); //bottom
begin
  FOriginalPageControlWndProc4(Message);
  with Message do
    if (Msg = TCM_ADJUSTRECT) and (Message.WParam = 0) then
    begin
      PRect(LParam)^.Top := PRect(LParam)^.Top-7;
      PRect(LParam)^.left := PRect(LParam)^.left;
      InflateRect(PRect(LParam)^, 5, 1);
    end;
end;

procedure TMainForm.PageControlWndProc5(var Message: TMessage); //search
begin
  FOriginalPageControlWndProc5(Message);
  with Message do
    if (Msg = TCM_ADJUSTRECT) and (Message.WParam = 0) then
    begin
      PRect(LParam)^.Top := PRect(LParam)^.Top-3;
      PRect(LParam)^.Bottom := PRect(LParam)^.Bottom +2;
      PRect(LParam)^.left := PRect(LParam)^.left;
      InflateRect(PRect(LParam)^, 4, 1);
    end;
end;

procedure TMainForm.CheckFile(FileName, MyDir, MyGroup:string; ImageIndex, FileSize: integer);
var
  ListItem: TListitem;
begin
  with ConfigForm do
    begin

     if CheckDest(FileName) then
     begin
       ListItem := FindListview.Items.Add;
       if ImageIndex<>0 then listitem.ImageIndex:= GetImgIndex(FileName) else
       ListItem.ImageIndex := ImageIndex;
       ListItem.Caption := ExtractFileName(FileName);
       ListItem.SubItems.add(MyDir);
       ListItem.SubItems.add(MyGroup);

       if ImageIndex <> 0 then
       begin
         if FileSize > 1024 then
           ListItem.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024))
         else
           ListItem.SubItems.Add(inttostr(FileSize)+'B');
       end;

       //StrListSearch.Add(' 工作组:'+GroupFunc(MyGroup)+' 地址:'+MyDir+'\'+FileName);
     end;

     if CheckMP3(FileName) then
     begin
       ListItem := MP3Listview.Items.Add;
       if ImageIndex<>0 then listitem.ImageIndex:= GetImgIndex(FileName) else
       ListItem.ImageIndex := ImageIndex;
       ListItem.Caption := ExtractFileName(FileName);
       ListItem.SubItems.add(MyDir);
       ListItem.SubItems.add(MyGroup);

       if ImageIndex <> 0 then
       begin
         if FileSize > 1024 then
           ListItem.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024))
         else
           ListItem.SubItems.Add(inttostr(FileSize)+'B');
       end;

       //StrListMp3.Add(' 工作组:'+GroupFunc(MyGroup)+' 地址:'+MyDir+'\'+FileName);
     end;

     if CheckMovie(FileName) then
     begin
       ListItem := MovieListview.Items.Add;
       if ImageIndex<>0 then listitem.ImageIndex:= GetImgIndex(FileName) else
       ListItem.ImageIndex := ImageIndex;
       ListItem.Caption := ExtractFileName(FileName);
       ListItem.SubItems.add(MyDir);
       ListItem.SubItems.add(MyGroup);

       if ImageIndex <> 0 then
       begin
         if FileSize > 1024 then
           ListItem.SubItems.Add(FormatFloat('#,###" KB"',  FileSize/ 1024))
         else
           ListItem.SubItems.Add(inttostr(FileSize)+'B');
       end;

       //StrListMovie.Add(' 工作组:'+GroupFunc(MyGroup)+' 地址:'+MyDir+'\'+FileName);
     end;

  end;
end;

procedure TMainForm.OpenIni;
begin

  ini:=Tinifile.create(AppDir+'LanExplorer.ini');
  if not fileexists('LanExplorer.ini')
  then
  begin
    ini.writeInteger('window position','top',top);
    ini.writeInteger('window position','left',left);
    ini.writeInteger('window position','width',width);
    ini.writeInteger('window position','height',height);

    ini.writeInteger('panel position','left_panel',LeftPanel.Width);
    //ini.writeInteger('panel position','right_panel',RightPanel.Width);
    ini.writeInteger('panel position','bottom_panel',BottomPanel.Height);

    ini.writeString('Dock','RightDockPanel','alRight');

    // nbtstat IP address
    ini.writeString('NBT_IP','IP1','192.168.0.1');
    ini.writeString('NBT_IP','IP2','192.168.0.255');

    // TCP port scan address
    ini.writeString('TCP_PORT_SCAN','IP1','192.168.0.1');
    ini.writeString('TCP_PORT_SCAN','IP2','192.168.0.255');

    // ping IP address
    ini.writeString('PING','IP1','192.168.0.1');
    ini.writeString('PING','IP2','192.168.0.255');

    // Scan IP address
    ini.writeString('SCAN','IP1','192.168.0.1');
    ini.writeString('SCAN','IP2','192.168.0.255');

    // Save history or not
    ini.writeString('history','save','yes');
    ini.writeString('history','save_when_share','yes');
    ini.writeInteger('history','count', 100);
    ini.writeString('history','save_nbt','yes');

    // Search Type
    ini.writeString('search_type','share','yes');
    ini.writeString('search_type','ftp','yes');
    ini.writeString('search_type','http','yes');
  end
  else
  begin
    top:=ini.ReadInteger('window position','top',50);
    left:=ini.ReadInteger('window position','left',50);
    width:=ini.ReadInteger('window position','width',500);
    height:=ini.ReadInteger('window position','height',50);

    if (width=screen.Width)and(height=screen.Height)then WindowState:=wsMaximized; 

    LeftPanel.Width:=ini.ReadInteger('panel position','left_panel',LeftPanel.Width);
    //RightPanel.Width:=ini.ReadInteger('panel position','right_panel',RightPanel.Width);
    BottomPanel.Height:=ini.ReadInteger('panel position','bottom_panel',BottomPanel.Height);

    //nbtstat IP address
    Nbt_IP1 := ini.ReadString('NBT_IP', 'IP1', '192.168.0.1');
    Nbt_IP2 := ini.ReadString('NBT_IP', 'IP2', '192.168.0.255');

    //TCP port scan address
    ScanPort_IP1 := ini.ReadString('TCP_PORT_SCAN','IP1','192.168.0.1');
    ScanPort_IP2 := ini.ReadString('TCP_PORT_SCAN','IP2','192.168.0.255');

    //ping IP address
    Ping_IP1 := ini.ReadString('PING','IP1','192.168.0.1');
    Ping_IP2 := ini.ReadString('PING','IP2','192.168.0.255');

    //CheckIpForm.edtStart.Text
    edtIP1.Text := ini.ReadString('SCAN', 'IP1', '192.168.0.1');
    edtIP2.Text := ini.ReadString('SCAN', 'IP2', '192.168.0.255');

    // Save History or not
    cbSaveHistory.Checked := (ini.ReadString('history','save','yes') = 'yes');
    cbSaveOpt.Checked := (ini.ReadString('history','save_when_share','yes') = 'yes');
    seHistoryCount.Value := ini.ReadInteger('history','count', 100);
    bNotAutoSaveNbt := (ini.ReadString('history','save_nbt','yes') = 'yes');

    // Search Type
    cbShare.Checked := (ini.ReadString('search_type','share','yes') = 'yes');
    cbFtp.Checked := (ini.ReadString('search_type','ftp','yes') = 'yes');
    cbHttp.Checked := (ini.ReadString('search_type','http','yes') = 'yes');
  end;
  ini.Free;
  
  
end;

procedure TMainForm.SaveIni;
begin

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -