System.IO.DriveInfo returns wrong disk space values

£可爱£侵袭症+ 提交于 2020-01-04 19:48:48

问题


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:


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.



来源:https://stackoverflow.com/questions/24252100/system-io-driveinfo-returns-wrong-disk-space-values

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!