Example #1
0
static int procFS_readdir(const char *path, void *buf, fuse_fill_dir_t filler,
			 off_t offset, struct fuse_file_info *fi)
{

	(void) offset;
	(void) fi;

	if (strcmp(path, "/") != 0)
		return -ENOENT;

	filler(buf, ".", NULL, 0);
	filler(buf, "..", NULL, 0);

	char *procPath = "/proc/";
	DIR *dp;
    	struct dirent *de;
    
	dp = opendir(procPath);
    
	if (dp == NULL)
        	return -errno;

    	while ((de = readdir(dp)) != NULL) {

		if(isValidFileName(de->d_name))
					filler(buf, de->d_name, NULL, 0);
		else 
			continue;
	}

        closedir(dp);


	return 0;
}
Example #2
0
void FileSystemManager::setFileAttributes(QString fileName, uint attribute)
{
	if (isValidFileName(fileName))
	{
		// Set the file attributes on this file
		SetFileAttributes((LPCTSTR) fileName.utf16(), attribute);
	}
}
Example #3
0
static int procFS_open(const char *path, struct fuse_file_info *fi)
{
	if (!isValidFileName(path + 1)) 
		return -ENOENT;

	if ((fi->flags & 3) != O_RDONLY)
		return -EACCES;

	return 0;
}
StateDescriptorReader::StateDescriptorReader(const char* stateDescriptorPath) { 
	fileName = NULL;
	fileNameIsValid = false;
			
	if(stateDescriptorPath != NULL) {
		fileName = new char[2000];	 	
		strcpy(fileName, stateDescriptorPath);				
		if (isValidFileName()) {
			fileNameIsValid = true;	 	
		}
	}	
	stateDescriptorContent = NULL;
	read();
	
}
Example #5
0
static int procFS_getattr(const char *path, struct stat *stbuf)
{
	int res = 0;

	memset(stbuf, 0, sizeof(struct stat));
	if (strcmp(path, "/") == 0) {
		stbuf->st_mode = S_IFDIR | 0755;
		stbuf->st_nlink = 2;
	} else if (isValidFileName(path)) {
		stbuf->st_mode = S_IFREG | 0444;
		stbuf->st_nlink = 1;
		char infobuffer[MAX_STAT_INFO];
		stbuf->st_size = readProcStatFile(path, &infobuffer[0]);
	} 
	else
		res = -ENOENT;

	return res;
}
Example #6
0
static int procFS_read(const char *path, char *buf, size_t size, off_t offset,
		      struct fuse_file_info *fi)
{
	(void) fi;
	size_t filesize = 0;
	char infobuffer[MAX_STAT_INFO];
	if(isValidFileName(path)){
		filesize = readProcStatFile(path, &infobuffer[0]);
		
		if(offset < filesize){
			if(offset + size > filesize)
				size = filesize - offset;
			memcpy(buf, &infobuffer[offset], size);
		}
		else{
			size = 0;
		}

		return size;
	}	
	else{
		return 0;
	}
}
Example #7
0
StrList FileSystemManager::getDirectoryContents(QString dirPath, QString filter)
{
#ifdef WIN32
	WIN32_FIND_DATA ffd;
	vector<QString> listing;
	HANDLE hFind = NULL;

	// Return early if no directory
	if (!isValidFileName(dirPath))
	{
		return listing;
	}

	if (!dirPath.endsWith("\\"))
	{
		// Add a slash to the end of the Path
		dirPath.append("\\");
	}

	hFind = FindFirstFile((LPCTSTR) (dirPath + filter).utf16(), &ffd);
	if (hFind != INVALID_HANDLE_VALUE)
	{
		do
		{
			// Add the filename to the list
			bool isHidden = (ffd.dwFileAttributes & Hidden) > 0;
			if (!isHidden || GLOBAL(settings).LoadHiddenFiles)
			{
				QString fileName = QString::fromUtf16((const ushort *) ffd.cFileName);
				if (fileName != "." && 
					fileName != "..")
				{
					listing.push_back(dirPath + fileName);
				}
			}
		} while (FindNextFile(hFind, &ffd));

		FindClose(hFind);
	}

	return listing;
#else
	vector<QString> fileListing;

	QStringList filters;
	filters << filter;
	QDir directory(dirPath);
	if (exists(directory))
	{
		directory.setNameFilters(filters);
		directory.setFilter(QDir::AllEntries | QDir::NoDotAndDotDot);
		directory.setSorting(QDir::Name | QDir::DirsFirst);

		QFileInfoList list = directory.entryInfoList();
		for (int i = 0; i < list.size(); ++i)
		{
			fileListing.push_back(native(list[i]));
		}
	}

	return fileListing;
#endif
}
Example #8
0
bool FileSystemManager::moveFilesXP(vector<FileSystemActor *>& objList, QString& destDir, vector<FileSystemActor *>& failedObj, vector<FileSystemActor*>& replacedObj)
{
	SHFILEOPSTRUCT fileOperation = { 0 };
	QString toPath(destDir);
	set<FileSystemActor *> duplicateExists;

	TCHAR * fromPaths = allocateStringFromPathsArray(objList);
	TCHAR * fromPathsOffset = fromPaths;

	for (uint i = 0; i < objList.size(); i++)
	{
		FileSystemActor *fsData = objList[i];
		
		if (!isValidFileName(fsData->getFullPath()))
		{
			failedObj = objList;
			delete fromPaths;
			return false;
		}

		// build the from-path string
		lstrcpy(fromPathsOffset, (LPCTSTR) fsData->getFullPath().utf16());
		fromPathsOffset += fsData->getFullPath().size() + 1;

		// save the set of items that have duplicate names, so that we
		// can reference them if the move fails
		QDir destP(destDir);
		if (isValidFileName(native(make_file(destDir, filename(fsData->getFullPath())))))
			duplicateExists.insert(fsData);
	}

	TCHAR newp[MAX_PATH] = {0};
	lstrcpy(newp, (LPCTSTR) toPath.utf16());

	fileOperation.hwnd = winOS->GetWindowsHandle();
	fileOperation.wFunc = FO_MOVE;
	fileOperation.pFrom = fromPaths;
	fileOperation.pTo = newp;
	fileOperation.fFlags = FOF_ALLOWUNDO;

	// Do the windows file operations for Move
	bool succeeded = (SHFileOperation(&fileOperation) == 0) && !fileOperation.fAnyOperationsAborted;

	for (uint i = 0; i < objList.size(); i++)
	{
		FileSystemActor * fsData = objList[i];

		QFileInfo p(fsData->getFullPath());
		QFileInfo destP = make_file(destDir, p.fileName());

		// Determine which files failed and which replaced existing ones
		if (isValidFileName(fsData->getFullPath()))
		{
			failedObj.push_back(fsData);
		}
		else if (duplicateExists.find(fsData) != duplicateExists.end())
		{
			replacedObj.push_back(fsData);
		}
	}

	delete fromPaths;
	return succeeded;
}
Example #9
0
bool FileSystemManager::deleteFiles(vector<FileSystemActor *> objList, vector<FileSystemActor *> &failedObj, bool confirm, bool skipRecycleBin)
{
	if (objList.empty())
		return true;
	
	FileSystemActor *data;
	SHFILEOPSTRUCT fileOperation = { 0 };
	vector<FileSystemActor *> delList;
	int numVirtualIconsDeleted = 0;

	TCHAR * fromPaths = allocateStringFromPathsArray(objList);
	TCHAR * fromPathsOffset = fromPaths;

	// build the paths of files to delete
	for (int i = 0; i < objList.size(); i++)
	{
		// Check if its a filesystem actor
		if (objList[i]->getObjectType() == ObjectType(BumpActor, FileSystem))
		{
			data = (FileSystemActor *) objList[i];

			// Exclude Virtual folders
			if (!data->isFileSystemType(Virtual))
			{
				// Check to see if this file is actually on the hard disk or not
				if (isValidFileName(data->getFullPath()))
				{
					// build the from-path string
					lstrcpy(fromPathsOffset, (LPCTSTR) data->getFullPath().utf16());
					fromPathsOffset += data->getFullPath().size() + 1;

					delList.push_back(data);
				}
			}
			else
			{
				// prompt the user
				dlgManager->clearState();
				dlgManager->setCaption(QT_TR_NOOP("Remove from desktop?"));
				dlgManager->setPrompt(QT_TR_NOOP("Are you sure you want to remove %1 from your desktop?\n(You can re-enable it in Windows' Desktop Properties dialog)").arg(data->getFullPath()));
				if (dlgManager->promptDialog(DialogYesNo))
				{
					// we try and set the associated registry values for these icons
					winOS->SetIconAvailability(winOS->GetIconTypeFromFileName(data->getFullPath()), false);
					// but fade and delete the actor anyways
					FadeAndDeleteActor(data);
				}
				++numVirtualIconsDeleted;
			}
		}
	}

	if ((delList.size() + numVirtualIconsDeleted) != objList.size())
	{
		// Alert the user that one of more VIRTUAL files are in the selection
		MessageClearPolicy clearPolicy;
			clearPolicy.setTimeout(4);
		scnManager->messages()->addMessage(new Message("deleteFiles", QT_TR_NOOP("Some items cannot be deleted (ie. My Computer, Recycle Bin)\nPlease remove them through Windows' Desktop properties"), Message::Warning, clearPolicy));
	}

	if (!delList.empty())
	{
		// Delete the specific files
		fileOperation.hwnd = winOS->GetWindowsHandle();
		fileOperation.wFunc = FO_DELETE;
		fileOperation.pFrom = fromPaths;
		fileOperation.pTo = L"\0\0";
		fileOperation.fFlags = (skipRecycleBin ? 0 : FOF_ALLOWUNDO) | (confirm ? NULL : FOF_NOCONFIRMATION);

		// Remove the item form the listener before deleting
		for (uint i = 0; i < delList.size(); i++)
		{
			if (delList[i]->isPileized())
			{
				removeObject(delList[i]->getPileizedPile());
			}
		}

		SHFileOperation(&fileOperation);

		// See if there were any items that could not be deleted
		for (uint i = 0; i < delList.size(); i++)
		{
			if (isValidFileName(delList[i]->getFullPath()))
			{
				failedObj.push_back(delList[i]);
			}else{
				delList[i]->setLinearVelocity(Vec3(0.0f));
				delList[i]->setAngularVelocity(Vec3(0.0f));
				delList[i]->putToSleep();
			}
		}
	}

	delete fromPaths;
	return failedObj.size() == 0;
}