Exemple #1
0
std::vector<unicode_t> GetHomeUriWin()
{
	wchar_t homeDrive[0x100];
	wchar_t homePath[0x100];
	int l1 = GetEnvironmentVariableW( L"HOMEDRIVE", homeDrive, 0x100 );
	int l2 = GetEnvironmentVariableW( L"HOMEPATH", homePath, 0x100 );

	if ( l1 > 0 && l1 < 0x100 && l2 > 0 && l2 < 0x100 )
	{
		return carray_cat<unicode_t>( Utf16ToUnicode( homeDrive ).data(), Utf16ToUnicode( homePath ).data() );
	}

	return std::vector<unicode_t>();
}
FSString FSWin32Net::Uri( FSPath& path )
{
	NETRESOURCEW* p = _res.Get();

	if ( p && p->lpRemoteName )
	{
		return FSString( Utf16ToUnicode( p->lpRemoteName ).data() );
	}

	return FSString( "Network" );
}
Exemple #3
0
std::vector<unicode_t> GetTempUriWin()
{
	wchar_t TempPath[0x100];
	int l1 = GetEnvironmentVariableW( L"TMP", TempPath, 0x100 );

	if ( l1 > 0 && l1 < 0x100 )
	{
		return Utf16ToUnicode( TempPath );
	}

	return std::vector<unicode_t>();
}
int FSWin32Net::ReadDir ( FSList* list, FSPath& path, int* err, FSCInfo* info )
{
	list->Clear();

	if ( path.Count() > 1 )
	{
		if ( err ) { *err = ERRNOSUPPORT; }

		return -1;
	}


	WNetEnumerator en;

	if ( !en.Open( _res.Get() ) )
	{
		SetError( err, GetLastError() );
		return -1;
	}

	try
	{
		while ( true )
		{
			if ( info && info->Stopped() )
			{
				return -2;
			}

			DWORD dwErr = 0;
			NETRESOURCEW* p = en.Next( &dwErr );

			if ( !p )
			{
				if ( !dwErr ) { break; }

				SetError( err, dwErr );
				return -1;
			}

			if ( !p->lpRemoteName ) { continue; }

			wchar_t* pName = p->lpRemoteName;

			if ( p->dwDisplayType == RESOURCEDISPLAYTYPE_SHARE || p->dwDisplayType == RESOURCEDISPLAYTYPE_SERVER )
			{
				//выкинуть из названия шары имя сервера, а из названия сервера - косые символы
				wchar_t* last = 0;

				for ( wchar_t* s = pName; *s; s++ )
					if ( *s == '\\' ) { last = s; }

				if ( last && last[1] ) { pName = last + 1; }
			}

			clPtr<FSNode> pNode = new FSNode();

			pNode->name.Set( CS_UNICODE, Utf16ToUnicode( pName ).data() );
			pNode->st.mode = S_IFDIR;
			pNode->st.mode |= 0664;

			pNode->_w32NetRes = W32NetRes( p );

			switch ( p->dwDisplayType )
			{
					//case RESOURCEDISPLAYTYPE_GENERIC: return "GENERIC";
				case RESOURCEDISPLAYTYPE_DOMAIN:
				case RESOURCEDISPLAYTYPE_GROUP:
				case RESOURCEDISPLAYTYPE_NETWORK:
					pNode->extType = FSNode::WORKGROUP;
					break;

				case RESOURCEDISPLAYTYPE_SERVER:
					pNode->extType = FSNode::SERVER;
					break;

				case RESOURCEDISPLAYTYPE_DIRECTORY:
				case RESOURCEDISPLAYTYPE_SHARE:
					pNode->extType = FSNode::FILESHARE;
					break;
			};

			list->Append( pNode );
		};

		return 0;
	}
	catch ( ... )
	{
		throw;
	}

	SetError( err, 100 );
	return -1;
}
int FSSys::ReadDir( FSList* list, FSPath& _path, int* err, FSCInfo* info )
{
	list->Clear();
	FSPath path( _path );
	WIN32_FIND_DATAW ent;

	HANDLE handle = FindFirstFileW( FindPathStr( _drive, path.GetUnicode(), L"\\*" ).data(), &ent );

	if ( handle == INVALID_HANDLE_VALUE )
	{
		DWORD ret = GetLastError();

		if ( ret == ERROR_FILE_NOT_FOUND ) { return 0; }

		SetError( err, GetLastError() );
		return -1;
	}

	try
	{
		while ( true )
		{
			if ( info && info->Stopped() )
			{
				FindClose( handle );
				return -2;
			}

			//skip . and ..
			if ( !( ent.cFileName[0] == '.' && ( !ent.cFileName[1] || ( ent.cFileName[1] == '.' && !ent.cFileName[2] ) ) ) )
			{
				clPtr<FSNode> pNode = new FSNode();
				pNode->name.Set( CS_UNICODE, Utf16ToUnicode( ent.cFileName ).data() );

				pNode->st.dwFileAttributes = ent.dwFileAttributes;
				pNode->st.size = ( seek_t( ent.nFileSizeHigh ) << 32 ) + ent.nFileSizeLow;

				pNode->st.mtime = ent.ftLastWriteTime;

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

				pNode->st.mode |= 0664;
				list->Append( pNode );
			}

			if ( !FindNextFileW( handle, &ent ) )
			{
				if ( GetLastError() == ERROR_NO_MORE_FILES ) { break; }

				SetError( err, GetLastError() );
				FindClose( handle );
				return -1;
			}
		};

		FindClose( handle );

		return 0;
	}
	catch ( ... )
	{
		FindClose( handle );
		throw;
	}

	SetError( err, 100 );
	return -1;
}