A game about forced loneliness, made by TACStudios
at master 54 lines 1.6 kB view raw
1using System.IO; 2using UnityEditor.VersionControl; 3 4namespace UnityEditor.Timeline 5{ 6 static class FileUtility 7 { 8 internal static bool IsReadOnly(UnityEngine.Object asset) 9 { 10 return IsReadOnlyImpl(asset); 11 } 12 13#if UNITY_2021_2_OR_NEWER 14 static bool IsReadOnlyImpl(UnityEngine.Object asset) 15 { 16 string assetPath = AssetDatabase.GetAssetPath(asset); 17 if (string.IsNullOrEmpty(assetPath)) 18 return false; 19 20 if (Provider.enabled && VersionControlUtils.IsPathVersioned(assetPath)) 21 { 22 return !AssetDatabase.CanOpenForEdit(asset, StatusQueryOptions.UseCachedIfPossible); 23 } 24 25 return (uint)(File.GetAttributes(assetPath) & FileAttributes.ReadOnly) > 0U; 26 } 27#else 28 static bool IsReadOnlyImpl(UnityEngine.Object asset) 29 { 30 string assetPath = AssetDatabase.GetAssetPath(asset); 31 if (Provider.enabled) 32 { 33 if (!Provider.isActive) 34 return false; 35 36 Asset vcAsset = Provider.GetAssetByPath(assetPath); 37 if (Provider.IsOpenForEdit(vcAsset)) 38 return false; 39 40 41 //I can't get any of the Provider checks to work, but here we should check for exclusive checkout issues. 42 return false; 43 } 44 45 46 if (!string.IsNullOrEmpty(assetPath)) 47 { 48 return (File.GetAttributes(assetPath) & FileAttributes.ReadOnly) != 0; 49 } 50 return false; 51 } 52#endif 53 } 54}