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

📄 file.cpp

📁 多级目录文件管理多级目录文件管理多级目录文件管理
💻 CPP
📖 第 1 页 / 共 2 页
字号:
//---------------------------------------------------------------------------

#include <vcl.h>
#pragma hdrstop

#include "file.h"
#include "newfile.h"
#include "showfile.h"
#include "property.h"
#include "help.h"
//---------------------------------------------------------------------------
#pragma package(smart_init)
#pragma resource "*.dfm"
Tmainfrm *mainfrm;
MFD *root,*mpos,*cutfolder,*copyfolder;
TTreeNode *SelNode;
UFD *opfile,*selfile,*cutfile,*copyfile;
int flag=4;
String addrstr;
//---------------------------------------------------------------------------
__fastcall Tmainfrm::Tmainfrm(TComponent* Owner)
        : TForm(Owner)
{
}
//---------------------------------------------------------------------------



void __fastcall Tmainfrm::BtGotoClick(TObject *Sender)
{
        FindAddr();
        ListRefresh();
}
//---------------------------------------------------------------------------



void __fastcall Tmainfrm::FormCreate(TObject *Sender)
{
        MFD *p,*q;
        UFD *f,*r;
        TTreeNode *TreeNode,*FileNode;
        root=(MFD*)malloc(sizeof(MFD));
        root->name="root";
        root->parent=NULL;
        root->folder=NULL;
        root->file=NULL;
        root->next=NULL;
        TreeView->Items->Add(NULL,root->name);
        TreeView->TopItem->ImageIndex=5;
        TreeView->TopItem->SelectedIndex=5;
        for(int i=0;i<3;i++){
        TreeNode=TreeView->Items->GetFirstNode();
        p=(MFD*)malloc(sizeof(MFD));
        p->name="用户"+IntToStr(i);
        p->parent=NULL;
        p->folder=NULL;
        p->file=NULL;
        p->next=NULL;
        if(root->folder==NULL)  {root->folder=p;p->parent=root;}
        else{
                q=root->folder;
                while(q->next!=NULL) q=q->next;
                q->next=p;
                p->parent=q;
          }
          TreeView->Items->AddChild(TreeNode,p->name);
          TreeNode=TreeNode->GetLastChild();
          ListView->AddItem(p->name,NULL);
          for(int j=0;j<3;j++){
                f=(UFD*)malloc(sizeof(UFD));
                f->filename="文件"+IntToStr(j);
                strcpy(f->text,"");
                f->pt=111;
                f->len=0;
                f->next=NULL;
                if(p->file==NULL) {p->file=f; f->parent=NULL;}
                else{
                        r=p->file;
                        while(r->next!=NULL) r=r->next;
                        f->parent=r;
                        r->next=f;
                }
                }
        }
       // copyfolder=(MFD *)malloc(sizeof(MFD));
        /*copyfile=(UFD *)malloc(sizeof(UFD));
        copyfile->filename="copyfile";
        strcpy(copyfile->text,"file");
        copyfile->pt=111;
        copyfile->len=4;
        copyfile->parent=NULL;
        copyfile->next=NULL;     */
}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::ListViewDblClick(TObject *Sender)
{
        TListItem *ListItem;
        String str=Comboaddr->Text;
        ListItem=ListView->Selected;
        if(ListItem==NULL) return;
        if(ListItem->ImageIndex==1){
          FindAddr();
          for(opfile=mpos->file;opfile!=NULL;opfile=opfile->next)
          {
             if(opfile==NULL)  {ShowMessage("文件打开失败!");return;}
             if(opfile->filename==ListItem->Caption){
                showfrm->Editname->Text=opfile->filename;
                showfrm->Lsize->Caption=IntToStr(opfile->len)+"(K)";
                showfrm->Memo->Text=opfile->text;
                int i=opfile->pt/100;
                int j=(opfile->pt%100)/10;
                int k=(opfile->pt%100)%10;
                if(i==1) showfrm->Lread->Caption="允许读";
                else
                        {showfrm->Lread->Caption="禁止读";Application->MessageBoxA("此文件禁止读!","警告",MB_ICONWARNING);return;}
                if(j==1){showfrm->Lwrite->Caption="允许写"; showfrm->Memo->Enabled=true;}
                else
                        {showfrm->Lwrite->Caption="禁止写";showfrm->Memo->Enabled=false;}
                if(k==1) showfrm->Lgo->Caption="可执行";
                else     showfrm->Lgo->Caption="不可执行";
                showfrm->BtSave->Enabled=false;
                showfrm->Show();
                return;
             }
            }
            if(opfile==NULL)  {ShowMessage("文件打开失败!");return;}
          }
          else{
           if(ListItem!=NULL){
           if(str=="root:\\")  str=str+ListItem->Caption;
           else               str=str+"\\"+ListItem->Caption;
           Comboaddr->Text=str;
           FindAddr();
           ListRefresh();
          }
        }
}
//---------------------------------------------------------------------------



void __fastcall Tmainfrm::TreeViewContextPopup(TObject *Sender,
      TPoint &MousePos, bool &Handled)
{
        TTreeNode *TreeNode;
        TreeNode=TreeView->GetNodeAt(MousePos.x,MousePos.y);
        if(TreeNode==NULL) return;
        TreeNode->Selected=true;
}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::TreeViewDblClick(TObject *Sender)
{
        O2Click(Sender);
}
//---------------------------------------------------------------------------



void __fastcall Tmainfrm::O2Click(TObject *Sender)
{
        String rootstr,str;
        TTreeNode *TreeNode,*ChildNode;
        POINT pos;
        ::GetCursorPos(&pos);
        ::ScreenToClient(TreeView->Handle,&pos);
        TreeNode=TreeView->Selected;
        if(TreeNode==NULL) return;
        str=TreeNode->Text;
        if(TreeNode->Level==0)
                {Comboaddr->Text="root:\\";FindAddr();ListRefresh();return;}
        while(TreeNode->Parent->Level!=0){
                TreeNode=TreeNode->Parent;
                rootstr=TreeNode->Text+"\\";
                str=rootstr+str;
        }
        rootstr="root:\\"+str;
        Comboaddr->Text=rootstr;
        FindAddr();
        ListRefresh();

}
//---------------------------------------------------------------------------


void Tmainfrm::ListRefresh()
{
      MFD *r;
      UFD *f;
      TListItem *ListItem;
      ListView->Clear();
      if(mpos==NULL)   return;
      for(r=mpos->folder;r!=NULL;r=r->next)
      {
        if(r==NULL)  break;
        ListItem=ListView->Items->Add();
        ListItem->Caption=r->name;
        ListItem->ImageIndex=0;
      }
      if(mpos->file==NULL)  return;
      for(f=mpos->file;f!=NULL;f=f->next)
      {
        ListItem=ListView->Items->Add();
        ListItem->Caption=f->filename;
        ListItem->ImageIndex=1;
      }

}

void Tmainfrm::FindAddr()
{
        int i;
        MFD *npos;
        String rootstr,flostr;
        rootstr=Comboaddr->Text;
        if(rootstr.SubString(1,rootstr.Pos("\\"))!="root:\\")
        {Application->MessageBoxA("地址错误,请重新输入!","地址错误",MB_ICONERROR);mpos=root;Comboaddr->Text="root:\\";return;}
        mpos=root;
        while(rootstr!=""){
                i=rootstr.Pos("\\");
                if(i!=0)
                  {flostr=rootstr.SubString(1,i-1); rootstr=rootstr.Delete(1,i); }
                else
                  {flostr=rootstr;rootstr=""; }
                  if(flostr=="root:") npos=mpos->folder;
                  else{
                  for(;npos!=NULL;npos=npos->next)
                  {
                    if(npos==NULL) return;
                    if(npos->name==flostr) {mpos=npos;npos=mpos->folder;goto next;}
                  }
                  if(npos==NULL)
                  {Application->MessageBoxA("地址错误,请重新输入!","地址错误",MB_ICONERROR);mpos=root;Comboaddr->Text="root:\\";return;}
                 }
                 next:  if(rootstr=="") return;
        }
}


void __fastcall Tmainfrm::TreeViewClick(TObject *Sender)
{
        O2Click(Sender);        
}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::F2Click(TObject *Sender)
{
        MFD *p,*q;
        FindAddr();
        if(mpos==NULL) return;
        AnsiString inputstr=InputBox("新建文件夹","新文件夹名","超级文件夹");
        q=mpos->folder;
        while(q!=NULL)
        {
         if(q->name==inputstr)
         {
          Application->MessageBoxA("文件夹重名,请重新输入!","文件夹重名",MB_ICONERROR);
          return;
         }
         q=q->next;
        }
         p=(MFD*)malloc(sizeof(MFD));
         p->name=inputstr;
         p->folder=NULL;
         p->parent=NULL;
         p->file=NULL;
         p->next=NULL;
         q=mpos->folder;
         if(q==NULL) {mpos->folder=p;p->parent=mpos;}
         else{
                while(q->next!=NULL) q=q->next;
                q->next=p;
                p->parent=q;
             }
         ListRefresh();
         FindTNode();
         if(SelNode==NULL) return;
         TreeView->Items->AddChild(SelNode,p->name);


}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::N9Click(TObject *Sender)
{
        FindAddr();
        newfrm->EditLen->Text="4";
        newfrm->Memo->Text="file";
        newfrm->Show();
                
}
//---------------------------------------------------------------------------


void Tmainfrm::FindTNode()
{
        int i;
        TTreeNode *ChildNode;
        String rootstr,flostr;
        rootstr=Comboaddr->Text;
        SelNode=TreeView->TopItem;
        while(rootstr!=""){
                i=rootstr.Pos("\\");
                if(i!=0)
                  {flostr=rootstr.SubString(1,i-1); rootstr=rootstr.Delete(1,i); }
                else
                  {flostr=rootstr;rootstr=""; }
                  if(flostr=="root:") ChildNode=SelNode->getFirstChild();
                  else{
                  for(;ChildNode!=NULL;ChildNode=SelNode->GetNextChild(ChildNode))
                  {
                        if(ChildNode==NULL)   return;
                        if(ChildNode->Text==flostr)
                        {SelNode=ChildNode;ChildNode=SelNode->getFirstChild();break;}
                  }
                  }
                  if(rootstr=="") return;
        }
}
void __fastcall Tmainfrm::ButtonBackClick(TObject *Sender)
{
        ButtonUpClick(Sender);
}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::N7Click(TObject *Sender)
{
        ListViewDblClick(Sender);
}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::ComboaddrKeyDown(TObject *Sender, WORD &Key,
      TShiftState Shift)
{
         if(Key==VK_RETURN)
         BtGotoClick(Sender);
                 
}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::ButtonUpClick(TObject *Sender)
{
        String  bustr,str;
        if(Comboaddr->Text=="root:\\")  return;
        bustr=Comboaddr->Text;
        str="";
        while(bustr!=""){
                int i=bustr.Pos("\\");
                if(i==0)  break;
                str=str+bustr.SubString(1,i);
                bustr.Delete(1,i);
                }
                if(str!="root:\\")
                   str=str.SubString(1,str.Length()-1);
                   Comboaddr->Text=str;
                   FindAddr();
                   ListRefresh();

}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::N11Click(TObject *Sender)
{
        ListView->ViewStyle=vsIcon;
}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::N13Click(TObject *Sender)
{
         ListView->ViewStyle=vsList;
}
//---------------------------------------------------------------------------


void __fastcall Tmainfrm::N12Click(TObject *Sender)
{
        ListView->ViewStyle=vsSmallIcon;
}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::N15Click(TObject *Sender)
{
        TListItem *ListItem;
        ListItem=ListView->Selected;
        if(ListItem==NULL) return;
        FindAddr();
        for(selfile=mpos->file;selfile!=NULL;selfile=selfile->next)
        {
         if(selfile==NULL)   return;
         if(selfile->filename==ListItem->Caption){
           profrm->EditName->Text=selfile->filename;
           profrm->Lpos->Caption=Comboaddr->Text;
           profrm->Lsize->Caption=IntToStr(selfile->len)+"(K)";
           if(selfile->pt/100==1)      profrm->RadioButton1->Checked=true;
           else                  profrm->RadioButton2->Checked=true;
           if((selfile->pt%100)/10==1) profrm->RadioButton3->Checked=true;
           else                  profrm->RadioButton4->Checked=true;
           if((selfile->pt%100)%10==1) profrm->RadioButton5->Checked=true;
           else                  profrm->RadioButton6->Checked=true;
           profrm->Button3->Enabled=false;
           profrm->Show();
           return;
         }
        }
        if(selfile==NULL) return;

}
//---------------------------------------------------------------------------

void __fastcall Tmainfrm::C1Click(TObject *Sender)
{
        this->Close();        

⌨️ 快捷键说明

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