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

📄 fileop.pas

📁 是一个手机功能的模拟程序
💻 PAS
📖 第 1 页 / 共 2 页
字号:
unit fileop;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Buttons, ExtCtrls, Grids,  DirOutln,
  ShellCtrls, ComCtrls, FileCtrl, ImgList;

type
  TForm_fileop = class(TForm)
    BitBtn3: TBitBtn;
    Edit_PC: TEdit;
    DriveComboBox1: TDriveComboBox;
    FilterComboBox1: TFilterComboBox;
    DirectoryListBox1: TDirectoryListBox;
    FileListBox1: TFileListBox;
    SpeedButton_uploadfile: TSpeedButton;
    SpeedButton_downloadfile: TSpeedButton;
    ListView_file: TListView;
    StatusBar_fileop: TStatusBar;
    TreeView_dir: TTreeView;
    ImageList_fileop: TImageList;
    SpeedButton_Delfile: TSpeedButton;
    SpeedButton_uploaddir: TSpeedButton;
    SpeedButton_downloaddir: TSpeedButton;
    SpeedButton_deldir: TSpeedButton;
    procedure BitBtn3Click(Sender: TObject);
    procedure FileListBox1Click(Sender: TObject);
    procedure TreeView_dirChange(Sender: TObject; Node: TTreeNode);
    procedure SpeedButton_downloadfileClick(Sender: TObject);
    procedure SpeedButton_uploadfileClick(Sender: TObject);
    procedure SpeedButton_DelfileClick(Sender: TObject);
    procedure ListView_fileColumnClick(Sender: TObject;
      Column: TListColumn);
    procedure SpeedButton_downloaddirClick(Sender: TObject);
    procedure SpeedButton_uploaddirClick(Sender: TObject);
    procedure FormActivate(Sender: TObject);
    procedure SpeedButton_deldirClick(Sender: TObject);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
  private
    { Private declarations }
    FLastIndex_file:Integer;
  public
    { Public declarations }
  end;

var
  Form_fileop: TForm_fileop;

implementation

uses global, main, progressbar;
{$R *.dfm}

function transdigital(s:string):string;//去处文件大小中的千分号
var i:integer;
begin
  i:=pos(',',s);
  while i>0 do
  begin
    delete(s,i,1);
    i:=pos(',',s);
  end;
  result:=s;
end;

function CustSortAsc(Item1, Item2:TListItem;ColIndex: Integer): Integer; stdcall;
var
  Item1Str:string;
  Item2Str:string;
begin
  Result := 0;
  Item1Str :='';
  Item2Str :='';

  if ColIndex < 0 then Exit;

  if ColIndex = 0 then
  begin
    Item1Str := Item1.Caption;
    Item2Str := Item2.Caption;
  end
  else
  begin
    if ColIndex <= Item1.SubItems.Count then
      Item1Str := Item1.SubItems[ColIndex - 1];
    if ColIndex <= Item2.SubItems.Count then
      Item2Str := Item2.SubItems[ColIndex - 1];
    if ColIndex=1 then
    begin
      item1str:=format('%.10d',[strtoint64(transdigital(item1str))]);
      item2str:=format('%.10d',[strtoint64(transdigital(item2str))]);;
    end;
  end;
  Result := CompareText(Item1Str, Item2Str);

  // If one of the strings is empty, make the other string sort before it

  if (Result > 0) and (Item2Str = '') then Result := -1
  else if (Result < 0) and (Item1Str ='') then Result := 1;
end; {= CustSortAsc =}

function CustSortDesc(Item1, Item2: TListItem;ColIndex: Integer): Integer; stdcall;
begin
  Result := CustSortAsc(Item1, Item2, ColIndex);
  Result := Result*-1;
end; {= CustSortDesc =}

procedure TForm_fileop.BitBtn3Click(Sender: TObject);
begin
  close;
end;

procedure pc_callback_FILEGetInfo(p:pointer);
var tempname:string;
    showstr:string;
begin
  if PPC_Interface_Info(p).status<>ord(PC_Error_NoError) then
  begin
    case PPC_Interface_Info(p).status of
      ord(PC_Error_SerialNoResponse):
      begin
        Form_fileop.statusbar_fileop.Panels[0].Text:='通讯超时,可能串口连接有故障';//说明target响应timeout,for example:serial is invalid
        Serial_Close;
        Form_fileop.StatusBar_fileop.Panels[1].Text:='未连接';
      end;
      ord(PC_Error_MMINotAllow):Form_fileop.statusbar_fileop.Panels[0].Text:='手机未设在同步状态菜单内';//手机不允许pc同步, 要先进入菜单工具箱->pc同步
      ord(PC_Error_MMINeedPause):Form_fileop.statusbar_fileop.Panels[0].Text:='有电话进来,同步暂停';
    end;
    status_FILE:=PC_FILE_status_init;
    form_progressbar.ProgressBar1.Position:=1;
    form_progressbar.Hide;
    form_progressbar.close;
    Form_fileop.TreeView_dir.ClearSelection;
    Form_fileop.TreeView_dir.FullCollapse;
    Form_fileop.ListView_file.clear;
    if PPC_Interface_Info(p).pdata_cmd<>nil then
      freemem(PPC_Interface_Info(p).pdata_cmd);
    if PPC_Interface_Info(p).pdata_dlbuff<>nil then
      freemem(PPC_Interface_Info(p).pdata_dlbuff);
    if p<>nil then
     freemem(p);
    exit;
  end;
  case status_FILE of
    PC_FILE_status_init:
    begin
      if PPC_Interface_Info(p).pdata_cmd<>nil then
        freemem(PPC_Interface_Info(p).pdata_cmd);
      if PPC_Interface_Info(p).pdata_dlbuff<>nil then
        freemem(PPC_Interface_Info(p).pdata_dlbuff);
      if p<>nil then
       freemem(p);
      exit;
    end;
    PC_FILE_status_getfileinfo: //获得Sim电话本和手机电话本里的电话号码数目后,处理
    begin
      dogetfileinfo(p);
      Form_fileop.TreeView_dir.Cursor:=crDefault;
      Form_fileop.StatusBar_fileop.Panels[0].Text:='获取目录信息完成!';
    end;
    PC_FILE_status_DLfile:
    begin
      dodownloadfile(p);
      showstr:='正在下载文件(还剩 '+inttostr(fileList.Count-1)+'个)';
      form_progressbar.Label_status.Caption:=showstr;
      form_progressbar.ProgressBar1.StepIt;
      Form_fileop.FileListBox1.Update;//实时更新本地文件目录
      Form_fileop.FileListBox1.Selected[Form_fileop.FileListBox1.count-1]:=true; //需要选择一下filelistbox中的文件,否则前面的文件图标不显示
      if filelist.Items[0]<>nil then freemem(filelist.Items[0]);
      filelist.Delete(0);
      if filelist.Count>0 then
      begin
        getfile(@pc_callback_FILEGetInfo,strpas(PFileRec(filelist.items[0]).Pathname)+'/'+strpas(PFileRec(filelist.items[0]).filename));
        exit;
      end;
      Form_fileop.FileListBox1.Update;//实时更新本地文件目录
      Form_fileop.statusbar_fileop.Panels[0].Text:='下载文件完成!';
      Form_fileop.FileListBox1.ClearSelection;
      Form_fileop.TreeView_dirChange(nil,Form_fileop.TreeView_dir.Selected);
      exit;//因为要去重新获取getfileinfo,所以直接退出,不能去做status_FILE:=PC_FILE_status_init;
      //但是这样进度窗口要等下载一次文件信息后才能关掉,比较慢。
    end;
    PC_FILE_status_ULfile:
    begin
      douploadfile(p);
      showstr:='正在上载文件(还剩 '+inttostr(fileList.Count-1)+'个)';
      Form_progressbar.Label_status.Caption:=showstr;
      form_progressbar.ProgressBar1.StepIt;

      if filelist.Items[0]<>nil then freemem(filelist.Items[0]);
      filelist.Delete(0);
      if filelist.Count>0 then
      begin
        putfile(@pc_callback_FILEGetInfo,strpas(PFileRec(filelist.items[0]).filename),strpas(PFileRec(filelist.items[0]).Pathname)+'/');
        exit;
      end;
      Form_fileop.statusbar_fileop.Panels[0].Text:='上载文件完成!';
      Form_fileop.TreeView_dirChange(nil,Form_fileop.TreeView_dir.Selected);
      exit;//因为要去重新获取getfileinfo,所以直接退出,不能去做status_FILE:=PC_FILE_status_init;
       //但是这样进度窗口要等下载一次文件信息后才能关掉,比较慢。
   end;
    PC_FILE_status_Delfile:
    begin
      doDelfile(p);
      form_progressbar.ProgressBar1.StepIt;
      tempname:=strpas(PFileRec(filelist.items[0]).filename);
      if filelist.Items[0]<>nil then freemem(filelist.Items[0]);
      filelist.Delete(0);
      if filelist.Count>0 then
      begin
        showstr:='正在删除文件(还剩 '+inttostr(fileList.Count)+'个)';
        form_progressbar.Label_status.Caption:=showstr;
        Delfile(@pc_callback_FILEGetInfo,strpas(PFileRec(filelist.items[0]).Pathname)+'/'+strpas(PFileRec(filelist.items[0]).filename));
        exit;
      end;
      Form_fileop.statusbar_fileop.Panels[0].Text:='删除完成!';
      Form_fileop.FileListBox1.ClearSelection;
      if tempname='' then//表示被删除的是目录,所以要选择上一层的目录
        Form_fileop.TreeView_dir.Selected:=Form_fileop.TreeView_dir.Selected.Parent
      else//表示被删除的是文件,所以仍旧选择目录
        Form_fileop.TreeView_dirChange(nil,Form_fileop.TreeView_dir.Selected);
      exit;//因为要去重新获取getfileinfo,所以直接退出,不能去做status_FILE:=PC_FILE_status_init;
      //但是这样进度窗口要等下载一次文件信息后才能关掉,比较慢。
    end;
  end;
  status_FILE:=PC_FILE_status_init;
  form_progressbar.ProgressBar1.Position:=1;
  form_progressbar.Hide;
  form_progressbar.close;
end;

procedure TForm_fileop.FileListBox1Click(Sender: TObject);
var
  sr: TSearchRec;
  FileAttrs: Integer;
begin
  edit_pc.Text:=FileListBox1.FileName;
  FileAttrs:=0;
  if fileexists(edit_pc.text) then
  begin
    if FindFirst(edit_pc.Text, FileAttrs, sr) = 0 then
      FileListBox1.Hint:=format('%.0n',[sr.Size*1.0])+'字节';
  end;
end;

procedure TForm_fileop.TreeView_dirChange(Sender: TObject;
  Node: TTreeNode);
var pathname:string;
    tempnode:TTreeNode;
begin
  tempnode:=node;
  if tempnode=nil then exit;
  TreeView_dir.Cursor:=crHourGlass;
  pathname:='';
  if tempnode.level>0 then
  begin
    repeat
      pathname:='/'+tempnode.Text+pathname;
      tempnode:=tempnode.Parent;
      tempnode.ImageIndex:=1;
    until tempnode.Level=0;
  end else
    pathname:='/';
  status_FILE:=PC_FILE_status_Getfileinfo;
  getfileInfo(@pc_callback_FILEGetInfo,pathname);
  FLastIndex_file :=-1;
end;

procedure TForm_fileop.SpeedButton_downloadfileClick(Sender: TObject);
var pathname:string;
    tempnode:TTreeNode;
    itemSelected:TListItem;
    tempFileRec:PFileRec;
    showstr:string;
begin
  while FileList.Count>0 do
  begin
    if filelist.Items[0]<>nil then freemem(filelist.Items[0]);
    filelist.Delete(0);
  end;

  tempnode:=TreeView_dir.Selected;
  if tempnode=nil then exit;
  pathname:='';
  if tempnode.level>0 then
  begin
    repeat
      pathname:='/'+tempnode.Text+pathname;
      tempnode:=tempnode.Parent;
      tempnode.ImageIndex:=1;
    until tempnode.Level=0;
  end;

  itemSelected:=ListView_file.Selected;
  while itemSelected<>nil do
  begin
    if FileExists(Form_fileop.FileListBox1.Directory+'\'+itemSelected.Caption) then
      if MessageDlg('下载的文件'''+itemSelected.Caption+'''在PC上已存在,是否要覆盖?',mtConfirmation, [mbYes, mbNo], 0)=mrNo then
        break;
    getmem(tempFileRec,sizeof(TFileRec));
    strpcopy(tempFileRec.Pathname,pathname);
    strpcopy(tempFileRec.Filename,itemSelected.Caption);
    tempFileRec.Filesize:=strtoint64(transdigital(itemSelected.SubItems[0]));
    tempFileRec.ReadOnly:=itemSelected.SubItems[1]='是';
    FileList.Add(tempFileRec);
    itemSelected:=ListView_file.GetNextItem(itemSelected, sdAll, [isSelected]);
  end;

  if FileList.Count>0 then
  begin
    Form_fileop.statusbar_fileop.Panels[0].Text:='正在下载文件';
    status_FILE:=PC_FILE_status_DLfile;
    getfile(@pc_callback_FILEGetInfo,strpas(PFileRec(filelist.items[0]).Pathname)+'/'+strpas(PFileRec(filelist.items[0]).filename));
    showstr:='正在下载文件(共 '+inttostr(filelist.Count)+'个)';
    form_progressbar.Label_status.Caption:=showstr;
    form_progressbar.ProgressBar1.Max:=filelist.Count+1;
    form_progressbar.ProgressBar1.Min:=1;
    form_progressbar.ProgressBar1.Step:=1;
    form_progressbar.ProgressBar1.Position:=1;
    form_progressbar.Showmodal;
    //    SpeedButton_download.Enabled:=false;
  end;
end;

procedure TForm_fileop.SpeedButton_uploadfileClick(Sender: TObject);
var tempitem:TListItem;
    pathname,filename:string;
    tempnode:TTreeNode;
    tempFileRec:PFileRec;
    sr: TSearchRec;
    FileAttrs: Integer;
    i:integer;
    showstr:string;
begin
  while FileList.Count>0 do
  begin

⌨️ 快捷键说明

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