예제 #1
0
        private void UpdateDiskSpace()
        {
            int    diskValue = 0;
            string diskText  = "--- GB free";

            ActionCopyMoveRename activeCmAction = GetActiveCmAction();

            if (activeCmAction is null)
            {
                return;
            }

            string        folder = activeCmAction.TargetFolder;
            DirectoryInfo toRoot = !string.IsNullOrEmpty(folder) && !folder.StartsWith("\\\\", StringComparison.Ordinal) ? new DirectoryInfo(folder).Root : null;

            if (toRoot != null)
            {
                System.IO.DriveInfo di;
                try
                {
                    // try to get root of drive
                    di = new System.IO.DriveInfo(toRoot.ToString());
                }
                catch (ArgumentException)
                {
                    di = null;
                }

                try
                {
                    if (di != null)
                    {
                        (diskValue, diskText) = DiskValue(di.TotalFreeSpace, di.TotalSize);
                    }
                }
                catch (UnauthorizedAccessException)
                {
                }
                catch (IOException)
                {
                }
            }

            DirectoryInfo toUncRoot = !string.IsNullOrEmpty(folder) && folder.StartsWith("\\\\", StringComparison.Ordinal) ? new DirectoryInfo(folder).Root : null;

            if (toUncRoot != null)
            {
                FileSystemProperties driveStats = FileHelper.GetProperties(toUncRoot.ToString());
                long?availableBytes             = driveStats.AvailableBytes;
                long?totalBytes = driveStats.TotalBytes;
                if (availableBytes.HasValue && totalBytes.HasValue)
                {
                    (diskValue, diskText) = DiskValue(availableBytes.Value, totalBytes.Value);
                }
            }

            pbDiskSpace.Value = diskValue;
            txtDiskSpace.Text = diskText;
        }
예제 #2
0
        private void UpdateDiskSpace()
        {
            int    diskValue = 0;
            string diskText  = "--- GB free";

            ActionCopyMoveRename activeCMAction = null;

            activeCMAction = GetActiveCmAction();

            if (activeCMAction is null)
            {
                return;
            }


            string        folder = activeCMAction.TargetFolder;
            DirectoryInfo toRoot = (!string.IsNullOrEmpty(folder) && !folder.StartsWith("\\\\")) ? new DirectoryInfo(folder).Root : null;

            if (toRoot != null)
            {
                System.IO.DriveInfo di;
                try
                {
                    // try to get root of drive
                    di = new System.IO.DriveInfo(toRoot.ToString());
                }
                catch (System.ArgumentException)
                {
                    di = null;
                }

                if (di != null)
                {
                    int pct = (int)((1000 * di.TotalFreeSpace) / di.TotalSize);
                    diskValue = 1000 - pct;
                    diskText  = di.TotalFreeSpace.GBMB(1) + " free";
                }
            }

            DirectoryInfo toUNCRoot = (!string.IsNullOrEmpty(folder) && folder.StartsWith("\\\\")) ? new DirectoryInfo(folder).Root : null;

            if (toUNCRoot != null)
            {
                FileSystemProperties driveStats = FileHelper.GetProperties(toUNCRoot.ToString());
                if (driveStats != null)
                {
                    int pct = (int)((1000 * driveStats.AvailableBytes) / driveStats.TotalBytes);
                    diskValue = 1000 - pct;
                    diskText  = (driveStats.AvailableBytes ?? 0).GBMB(1) + " free";
                }
            }

            this.pbDiskSpace.Value = diskValue;
            this.txtDiskSpace.Text = diskText;
        }