Esempio n. 1
0
int FSSys::Rename ( FSPath&  oldpath, FSPath& newpath, int* err,  FSCInfo* info )
{
	if ( MoveFileW(
	        SysPathStr( _drive, oldpath.GetUnicode( '\\' ) ).data(),
	        SysPathStr( _drive, newpath.GetUnicode( '\\' ) ).data()
	     ) ) { return 0; }

	SetError( err, GetLastError() );
	return -1;
}
Esempio n. 2
0
int FSSys::OpenCreate   ( FSPath& path, bool overwrite, int mode, int flags,  int* err, FSCInfo* info )
{
	DWORD diseredAccess = GENERIC_READ | GENERIC_WRITE;
	DWORD shareMode = 0;
	DWORD creationDisposition = ( overwrite ) ? CREATE_ALWAYS  : CREATE_NEW;
//???

	HANDLE h = CreateFileW( SysPathStr( _drive, path.GetUnicode( '\\' ) ).data(), diseredAccess, FILE_SHARE_WRITE, 0, creationDisposition, 0, 0 );

	if ( h == INVALID_HANDLE_VALUE )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	int fd = handles.New();
	HANDLE* p = this->handles.Handle( fd );

	if ( !p )
	{
		SetError( err, ERROR_INVALID_PARAMETER );
		CloseHandle( h );
		return -1;
	}

	*p = h;
	return fd;
}
Esempio n. 3
0
int FSSys::OpenRead  ( FSPath& path, int flags, int* err, FSCInfo* info )
{
	int shareFlags = 0;

	if ( flags & FS::SHARE_READ ) { shareFlags |= FILE_SHARE_READ; }

	if ( flags & FS::SHARE_WRITE ) { shareFlags |= FILE_SHARE_WRITE; }

	HANDLE h = CreateFileW( SysPathStr( _drive, path.GetUnicode( '\\' ) ).data(), GENERIC_READ, shareFlags, 0, OPEN_EXISTING, 0, 0 );

	//file_open(SysPathStr(_drive, path.GetUnicode('\\')).ptr());
	if ( h == INVALID_HANDLE_VALUE )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	int fd = handles.New();
	HANDLE* p = this->handles.Handle( fd );

	if ( !p )
	{
		SetError( err, ERROR_INVALID_PARAMETER );
		CloseHandle( h );
		return -1;
	}

	*p = h;
	return fd;
}
Esempio n. 4
0
int FSSys::MkDir( FSPath& path, int mode, int* err,  FSCInfo* info )
{
	if ( CreateDirectoryW( SysPathStr( _drive, path.GetUnicode( '\\' ) ).data(), 0 ) ) { return 0; }

	DWORD e = GetLastError();

	if ( e == ERROR_ALREADY_EXISTS ) { return 0; }

	SetError( err, e );
	return -1;
}
Esempio n. 5
0
int FSSys::Stat( FSPath& path, FSStat* fsStat, int* err, FSCInfo* info )
{
	if ( _drive >= 0 && path.Count() == 1 || _drive == -1 && path.Count() == 3 )
	{
		//pseudo stat
		fsStat->size = 0;
		fsStat->dwFileAttributes = FILE_ATTRIBUTE_DIRECTORY;
		fsStat->mode = S_IFDIR;
		fsStat->mtime = 0;
		fsStat->mode |= 0664;
		return 0;
	}

	WIN32_FIND_DATAW ent;
	HANDLE handle = FindFirstFileW( SysPathStr( _drive, path.GetUnicode() ).data(), &ent );

	if ( handle == INVALID_HANDLE_VALUE )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	try
	{
		fsStat->size = ( seek_t( ent.nFileSizeHigh ) << 32 ) + ent.nFileSizeLow;
		fsStat->dwFileAttributes = ent.dwFileAttributes;
		fsStat->mtime = ent.ftLastWriteTime;

		if ( ent.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY )
		{
			fsStat->mode = S_IFDIR;
		}
		else
		{
			fsStat->mode = S_IFREG;
		}

		fsStat->mode |= 0664;
		FindClose( handle );
		return 0;
	}
	catch ( ... )
	{
		FindClose( handle );
		throw;
	}

	//...
	SetError( err, 50 );
	return -1;
}
Esempio n. 6
0
int FSSys::RmDir( FSPath& path, int* err, FSCInfo* info )
{
	std::vector<wchar_t> sp = SysPathStr( _drive, path.GetUnicode( '\\' ) );

	if ( RemoveDirectoryW( sp.data() ) ) { return 0; }

	DWORD lastError  = GetLastError();

	if ( lastError == ERROR_ACCESS_DENIED ) //возможно read only аттрибут, пытаемся сбросить
	{
		if ( SetFileAttributesW( sp.data(), 0 ) && RemoveDirectoryW( sp.data() ) ) { return 0; }

		lastError  = GetLastError();
	}

	SetError( err, lastError );
	return -1;
}
Esempio n. 7
0
int FSSys::SetFileTime  ( FSPath& path, FSTime aTime, FSTime mTime, int* err, FSCInfo* info )
{
	HANDLE h = CreateFileW( SysPathStr( _drive, path.GetUnicode( '\\' ) ).data(), FILE_WRITE_ATTRIBUTES , 0, 0, OPEN_EXISTING, 0, 0 );

	if ( h == INVALID_HANDLE_VALUE )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	FILETIME at = aTime;
	FILETIME mt = mTime;

	if ( !::SetFileTime( h, NULL, &at, &mt ) )
	{
		SetError( err, GetLastError() );
		CloseHandle( h );
		return -1;
	}

	CloseHandle( h );
	return 0;
}
Esempio n. 8
0
int FSTmp::Rename(FSPath&  oldpath, FSPath& newpath, int* err, FSCInfo* info)
{
	FSTmpNode* n = rootDir.findByName(oldpath.GetItem(oldpath.Count() - 1));
	if (n == 0)
	{
		return FS::SetError(err, FSTMP_ERROR_FILE_NOT_FOUND);
	}
	else
	{
		if (n->nodeType == FSTmpNode::NODE_FILE)
		{
			int ret = baseFS->Rename(n->baseFSPath, newpath, err, info);
			if (ret != 0)
				return ret;
			n->name = newpath.GetUnicode();
			return SetError(err, 0);
		}
		else
		{// XXX ??? add case when new and old path are in different dirs
			((FSTmpNode*)(n))->name = *newpath.GetItem(newpath.Count() - 1);
			return SetError(err, 0);
		}
	}
}
Esempio n. 9
0
FSString FSSys::Uri( FSPath& path )
{
	unicode_t pref[0x100];
	unicode_t* p = pref;

	if ( _drive > 0 && _drive < 'z' - 'a' + 1 ) //+1 ???
	{
		*( p++ ) = 'A' + _drive;
		*( p++ ) = ':';
	}
	else if ( _drive == -1 )
	{
		*( p++ ) = '\\';
	}
	else
	{
		*( p++ ) = '?';
		*( p++ ) = ':';
	}

	*p = 0;

	return FSString( carray_cat<unicode_t>( pref, path.GetUnicode() ).data() );
}
Esempio n. 10
0
FSString FSSys::Uri( FSPath& path )
{
	return FSString( path.GetUnicode() );
}