using UnityEditor; using UnityEngine; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Perforce.P4; namespace P4Connect { public partial class Engine { /// <summary> /// This class is private because you shouldn't use it directly, talk to the Engine instead! /// </summary> class Operations { public static IList<FileSpec> RevertAndDelete(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, null); var result = con.P4Client.DeleteFiles(allFiles, null); Utils.LogFiles(result, "Deleting {0}"); return result; } public static IList<FileSpec> Delete(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); var result = con.P4Client.DeleteFiles(allFiles, null); Utils.LogFiles(result, "Deleting {0}"); return result; } public static IList<FileSpec> Revert(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { #if DEBUG log.Debug("Revert: file: "+ Logger.FileAndMetaListToString(list.ToList()) + " ignore: " + Logger.FileAndMetaListToString(ignoreList.ToList())); #endif AssetDatabase.StartAssetEditing(); var allFiles = NonNullFilesAndMeta(list); var allFilesMetaRaw = GetFileMetaData(con, allFiles, null); List<FileMetaData> allFilesMeta = new List<FileMetaData>(); Utils.GetMatchingMetaData(allFiles, allFilesMetaRaw, allFilesMeta); // Fix reverting a move/delete file, and while we're at it for (int i = 0; i < allFiles.Count; ++i) { if (allFilesMeta[i] != null && allFilesMeta[i].Action == FileAction.MoveDelete) { // See if the matching Move/Add is in the list var moveAddMetaList = GetFileMetaData(con, null, FileSpec.DepotSpec(allFilesMeta[i].MovedFile.Path)); if (moveAddMetaList != null && moveAddMetaList.Count > 0) { if (!allFiles.Any(f => f.LocalPath == moveAddMetaList[0].LocalPath)) { allFiles[i] = FileSpec.LocalSpec(moveAddMetaList[0].LocalPath.Path); } } } } // get directories from the list that need to be deleted //List<string> dirsToDelete = new List<string>(); //foreach (var fileAndMeta in list) //{ // if (fileAndMeta.Meta != null) // { // string assetMetaPath = Utils.LocalPathToAssetPath(fileAndMeta.Meta.LocalPath.Path); // string assetPath = Utils.AssetFromMeta(assetMetaPath); // if (Utils.IsDirectory(assetPath)) // { // FileState metaState = GetFileState(fileAndMeta.Meta, con); // if (metaState == FileState.MarkedForAdd || metaState == FileState.MarkedForAddMove) // { // // We should delete the folder once done // dirsToDelete.Add(Utils.AssetPathToFullPath(assetPath)); // } // } // } //} var result = con.P4Client.RevertFiles(allFiles, new RevertCmdOptions(RevertFilesCmdFlags.None, -1)); Utils.LogFiles(result, "Reverting {0}"); // Delete folders //foreach (string folder in dirsToDelete) //{ // try // { // System.IO.Directory.Delete(folder, true); // } // catch (System.IO.DirectoryNotFoundException) // { // // Ignore missing folders, they may have already been deleted // } //} AssetDatabase.StopAssetEditing(); //AssetDatabase.Refresh(); #if DEBUG log.Debug("...Revert results: " + Logger.FileSpecListToString(result)); #endif return result; } public static List<FileSpec> RevertIfUnchanged(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { List<FileSpec> assetsToRevert = new List<FileSpec>(); List<FileSpec> metasToRevertIfUnchanged = new List<FileSpec>(); foreach (var fileAndMeta in list) { if (fileAndMeta.File != null) assetsToRevert.Add(fileAndMeta.File); else metasToRevertIfUnchanged.Add(fileAndMeta.Meta); } // Revert orphan metas first List<FileSpec> revertedFiles = new List<FileSpec>(); if (metasToRevertIfUnchanged.Count > 0) { var res = con.P4Client.RevertFiles(metasToRevertIfUnchanged, new Options(RevertFilesCmdFlags.UnchangedOnly, -1)); if (res != null) revertedFiles.AddRange(res); } // Then assets if (assetsToRevert.Count > 0) { var res = con.P4Client.RevertFiles(assetsToRevert, new Options(RevertFilesCmdFlags.UnchangedOnly, -1)); if (res != null) revertedFiles.AddRange(res); } // Now revert metas associated with assets if (revertedFiles != null && revertedFiles.Count > 0) { List<FileSpec> metasToRevert = new List<FileSpec>(); for (int i = 0; i < revertedFiles.Count; ++i) { string metaPath = Utils.MetaFromAsset(revertedFiles[i].LocalPath.Path); var llist = list.ToList(); int metaIndex = llist.FindIndex(fm => { bool metaMatches = false; if (fm.Meta != null) { metaMatches = String.Compare(metaPath, fm.Meta.LocalPath.Path, StringComparison.InvariantCultureIgnoreCase) == 0; } return metaMatches; }); if (metaIndex != -1) { metasToRevert.Add(list[metaIndex].Meta); } } // Revert metas associated with assets if (metasToRevert.Count > 0) { var revertMetaResult = con.P4Client.RevertFiles(metasToRevert, new RevertCmdOptions(RevertFilesCmdFlags.None, -1)); if (revertMetaResult != null) revertedFiles.AddRange(revertMetaResult); } } if (revertedFiles.Count > 0) { Utils.LogFiles(revertedFiles, "Reverting (unchanged) {0}"); } return revertedFiles; } public static IList<FileSpec> RevertAndCheckout(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, null); var result = con.P4Client.EditFiles(allFiles, null); Utils.LogFiles(result, "Restoring {0}"); Utils.CheckForMissingFilesAndWarn(allFiles, result, "The following files could not be checked out:"); return result; } public static IList<FileSpec> RevertAndCheckoutNoOverwrite(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, new Options(RevertFilesCmdFlags.ServerOnly, -1)); var result = con.P4Client.EditFiles(allFiles, null); Utils.LogFiles(result, "Checking out {0} and keeping current modifications"); Utils.CheckForMissingFilesAndWarn(allFiles, result, "The following files could not be checked out:"); return result; } public static IList<FileSpec> Add(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); // Check for wildcards var wild = VerifyWildcards(list); var result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { AddFilesCmdFlags flags = AddFilesCmdFlags.None; if (wild == WildcardCheck.Force) { flags = AddFilesCmdFlags.KeepWildcards; } // Use the Server Typemap if (Config.UseTypemap) { if (wild == WildcardCheck.Force) { flags = AddFilesCmdFlags.KeepWildcards; } AddFilesCmdOptions options = new AddFilesCmdOptions(flags, -1, null); var added = con.P4Client.AddFiles(allFiles, options); if (added != null) result.AddRange(added); } else // Use the built-in typemap { // Use text or binary based on the editor settings List<FileSpec> textFiles = new List<FileSpec>(); List<FileSpec> binaryFiles = new List<FileSpec>(); List<FileSpec> unknownFiles = new List<FileSpec>(); Utils.FilterTextAndBinary(allFiles, textFiles, binaryFiles, unknownFiles); AddFilesCmdOptions optionsText = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Text, FileTypeModifier.None)); AddFilesCmdOptions optionsBinary = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Binary, FileTypeModifier.None)); AddFilesCmdOptions optionsUnknown = new AddFilesCmdOptions(flags, -1, null); if (textFiles.Count > 0) { var added = con.P4Client.AddFiles(textFiles, optionsText); if (added != null) result.AddRange(added); } if (binaryFiles.Count > 0) { var added = con.P4Client.AddFiles(binaryFiles, optionsBinary); if (added != null) result.AddRange(added); } if (unknownFiles.Count > 0) { var added = con.P4Client.AddFiles(unknownFiles, optionsUnknown); if (added != null) result.AddRange(added); } } Utils.LogFiles(result, "Adding {0}"); } return result; } public static List<FileSpec> RevertAndAddNoOverwrite(PerforceConnection con, List<FileAndMeta> list, List<FileAndMeta> moveToList) { var wild = VerifyWildcards(moveToList); List<FileSpec> result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { AddFilesCmdFlags flags = wild == WildcardCheck.Force ? AddFilesCmdFlags.KeepWildcards : AddFilesCmdFlags.None; for (int i = 0; i < list.Count; ++i) { if (list[i].File != null) { con.P4Client.RevertFiles(new Options(RevertFilesCmdFlags.ServerOnly, -1), list[i].File); AddFilesCmdOptions options = null; switch (Utils.FilterTextAndBinary(moveToList[i].File)) { case Utils.FilterTextAndBinaryResult.Binary: options = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Binary, FileTypeModifier.None)); break; case Utils.FilterTextAndBinaryResult.Text: options = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Text, FileTypeModifier.None)); break; case Utils.FilterTextAndBinaryResult.Unknown: options = new AddFilesCmdOptions(flags, -1, null); break; } var added = con.P4Client.AddFiles(options, moveToList[i].File); if (added != null) result.AddRange(added); } if (list[i].Meta != null) { con.P4Client.RevertFiles(new Options(RevertFilesCmdFlags.ServerOnly, -1), list[i].Meta); AddFilesCmdOptions options = null; switch (Utils.FilterTextAndBinary(moveToList[i].Meta)) { case Utils.FilterTextAndBinaryResult.Binary: options = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Binary, FileTypeModifier.None)); break; case Utils.FilterTextAndBinaryResult.Text: options = new AddFilesCmdOptions(flags, -1, new FileType(BaseFileType.Text, FileTypeModifier.None)); break; case Utils.FilterTextAndBinaryResult.Unknown: options = new AddFilesCmdOptions(flags, -1, null); break; } var added = con.P4Client.AddFiles(options, moveToList[i].Meta); if (added != null) result.AddRange(added); } } Utils.LogFiles(result, moveToList, "Moving new file {0} to {1}"); } return result; } public static IList<FileSpec> Checkout(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); IList<FileSpec> result = new List<FileSpec>(); if (allFiles.Count > 0) { result = con.P4Client.EditFiles(allFiles, null); Utils.LogFiles(result, "Checking out {0}"); Utils.CheckForMissingFilesAndWarn(allFiles, result, "The following files could not be checked out:"); } return result; } public static List<FileSpec> Move(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> moveToList) { var wild = VerifyWildcards(moveToList); List<FileSpec> result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { MoveFileCmdFlags flags = wild == WildcardCheck.Force ? MoveFileCmdFlags.ServerOnly | MoveFileCmdFlags.Force : MoveFileCmdFlags.ServerOnly; Options options = new Options(flags, -1, null); for (int i = 0; i < list.Count; ++i) { if (list[i].File != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].File); var moved = con.P4Client.MoveFiles(list[i].File, moveToList[i].File, options); if (moved != null) result.AddRange(moved); } if (list[i].Meta != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].Meta); var moved = con.P4Client.MoveFiles(list[i].Meta, moveToList[i].Meta, options); if (moved != null) result.AddRange(moved); } } Utils.LogFiles(result, moveToList, "Moving/Renaming {0} to {1}"); } return result; } public static List<FileSpec> RevertAndMove(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> moveToList) { var wild = VerifyWildcards(moveToList); List<FileSpec> result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { MoveFileCmdFlags flags = wild == WildcardCheck.Force ? MoveFileCmdFlags.ServerOnly | MoveFileCmdFlags.Force : MoveFileCmdFlags.ServerOnly; Options options = new Options(flags, -1, null); var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, null); for (int i = 0; i < list.Count; ++i) { if (list[i].File != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].File); var moved = con.P4Client.MoveFiles(list[i].File, moveToList[i].File, options); if (moved != null) result.AddRange(moved); } if (list[i].Meta != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].Meta); var moved = con.P4Client.MoveFiles(list[i].Meta, moveToList[i].Meta, options); if (moved != null) result.AddRange(moved); } } Utils.LogFiles(result, moveToList, "Moving/Renaming {0} to {1}"); } return result; } public static List<FileSpec> RevertAndMoveNoOverwrite(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> moveToList) { var wild = VerifyWildcards(moveToList); List<FileSpec> result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { MoveFileCmdFlags flags = wild == WildcardCheck.Force ? MoveFileCmdFlags.ServerOnly | MoveFileCmdFlags.Force : MoveFileCmdFlags.ServerOnly; Options options = new Options(flags, -1, null); var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, new Options(RevertFilesCmdFlags.ServerOnly, -1)); for (int i = 0; i < list.Count; ++i) { if (list[i].File != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].File); var moved = con.P4Client.MoveFiles(list[i].File, moveToList[i].File, options); if (moved != null) result.AddRange(moved); } if (list[i].Meta != null) { con.P4Client.EditFiles(new Options(EditFilesCmdFlags.ServerOnly, -1, null), list[i].Meta); var moved = con.P4Client.MoveFiles(list[i].Meta, moveToList[i].Meta, options); if (moved != null) result.AddRange(moved); } } Utils.LogFiles(result, moveToList, "Moving/Renaming {0} to {1}"); } return result; } public static List<FileSpec> MoveToNewLocation(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> moveToList) { var wild = VerifyWildcards(moveToList); List<FileSpec> result = new List<FileSpec>(); if (wild != WildcardCheck.Cancel) { MoveFileCmdFlags flags = wild == WildcardCheck.Force ? MoveFileCmdFlags.ServerOnly | MoveFileCmdFlags.Force : MoveFileCmdFlags.ServerOnly; Options options = new Options(flags, -1, null); for (int i = 0; i < list.Count; ++i) { if (list[i].File != null) { var moved = con.P4Client.MoveFiles(list[i].File, moveToList[i].File, options); if (moved != null) result.AddRange(moved); } if (list[i].Meta != null) { var moved = con.P4Client.MoveFiles(list[i].Meta, moveToList[i].Meta, options); if (moved != null) result.AddRange(moved); } } Utils.LogFiles(result, moveToList, "Moving/Renaming {0} to {1}"); } return result; } public static IList<FileSpec> GetLatest(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { log.Debug("getlatest: " + Logger.FileAndMetaListToString(list.ToList())); var allFiles = NonNullFilesAndMeta(list); var result = PerformGetLastestAndPostChecks(con, allFiles, null); return result; } public static IList<FileSpec> ForceGetLatest(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); var result = PerformGetLastestAndPostChecks(con, allFiles, new Options(SyncFilesCmdFlags.Force, -1)); return result; } public static IList<FileSpec> RevertAndGetLatest(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); con.P4Client.RevertFiles(allFiles, null); var result = PerformGetLastestAndPostChecks(con, allFiles, new Options(SyncFilesCmdFlags.Force, -1)); return result; } public static IList<FileSpec> Lock(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); var result = con.P4Client.LockFiles(allFiles, null); Utils.LogFiles(result, "Locking {0}"); return result; } public static IList<FileSpec> Unlock(PerforceConnection con, IList<FileAndMeta> list, IList<FileAndMeta> ignoreList) { var allFiles = NonNullFilesAndMeta(list); var result = con.P4Client.UnlockFiles(allFiles, null); Utils.LogFiles(result, "Unlocking {0}"); return result; } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 19640 | Liz Lam | "Forking branch Main of perforce-software-p4connect to liz_lam-p4connect." | ||
//guest/perforce_software/p4connect/main/src/P4Connect/P4Connect/P4Connect.Engine.Operations.cs | |||||
#2 | 16350 | Norman Morse |
Minor Code Clean Up Minor Documentation Clean Up Changed Post Processor callback to ignore directories Added option to use Server Typemap |
||
#1 | 16209 | Norman Morse | Move entire source tree into "main" branch so workshop code will act correctly. | ||
//guest/perforce_software/p4connect/src/P4Connect/P4Connect/P4Connect.Engine.Operations.cs | |||||
#6 | 15244 | Norman Morse |
Better Directory support in "add" "get latest" "refresh" and other commands. Improved Project Root detection Various Bug Fixes and Clean up |
||
#5 | 15079 | Norman Morse |
Rewrote AssetStatusCache to Cache AssetStatuses and FileMetaData Fixed Edge conditions on Engine Operations Change Debug output defaults. Will now Checkout files which request to be "added" but which already exist in perforce. Output P4Connect version to log on initialization. |
||
#4 | 13864 | Norman Morse | Final fixes for GA.5 release. | ||
#3 | 12512 | Norman Morse | Integrate from Dev branch, preparing for Beta3 release | ||
#2 | 12135 | Norman Morse |
Integrate dev branch changes into main. This code is the basiis of the 2.7 BETA release which provides Unity 5 compatibility |
||
#1 | 10940 | Norman Morse |
Inital Workshop release of P4Connect. Released under BSD-2 license |