No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

FileUtility.cs 1.6KB

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