The UNITY_EDITOR code doesn't work on Windows as Mono doesn't implemented the DriveInfo stuff.
Better use this solution(at least for Windows): http://stackoverflow.com/questions/1393711/get-free-disk-space
Here my changes:
public class DiskSpace
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
//http://stackoverflow.com/questions/1393711/get-free-disk-space
[DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
[return: MarshalAs(UnmanagedType.Bool)]
public static extern bool GetDiskFreeSpaceEx(string lpDirectoryName, out ulong lpFreeBytesAvailable, out ulong lpTotalNumberOfBytes, out ulong lpTotalNumberOfFreeBytes);
#elif UNITY_ANDROID
#elif UNITY_IPHONE
[DllImport("__Internal")]
private static extern long _iDiskSpace_FreeSpece(string path);
#endif
public static long FreeSpece {
get
{
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN
ulong free = 0, dummy1 = 0, dummy2 = 0;
if (GetDiskFreeSpaceEx(Application.persistentDataPath, out free, out dummy1, out dummy2))
{
return (long)free;
}
#elif UNITY_ANDROID
using(AndroidJavaObject statFs = new AndroidJavaObject( "android.os.StatFs", Application.persistentDataPath)) {
//statFs.getBlockSize() * statFs.getAvailableBlocks()
return statFs.Call<int>("getBlockSize") * statFs.Call<int>("getAvailableBlocks");
}
#elif UNITY_IPHONE
return _iDiskSpace_FreeSpece(Application.persistentDataPath);
#endif
return -1;
}
The UNITY_EDITOR code doesn't work on Windows as Mono doesn't implemented the DriveInfo stuff.
Better use this solution(at least for Windows): http://stackoverflow.com/questions/1393711/get-free-disk-space
Here my changes: