Ejemplo n.º 1
0
        private void Init(Repository repository, Client nWorkspace, String nName, String nDepotPath, String nLocalPath, P4Directory parent)
        {
            if (repository == null)
            {
                throw new ArgumentNullException("server", "P4Directory requires a valid Repository");
            }
            if (String.IsNullOrEmpty(nDepotPath) && String.IsNullOrEmpty(nLocalPath))
            {
                throw new ArgumentNullException("nDepotPath/nLocalPath",
                                                "Must provide either the local path or path in the depot.");
            }

            _repository = repository;
            Workspace   = nWorkspace;
            name        = nName;
            depotPath   = nDepotPath;
            localPath   = nLocalPath;

            // We'll determine the unspecified paths when( if) we add files to a
            // directory, because the server will provide us with enough
            // information to accurately determine the correct paths, because
            // depending on the mapping, the structure of the two trees might
            // differ in the levels between the roots and the first directories
            // down ith tree containing files.

            //if( String.IsNullOrEmpty( nLocalPath ) && parent != null && !String.IsNullOrEmpty( parent.LocalPath ) )
            //{
            //    // see if we can determine the local directory if not specified
            //    localPath = String.Format( "{0}/{1}", parent.LocalPath, Path.GetFileName( depotPath ) );
            //}
            //if( String.IsNullOrEmpty( nDepotPath ) && parent != null && !String.IsNullOrEmpty( parent.DepotPath ) )
            //{
            //    // see if we can determine the depot directory if not specified
            //    depotPath = String.Format( "{0}/{1}", parent.DepotPath, Path.GetFileName( localPath ) );
            //}
            parentDirectory = parent;
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Expand the directory by filling in the list of child directories
        /// and file within the directory.
        /// </summary>
        /// <returns>false if an error prevented completion</returns>
        public bool Expand()
        {
            if (String.IsNullOrEmpty(depotPath))
            {
                return(false);
            }

            // if we have the depot path, get a list of the subdirectories from the depot
            if (!String.IsNullOrEmpty(depotPath))
            {
                IList <string> subdirs = _repository.GetDepotDirs(null, String.Format("{0}/*", depotPath));
                if ((subdirs != null) && (subdirs.Count > 0))
                {
                    subdirectories = P4DirectoryMap.FromDirsOutput(_repository, Workspace, this, subdirs);
                    foreach (P4Directory dir in subdirectories.Values)
                    {
                        dir.InDepot = true;
                    }
                }

                IList <FileMetaData> fileList = _repository.GetFileMetaData(null, FileSpec.DepotSpec(String.Format("{0}/*", depotPath)));
                // get a list of the files in the directory

                if (fileList != null)
                {
                    files = P4FileMap.FromFstatOutput(fileList);

                    // if the directory contains files from the depot, we can use
                    // the local path of one of those files to determine the local
                    // path for this directory
                    if ((String.IsNullOrEmpty(localPath)) && (files != null) && (files.Count > 0))
                    {
                        foreach (FileMetaData f in files.Values)
                        {
                            if ((f.LocalPath != null) && !String.IsNullOrEmpty(f.LocalPath.Path))
                            {
                                localPath = f.LocalPath.GetDirectoryName();
                                break;
                            }
                        }
                    }
                }
            }
            // if we have a workspace and a local path, match the files and
            // subdirectories in the depot with the files in the file system
            if ((!String.IsNullOrEmpty(localPath)) && (Workspace != null))
            {
                DirectoryInfo[] directoryList = null;
                FileInfo[]      fileList      = null;
                try
                {
                    DirectoryInfo di = new DirectoryInfo(localPath);

                    directoryList = di.GetDirectories();
                    fileList      = di.GetFiles();
                }
                catch (Exception ex)
                {
                    //LogFile.LogException( "Initializing Directory from Workspace", ex );
                }

                // get the subdirectories listed in the file and match them up
                // with the one in the list from the depot
                if ((directoryList != null) && (directoryList.Length > 0))
                {
                    foreach (DirectoryInfo di in directoryList)
                    {
                        string itemName = di.Name;
                        if (subdirectories.ContainsKey(itemName))
                        {
                            subdirectories[itemName].InWorkspace = true;
                        }
                        else
                        {
                            P4Directory subDir = new P4Directory(_repository, Workspace, itemName, null, di.FullName, parentDirectory);
                            subDir.InDepot           = false;
                            subDir.InWorkspace       = true;
                            subdirectories[itemName] = subDir;
                        }
                    }
                }

                // get the files listed in the subdirectory and match them up
                // with the one in the list from the depot
                if ((fileList != null) && (fileList.Length > 0))
                {
                    foreach (FileInfo fi in fileList)
                    {
                        string itemName = fi.Name;
                        if (files.ContainsKey(itemName) == false)
                        {
                            FileMetaData file = new FileMetaData();
                            file.LocalPath  = new LocalPath(fi.FullName);
                            file.DepotPath  = null;
                            file.FileSize   = fi.Length;
                            files[itemName] = file;
                        }
                    }
                }
            }
            return(true);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Create a new P4Directory
        /// </summary>
        /// <param name="server">Perforce Server</param>
        /// <param name="nWorkspace">Active workspace(client), can be null</param>
        /// <param name="nDepotPath">Full path in the depot, can be null</param>
        /// <param name="nLocalPath">Full path in the local file system, can be null</param>
        /// <param name="parent">Parent directory, can be null</param>
        /// <remarks>
        /// Either the depot or local path can be null, not both. The file name
        /// will be taken from the depot path if provided, otherwise from the
        /// local path
        /// </remarks>
        public P4Directory(Repository repository, Client nWorkspace, String nDepotPath, String nLocalPath, P4Directory parent)
        {
            String nName;

            if (!String.IsNullOrEmpty(nDepotPath))
            {
                nName = nDepotPath.Substring(nDepotPath.LastIndexOf('/') + 1);
            }
            else if (!String.IsNullOrEmpty(nLocalPath))
            {
                nName = nLocalPath.Substring(nLocalPath.LastIndexOf('/') + 1);
            }
            else
            {
                nName = "????";
            }
            Init(repository, nWorkspace, nName, nDepotPath, nLocalPath, parent);
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Create a new P4Directory
 /// </summary>
 /// <param name="server">Perforce Server</param>
 /// <param name="nWorkspace">Active workspace(client), can be null</param>
 /// <param name="nName">The name of the directory</param>
 /// <param name="nDepotPath">Full path in the depot, can be null</param>
 /// <param name="nLocalPath">Full path in the local file system, can be null</param>
 /// <param name="parent">Parent directory, can be null</param>
 /// <remarks>
 /// Either the depot or local path can be null, not both.
 /// </remarks>
 public P4Directory(Repository repository, Client nWorkspace, String nName, String nDepotPath, String nLocalPath, P4Directory parent)
 {
     Init(repository, nWorkspace, nName, nDepotPath, nLocalPath, parent);
 }