modio / modio-unity

Unity Engine Plugin for easily integrating mod.io into your game - the UGC management service for game developers
https://mod.io
MIT License
28 stars 7 forks source link

Crash on IL2CPP due to a attempt to instantiate DriveInfo class #2

Open IronWarrior opened 1 year ago

IronWarrior commented 1 year ago

Tested using Version v2023.7.1 from the Unity Asset Store (latest as of this post). In SystemIODataService.IsThereEnoughDiskSpaceFor we currently have

        public async Task<bool> IsThereEnoughDiskSpaceFor(long bytes)
        {
            try
            {
#if UNITY_ANDROID
                //DriveInfo is not supported on iLcpp
                AndroidJNI.AttachCurrentThread();
                var statFs = new AndroidJavaObject("android.os.StatFs", persistentDataPath);
                var freeBytes = statFs.Call<long>("getFreeBytes");
                return bytes < freeBytes;
#else
                FileInfo f = new FileInfo(PersistentDataRootDirectory);
                string drive = Path.GetPathRoot(f.FullName);
                var d = new DriveInfo(drive);
                return bytes < d.AvailableFreeSpace;
#endif
            }
            catch(Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }

which correctly notes that DriveInfo is not supported in IL2CPP, as recorded here.

However, it will be used on any platform other than Android which would cause the crash (I have only been testing this on Standalone). Previous modio versions had

        public async Task<bool> IsThereEnoughDiskSpaceFor(long bytes)
        {
            // Not implemented for this platform
            return true;
        }

Not sure if there is any solution here for IL2CPP beyond just allowing the installation attempt to proceed (and fail) and then catch the IOException?