A game about forced loneliness, made by TACStudios
at master 3.0 kB view raw
1using System.Collections.Generic; 2using System.Linq; 3 4using Codice.Client.BaseCommands; 5using Codice.CM.Common; 6using Unity.PlasticSCM.Editor.AssetUtils; 7 8namespace Unity.PlasticSCM.Editor 9{ 10 internal static class ProjectPackages 11 { 12 internal static bool ShouldBeResolvedFromPaths( 13 WorkspaceInfo wkInfo, List<string> updatedItems) 14 { 15 if (IsDynamicWorkspace(wkInfo)) 16 return true; 17 18 return updatedItems.Any(ShouldPathBeResolved); 19 } 20 21 internal static bool ShouldBeResolvedFromUpdateReport( 22 WorkspaceInfo wkInfo, List<string> updatedItems) 23 { 24 if (IsDynamicWorkspace(wkInfo)) 25 return true; 26 27 updatedItems = updatedItems.Select(GetPathFromUpdateReport).ToList(); 28 29 return updatedItems.Any(ShouldPathBeResolved); 30 } 31 32 internal static bool ShouldBeResolvedFromUpdateProgress( 33 WorkspaceInfo wkInfo, UpdateProgress progress) 34 { 35 if (progress == null) 36 return false; 37 38 if (IsDynamicWorkspace(wkInfo)) 39 return true; 40 41 return ShouldBeResolved(progress.AddedItems.Where(i => !i.IsDirectory)) 42 || ShouldBeResolved(progress.DeletedItems) 43 || ShouldBeResolved(progress.ChangedItems.Where(i => !i.IsDirectory)) 44 || ShouldBeResolved(progress.MovedItems); 45 } 46 47 static bool IsDynamicWorkspace(WorkspaceInfo wkInfo) 48 { 49 // We cannot obtain the updated items from a dynamic workspace, so for the moment, 50 // we'll force the Packages reimport for these kind of workspaces. 51 return Codice.CM.WorkspaceServer.IsDynamicWorkspace.Check(wkInfo); 52 } 53 54 static bool ShouldBeResolved(IEnumerable<UpdateProgress.UpdatedItem> items) 55 { 56 return items.Select(i => i.Path).Any(ShouldPathBeResolved) 57 || items.Any(i => i.IsDirectory); 58 } 59 60 static bool ShouldBeResolved(IEnumerable<UpdateProgress.UpdatedMovedItem> items) 61 { 62 return items.Select(i => i.DstPath).Any(ShouldPathBeResolved) 63 || items.Any(i => i.IsDirectory); 64 } 65 66 static bool ShouldPathBeResolved(string path) 67 { 68 return AssetsPath.IsPackagesRootElement(path) 69 || AssetsPath.IsScript(path); 70 } 71 72 static string GetPathFromUpdateReport(string item) 73 { 74 if (string.IsNullOrEmpty(item)) 75 return string.Empty; 76 77 // For full workspaces we expect to receive the updated items with format <{UPDATE_TYPE}:{ITEM_PATH}> 78 if (!item.StartsWith("<") || !item.EndsWith(">")) 79 return string.Empty; 80 81 int startIndex = item.IndexOf(":") + 1; 82 83 if (startIndex == 0) 84 return string.Empty; 85 86 int endIndex = item.Length - 1; 87 88 return item.Substring(startIndex, endIndex - startIndex); 89 } 90 } 91}