using UnityEngine; using UnityEditor; using System; using System.Collections.Generic; using System.Linq; using System.Text; using Perforce.P4; using log4net; namespace P4Connect { public class ChangeManager { private static readonly ILog log = LogManager.GetLogger(typeof(ChangeManager)); private static ChangeManager _CurrentInstance = null; static int DEFAULT_CHANGE = -1; static Dictionary<int, Changelist> _changes = null; private ChangeManager() { } public static ChangeManager GetInstance { get { if (_CurrentInstance == null) { _CurrentInstance = new ChangeManager(); } return _CurrentInstance; } } public void Refresh() { if (Config.PerforceEnabled) { using (PerforceConnection con = new PerforceConnection()) { GetInstance.RefreshChangeLists(con); } // Engine.PerformOpenConnectionOperation(con => _CurrentInstance.RefreshChangeLists(con.Connection)); } } public void Refresh(int changeId) { if (Config.PerforceEnabled) { using (PerforceConnection con = new PerforceConnection()) { GetInstance.RefreshChange(con, changeId); } //Engine.PerformOpenConnectionOperation(con => _CurrentInstance.RefreshChange(con.Connection, changeId)); } } public void RefreshAll() { if (Config.PerforceEnabled) { using (PerforceConnection con = new PerforceConnection()) { GetInstance.RefreshChangeLists(con, true); } //Engine.PerformOpenConnectionOperation(con => _CurrentInstance.RefreshChangeLists(con.Connection, true)); } } public IList<Changelist> Changelists { get { if (_changes == null) { RefreshAll(); } return (_changes.Values.ToList()); } } public Changelist GetChangelist(int id) { if (_changes.ContainsKey(id)) { return (_changes[id]); } Debug.Break(); return null; } public static string ChangeIdToString(int id) { if (id <= DEFAULT_CHANGE) return "default"; return id.ToString(); } public IEnumerable<string> LocalOpenedFiles { get { //if (_changes == null || (! _changes.ContainsKey(DEFAULT_CHANGE))) //{ Refresh(); Refresh(DEFAULT_CHANGE); //} log.DebugFormat("Changelists: {0}", _changes.Count); IList<FileMetaData> files = _changes[DEFAULT_CHANGE].Files; if (files != null) { log.DebugFormat("file: {0}", files[0].ToString()); for (int i = 0; i < files.Count; ++i) { yield return Utils.ClientPathToLocalPath(files[i].ClientPath.Path); } } } } /// <summary> /// Helper method to check if a file is in the depot list /// </summary> /// <param name="arOpenedFiles"></param> /// <param name="match"></param> /// <returns></returns> public bool Contains(Predicate<FileMetaData> aMatch) { foreach (FileMetaData fmd in _changes[DEFAULT_CHANGE].Files) { if (aMatch(fmd)) return true; } return false; } // Collect all the Changelists and put them in the _changes dictionary void RefreshChangeLists(PerforceConnection p4conn, bool all = false) { if (Config.PerforceEnabled) { log.DebugFormat("RefreshChangeLists {0}", all.ToString()); _changes = new Dictionary<int, Changelist>(); // Create a placeholder for the default change Changelist dchange = new Changelist() { Description = "Default", OwnerName = Config.Username, ClientId = Config.Workspace }; dchange.initialize(p4conn.P4Connection); _changes.Add(DEFAULT_CHANGE, dchange); if (all) { RefreshChange(p4conn, DEFAULT_CHANGE); } // Now go get the numbered change lists ChangesCmdOptions opts = new ChangesCmdOptions(ChangesCmdFlags.FullDescription, null, 0, ChangeListStatus.Pending, null); IList<Changelist> allChanges = p4conn.P4Depot.GetChangelists(opts, null); if (allChanges != null) { foreach (var change in allChanges) { change.initialize(p4conn.P4Connection); _changes.Add(change.Id, change); if (all) { RefreshChange(p4conn, change.Id); } } } } } // Collect all the files and shelves for a specific changelist void RefreshChange( PerforceConnection p4conn, int changeId) { if (Config.PerforceEnabled) { log.DebugFormat("RefreshChange {0}", changeId); if (changeId <= DEFAULT_CHANGE) { RefreshDefaultChange(p4conn); return; } // Get files _changes[changeId].initialize(p4conn.P4Connection); // Get shelves too P4Command cmd = new P4Command(p4conn.P4Connection, "describe", true, "-S", changeId.ToString()); P4CommandResult results = cmd.Run(); if ((results.Success) && (results.TaggedOutput != null) && (results.TaggedOutput.Count > 0)) { _changes[changeId].FromChangeCmdTaggedOutput(results.TaggedOutput[0], true, string.Empty, false); // FIXME: the time zone is wrong. } } } void RefreshDefaultChange(PerforceConnection p4conn) { // Use "p4 opened -c default" to get the opened files in the default changelist Options opts = new Options(); opts["-c"] = "default"; opts["-C"] = Config.Workspace; IList<File> allOpenedFiles = p4conn.P4Depot.GetOpenedFiles(null, opts); if (allOpenedFiles != null) { _changes[DEFAULT_CHANGE].Files.Clear(); foreach (File fd in allOpenedFiles) { FileMetaData fmd = fd; _changes[DEFAULT_CHANGE].Files.Add(fmd); } } } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#10 | 16251 | Norman Morse | Update Dev branch to match reorganization in workshop | ||
#9 | 14236 | Norman Morse | update dev branch with GA.8 release files | ||
#8 | 13872 | Norman Morse | Update dev branch from GA.5 release | ||
#7 | 12863 | Norman Morse |
import from main Recently updated from internal Several Bugfixes logging clean up |
||
#6 | 12564 | Norman Morse |
Made ChangeManager into Static Class. Improved close window behavior for when connection is invalid Fixed localOpenFiles not updating on submit |
||
#5 | 12558 | Norman Morse | Integrate from main to dev | ||
#4 | 12501 | Norman Morse |
Rewrote Configuration Window. Provided buttons to read values and to save configurations. Removed P4Config settings, replaced with P4Config button and reports to Debug.Log() Removed SaveConfigurationAsset Setting, replaced with "Save as Asset" button. Made Connection Configuration read only while connected. Made dialogs disappear if they become disconnected during OnGui() Bumped Beta Value. |
||
#3 | 12480 | Norman Morse |
Fixed crash in logging. Worked on UI issues. Cleaned up some connection usage. Still looking for the problem with pending changes. |
||
#2 | 12473 | Norman Morse | More minor fixes to logging and config | ||
#1 | 12445 | Norman Morse |
Integrated log4net and nunit into P4Connect. Still need cleanup and debugging, good enough for dev tree Also added ChangeManager and ChangeLists Classes for future use with multiple changes. |