예제 #1
0
        /// <summary>
        /// Create a directory map from the output of a 'dirs' command
        /// </summary>
        /// <param name="pserver">Perforce server</param>
        /// <param name="Workspace">Active workspace, if any</param>
        /// <param name="parent">Parent directory for all the directories in the map</param>
        /// <param name="dirsOutput">Output from a 'dirs' command</param>
        /// <returns>THe list of P4Directories</returns>
        public static P4DirectoryMap FromDirsOutput(Repository repository, Client Workspace, P4Directory parent, IList <string> dirsOutput)
        {
            if (dirsOutput == null || dirsOutput.Count < 1)
            {
                return(null);
            }

            P4DirectoryMap value = new P4DirectoryMap();

            foreach (string path in dirsOutput)
            {
                P4Directory dir = new P4Directory(repository, Workspace, path, null, parent);
                value[dir.Name] = dir;
                dir.InDepot     = true;
                dir.InWorkspace = false;                 // won't know till later
            }
            return(value);
        }
예제 #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);
        }