AssetStatusCache.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. Action repaintProjectWindow)
  21. {
  22. mLocalStatusCache = new LocalStatusCache(wkInfo);
  23. mRemoteStatusCache = new RemoteStatusCache(
  24. wkInfo,
  25. isGluonMode,
  26. repaintProjectWindow);
  27. mLockStatusCache = new LockStatusCache(
  28. wkInfo,
  29. repaintProjectWindow);
  30. }
  31. AssetStatus IAssetStatusCache.GetStatusForPath(string fullPath)
  32. {
  33. AssetStatus localStatus = mLocalStatusCache.GetStatus(fullPath);
  34. if (!ClassifyAssetStatus.IsControlled(localStatus))
  35. return localStatus;
  36. AssetStatus remoteStatus = mRemoteStatusCache.GetStatus(fullPath);
  37. AssetStatus lockStatus = mLockStatusCache.GetStatus(fullPath);
  38. return localStatus | remoteStatus | lockStatus;
  39. }
  40. AssetStatus IAssetStatusCache.GetStatusForGuid(string guid)
  41. {
  42. string fullPath = GetAssetPath(guid);
  43. if (string.IsNullOrEmpty(fullPath))
  44. return AssetStatus.None;
  45. return ((IAssetStatusCache)this).GetStatusForPath(fullPath);
  46. }
  47. LockStatusData IAssetStatusCache.GetLockStatusDataForPath(string path)
  48. {
  49. if (string.IsNullOrEmpty(path))
  50. return null;
  51. return mLockStatusCache.GetLockStatusData(path);
  52. }
  53. LockStatusData IAssetStatusCache.GetLockStatusData(string guid)
  54. {
  55. string fullPath = GetAssetPath(guid);
  56. return ((IAssetStatusCache)this).GetLockStatusDataForPath(fullPath);
  57. }
  58. void IAssetStatusCache.Clear()
  59. {
  60. mLocalStatusCache.Clear();
  61. mRemoteStatusCache.Clear();
  62. mLockStatusCache.Clear();
  63. }
  64. static string GetAssetPath(string guid)
  65. {
  66. string assetPath = AssetDatabase.GUIDToAssetPath(guid);
  67. if (string.IsNullOrEmpty(assetPath))
  68. return null;
  69. return Path.GetFullPath(assetPath);
  70. }
  71. readonly LocalStatusCache mLocalStatusCache;
  72. readonly RemoteStatusCache mRemoteStatusCache;
  73. readonly LockStatusCache mLockStatusCache;
  74. }
  75. }