C3204
2025-12-31 499a261e08f452aa81c4b5a4bad81550ec2e179d
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
 
namespace LB_SmartVisionCommon
{
    public class DiskInfoHelper
    {
        public static double GetFreeSpaceGB(string driveName)
        {
            try
            {
                DriveInfo drive = new DriveInfo(driveName);
                return drive.IsReady ? Math.Round((double)drive.AvailableFreeSpace / (1024 * 1024 * 1024), 2) : -1;
            }
            catch
            {
                return -1;
            }
        }
 
        public static Dictionary<string, object> GetDiskDetails(string driveName)
        {
            var result = new Dictionary<string, object>();
 
            try
            {
                DriveInfo drive = new DriveInfo(driveName);
 
                if (drive.IsReady)
                {
                    result["DriveName"] = drive.Name;
                    result["TotalSizeGB"] = Math.Round((double)drive.TotalSize / (1024 * 1024 * 1024), 2);
                    result["FreeSpaceGB"] = Math.Round((double)drive.AvailableFreeSpace / (1024 * 1024 * 1024), 2);
                    result["DriveFormat"] = drive.DriveFormat;
                    result["DriveType"] = drive.DriveType.ToString();
                }
            }
            catch (Exception ex)
            {
                result["Error"] = ex.Message;
            }
 
            return result;
        }
    }
}