System.IO.DriveInfo returns wrong disk space value

2019-07-21 18:56发布

UPDATE : This issue doesn't appear on Android devices I've tested. It returns good values. Would really appreciate any pointers on this matter.

I am having trouble getting the correct AvailableFreeSpace values from my Mac desktop computer. I am working with Unity3D C#, and am using the following code :

DriveInfo[] drives = DriveInfo.GetDrives();

foreach(DriveInfo drive in drives)
{
    if (drive.IsReady)
    {
        Debug.Log(drive.Name);
        Debug.Log(drive.AvailableFreeSpace);
        Debug.Log(drive.TotalFreeSpace);
        Debug.Log(drive.TotalSize);
    }
}

My results are a bit weird. I'm only getting one drive : The name I'm getting is "/", and ythe values are wrong. AvailableFreeSpace returns a higher value than TotalSize, which makes no sense. Also, the DriveType is Unknown and the drive Format is unixfs, if that helps.

Don't know if I'm missing something obvious about the file structure on a Mac computer, maybe?

EDIT : I have a SATA HDD with 500go divided into two partitions. Shouldn't it give me 2 drives?

EDIT2 : My Monodevelop version is 4.0.1, so I don't think this is related to the bug reported years ago on version 2.10.0 or something like that.

What am I doing wrong?

1条回答
Juvenile、少年°
2楼-- · 2019-07-21 19:04

Posted to another forum, and apparently this is a Mono/Unity bug. The newest version of Unity uses an old Mono (the compiler, not MonoDevelop (the text editor)) :

http://unity3d.com/unity/faq#section-445

The bug returning incorrect values was fixed in a later version of Mono (2.10) and another bug concerning DriveInfo was also fixed in Mono version 3.0 :

http://www.mono-project.com/Release_Notes_Mono_2.10

http://www.mono-project.com/Release_Notes_Mono_3.0

So there's pretty much nothing to do except find another way to get the available disk space on a Mac.

查看更多
登录 后发表回答