📄 mainform.~cpp
字号:
ShowMessage("文件属性为只读,不可编辑");return;}
Form7->Sname->Caption=tempfile->name;
Form7->Stype->Caption=tempfile->name.SubString(tempfile->name.Length()-2,3)+"文件";
Form7->Spath->Caption=FilePath+tempfile->name;
Form7->Editlen->Text=IntToStr(tempfile->length);
Form7->Tag=0;
Form7->ShowModal();
if(Form7->Tag){
tempfile->length=Form7->Editlen->Text.ToInt();
ShowDir(CurrDir);
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N20Click(TObject *Sender)
{ //修改属性
TListItem *Item;
Item=ListView1->Selected;
String Name;
FILENODE tempfile;
DIRECTORY tempdir;
int index,share;
if(Item&&Item->ImageIndex==1) //修改文件属性
{
Name=Item->Caption;
tempfile=LocateFile(CurrDir,Name);
if(CurrUser!="root"&&tempfile->user!=CurrUser){
ShowMessage("你无权限修改该文件属性!");return;}
///////////////////////////////// Form3窗口初始化
Form3->Caption="修改文件属性";
Form3->TypeBox->Enabled=false;
Form3->EditName->Enabled=false;
Form3->EditLength->Enabled=false;
Form3->EditName->Text=tempfile->name.SubString(1,tempfile->name.Length()-4);
Form3->EditLength->Text=IntToStr(tempfile->length);
String type=tempfile->name.SubString(tempfile->name.Length()-2,3);
if(type=="txt")index=0;
else if(type=="mp3")index=1;
else if(type=="avi")index=2;
else if(type=="cpp")index=3;
else if(type=="jpg")index=4;
else index=5;
Form3->TypeBox->ItemIndex=index;
Form3->Property->ItemIndex=tempfile->property;
if(tempfile->share)Form3->CheckSh->Checked=true;
else Form3->CheckSh->Checked=false;
Form3->Tag=0;
Form3->ShowModal();
share=0;
//////////////////////////////////////
if(Form3->Tag){
if(Form3->CheckSh->Checked)share=1;
tempfile->share=share;
tempfile->property=Form3->Property->ItemIndex;
ShowDir(CurrDir);
}
}
else if(Item&&Item->ImageIndex==0){ //在ListView中修改文件夹
Name=Item->Caption;
tempdir=LocateDir(CurrDir,Name);
if(CurrUser!="root"&&tempdir->user!=CurrUser){
ShowMessage("你无权限修改该文件夹属性!");
return;
}
////////////////////////////////////////// Form4窗口初始化
Form4->Tag=0;
Form4->EditName->Text=tempdir->name;
Form4->EditName->Enabled=false;
Form4->Caption="修改文件夹属性";
Form4->Property->ItemIndex=tempdir->property;
if(tempdir->share)Form4->CheckSh->Checked=true;
else Form4->CheckSh->Checked=false;
Form4->ShowModal();
share=0;
//////////////////////////////////////////
if(Form4->Tag){
if(Form4->CheckSh->Checked)share=1;
tempdir->share=share;
tempdir->property=Form4->Property->ItemIndex;
ShowDir(CurrDir);
}
}
else if(TreeView1->Selected){ //在TreeView中修改文件夹
Name=CurrDir->name;
tempdir=CurrDir;
if(Name=="Root"){ShowMessage("根文件夹不可修改!");return;}
if(CurrUser!="root"&&tempdir->user!=CurrUser){ //文件夹删除权限
ShowMessage("你无权限删除该文件夹!");
return;
}
////////////////////////////////////////// Form4窗口初始化
Form4->Tag=0;
Form4->EditName->Text=tempdir->name;
Form4->EditName->Enabled=false;
Form4->Caption="修改文件夹属性";
Form4->Property->ItemIndex=tempdir->property;
if(tempdir->share)Form4->CheckSh->Checked=true;
else Form4->CheckSh->Checked=false;
Form4->ShowModal();
share=0;
//////////////////////////////////////////
if(Form4->Tag){
if(Form4->CheckSh->Checked)share=1;
tempdir->share=share;
tempdir->property=Form4->Property->ItemIndex;
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ManBnClick(TObject *Sender)
{ //管理用户
MFD m=Mfd->Next->Next;
Form8->ComboBox1->Clear();
while(m){
Form8->ComboBox1->Items->Add(m->user);
m=m->Next;
}
Form8->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N29Click(TObject *Sender)
{ //查找功能
Form9->Edit1->Clear();
Form9->Tag=0;
Form9->ShowModal();
if(Form9->Tag){
String path="";
String name=Form9->Edit1->Text;
DIRECTORY dir,subdir,OKdir;
FILENODE file;
TListItem *Item;
que.push(CurrDir);
while(!que.empty())
{
dir=que.front();
que.pop();
OKdir=LocateDir(dir,name); //找到文件夹
file=LocateFile(dir,name); //找到文件
if(OKdir||file){
while(dir){ //取得路径
path=dir->name+"\\"+path; dir=dir->father; }
ComboBox1->Text=path;
JumpToClick(Sender); //跳转到目的目录
Item=ListView1->FindCaption(0,name,true,false,true);
ListView1->SetFocus();
Item->Selected=true; //选中目的文件或目录
ShowMessage("查找成功!");
return;
}
subdir=dir->dirpoint;
while(subdir) //子目录入队列
{que.push(subdir);
subdir=subdir->next;
}
}
ShowMessage("找不到指定名称的文件或文件夹");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N25Click(TObject *Sender)
{ //复制功能
TListItem *Item;
Item=ListView1->Selected;
String Name;
if(Item&&Item->ImageIndex==1) //复制文件
{
Name=Item->Caption;
Clip->filenode=LocateFile(CurrDir,Name);
Clip->share=1;
Clip->property=0;
}
else if(Item&&Item->ImageIndex==0) //在ListView中复制目录
{
Name=Item->Caption;
Clip->dirpoint=LocateDir(CurrDir,Name);
Clip->share=2;
Clip->property=0;
}
else if(TreeView1->Selected){ //在TreeView中复制目录
Name=CurrDir->name;
if(Name=="Root"){ShowMessage("根文件夹不可复制!");return;}
Clip->dirpoint=CurrDir;
Clip->share=2;
Clip->property=0;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N26Click(TObject *Sender)
{ //剪切功能
TListItem *Item;
Item=ListView1->Selected;
String Name;
if(Item&&Item->ImageIndex==1) //剪切文件
{
Name=Item->Caption;
Clip->filenode=LocateFile(CurrDir,Name);
if(CurrUser!="root"&&CurrUser!=Clip->filenode->user){
ShowMessage("你无限权剪切该文件");return;}
Clip->share=1;
Clip->property=1;
}
else if(Item&&Item->ImageIndex==0) //在ListView中剪切目录
{
Name=Item->Caption;
Clip->dirpoint=LocateDir(CurrDir,Name);
if(CurrUser!="root"&&CurrUser!=Clip->dirpoint->user){
ShowMessage("你无限权剪切该文件");return;}
Clip->share=2;
Clip->property=1;
}
else if(TreeView1->Selected){ //在TreeView中剪切目录
Name=CurrDir->name;
if(Name=="Root"){ShowMessage("根文件夹不可剪切!");return;}
Clip->dirpoint=CurrDir;
if(CurrUser!="root"&&CurrUser!=Clip->dirpoint->user){
ShowMessage("你无限权剪切该文件");return;}
Clip->share=2;
Clip->property=1;
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N27Click(TObject *Sender)
{ //粘贴功能
FILENODE file=Clip->filenode;
DIRECTORY dir=Clip->dirpoint,subdir;
if(CurrUser!="root"&&CurrUser!=CurrDir->user&&CurrDir->property==0){
ShowMessage("你无限权粘贴文件到此目录");return;}
if(!Clip->share)return;
//////////////////////////////////////////////////////////////////
else if(Clip->share==1){ //剪贴板是文件
if(Clip->property==0){//复制 改变创建用户
if(CreateFile(CurrDir,file->name,CurrUser,file->length,file->property,file->share))
{
ShowDir(CurrDir);
Clip->share=0; //剪贴版置空
}
}
////////////////////////////////////////////////////////////////////
else { //剪切
if(SameFile(CurrDir,file->name)){ShowMessage("文件已存在,无法创建!");return;}
FILENODE PreFile;
FILENODE CurrFile;
subdir=file->father;
CurrFile=PreFile=subdir->filenode;
if(CurrFile==file)subdir->filenode=CurrFile->next;
else {
CurrFile=CurrFile->next;
while(CurrFile!=file)
{ PreFile=CurrFile; //取出file节点
CurrFile=CurrFile->next;
}
PreFile->next=CurrFile->next;
}
subdir->filenum--;
InsertFile(CurrDir,file);
CurrDir->filenum++;
ShowDir(CurrDir);
Clip->share=0; //剪贴版置空
}
}
///////////////////////////////////////////////////////////
else if(Clip->share==2){ //剪贴板是目录
if(Clip->property==0){ //目录复制
if(SameDir(CurrDir,dir->name)){ShowMessage("文件夹已存在,无法创建!");return;}
DIRECTORY tempdir=CurrDir;
CreateDir(CurrDir,dir->name,CurrUser,dir->property,dir->share);
que.push(dir); //从复制目录结构
while(!que.empty())
{
dir=que.front();
que.pop();
tempdir=LocateDir(tempdir,dir->name);
file=dir->filenode;
while(file){
if(file->del==0&&dir->del==0)
CreateFile(tempdir,file->name,CurrUser,file->length,dir->property,dir->share);
file=file->next;
}
subdir=dir->dirpoint;
while(subdir) //子目录入队列
{
if(subdir->del==0&&dir->del==0)
CreateDir(tempdir,subdir->name,CurrUser,subdir->property,subdir->share);
que.push(subdir);
subdir=subdir->next;
}
} //while
TreeView1->Items->Clear();
ListTree(Root,NULL,0);
JumpToClick(Sender);
ShowDir(CurrDir);
Clip->share=0; //剪贴版置空
}
////////////////////////////////////////////////////////
else { //目录剪切
if(SameDir(CurrDir,dir->name)){ShowMessage("文件夹已存在,无法创建!");return;}
DIRECTORY PreDir;
DIRECTORY CuDir;
subdir=dir->father;
CuDir=PreDir=subdir->dirpoint;
if(CuDir==dir)
{subdir->dirpoint=CuDir->next; //取出dir节点
}
else {
CuDir=CuDir->next;
while(CuDir!=dir)
{ PreDir=CuDir;
CuDir=CuDir->next;
}
PreDir->next=CuDir->next;
}
subdir->dirnum--;
InsertDir(CurrDir,dir);
CurrDir->dirnum++;
TreeView1->Items->Clear();
ListTree(Root,NULL,0);
JumpToClick(Sender);
ShowDir(CurrDir);
Clip->share=0; //剪贴版置空
}
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::N30Click(TObject *Sender)
{
Form10->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ToolButton10Click(TObject *Sender)
{ //查找功能
Form9->Edit1->Clear();
Form9->Tag=0;
Form9->ShowModal();
if(Form9->Tag){
String path="";
String name=Form9->Edit1->Text;
DIRECTORY dir,subdir,OKdir;
FILENODE file;
TListItem *Item;
que.push(CurrDir);
while(!que.empty())
{
dir=que.front();
que.pop();
OKdir=LocateDir(dir,name); //找到文件夹
file=LocateFile(dir,name); //找到文件
if(OKdir||file){
while(dir){ //取得路径
path=dir->name+"\\"+path; dir=dir->father; }
ComboBox1->Text=path;
JumpToClick(Sender); //跳转到目的目录
Item=ListView1->FindCaption(0,name,true,false,true);
ListView1->SetFocus();
Item->Selected=true; //选中目的文件或目录
ShowMessage("查找成功!");
return;
}
subdir=dir->dirpoint;
while(subdir) //子目录入队列
{que.push(subdir);
subdir=subdir->next;
}
}
ShowMessage("找不到指定名称的文件或文件夹");
}
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ToolButton18Click(TObject *Sender)
{
Form10->ShowModal();
}
//---------------------------------------------------------------------------
void __fastcall TForm2::ToolButton11Click(TObject *Sender)
{
//转到指定路径
TTreeNode *tree=TreeView1->TopItem;
int i=2,j,t,k,f=0;
String Path=ComboBox1->Text,Str;
if(Path==""){ShowMessage("请输入路径");return;}
i=Path.Pos("\\");
if(i==0){ShowMessage("缺少符号'\\'");return;}
Str=Path.SubString(1,i-1);Path=Path.Delete(1,i);
if(Str!="Root"){ShowMessage("根目录错误");return;}
while(Path!=""){
i=Path.Pos("\\");
if(i==0){ShowMessage("缺少符号'\\'");return;}
Str=Path.SubString(1,i-1);Path=Path.Delete(1,i);
t=tree->Count;
for(k=0;k<t;k++)
if(tree->Item[k]->Text==Str){
tree=tree->Item[k];f=1;break;}
if(!f){ShowMessage("路径不存在");return;}
i++;
}
tree->Selected=true;
tree->Expand(false);
CurrNode=tree;
OutPath(tree);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -