#include"pch.h"
#include<iostream>
#include <map>
#include<vector>
#include"File.h"
#include "Directory.h"
using namespace std;
#pragma warning(disable:4996)
map<string, string> OrderMessage; //记录相关指令的使用信息
map<string, string>up; //用户和密码
vector<string> currentPath;
Directory* root;
Directory* current;
//初始化程序
void initializeSystem();
//初步解析指令
void orderParsing(string &order, string &context);
//操作数解析
void contextParsing(string context, string &firstcontext, string &secondcontext);
//绝对路径解析
void pathParsing(vector<string> &path, string context);
//依据绝对路径找到当前目录
Directory* selectDirectory(vector<string> path);
//拷贝目录
void copyDir(string firstcontext, string secondcontext);
//新建目录
void mkDir(string context);
//void rnDir(vector<string> path, string Directoryname);
//删除目录
void delDir(string context);
//目录重命名
void rnDir(string path, string Directoryname);
//打印当前目录情况
void printDir();
//拷贝目录
void cpDir(string firstcontext, string secondcontext);
//返回上级
int cdReturn();
//进入目录
void cdPath(vector<string>path);
int cdNext(string context);
//创建文件
void createFile(string filename);
//删除文件
void deleteFile(string filename);
//重命名文件
void renameFile(string postname, string newname);
//复制文件
void copyFile(string firstcontext, string secondcontext);
//写文件
void writeFile(string filename);
//读文件
void readFile(string filename);
//显示帮助信息
void printHelp();
//清屏
void cleanPrinter();
int main()
{
initializeSystem();
cout << "Microsoft Windows [版本 10.0.17134.523]\n"
<< "(c)2018 Microsoft Corporation。保留所有权利。\n";
string order;
string context;
string firstcontext = "", secondcontext = "";
vector<string> path;
int i;
while (1)
{
//每次输入指令前自动换行
string path=currentPath[0];
for (i = 1; i < currentPath.size(); ++i)
path = path + '\\' + currentPath[i];
cout<<endl << path <<" $ ";
getline(cin, order);
orderParsing(order, context);
if (context.find_first_of(' ') != string::npos)
{
contextParsing(context, firstcontext, secondcontext);
}
if (order == "exit") //退出
{
break;
}
else if (order == "mkdir") //新建目录
{
if (context == "?")
{
cout << OrderMessage["mkdir"] << endl;
}
else if (context != "" && firstcontext == "")
{
mkDir(context);
//cout << currentlocal->catalogbother->catalogaddress << endl;
//cout << Memory[3] << endl;
}
else {
cout << OrderMessage["ordererror"] << endl;
}
}
else if (order == "deldir") //删除目录
{
if (context == "?")
{
cout << OrderMessage["deldir"] << endl;
}
else if (context == "")
{
cout << OrderMessage["ordererror"] << endl;
}
else if (firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
delDir(context);
}
}
else if (order == "rndir") //目录重命名
{
if (context == "?")
{
cout << OrderMessage["rndir"] << endl;
}
else if (firstcontext == "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
//pathParsing(path, firstcontext);
//rnDir(path, secondcontext);
//当前目录下
rnDir(firstcontext, secondcontext);
}
}
else if (order == "dir") //显示当前目录下的子目录
{
if (context == "?")
{
cout << OrderMessage["dir"] << endl;
}
else if (context != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
printDir();
}
}
else if (order == "cpdir") //目录拷贝
{
if (context == "?")
{
cout << OrderMessage["cpdir"] << endl;
}
else if (context == "" || firstcontext == "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
copyDir(firstcontext, secondcontext);
}
}
else if (order == "cd")
{
if (context == "?")
{
cout << OrderMessage["cd"] << endl;
}
else if (context == "" || firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
vector<string> content;
pathParsing(content, context);
cdPath(content);
}
}
else if (order == "create") //新建文件
{
if (context == "?")
{
cout << OrderMessage["create"] << endl;
}
else if (context == "" || firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
createFile(context);
}
}
else if (order == "delete") //删除文件
{
if (context == "?")
{
cout << OrderMessage["delete"] << endl;
}
else if (context == "" || firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
deleteFile(context);
}
}
else if (order == "rename") //文件重命名
{
if (context == "?")
{
cout << OrderMessage["rename"] << endl;
}
else if (firstcontext == "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
renameFile(firstcontext, secondcontext);
}
}
else if (order == "copy") //文件拷贝
{
if (context == "?")
{
cout << OrderMessage["copy"] << endl;
}
else if (firstcontext == "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
copyFile(firstcontext, secondcontext);
}
}
else if (order == "write") //读文件
{
if (context == "?")
{
cout << OrderMessage["write"] << endl;
}
else if (context == "" || firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
writeFile(context);
}
}
else if (order == "read") //写文件
{
if (context == "?")
{
cout << OrderMessage["read"] << endl;
}
else if (context == "" || firstcontext != "")
{
cout << OrderMessage["ordererror"] << endl;
}
else
{
readFile(context);
}
}
else if (order == "help") //帮助命令
{
printHelp();
}
else if(order == "clean")//清屏
{
cleanPrinter();
}
else if(order =="")
{ }
else //错误指令
{
cout << "系统不存在该指令,请重新输入\n";
}
context = "";
firstcontext = "";
secondcontext = "";
}
return 0;
}
//初始化程序
void initializeSystem()
{
//帮助信息
OrderMessage["mkdir"] = string(3, ' ') + "[mkdir]:新建目录--mkdir dirname--dirname表示目录名";
OrderMessage["dir"] = "Hello";
OrderMessage["rndir"] = "rndir";
OrderMessage["ordererror"] = "指令使用格式错误";
//根目录初始化
root = new Directory("root",NULL);
currentPath.push_back(string(root->dirName));
current = root;
/*创建目录*/
root->mkDir("yay");
root->mkDir("lzr");
root->mkDir("guest");
/*创建用户*/
string psw = "123";
up.insert(pair<string, string>(string("yay"),psw));
up.insert(pair<string, string>(string("lzr"),psw));
up.insert(pair<string, string>(string("guest"), psw));
root->createFile("sys.ini");
/*登陆*/
bool flag = false;
while (true)
{
cout << endl << current->dirName << " $ ";
string order, context;
getline(cin, order);
orderParsing(order, context);
if (order == "cd")
{
if (!up.count(context))
cout << "没有该用户目录" << endl;
else
{
while (true)
{
cout << "password: ";
string p;
cin >> p;
if (up[context] == p)
{
cdNext(context);
flag = true;
system("cls");
break;
}
}
}
}
if (flag)
break;
}
}
//初步解析指令
void orderParsing(string &order, string &context)
{
if (order.size()<1)
return;
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
这次操作系统的课程设计是一次对操作系统的算法知识和编程实践能力的一次良好的锻炼。在课程设计中,我认为相比于编程,更为困难的是数据结构和算法的设计。目录和文件这样的数据结构,需要包含怎么样的信息,决定了这个系统功能的上限。数据结构之间如何组织,如何提升性能。文件和目录在磁盘上应该如何保存。这些问题都应该在进行课程设计之初耗费了许多精力。然后就是系统应该给外部提供怎样的命令接口。 这次实验应用了软件工程的思想,在编程之初先进行了详细的设计。使得在后期开发的时候,编码实现容易了很多。进行功能开发,只需要将几个函数功能组合起来进行了。在编程阶段遇到的主要问题是,没有设计好异常处理的问题。就是,我调用的时候返回了一个空指针但我没有去处理,于是就直接把空指针传参了,这个算是程序开发过程中的一个主要的bug。 这次实验加深了对于文件系统的理解,但是还是有很多不足之处。仅仅实现了比较简单的功能。没有能够实现那些更加复杂的机制。比如实现权限控制,用户管理这些操作。
资源推荐
资源详情
资源评论
收起资源包目录
操作系统课程设计大作业(附源代码).rar (67个子文件)
操作系统课程设计大作业(附源代码)
操作系统
操作系统
Directory.cpp 5KB
Directory.h 2KB
操作系统.vcxproj.user 165B
File.h 1KB
File.cpp 2KB
Debug
FileManagementSystem.obj 957KB
操作系统.log 2KB
vc141.pdb 668KB
File.obj 60KB
操作系统.tlog
link-rc.write.1.tlog 2B
CL.write.1.tlog 3KB
link.4588-rc.read.1.tlog 2B
link-cvtres.write.1.tlog 2B
link.4588.write.1.tlog 2B
link.command.1.tlog 2B
CL.read.1.tlog 55KB
link.4588-cvtres.read.1.tlog 2B
link.4588-rc.write.1.tlog 2B
link-cvtres.read.1.tlog 2B
CL.command.1.tlog 3KB
link.4588-cvtres.write.1.tlog 2B
unsuccessfulbuild 0B
link.4588.read.1.tlog 2B
link-rc.read.1.tlog 2B
操作系统.lastbuildstate 217B
link.write.1.tlog 2B
link.read.1.tlog 2B
vc141.idb 275KB
Directory.obj 125KB
main.obj 177KB
pch.obj 2KB
操作系统.vcxproj.filters 1KB
pch.cpp 200B
FileManagementSystem.cpp 15KB
pch.h 639B
x64
Debug
FileManagementSystem.obj 1.46MB
操作系统.log 582B
vc141.pdb 548KB
File.obj 71KB
操作系统.tlog
CL.write.1.tlog 3KB
link.command.1.tlog 2KB
CL.read.1.tlog 56KB
CL.command.1.tlog 2KB
操作系统.lastbuildstate 215B
link.write.1.tlog 778B
link.read.1.tlog 4KB
vc141.idb 259KB
Directory.obj 318KB
pch.obj 2KB
操作系统.vcxproj 6KB
.vs
操作系统
v15
ipch
AutoPCH
1d1cf87bb113014
FILEMANAGEMENTSYSTEM (2).ipch 27.38MB
e89e1120ad29e560
DIRECTORY.ipch 28.75MB
1c6d9dd966820c81
FILEMANAGEMENTSYSTEM.ipch 32.44MB
2726f717b1545ac1
MAIN.ipch 28.31MB
72f67cfd56945237
FILE.ipch 26.06MB
3d6a05832a778491
FILEMANAGEMENTSYSTEM (2).ipch 27.38MB
9d483774cc11192b
FILEMANAGEMENTSYSTEM.ipch 27.38MB
19e895b451c557d2
FILEMANAGEMENTSYSTEM.ipch 31.38MB
44635c3cf2df9581
PCH.ipch 320KB
.suo 43KB
Browse.VC.db 5.38MB
Debug
操作系统.pdb 60KB
操作系统.sln 1KB
x64
Debug
操作系统.ilk 1.85MB
操作系统.exe 280KB
操作系统.pdb 1.89MB
操作系统课程设计.doc 935KB
共 67 条
- 1
资源评论
LiuCherry
- 粉丝: 8
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功