Exemplo n.º 1
0
/*
* Изтрива файловете с адреси подадени в parameters.
*/
void CommandPrompt::deleteFile(string parameters){
	/*
	* Извлича параметрите и ги записва в опашка.
	*/
	queue<string> filePaths = this->getPaths(parameters);
	
	/*
	* Тъй като ни трябва директорията в която се намира файла за да го изтрием,
	* не може да ползваме determinePathAndGetFile().
	*/
	queue<TextFile*> files;
	string fileName;
	string fileDir;
	Directory* tempDir;
	TextFile* fileAddress;
	int pos;
	while (!filePaths.empty()) {
		/*
		* Първо разделяме пътя от името на файла
		*/ 
		fileDir = filePaths.front();
		pos = fileDir.rfind('/') + 1;
		if (pos - 1 != string::npos) {
			while (pos < fileDir.size()) {
				fileName += fileDir[pos++];
			}
			pos = fileDir.rfind('/');
			fileDir = fileDir.erase(pos, fileDir.size());

			/*
			* Намираме директорията.
			*/
			tempDir = this->determinePathAndGetDir(fileDir);

			/*
			* Ако не съществува извеждаме грешка, иначе трием.
			*/
			if (tempDir == NULL)
				cerr << "File directory not found!" << endl;
			else {
				fileAddress = tempDir->findFileByName(fileName);
				if (fileAddress == NULL)
					cerr << "File not found!" << endl;
				else
					tempDir->removeFile(fileAddress);
			}
		}
		else {
			/*
			* Ако е подадено само името на файла в currentDir търсим и трием.
			*/
			fileAddress = currentDir->findFileByName(fileDir);
			if (fileAddress == NULL)
				cerr << "File not found!" << endl;
			else
				currentDir->removeFile(fileAddress);
		}
		filePaths.pop();
	}
}
Exemplo n.º 2
0
/*
* Помощтна функция, за запазване/въвеждане на файлове.
*/
void CommandPrompt::saveConcatenatedFile(string path, string data){
	/*
	* Ако няма данни и няма подаден адрес за запис връща.
	*/
	if (path.empty() && data.empty())
		return;

	/*
	* Ако няма данни се въвеждат.
	*/
	if (data.empty()) {
		char line[1000];
		string sline;
		while (sline != string(".")) {
			cin.getline(line, 1000);
			sline = line;
			if(sline != ".")
				data += sline;
		}
	}

	/*
	* Ако няма outputFile се извеждат данните, ако има
	* се намира/създава директория и се създава вайл в нея.
	* Наследява промените по големината на директориите.
	*/
	if (path.empty())
		cout << data << endl;
	else {
		string fileName = path;
		Directory* dir = fs.getRoot();
		int pos = path.rfind('/') + 1;
		if (pos - 1 != string::npos) {
			fileName = "";
			while (pos < path.size())
				fileName += path[pos++];
			pos = path.rfind('/');
			path = path.erase(pos, path.size());
			dir = this->createNestedDirectories(path);
		}
		else
			dir = currentDir;
		if (dir->nameAvailable(fileName)) {
			dir->addChild(new TextFile(dir->getFSysPath(),
				fs.getNextNumber(),
				data,
				fileName));
			dir->inheritSize(data.size());
		}
		else {
			dir->findFileByName(fileName)->concatData(data);
			dir->inheritSize(data.size());
		}
	}
}