示例#1
0
            private string FindFirstVolume()
            {
                // Need at least some length on initial call or we'll get ERROR_INVALID_PARAMETER
                _buffer.EnsureCharCapacity(400);

                _findHandle = VolumeMethods.Imports.FindFirstVolumeMountPointW(
                    _volumeName,
                    _buffer,
                    _buffer.CharCapacity);

                if (_findHandle.IsInvalid)
                {
                    WindowsError error = Errors.GetLastError();
                    switch (error)
                    {
                    // Not positive on this case as I haven't been able to get this API
                    // to fully work correctly yet.
                    case WindowsError.ERROR_MORE_DATA:
                        _buffer.EnsureCharCapacity(_buffer.CharCapacity + 64);
                        return(FindFirstVolume());

                    case WindowsError.ERROR_NO_MORE_FILES:
                        _lastEntryFound = true;
                        return(null);

                    default:
                        throw Errors.GetIoExceptionForError(error);
                    }
                }

                _buffer.SetLengthToFirstNull();
                return(_buffer.ToString());
            }
示例#2
0
 public static extern bool FindNextVolumeMountPointW(
     FindVolumeMountPointHandle hFindVolumeMountPoint,
     SafeHandle lpszVolumeMountPoint,
     uint cchBufferLength);
示例#3
0
 private void CloseHandle()
 {
     _findHandle?.Dispose();
     _findHandle = null;
 }