Esempio n. 1
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;
	}
	
}
Esempio n. 2
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);
}