Example #1
0
void FileCommands::cd(FileSystemUser* fileSystem, string path) {
	FileObject* fo = fileSystem->getFileObject();
	vector<string> dirs = StringService::pathSplit(path);
	int oldPos = fo->getPos();
	for(int i = 0; i<dirs.size(); ++i) {
		if(dirs[i]!="..") {
			if(!fo->containsObject(dirs[i])) {
				notFoundPath(path);
				fo->setPos(oldPos);
				return;		
			}else {
				fo->go(dirs[i]);
			}
		}else {
			fo->goUp();
		}
	}
	for(int i = 0; i<dirs.size(); ++i) {
		if(dirs[i] == "..") {
			fileSystem->cdUp();
		}else {
			fileSystem->cdDir(dirs[i]);
		}
	}
}
Example #2
0
void FileCommands::remfile(FileSystemUser* fileSystem, string file) {
	FileObject* fo = fileSystem->getFileObject();
	if(!fo->containsObject(file)) {
		notFoundFile(file);
		return;
	}
	string sys = fileSystem->getSystem();
	int t = fo->getObject(file);
	sys.erase(t, fo->getPos() - t - 1);
	fileSystem->setNewSystem(sys);
	fo->remObj(file);	
}
Example #3
0
void FileCommands::show(FileSystemUser* fileSystem, string fileName) {
	FileObject* fo = fileSystem->getFileObject();
	fileName += fileDelim;
	
	if(fo->containsObject(fileName)) {
		string content = fo->getFileContent(fileName);
		cout<<endl<<"\t"<<fileName<<endl<<endl<<content<<endl;
	}else {
		notFoundFile(fileName);
		return;
	}
}
Example #4
0
void FileCommands::mkfile(FileSystemUser* fileSystem, string file) {
	FileObject* fo = fileSystem->getFileObject();
	if(fo->containsObject(file)) {
		duplicateNames(file);
		return;
	}
	file += fileDelim;
	file += openDelim;
	file += closeDelim;
	fo->setEndPos();
	string sys = fileSystem->getSystem();
	sys.insert(fo->getPos(), file);
	fileSystem->setNewSystem(sys);
	fo->addObj(file);
}
Example #5
0
void FileCommands::mkdir(FileSystemUser* fileSystem, string dir) {
	FileObject* fo = fileSystem->getFileObject();
	if(fo->containsObject(dir)) {
		duplicateNames(dir);
		return;
	}
	
	dir += "{";
	dir += "}";
	fo->setEndPos();
	string sys = fileSystem->getSystem();
	sys.insert(fo->getPos(), dir);
	fileSystem->setNewSystem(sys);
	fo->addObj(dir);
}
Example #6
0
void FileCommands::remdir(FileSystemUser* fileSystem, string dir) {
	FileObject* fo = fileSystem->getFileObject();
	if(!fo->containsObject(dir)) {
		notFoundDir(dir);
		return;
	}
	string sys = fileSystem->getSystem();
	int t = fo->getObject(dir);
	cout<<"t: "<<t<<" pos:"<<fo->getPos()<<endl;
	if(fo->getPos() == fo->getBeginPos()) {
		fo->setEndPos();
	}
	sys.erase(t, fo->getPos() - t);
	fileSystem->setNewSystem(sys);	
	fo->remObj(dir);
}