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; } }
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); }
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); }