#include <stdlib.h>
#include <iostream.h>
#include <string.h>
#include <conio.h>
#include "Directory.h"
#include "DirHistory.h"
#include "FAT.h"
#include "File.h"
#include "UserList.h"
//***********************************************************************************************
DirHistory *history; //目录记录
Directory *currentDir; //当前目录
FAT *f; //FAT
UserList *nu; //用户列表
//***********************************************************************************************
//初始化
void initialize()
{
nu=new UserList();
f=new FAT();
Directory *root=new Directory("root");
Directory *dir1=new Directory("dir1");
Directory *dir2=new Directory("dir2");
Directory *dir3=new Directory("dir3");
File *f1=new File("f1",10,f->getSpace(10));
File *f2=new File("f2",25,f->getSpace(25));
root->addDirectory(dir1);
root->addDirectory(dir2);
root->addFile(f1);
dir2->addDirectory(dir3);
dir2->addFile(f2);
nu->addUser("u1",root);
}
//显示提示信息
void Information()
{
cout << "登录成功..."<<endl;
cout << endl<<" 命令符提示:" << endl<<endl;
cout << " create --> 创建文件" << endl;
cout << " del --> 删除文件" << endl;
cout << " open --> 打开文件" << endl;
cout << " close --> 关闭文件" << endl;
cout << " read --> 读取文件" << endl;
cout << " write --> 写入文件" << endl;
cout << " mkdir --> 创建目录" << endl;
cout << " deldir --> 删除目录" << endl;
cout << " cd --> 更改当前目录" << endl;
cout << " dir --> 列出当前目录" << endl;
cout << "------------------------------------" << endl;
cout << endl;
}
//登陆
void login()
{
char username[20];
char choice;
Directory *newroot=NULL;
while(true)
{
//输入用户名并登陆
cout << " 请输入您的名字 : " << flush;
cin >> username;
if( (newroot=nu->login(username))!=NULL ) break;
//用户不存在
cout << " 用户 " << username << " 不存在" << endl;
cout << " 您想创建用户 " << username << " ,并登陆吗? [Y/N] " << flush<<endl;
choice=getch();
if(choice=='Y' || choice=='y'){
newroot=new Directory("root");
nu->addUser(username,newroot);
system("cls");
break;
}
cout << endl;
}
currentDir=newroot;
history=new DirHistory(newroot);
system("cls");
Information();
}
//添加用户
void adduser()
{
char username[20];
Directory *newroot=NULL;
cout << " 请输入您想要注册的用户名 : " << flush;
cin >> username;
newroot=new Directory("root");
nu->addUser(username,newroot);
cout<<endl<<" 注册成功,请登录"<<endl<<endl;
login();
}
//获取用户输入的命令及其参数
void handleUserInput()
{
char command[10]="";
char param[20]="";
char sentence[31];
history->toString();
cout << ">" << flush;
cin.getline(sentence,31);
//分析输入的命令
int pos=0;
int cmdLength=0;
bool isCmd=true;
while(sentence[pos]!=NULL)
{
//空格为命令与参数的分隔
if(sentence[pos]==32 && isCmd){
cmdLength=pos;
isCmd=false;
}
//整合命令与参数字符串
if(isCmd) command[pos]=sentence[pos];
else param[pos-cmdLength-1]=sentence[pos];
pos++;
}
/////////////////////////////////////////////////////////////////////////////////////
// 创建文件
if(!strcmp(command,"create"))
{
char filename[20];
//char m ;
int length;
int blockNum;
cout << " 请输入文件名 : " << flush; cin >> filename;
cout << " 文件长度 : " << flush; cin>>length;
//m = getche() ;
//length = m-48 ;
blockNum=f->getSpace(length);
if(blockNum==-1){
cout << "没有足够的空间" << endl;
cout << endl;
return;
}
//创建新的文件节点
File *file=new File(filename,length,blockNum);
//是否插入成功
if(currentDir->addFile(file)){
cout <<endl<< "文件 <" << filename << "> 已添加." << endl;
cout << endl;
}
else{
cout << "文件 <" << filename << "> 已存在." << endl;
cout << endl;
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// 删除文件
else if(!strcmp(command,"del"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "del 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
//删除文件
File *tmp=currentDir->findFile(param);
if(tmp)
{
int block=tmp->blockNum;
currentDir->delFile(param,f);
}
else
{
cout << "文件 <" << param << "> 不存在!" << endl;
cout << endl;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////////
// 打开文件
else if(!strcmp(command,"open"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "open 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
if(!currentDir->findFile(param)){
cout << "文件 <" << param << "> 不存在!" << endl;
cout << endl;
}
}
cout << " 文件已成功打开."<<endl;
}
//////////////////////////////////////////////////////////////////////////////////////////////
// 关闭文件
else if(!strcmp(command,"close"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "close 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
if(!currentDir->findFile(param)){
cout << "文件 <" << param << "> 没有被打开" << endl;
cout << endl;
}
}
cout << " 文件已成功关闭."<<endl;
}
/////////////////////////////////////////////////////////////////////////////////////////////
// 读文件
else if(!strcmp(command,"read"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "read 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
if(currentDir->findFile(param)){
cout << "文件 <" << param << "> 已成功读出" << endl;
cout << endl;
}
else{
cout << "文件 <" << param << "> 不存在" << endl;
cout << endl;
}
}
}
//////////////////////////////////////////////////////////////////////////////////////////////
// 写文件
else if(!strcmp(command,"write"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "write 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
if(currentDir->findFile(param)){
cout << "文件 <" << param << "> 已成功写入" << endl;
cout << endl;
}
else{
cout << "文件 <" << param << "> 不存在!" << endl;
cout << endl;
}
}
}
/////////////////////////////////////////////////////////////////////////////////////////
// 创建目录
else if(!strcmp(command,"mkdir"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "mkdir 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
//插入新子目录节点到当前目录
Directory *dir=new Directory(param,NULL);
currentDir->addDirectory(dir);
}
}
///////////////////////////////////////////////////////////////////////////////////////////
// 删除目录
else if(!strcmp(command,"deldir"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "deldir 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else
{
//删除子目录节点
if(!currentDir->delDirectory(param,f)){
cout << "目录<" << param << "> 不存在" << endl;
cout << endl;
}
}
}
////////////////////////////////////////////////////////////////////////////////////////////
// 改变当前目录
else if(!strcmp(command,"cd"))
{
if(!strcmp(param,""))
{
//需要一个参数
cout << "cd 命令后面需要加一个操作目标." << endl;
cout << endl;
}
else if(!strcmp(param,".."))
{
//退回上级目录
if(currentDir->parent!=NULL){
currentDir=currentDir->parent;
}
history->getOut();
}
else
{
//寻找指定的子目录
Directory *subDir=currentDir->findDirectory(param);
if(subDir!=NULL)
{
//进入子目录
currentDir=subDir;
history->getInto(subDir);
没有合适的资源?快使用搜索试试~ 我知道了~
多用户多目录文件系统+代码
共17个文件
h:6个
dsp:2个
pdb:2个
需积分: 9 48 下载量 22 浏览量
2009-02-22
00:33:17
上传
评论 5
收藏 209KB RAR 举报
温馨提示
本课程设计要求设计一个模拟的多用户多级目录的文件系统。通过具体的文件存储空间的管理、文件的物理结构、目录结构和文件操作的实现,加深对文件系统内部功能和实现过程的理解。
资源推荐
资源详情
资源评论
收起资源包目录
.rar (17个子文件)
多用户多目录文件系统
FileSystem.opt 54KB
main.cpp 9KB
DirHistory.h 1KB
FileSystem.plg 1KB
main.dsp 3KB
FileSystem.dsp 5KB
FileSystem.ncb 97KB
FileSystem.dsw 545B
Debug
vc60.pdb 68KB
FileSystem.pdb 641KB
main.obj 64KB
FileSystem.exe 256KB
User.h 968B
Directory.h 5KB
File.h 2KB
UserList.h 2KB
FAT.h 3KB
共 17 条
- 1
资源评论
feifei0408
- 粉丝: 1
- 资源: 4
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功