Exemplo n.º 1
0
        public List <string> GetVirtualDisksImagePaths()
        {
            List <string> paths = new List <string>(4);

            // Query for vdisk providers
            IEnumVdsObject providerEnum;

            _service.QueryProviders(VDS_QUERY_PROVIDER_FLAG.VDS_QUERY_VIRTUALDISK_PROVIDERS, out providerEnum);
            Debug.WriteLine("Got Providers");

            // Iterate
            for (int i = 0; i < 12; i++)
            {
                uint   fetched;
                object unknown;
                providerEnum.Next(1, out unknown, out fetched);

                if (fetched == 0)
                {
                    break; //no next disk
                }
                // Cast to the required type
                IVdsVdProvider provider = (IVdsVdProvider)unknown;
                Debug.WriteLine("Got VD Provider");

                paths.AddRange(GetAllPaths(provider));
            }

            return(paths);
        }
Exemplo n.º 2
0
        public static IEnumerable <IVdsProvider> GetProviders(this IVdsService vdsService, VdsProviderMask providerMask = VdsProviderMask.Software)
        {
            IEnumVdsObject providerEnum;
            int            hr = vdsService.QueryProviders(providerMask, out providerEnum);

            Marshal.ThrowExceptionForHR(hr);

            object iface;
            int    fetched;

            while (0 == providerEnum.Next(1, out iface, out fetched))
            {
                yield return(iface as IVdsProvider);
            }
        }
Exemplo n.º 3
0
        public async Task <List <Disk> > GetDisksAsync()
        {
            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(VdsSession));
            }

            return(await VdsHelper.RunBlockingAction(() =>
            {
                var ret = new List <Disk>();

                foreach (var swProvider in VdsHelper.VdsEnumerate <IVdsSwProvider>((out IEnumVdsObject ppEnum) =>
                                                                                   mService.QueryProviders((uint)_VDS_QUERY_PROVIDER_FLAG.VDS_QUERY_SOFTWARE_PROVIDERS, out ppEnum)))
                {
                    foreach (var pack in VdsHelper.VdsEnumerate <IVdsPack>(swProvider.QueryPacks))
                    {
                        foreach (var disk in VdsHelper.VdsEnumerate <IVdsDisk>(pack.QueryDisks))
                        {
                            _VDS_DISK_PROP diskProps;
                            disk.GetProperties(out diskProps);

                            if (diskProps.dwDeviceType != FILE_DEVICE_DISK)
                            {
                                continue;
                            }
                            if (diskProps.status != _VDS_DISK_STATUS.VDS_DS_ONLINE)
                            {
                                //The disk might be ejected. Or a card reader might have no media in it.
                                continue;
                            }
                            if (diskProps.health != _VDS_HEALTH.VDS_H_HEALTHY)
                            {
                                //TODO: does it ever make sense to try to write a non-healthy drive?
                                continue;
                            }

                            //Other properties that might be usful to expose:
                            //* busType. For example, USB versus MMC
                            ret.Add(new Disk(disk, diskProps.id, diskProps.pwszName, diskProps.pwszFriendlyName, diskProps.dwMediaType == MEDIA_TYPE_RemovableMedia, checked ((long)diskProps.ullSize)));
                        }
                    }
                }

                ret.Sort();

                return ret;
            }));
        }