/// <summary> /// Generate a mapping of all scriptMappings in a project. /// Which means it creates a mapping between versions. /// </summary> /// <param name="oldIDs"></param> /// <param name="newIDs"></param> /// <returns></returns> public void MapAllClasses(List <ClassModel> oldIDs, List <ClassModel> newIDs, Action <List <ScriptMapping> > onComplete) { if (oldIDs == null || newIDs == null) { Debug.LogError("Old or new IDS are null. Cannot map without the old and new IDs"); } // List<ScriptMapping> unmergedScriptMappings = MapAllClasses(oldIDs, newIDs); List <ScriptMapping> unmergedScriptMappings = MapAllClassesRecursiveParent(oldIDs, newIDs); List <ScriptMapping> unmappedScriptMapping = unmergedScriptMappings .Where(script => script.HasBeenMapped == ScriptMapping.MappedState.NotMapped).ToList(); if (unmappedScriptMapping.Count == 0) { onComplete(unmappedScriptMapping); return; } ThreadUtility.RunMainTask(() => { MergeWizard mergeWizard = MergeWizard.CreateWizard(unmappedScriptMapping); mergeWizard.onComplete = (mergedScriptMapping) => { List <ScriptMapping> completed = unmappedScriptMapping.Merge(mergedScriptMapping); onComplete(completed); }; }); }
/// <see cref="Ankh.Commands.ICommandHandler.OnExecute" /> public void OnExecute(CommandEventArgs e) { List <SvnItem> svnItems = new List <SvnItem>(); ISvnStatusCache cache = e.GetService <ISvnStatusCache>(); switch (e.Command) { case AnkhCommand.ItemMerge: // TODO: Check for solution and/or project selection to use the folder instead of the file foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { svnItems.Add(item); } break; case AnkhCommand.ProjectMerge: foreach (SccProject p in e.Selection.GetSelectedProjects(false)) { IProjectFileMapper pfm = e.GetService <IProjectFileMapper>(); ISccProjectInfo info = pfm.GetProjectInfo(p); if (info != null && info.ProjectDirectory != null) { svnItems.Add(cache[info.ProjectDirectory]); } } break; case AnkhCommand.SolutionMerge: svnItems.Add(cache[e.GetService <IAnkhSolutionSettings>().ProjectRoot]); break; default: throw new InvalidOperationException(); } IEnumerable <string> selectedFiles = e.Selection.GetSelectedFiles(true); IAnkhOpenDocumentTracker tracker = e.GetService <IAnkhOpenDocumentTracker>(); using (DocumentLock lck = tracker.LockDocuments(selectedFiles, DocumentLockType.ReadOnly)) using (lck.MonitorChangesForReload()) using (MergeWizard dialog = new MergeWizard(e.Context, svnItems[0])) { DialogResult result = dialog.ShowDialog(e.Context); //result = uiService.ShowDialog(dialog); if (result == DialogResult.OK) { using (MergeResultsDialog mrd = new MergeResultsDialog()) { mrd.MergeActions = dialog.MergeActions; mrd.ResolvedMergeConflicts = dialog.ResolvedMergeConflicts; mrd.ShowDialog(e.Context); } } } }
/// <see cref="Ankh.Commands.ICommandHandler.OnExecute" /> public void OnExecute(CommandEventArgs e) { List<SvnItem> svnItems = new List<SvnItem>(); IFileStatusCache cache = e.GetService<IFileStatusCache>(); switch (e.Command) { case AnkhCommand.ItemMerge: // TODO: Check for solution and/or project selection to use the folder instead of the file foreach (SvnItem item in e.Selection.GetSelectedSvnItems(false)) { svnItems.Add(item); } break; case AnkhCommand.ProjectMerge: foreach (SvnProject p in e.Selection.GetSelectedProjects(false)) { IProjectFileMapper pfm = e.GetService<IProjectFileMapper>(); ISvnProjectInfo info = pfm.GetProjectInfo(p); if (info != null && info.ProjectDirectory != null) { svnItems.Add(cache[info.ProjectDirectory]); } } break; case AnkhCommand.SolutionMerge: svnItems.Add(cache[e.GetService<IAnkhSolutionSettings>().ProjectRoot]); break; default: throw new InvalidOperationException(); } IEnumerable<string> selectedFiles = e.Selection.GetSelectedFiles(true); IAnkhOpenDocumentTracker tracker = e.GetService<IAnkhOpenDocumentTracker>(); using (DocumentLock lck = tracker.LockDocuments(selectedFiles, DocumentLockType.ReadOnly)) using (lck.MonitorChangesForReload()) using (MergeWizard dialog = new MergeWizard(e.Context, svnItems[0])) { DialogResult result = dialog.ShowDialog(e.Context); //result = uiService.ShowDialog(dialog); if (result == DialogResult.OK) { using (MergeResultsDialog mrd = new MergeResultsDialog()) { mrd.MergeActions = dialog.MergeActions; mrd.ResolvedMergeConflicts = dialog.ResolvedMergeConflicts; mrd.ShowDialog(e.Context); } } } }
MigrateFields(string rootPath, string scenePath, List <ScriptMapping> scriptMappings, string[] lastSceneExport) { foreach (ScriptMapping script in scriptMappings) { if (script.HasBeenMapped == ScriptMapping.MappedState.NotChecked) { throw new NotImplementedException("Script has not been checked for mapping"); } } ScriptMapping[] unmappedScripts = scriptMappings .Where(field => field.HasBeenMapped == ScriptMapping.MappedState.NotMapped).ToArray(); if (unmappedScripts.Length > 0) { // Remove duplicate scripts List <ScriptMapping> scripts = unmappedScripts .GroupBy(field => field.newClassModel.FullName) .Select(group => group.First()).ToList(); EditorUtility.DisplayDialog("Merging fields necessary", "Could not merge all the fields to the class in the new project. You'll have to manually match old fields with the new fields", "Open merge window"); MergeWizard mergeWizard = MergeWizard.CreateWizard(scripts); mergeWizard.onComplete = (userAuthorizedList) => { MergingWizardCompleted(scriptMappings, rootPath, scenePath, lastSceneExport, userAuthorizedList); }; } else { MergingWizardCompleted(scriptMappings, rootPath, scenePath, lastSceneExport); } }
/// <summary> /// Parse the prefab. /// Change the guid's and fileID's on scripts and port the fields /// </summary> /// <param name="prefabFile"></param> /// <param name="originalAssetPath"></param> /// <param name="destinationAssetPath"></param> /// <param name="prefabs"></param> /// <param name="prefabGuid"></param> /// <exception cref="FormatException"></exception> /// <exception cref="NullReferenceException"></exception> public List <ScriptMapping> MigratePrefab(string prefabFile, string originalAssetPath, string destinationAssetPath, List <PrefabModel> prefabs, string prefabGuid, List <ScriptMapping> scriptMappings) { try { if (!prefabFile.EndsWith(".prefab")) { throw new FormatException("Could not parse prefab, not of type prefab, file : " + prefabFile); } Debug.Log("Started migration of prefab: " + prefabFile); if (BinaryUtility.IsBinaryFile(prefabFile)) { Debug.LogError("Could not parse file, since it's a binary file. Prefab file: " + prefabFile); return(scriptMappings); } PrefabModel currentPrefab = prefabs.FirstOrDefault(prefab => prefab.Guid == prefabGuid); if (currentPrefab == null) { Debug.LogError( "Could not find reference to the prefab with the guid. Might be a model file. Prefab: " + prefabFile); return(scriptMappings); } string originalProjectPath = ProjectPathUtility.getProjectPathFromFile(prefabFile); //Deserialize the old ID's List <ClassModel> oldIDs = Administration.Instance.oldIDsOverride ?? IDController.DeserializeIDs(originalProjectPath + constants.RelativeExportPath); if (oldIDs == null) { throw new NullReferenceException("Old IDs not set"); } //Deserialize the new ID's List <ClassModel> newIDs = Administration.Instance.newIDsOverride ?? IDController.DeserializeIDs(destinationAssetPath + constants.RelativeExportPath); if (newIDs == null) { throw new NullReferenceException("New IDs not set"); } string[] parsedPrefab = idController.TransformIDs(currentPrefab.Path, oldIDs, newIDs, ref scriptMappings); var unmappedScriptMappings = scriptMappings .Where(script => script.HasBeenMapped == ScriptMapping.MappedState.NotMapped).ToList(); if (unmappedScriptMappings.Count == 0) { parsedPrefab = fieldMappingController.MigrateFields(prefabFile, ref parsedPrefab, ref scriptMappings, originalAssetPath, destinationAssetPath); SavePrefabFile(parsedPrefab, currentPrefab, destinationAssetPath); } else { bool completed = false; ThreadUtility.RunMainTask(() => { MergeWizard wizard = MergeWizard.CreateWizard(unmappedScriptMappings); wizard.onComplete = mergedScriptMappings => { scriptMappings = scriptMappings.Merge(mergedScriptMappings); File.WriteAllText(destinationAssetPath + constants.RelativeScriptMappingPath, JsonConvert.SerializeObject(scriptMappings, constants.IndentJson)); ThreadUtility.RunTask(() => { parsedPrefab = fieldMappingController.MigrateFields(prefabFile, ref parsedPrefab, ref scriptMappings, originalAssetPath, destinationAssetPath); SavePrefabFile(parsedPrefab, currentPrefab, destinationAssetPath); }); completed = true; }; }); while (!completed) { Thread.Sleep(constants.THREAD_WAIT_TIME); } } } catch (Exception e) { Debug.LogError("Could not parse prefab: " + prefabFile + "\r\nException: " + e); } return(scriptMappings); }