A game about forced loneliness, made by TACStudios
1using System; 2using System.Collections; 3using System.Collections.Generic; 4using System.IO; 5 6using Codice.Client.BaseCommands; 7using Codice.Client.Commands; 8using Codice.Client.Commands.CheckIn; 9using Codice.Client.Common; 10using Codice.Client.Common.Threading; 11using Codice.CM.Common; 12using Codice.CM.Common.Checkin.Partial; 13using Codice.Client.GameUI.Checkin; 14using PlasticGui; 15using PlasticGui.Help.Conditions; 16 17namespace Unity.PlasticSCM.Editor.Views.CreateWorkspace 18{ 19 internal static class PerformInitialCheckin 20 { 21 internal static void IfRepositoryIsEmpty( 22 WorkspaceInfo wkInfo, 23 string repository, 24 bool isGluonWorkspace, 25 IPlasticAPI plasticApi, 26 IProgressControls progressControls, 27 CreateWorkspaceView.ICreateWorkspaceListener createWorkspaceListener, 28 PlasticWindow plasticWindow) 29 { 30 RepositoryInfo repInfo = null; 31 bool isEmptyRepository = false; 32 33 progressControls.ShowProgress(string.Empty); 34 35 IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); 36 waiter.Execute( 37 /*threadOperationDelegate*/ delegate 38 { 39 RepositorySpec repSpec = new SpecGenerator(). 40 GenRepositorySpec(false, repository, CmConnection.Get().UnityOrgResolver); 41 42 repInfo = plasticApi.GetRepositoryInfo(repSpec); 43 44 isEmptyRepository = IsEmptyRepositoryCondition. 45 Evaluate(wkInfo, repSpec, plasticApi); 46 }, 47 /*afterOperationDelegate*/ delegate 48 { 49 progressControls.HideProgress(); 50 51 if (waiter.Exception != null) 52 { 53 DisplayException(progressControls, waiter.Exception); 54 return; 55 } 56 57 if (!isEmptyRepository) 58 { 59 plasticWindow.RefreshWorkspaceUI(); 60 return; 61 } 62 63 CheckinPackagesAndProjectSettingsFolders( 64 wkInfo, isGluonWorkspace, plasticApi, 65 progressControls, createWorkspaceListener); 66 }); 67 } 68 69 static void CheckinPackagesAndProjectSettingsFolders( 70 WorkspaceInfo wkInfo, 71 bool isGluonWorkspace, 72 IPlasticAPI plasticApi, 73 IProgressControls progressControls, 74 CreateWorkspaceView.ICreateWorkspaceListener createWorkspaceListener) 75 { 76 progressControls.ShowProgress(PlasticLocalization.GetString( 77 PlasticLocalization.Name.UnityInitialCheckinProgress)); 78 79 IThreadWaiter waiter = ThreadWaiter.GetWaiter(10); 80 waiter.Execute( 81 /*threadOperationDelegate*/ delegate 82 { 83 PerformCheckinPackagesAndProjectSettingsFolders( 84 wkInfo, isGluonWorkspace, plasticApi); 85 }, 86 /*afterOperationDelegate*/ delegate 87 { 88 progressControls.HideProgress(); 89 90 if (waiter.Exception != null && 91 !IsMergeNeededException(waiter.Exception)) 92 { 93 DisplayException(progressControls, waiter.Exception); 94 return; 95 } 96 97 createWorkspaceListener.OnWorkspaceCreated(wkInfo, isGluonWorkspace); 98 }); 99 } 100 101 internal static void PerformCheckinPackagesAndProjectSettingsFolders( 102 WorkspaceInfo wkInfo, 103 bool isGluonWorkspace, 104 IPlasticAPI plasticApi) 105 { 106 List<string> paths = new List<string> { 107 Path.Combine(wkInfo.ClientPath, "Packages"), 108 Path.Combine(wkInfo.ClientPath, "ProjectSettings") 109 }; 110 111 string comment = PlasticLocalization.GetString( 112 PlasticLocalization.Name.UnityInitialCheckinComment); 113 114 PerformAdd(paths, plasticApi); 115 116 PerformCheckinForMode(wkInfo, paths, comment, isGluonWorkspace); 117 } 118 119 static void PerformAdd( 120 List<string> paths, 121 IPlasticAPI plasticApi) 122 { 123 AddOptions options = new AddOptions(); 124 options.AddPrivateParents = true; 125 options.CheckoutParent = true; 126 options.Recurse = true; 127 options.SearchForPrivatePaths = true; 128 options.SkipIgnored = true; 129 130 IList checkouts; 131 plasticApi.Add(paths.ToArray(), options, out checkouts); 132 } 133 134 static void PerformCheckinForMode( 135 WorkspaceInfo wkInfo, 136 List<string> paths, 137 string comment, 138 bool isGluonWorkspace) 139 { 140 if (isGluonWorkspace) 141 { 142 new BaseCommandsImpl().PartialCheckin(wkInfo, paths, comment); 143 return; 144 } 145 146 CheckinParams ciParams = new CheckinParams(); 147 ciParams.paths = paths.ToArray(); 148 ciParams.comment = comment; 149 ciParams.time = DateTime.MinValue; 150 ciParams.flags = CheckinFlags.Recurse | CheckinFlags.ProcessSymlinks; 151 152 new BaseCommandsImpl().CheckIn(ciParams); 153 } 154 155 static bool IsMergeNeededException(Exception exception) 156 { 157 if (exception == null) 158 return false; 159 160 // Check the check-in exception for gluon 161 if (exception is CheckinConflictsException) 162 return true; 163 164 // Check the check-in exceptions for plastic 165 return exception is CmClientMergeNeededException; 166 } 167 168 static void DisplayException( 169 IProgressControls progressControls, 170 Exception ex) 171 { 172 ExceptionsHandler.LogException( 173 "PerformInitialCheckin", ex); 174 175 progressControls.ShowError( 176 ExceptionsHandler.GetCorrectExceptionMessage(ex)); 177 } 178 } 179}