Exemple #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]);
		}
	}
}
Exemple #2
0
void FileCommands::edit(FileSystemUser* fileSystem, string fileName) {
	FileObject* fo = fileSystem->getFileObject();
	fileName += "$";
	int t = fo->getObject(fileName);
	if(t) {
		fo->setPos(t);
		string newContent;
		char buff[512];
		cout<<"enter new content: ";
		cin.getline(buff, 512);
		newContent = buff;
		int begPos = fo->getBeginPos();
		string sys = fileSystem->getSystem();
		fo->go(fileName);
		int beg = fo->getPos();
		fo->setEndPos();
		int end = fo->getPos();
		sys.erase(beg, end-beg + 1);
		sys.insert(beg, newContent);
		fileSystem->setNewSystem(sys);
		fo->setBeginPos(begPos);
		fo->setFileContent(fileName, newContent);
	}else {
		notFoundFile(fileName);
		return;
	}
	
}