AssetStatusCache.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. using System;
  2. using System.IO;
  3. using UnityEditor;
  4. using Codice.CM.Common;
  5. namespace Unity.PlasticSCM.Editor.AssetsOverlays.Cache
  6. {
  7. internal interface IAssetStatusCache
  8. {
  9. AssetStatus GetStatusForPath(string fullPath);
  10. AssetStatus GetStatusForGuid(string guid);
  11. LockStatusData GetLockStatusData(string guid);
  12. LockStatusData GetLockStatusDataForPath(string path);
  13. void Clear();
  14. }
  15. internal class AssetStatusCache : IAssetStatusCache
  16. {
  17. internal AssetStatusCache(
  18. WorkspaceInfo wkInfo,
  19. bool isGluonMode)
  20. {
  21. mLocalStatusCache = new LocalStatusCache(wkInfo);
  22. mRemoteStatusCache = new RemoteStatusCache(
  23. wkInfo,
  24. isGluonMode,
  25. ProjectWindow.Repaint);
  26. mLockStatusCache = new LockStatusCache(
  27. wkInfo,
  28. ProjectWindow.Repaint);
  29. }
  30. AssetStatus IAssetStatusCache.GetStatusForPath(string fullPath)
  31. {
  32. AssetStatus localStatus = mLocalStatusCache.GetStatus(fullPath);
  33. if (!ClassifyAssetStatus.IsControlled(localStatus))
  34. return localStatus;
  35. AssetStatus remoteStatus = mRemoteStatusCache.GetStatus(fullPath);
  36. AssetStatus lockStatus = mLockStatusCache.GetStatus(fullPath);
  37. return localStatus | remoteStatus | lockStatus;
  38. }
  39. AssetStatus IAssetStatusCache.GetStatusForGuid(string guid)
  40. {
  41. string fullPath = GetAssetPath(guid);
  42. if (string.IsNullOrEmpty(fullPath))
  43. return AssetStatus.None;
  44. return ((IAssetStatusCache)this).GetStatusForPath(fullPath);
  45. }
  46. LockStatusData IAssetStatusCache.GetLockStatusDataForPath(string path)
  47. {
  48. if (string.IsNullOrEmpty(path))
  49. return null;
  50. return mLockStatusCache.GetLockStatusData(path);
  51. }
  52. LockStatusData IAssetStatusCache.GetLockStatusData(string guid)
  53. {
  54. string fullPath = GetAssetPath(guid);
  55. return ((IAssetStatusCache)this).GetLockStatusDataForPath(fullPath);
  56. }
  57. void IAssetStatusCache.Clear()
  58. {
  59. mLocalStatusCache.Clear();
  60. mRemoteStatusCache.Clear();
  61. mLockStatusCache.Clear();
  62. }
  63. static string GetAssetPath(string guid)
  64. {
  65. string assetPath = AssetDatabase.GUIDToAssetPath(guid);
  66. if (string.IsNullOrEmpty(assetPath))
  67. return null;
  68. return Path.GetFullPath(assetPath);
  69. }
  70. readonly LocalStatusCache mLocalStatusCache;
  71. readonly RemoteStatusCache mRemoteStatusCache;
  72. readonly LockStatusCache mLockStatusCache;
  73. }
  74. }