Exemple #1
0
        public async Task Dismount(AppxVolume volume, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            using var session = await PowerShellSession.CreateForAppxModule().ConfigureAwait(false);

            using var command = session.AddCommand("Dismount-AppxVolume");
            command.AddParameter("Volume", volume.Name);
            await session.InvokeAsync(progress).ConfigureAwait(false);
        }
Exemple #2
0
        public Task Mount(AppxVolume volume, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            var proxyObject = new MountDto
            {
                Name = volume.Name
            };

            return(this.client.Invoke(proxyObject, cancellationToken, progress));
        }
Exemple #3
0
        public Task SetDefault(AppxVolume volume, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            var proxyObject = new SetDefaultDto
            {
                DrivePath = volume.PackageStorePath
            };

            return(this.client.Invoke(proxyObject, cancellationToken, progress));
        }
Exemple #4
0
        public async Task <AppxVolume> GetVolumeForPath(string path, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            var di = new DirectoryInfo(path);

            if (!di.Exists)
            {
                throw new DirectoryNotFoundException("Directory was not found.");
            }

            if (di.Attributes.HasFlag(FileAttributes.ReparsePoint))
            {
                var target = GetSymbolicLinkTarget(di);
                path = target;
            }

            using var session = await PowerShellSession.CreateForAppxModule().ConfigureAwait(false);

            using var command = session.AddCommand("Get-AppPackageVolume");
            command.AddParameter("Path", path);

            var result = await session.InvokeAsync(progress).ConfigureAwait(false);

            var item = result.FirstOrDefault();

            if (item == null)
            {
                return(null);
            }

            var name             = (string)item.Properties.FirstOrDefault(p => p.Name == "Name")?.Value;
            var packageStorePath = (string)item.Properties.FirstOrDefault(p => p.Name == "PackageStorePath")?.Value;

            var letter = packageStorePath != null && packageStorePath.Length > 2 && packageStorePath[1] == ':' ? packageStorePath.Substring(0, 1) + ":\\" : null;

            var appxVolume = new AppxVolume {
                Name = name, PackageStorePath = packageStorePath
            };

            if (letter == null)
            {
                return(appxVolume);
            }

            var drive = DriveInfo.GetDrives().FirstOrDefault(d => d.RootDirectory.FullName.StartsWith(letter, StringComparison.OrdinalIgnoreCase));

            if (drive == null)
            {
                return(appxVolume);
            }

            appxVolume.IsDriveReady       = drive.IsReady;
            appxVolume.DiskLabel          = drive.VolumeLabel;
            appxVolume.Capacity           = drive.TotalSize;
            appxVolume.AvailableFreeSpace = drive.AvailableFreeSpace;

            return(appxVolume);
        }
Exemple #5
0
        public Task MovePackageToVolume(AppxVolume volume, AppxPackage package, CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            if (volume == null)
            {
                throw new ArgumentNullException(nameof(volume));
            }

            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            return(this.MovePackageToVolume(volume.Name, package.FullName, cancellationToken, progress));
        }
        public MovePackageToVolumeDto(AppxPackage package, AppxVolume volume)
        {
            if (package == null)
            {
                throw new ArgumentNullException(nameof(package));
            }

            if (volume == null)
            {
                throw new ArgumentNullException(nameof(volume));
            }

            this.PackageFullName   = package.FullName;
            this.VolumePackagePath = volume.PackageStorePath;
        }
Exemple #7
0
        public async Task <AppxVolume> GetDefault(CancellationToken cancellationToken = default, IProgress <ProgressData> progress = default)
        {
            using var session = await PowerShellSession.CreateForAppxModule().ConfigureAwait(false);

            using var command = session.AddCommand("Get-AppxDefaultVolume");

            var result = await session.InvokeAsync(progress).ConfigureAwait(false);

            var item = result.FirstOrDefault();

            if (item == null)
            {
                return(null);
            }

            var baseType         = item.BaseObject.GetType();
            var name             = (string)baseType.GetProperty("Name")?.GetValue(item.BaseObject);
            var packageStorePath = (string)baseType.GetProperty("PackageStorePath")?.GetValue(item.BaseObject);

            var letter = packageStorePath != null && packageStorePath.Length > 2 && packageStorePath[1] == ':' ? packageStorePath.Substring(0, 1) + ":\\" : null;

            var appxVolume = new AppxVolume {
                Name = name, PackageStorePath = packageStorePath
            };

            if (letter != null)
            {
                var drive = DriveInfo.GetDrives().First(d => d.RootDirectory.FullName.StartsWith(letter, StringComparison.OrdinalIgnoreCase));
                if (drive != null)
                {
                    appxVolume.IsDriveReady       = drive.IsReady;
                    appxVolume.DiskLabel          = drive.VolumeLabel;
                    appxVolume.Capacity           = drive.TotalSize;
                    appxVolume.AvailableFreeSpace = drive.AvailableFreeSpace;
                }
            }

            return(appxVolume);
        }
Exemple #8
0
 public DismountDto(AppxVolume volume) : this(volume.Name)
 {
 }
Exemple #9
0
 public VolumeViewModel(AppxVolume model)
 {
     this.Model = model;
 }
Exemple #10
0
 public VolumeCandidateViewModel(AppxVolume model)
 {
     this.Model = model;
 }
 public SetDefaultDto(AppxVolume volume) : this(volume.PackageStorePath)
 {
 }
Exemple #12
0
 public DeleteDto(AppxVolume volume) : this(volume.Name)
 {
 }