예제 #1
0
        public static bool EnsureFileCheckedOutInSourceControl(params string[] filePaths)
        {
#if PUBLIC_RELEASE
            return(true);
#else
            try {
                var conn = GetP4Connection();
                if (conn == null)
                {
                    return(false);
                }

                FileSpec[] filesToEdit = filePaths
                                         .Select(path => new FileSpec(null, null, new LocalPath(path), null))
                                         .ToArray();

                var options            = new EditCmdOptions(EditFilesCmdFlags.None, -1, null);
                IList <FileSpec> files = conn.Client.EditFiles(options, filesToEdit);

                return(true);
            } catch (Exception) {
                return(false);
            }
#endif // PUBLIC_RELEASE
        }
예제 #2
0
        public static List <string> FileOperation(List <string> filePathList, FileAction action)
        {
            IList <FileSpec> filesEdited = null;
            Perforce         server      = new Perforce();

            if (server.Enabled == false)
            {
                return(new List <string>());
            }

            try
            {
                server.DiscoverClient(GetFilePath(filePathList[0]));
                // connect to the server
                server.Connect();

                foreach (string filePath in filePathList)
                {
                    string   fixedFilePath = GetFilePath(filePath);
                    FileSpec fileToAdd     = new FileSpec(new ClientPath(fixedFilePath));

                    if (System.IO.File.Exists(fixedFilePath) == true)
                    {
                        EditCmdOptions options = new EditCmdOptions(EditFilesCmdFlags.None, 0, null);
                        // run the command with the current connection
                        if (action == FileAction.Add)
                        {
                            filesEdited = server.Repository.Connection.Client.AddFiles(options, fileToAdd);
                        }
                        else if (action == FileAction.Edit)
                        {
                            filesEdited = server.Repository.Connection.Client.EditFiles(options, fileToAdd);
                        }
                        else if (action == FileAction.Delete)
                        {
                            filesEdited = server.Repository.Connection.Client.DeleteFiles(options, fileToAdd);
                        }
                        else if (action == FileAction.Reverted)
                        {
                            filesEdited = server.Repository.Connection.Client.RevertFiles(options, fileToAdd);
                        }
                    }
                }
            }
            finally
            {
                server.Disconnect();
            }

            List <FileSpec> fileSpecList = new List <FileSpec>();

            if (filesEdited != null)
            {
                fileSpecList = new List <FileSpec>(filesEdited);
            }
            return(fileSpecList.Select(x => x.ClientPath.ToString()).ToList());
        }
예제 #3
0
        public void Checkout(FileSpec filespec, Changelist cl)
        {
            var options = new EditCmdOptions(EditFilesCmdFlags.None, cl?.Id ?? 0, null);
            var list    = this.Repository.Connection.Client.EditFiles(options, filespec);

            if (list != null)
            {
                foreach (var fn in list)
                {
                    //Logger.Log($"Checked out: {fn}");
                }
            }
        }