public static void ThrowIfNotEnoughDiskSpaceAvailable(IComponent component, long additionalBuffer = 0,
                                                       CalculationOption option = CalculationOption.All)
 {
     foreach (var diskData in new DiskSpaceCalculator(component, additionalBuffer, option).CalculatedDiskSizes)
     {
         if (!diskData.Value.HasEnoughDiskSpace)
         {
             throw new OutOfDiskspaceException(
                       $"There is not enough space to install “{component.Name}”. {diskData.Key} is required on drive {diskData.Value.RequestedSize + additionalBuffer} " +
                       $"but you only have {diskData.Value.AvailableDiskSpace} available.");
         }
     }
 }
Beispiel #2
0
        private void SetTextboxEnabled()
        {
            var densEnabled = !rb_Density.Checked;
            var presEnabled = !rb_Pressure.Checked;
            var tempEnabled = !rb_Temperature.Checked;

            if (tempEnabled && presEnabled)
            {
                _mCalculationOption = CalculationOption.CalculateDensity;
            }
            else if (tempEnabled && densEnabled)
            {
                _mCalculationOption = CalculationOption.CalculatePressure;
            }
            else if (presEnabled && densEnabled)
            {
                _mCalculationOption = CalculationOption.CalculateTemperature;
            }
            else
            {
                MessageBox.Show(@"Unable to determine calculation option.");
            }

            if (tb_tpd_Density.Enabled != densEnabled)
            {
                tb_tpd_Density.Enabled = densEnabled;
            }

            if (tb_tpd_Pressure.Enabled != presEnabled)
            {
                tb_tpd_Pressure.Enabled = presEnabled;
            }

            if (tb_tpd_Temperature.Enabled != tempEnabled)
            {
                tb_tpd_Temperature.Enabled = tempEnabled;
            }

            SetCalcButtonProperties();
        }
        internal DiskSpaceCalculator(IComponent component, long additionalBuffer = 0, CalculationOption option = CalculationOption.All)
        {
            CalculatedDiskSizes = new Dictionary <string, DriveSpaceData>(StringComparer.OrdinalIgnoreCase);

            var destinationRoot = FileSystemExtensions.GetPathRoot(component.Destination);
            var backupRoot      = FileSystemExtensions.GetPathRoot(UpdateConfiguration.Instance.BackupPath);

            if (string.IsNullOrEmpty(backupRoot))
            {
                backupRoot = destinationRoot;
            }



            if (ComponentDownloadPathStorage.Instance.TryGetValue(component, out var downloadPath) && option.HasFlag(CalculationOption.Download))
            {
                var downloadRoot = FileSystemExtensions.GetPathRoot(downloadPath);
                if (!string.IsNullOrEmpty(downloadPath))
                {
                    SetSizeMembers(component.OriginInfo?.Size, downloadRoot !);
                }
            }

            if (option.HasFlag(CalculationOption.Install))
            {
                SetSizeMembers(component.OriginInfo?.Size, destinationRoot !);
            }
            if (option.HasFlag(CalculationOption.Backup))
            {
                SetSizeMembers(component.DiskSize, backupRoot !);
            }

            foreach (var sizes in CalculatedDiskSizes)
            {
                try
                {
                    var driveFreeSpace = FileSystemExtensions.GetDriveFreeSpace(sizes.Key);
                    sizes.Value.AvailableDiskSpace = driveFreeSpace;
                    sizes.Value.HasEnoughDiskSpace = driveFreeSpace >= sizes.Value.RequestedSize + additionalBuffer;
                }
                catch
                {
                    sizes.Value.HasEnoughDiskSpace = false;
                    HasEnoughDiskSpace             = false;
                }
            }
        }