@@ -7,20 +7,17 @@ namespace GitHub.Unity
77{
88 class LfsLocksModificationProcessor : UnityEditor . AssetModificationProcessor
99 {
10- private static ILogging logger ;
11- private static ILogging Logger { get { return logger = logger ?? LogHelper . GetLogger < LfsLocksModificationProcessor > ( ) ; } }
12-
10+ private static ILogging Logger = LogHelper . GetLogger < LfsLocksModificationProcessor > ( ) ;
1311 private static IRepository repository ;
14-
12+ private static IPlatform platform ;
1513 private static List < GitLock > locks = new List < GitLock > ( ) ;
16-
1714 private static CacheUpdateEvent lastLocksChangedEvent ;
1815
19- public static void Initialize ( IRepository repo )
16+ public static void Initialize ( IRepository repo , IPlatform plat )
2017 {
21- Logger . Trace ( "Initialize HasRepository:{0}" , repo != null ) ;
22-
18+ //Logger.Trace("Initialize HasRepository:{0}", repo != null);
2319 repository = repo ;
20+ platform = plat ;
2421
2522 if ( repository != null )
2623 {
@@ -29,24 +26,15 @@ public static void Initialize(IRepository repo)
2926 }
3027 }
3128
32- private static void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
33- {
34- if ( ! lastLocksChangedEvent . Equals ( cacheUpdateEvent ) )
35- {
36- lastLocksChangedEvent = cacheUpdateEvent ;
37- locks = repository . CurrentLocks ;
38- }
39- }
40-
4129 public static string [ ] OnWillSaveAssets ( string [ ] paths )
4230 {
43- Logger . Trace ( "OnWillSaveAssets: [{0}]" , string . Join ( ", " , paths ) ) ;
31+ // Logger.Trace("OnWillSaveAssets: [{0}]", string.Join(", ", paths));
4432 return paths ;
4533 }
4634
4735 public static AssetMoveResult OnWillMoveAsset ( string oldPath , string newPath )
4836 {
49- Logger . Trace ( "OnWillMoveAsset:{0}->{1}" , oldPath , newPath ) ;
37+ // Logger.Trace("OnWillMoveAsset:{0}->{1}", oldPath, newPath);
5038
5139 var result = AssetMoveResult . DidNotMove ;
5240 if ( IsLocked ( oldPath ) )
@@ -62,22 +50,17 @@ public static AssetMoveResult OnWillMoveAsset(string oldPath, string newPath)
6250
6351 public static AssetDeleteResult OnWillDeleteAsset ( string assetPath , RemoveAssetOptions option )
6452 {
65- Logger . Trace ( "OnWillDeleteAsset:{0}" , assetPath ) ;
66-
67- if ( IsLocked ( assetPath ) )
68- {
69- return AssetDeleteResult . FailedDelete ;
70- }
71- return AssetDeleteResult . DidNotDelete ;
53+ //Logger.Trace("OnWillDeleteAsset:{0}", assetPath);
54+ return IsLocked ( assetPath ) ? AssetDeleteResult . FailedDelete : AssetDeleteResult . DidNotDelete ;
7255 }
7356
7457 public static bool IsOpenForEdit ( string assetPath , out string message )
7558 {
76- Logger . Trace ( "IsOpenForEdit:{0}" , assetPath ) ;
77-
78- if ( IsLocked ( assetPath ) )
59+ // Logger.Trace("IsOpenForEdit:{0}", assetPath);
60+ var lck = GetLock ( assetPath ) ;
61+ if ( lck . HasValue )
7962 {
80- message = "File is locked for editing!" ;
63+ message = "File is locked for editing by " + lck . Value . User ;
8164 return false ;
8265 }
8366 else
@@ -87,21 +70,38 @@ public static bool IsOpenForEdit(string assetPath, out string message)
8770 }
8871 }
8972
73+ private static void RepositoryOnLocksChanged ( CacheUpdateEvent cacheUpdateEvent )
74+ {
75+ if ( ! lastLocksChangedEvent . Equals ( cacheUpdateEvent ) )
76+ {
77+ lastLocksChangedEvent = cacheUpdateEvent ;
78+ locks = repository . CurrentLocks ;
79+ }
80+ }
81+
9082 private static bool IsLocked ( string assetPath )
9183 {
92- if ( repository != null )
93- {
84+ return GetLock ( assetPath ) . HasValue ;
85+ }
86+
87+ private static GitLock ? GetLock ( string assetPath )
88+ {
89+ GitLock ? gitLock = null ;
90+ if ( repository != null )
91+ {
9492 var repositoryPath = EntryPoint . Environment . GetRepositoryPath ( assetPath . ToNPath ( ) ) ;
95- var gitLock = locks . FirstOrDefault ( @lock => @lock . Path == repositoryPath ) ;
96- if ( ! gitLock . Equals ( GitLock . Default ) )
93+ var lck = locks . FirstOrDefault ( @lock => @lock . Path == repositoryPath ) ;
94+ if ( ! lck . Equals ( GitLock . Default ) )
9795 {
98- Logger . Trace ( "Lock found on: {0}" , assetPath ) ;
99-
100- //TODO: Check user and return true
96+ var user = platform . Keychain . Connections . FirstOrDefault ( ) ;
97+ if ( ! lck . User . Equals ( user ) )
98+ {
99+ gitLock = lck ;
100+ }
101+ //Logger.Trace("Lock found on: {0}", assetPath);
101102 }
102103 }
103-
104- return false ;
104+ return gitLock ;
105105 }
106106 }
107- }
107+ }
0 commit comments