using UnityEditor; using UnityEngine; using Perforce.P4; using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace P4Connect { public class OpenedConnection { public PerforceConnection Connection { get { return _Connection; } } public IList Files { get { return _Files; } } // Give read-only access to the server we're connected to public Server P4Server { get { return _Connection.P4Server; } } // Give read-only access to the current depot public Repository P4Depot { get { return _Connection.P4Depot; } } // Give read-only access to the current connection public Connection P4Connection { get { return _Connection.P4Depot.Connection; } } // Give read-only access to the current client public Client P4Client { get { return _Connection.P4Depot.Connection.Client; } } public IEnumerable LocalOpenedFiles { get { if (_Files != null) { for (int i = 0; i < _Files.Count; ++i) { yield return Utils.ClientPathToLocalPath(_Files[i].ClientPath.Path); } } } } PerforceConnection _Connection; List _Files; public OpenedConnection(PerforceConnection aOpenedConnection) { _Connection = aOpenedConnection; Options opts = new Options(); opts["-c"] = "default"; opts["-C"] = Config.Workspace; IList allOpenedFiles = aOpenedConnection.P4Depot.GetOpenedFiles(null, opts); if (allOpenedFiles != null) { _Files = new List(allOpenedFiles); } else { _Files = new List(); } } /// /// Helper method to check if a file is in the depot list /// /// /// /// public bool Contains(Predicate aMatch) { if (Files == null) { return false; } else { foreach (File file in Files) { if (aMatch(file)) return true; } return false; } } } }