public bool Run(PerforceConnection Perforce, TextWriter Log, out string ErrorMessage)
            {
                PerforceConnection PerforceClient = new PerforceConnection(Perforce.UserName, ClientName, Perforce.ServerAndPort);

                PerforceSpec ClientSpec;

                if (!PerforceClient.TryGetClientSpec(Perforce.ClientName, out ClientSpec, Log))
                {
                    ErrorMessage = String.Format("Unable to get client spec for {0}", ClientName);
                    return(false);
                }

                string ClientRoot = ClientSpec.GetField("Root");

                if (String.IsNullOrEmpty(ClientRoot))
                {
                    ErrorMessage = String.Format("Client '{0}' does not have a valid root directory.", ClientName);
                    return(false);
                }

                List <PerforceFileRecord> FileRecords = new List <PerforceFileRecord>();

                foreach (string Pattern in Patterns)
                {
                    string Filter = String.Format("//{0}/{1}", ClientName, Pattern);

                    List <PerforceFileRecord> WildcardFileRecords = new List <PerforceFileRecord>();
                    if (!PerforceClient.FindFiles(Filter, out WildcardFileRecords, Log))
                    {
                        ErrorMessage = String.Format("Unable to enumerate files matching {0}", Filter);
                        return(false);
                    }

                    FileRecords.AddRange(WildcardFileRecords);
                }

                string ClientPrefix = ClientRoot + Path.DirectorySeparatorChar;

                Paths = new List <string>();
                foreach (PerforceFileRecord FileRecord in FileRecords)
                {
                    if (FileRecord.ClientPath.StartsWith(ClientPrefix, StringComparison.InvariantCultureIgnoreCase))
                    {
                        Paths.Add(FileRecord.ClientPath.Substring(ClientRoot.Length).Replace(Path.DirectorySeparatorChar, '/'));
                    }
                }

                ErrorMessage = null;
                return(true);
            }
Пример #2
0
        public bool GetActiveStream(out string StreamName, TextWriter Log)
        {
            PerforceSpec ClientSpec;

            if (TryGetClientSpec(ClientName, out ClientSpec, Log))
            {
                StreamName = ClientSpec.GetField("Stream");
                return(StreamName != null);
            }
            else
            {
                StreamName = null;
                return(false);
            }
        }
Пример #3
0
        private void EventDoWork( object sender, DoWorkEventArgs e )
        {
            List<string> clients = P4Shell.GetClients();

            if( this.listBoxClientSpecs.InvokeRequired )
            {
                this.listBoxClientSpecs.Invoke( new AddItemsDelegate( this.AddItems ), new object[] { clients } );
            }
            else
            {
                AddItems( clients );
            }

            for( int ii=0; ii<clients.Count; ++ii )
            {
                if( m_BackgroundWorker.CancellationPending )
                {
                    e.Cancel = true;
                    break;
                }

                string		client		= clients[ii];
                ClientSpec	clientSpec	= new ClientSpec( client );

                if( P4Shell.GetClientSpec( client, ref clientSpec ) )
                {
                    if( clientSpec.Owner != P4Shell.User )
                    {
                        if( this.listBoxClientSpecs.InvokeRequired )
                        {
                            this.listBoxClientSpecs.Invoke( new RemoveItemDelegate( this.RemoveItem ), new object[] { clientSpec.Client } );
                        }
                        else
                        {
                            RemoveItem( clientSpec.Client );
                        }
                    }
                }

                float progress = ii / (float)clients.Count;
                m_BackgroundWorker.ReportProgress((int)(progress * 100));
            }
        }
Пример #4
0
        public static List<ClientSpec> GetClientSpecs()
        {
            List<ClientSpec> clientSpecList = new List<ClientSpec>();

            List<string> clientList = P4Shell.GetClients();

            foreach( string client in clientList )
            {
                ClientSpec clientSpec = new ClientSpec( client );

                if( GetClientSpec( client, ref clientSpec ) )
                {
                    clientSpecList.Add( clientSpec );
                }
            }

            return clientSpecList;
        }
Пример #5
0
        public static bool GetClientSpec( string client, ref ClientSpec clientSpec )
        {
            Execute( string.Format( "client -o {0}", client ), null );

            if( m_Error.Length > 0 )
                return false;

            string[] output = m_Output.Split( new string[]{"\r\n"}, StringSplitOptions.None );

            for( int lineIndex=0; lineIndex<output.Length; ++lineIndex )
            {
                string line = output[lineIndex];

                if( line.Length == 0 )
                    continue;

                if( line.StartsWith( "#" ) )
                    continue;

                if( line.StartsWith( "Update:" ) )
                {
                    clientSpec.UpdateDate = line.Substring( line.IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "Access:" ) )
                {
                    clientSpec.AccessDate = line.Substring( line.IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "Owner:" ) )
                {
                    clientSpec.Owner = line.Substring( line.IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "Host:" ) )
                {
                    clientSpec.Host = line.Substring( line.IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "Description:" ) )
                {
                    // The next line holds our description.
                    // Currently we assume a 1 line description.
                    ++lineIndex;
                    clientSpec.Description = output[lineIndex].Substring( output[lineIndex].IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "Root:" ) )
                {
                    clientSpec.Root = line.Substring( line.IndexOf( '\t' ) ).Trim();
                }
                else if( line.StartsWith( "Options:" ) )
                {
                    string[] options = line.Substring( line.IndexOf( '\t' ) + 1 ).Split( new char[]{ ' ' } );

                    clientSpec.AllWrite		= !options[0].StartsWith( "no" );
                    clientSpec.Clobber		= !options[1].StartsWith( "no" );
                    clientSpec.Compress		= !options[2].StartsWith( "no" );
                    clientSpec.Locked		= !options[3].StartsWith( "un" );
                    clientSpec.ModTime		= !options[4].StartsWith( "no" );
                    clientSpec.RmDir		= !options[5].StartsWith( "no" );
                }
                else if( line.StartsWith( "LineEnd:" ) )
                {
                    clientSpec.LineEnd = line.Substring( line.IndexOf( '\t' ) + 1 );
                }
                else if( line.StartsWith( "View:" ) )
                {
                    // The following lines hold our views.
                    int viewCount = 0;
                    while( line.Length > 0 )
                    {
                        ++lineIndex;
                        line = output[lineIndex];

                        clientSpec.View.Add( line.Trim() );
                        ++viewCount;
                    }
                }
            }

            return true;
        }