Example #1
0
    /// <summary>
    /// 设置文件夹下所有的可提交的文件
    /// </summary>
    /// <param name="files"></param>
    public void SetSVNToolFolderNeedSyncFoldersAndFiles(List <SVNToolPath> paths)
    {
        existFildOrFolderHasStatus = false;

        if (paths.Count == 0)
        {
            return;
        }

        existFildOrFolderHasStatus = true;

        List <SVNToolFile>   newFiles   = new List <SVNToolFile>();
        List <SVNToolFolder> newFolders = new List <SVNToolFolder>();

        existNewFileOrFolder = false;

        // 判断路径是文件还是文件夹
        foreach (SVNToolPath toolPath in paths)
        {
            if (toolPath.pathType == EnumSVNToolPathType.NO_CONTROL)
            {
                existNewFileOrFolder = true;
                continue;
            }

            String s = toolPath.path;
            if (s.IndexOf('.', s.LastIndexOf('/')) > -1)
            {
                newFiles.Add(new SVNToolFile(s));
            }
            else
            {
                existNewFileOrFolder = true;
                newFolders.Add(new SVNToolFolder(s));
            }
        }

        contentNeedSyncFiles   = newFiles;
        contentNeedSyncFolders = newFolders;

        if (contentNeedSyncFiles.Count > 0)
        {
            StringBuilder stringBuilder = new StringBuilder();
            foreach (SVNToolFile file in contentNeedSyncFiles)
            {
                file.CanBeCommit = true;
                stringBuilder.Append(file.path).Append(" ");
            }

            String[] resultFilesInfo = UESvnOperation.GetSvnOperation().ShowFileUrl(stringBuilder.ToString()).Split('\n');
            for (Int32 i = 0; i < contentNeedSyncFiles.Count; i++)
            {
                contentNeedSyncFiles[i].SyncFileSVNURL(resultFilesInfo[i]);
            }
        }
        else
        {
            openFolder = false;
        }
    }
    private void CommitFoldersAndFiles()
    {
        Boolean ifShowLog = false;

        StringBuilder pathBuilder = new StringBuilder();

        // 提交所有文件
        foreach (SVNToolPrefab prefab in storedPrefabs)
        {
            if (!prefab.ifSelected)
            {
                continue;
            }

            foreach (SVNToolFile file in prefab.contentFilePath)
            {
                if (SVNToolUtil.GetSVNToolFileStateJob(file.path))
                {
                    pathBuilder.Append(file.path.Trim()).Append(" ");
                }
            }
        }

        if (!String.IsNullOrEmpty(pathBuilder.ToString()))
        {
            ifShowLog = true;
            UESvnOperation.GetSvnOperation().CommitFile(pathBuilder.ToString());
        }

        // 提交所有文件夹
        foreach (SVNToolPrefab prefab in storedPrefabs)
        {
            if (!prefab.ifSelected)
            {
                continue;
            }

            foreach (SVNToolFolder folder in prefab.contentFolderPath)
            {
                folder.SetSVNToolFolderNeedSyncFoldersAndFiles(SVNToolUtil.GetNeedCommitSVNToolFileList(folder.path));

                if (folder.existFildOrFolderHasStatus)
                {
                    ifShowLog = true;
                    UESvnOperation.GetSvnOperation().CommitFile(folder.path);
                }
            }
        }

        // 如果存在可提交的内容,则展示日志
        if (ifShowLog)
        {
            UESvnOperation.GetSvnOperation().ShowCommitLog(Application.dataPath);
        }

        Close();
    }
Example #3
0
 public void SyncFileSVNURL(String url = "")
 {
     if (String.IsNullOrEmpty(url))
     {
         // 获取SVN中URL的路径
         svnURL = UESvnOperation.GetSvnOperation().ShowFileUrl(path).Trim();
     }
     else
     {
         svnURL = url.Trim();
     }
 }
    private void SVNToolWindowWriteFileField(SVNToolFile file)
    {
        // 浏览模式 - 仅展示需同步文件
        if (file.GetSVNToolFileCurrentSyncState() == EnumSVNToolFileNeedSyncState.SELECTED_NEED_COMMIT)
        {
            SetSVNToolFileCanBeCommitColor();
        }
        else if (file.GetSVNToolFileCurrentSyncState() == EnumSVNToolFileNeedSyncState.NEED_COMMIT_WITHOUT_SEELCTED)
        {
            SetSVNToolFileNeedSelectedColor();
        }

        Boolean preSelected = file.ifSelected;

        file.ifSelected = GUILayout.Toggle(file.ifSelected, "", GUILayout.Width(20));
        if (file.ifSelected != preSelected)
        {
            ifChooseDataDirty = true;
            OnChangeSelectSVNToolFile(file);
            SaveSVNToolPrefabs();        // 保存配置
            GUI.FocusControl("zero");    // 取消聚焦,防止选中“当前已选择”后不刷新
        }

        EditorGUILayout.LabelField(file.name, GUILayout.MinWidth(m_RightPathTextLength));
        GUILayout.FlexibleSpace();

        if (GUILayout.Button("Find", GUILayout.Width(40)))
        {
            UESvnOperation.GetSvnOperation().ShowFileInExplorer(file.path);
        }
        if (GUILayout.Button("完整路径", GUILayout.Width(70)))
        {
            ShowNotification(new GUIContent(file.svnURL));
        }
        if (GUILayout.Button("查看差异", GUILayout.Width(70)))
        {
            UESvnOperation.GetSvnOperation().DiffFile(file.path);
        }

        SetDefaultSVNToolBackgroundColor();
    }
Example #5
0
    /// <summary>
    /// 获取文件夹路径下所有可提交的文件
    /// </summary>
    /// <param name="path"></param>
    /// <returns></returns>
    public static List <SVNToolPath> GetNeedCommitSVNToolFileList(String path)
    {
        List <SVNToolPath> res        = new List <SVNToolPath>();
        String             commandRes = UESvnOperation.GetSvnOperation().FolderStatus(path);

        if (String.IsNullOrEmpty(commandRes))
        {
            return(res);
        }

        // 拆解SVN结果
        String[] resList = commandRes.Split('\n');
        foreach (string s in resList)
        {
            // 如果字符串中的数据为修改后的
            if (s.Length > 8)
            {
                EnumSVNToolPathType pathType = EnumSVNToolPathType.NO_CONTROL;
                if (s.StartsWith("?"))
                {
                    pathType = EnumSVNToolPathType.NO_CONTROL;
                }
                else if (s.StartsWith("!"))
                {
                    pathType = EnumSVNToolPathType.DEL;
                }
                else
                {
                    pathType = EnumSVNToolPathType.MODIFY;
                }
                res.Add(new SVNToolPath(s.Substring(8).Replace('\\', '/').Trim(), pathType));
            }
        }

        return(res);
    }
    private void SetSVNToolPrefabGUI()
    {
        EditorGUILayout.BeginHorizontal(GUILayout.Height(500));

        #region  择预设

        EditorGUILayout.BeginVertical(GUI.skin.box, GUILayout.Width(200));

        // 顶部按钮
        EditorGUILayout.BeginHorizontal(GUILayout.Width(270));

        EditorGUILayout.LabelField("预设选择", GUILayout.Width(100));
        GUILayout.FlexibleSpace();
        if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
        {
            if (GUILayout.Button("注销", GUILayout.Width(50)))
            {
                PlayerPrefs.DeleteKey(SVN_TOOL_USER_ID_PREF_NAME);
                m_SvnToolUserID  = null;
                m_FinishReadData = false;
            }

            if (GUILayout.Button("新增", GUILayout.Width(50)))
            {
                Int32 largeID = 1;
                // 拿到最大的ID
                foreach (SVNToolPrefab storedPrefab in storedPrefabs)
                {
                    largeID = Math.Max(largeID, storedPrefab.ID);
                }

                m_SelectedPrefab = new SVNToolPrefab(largeID + 1);
                storedPrefabs.Add(m_SelectedPrefab);
            }

            GUI.enabled = SetIfCurrentActionEnableBySelected();
            if (GUILayout.Button("删除", GUILayout.Width(50)))
            {
                storedPrefabs.Remove(m_SelectedPrefab);
                m_SelectedPrefab = null;
            }

            GUI.enabled = true;

            if (GUILayout.Button("保存", GUILayout.Width(50)))
            {
                SaveSVNToolPrefabs();
                // 刷新状态
                InitSyncSVNToolPrefabStatus();
            }
        }
        else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW)
        {
            if (GUILayout.Button("开启配置", GUILayout.Width(70)))
            {
                m_CurrentEditState = EnumSVNToolWindowEditState.EDIT;
                if (null != m_SelectedPrefab)
                {
                    foreach (SVNToolFolder folder in m_SelectedPrefab.contentFolderPath)
                    {
                        folder.openFolder = false;
                    }
                }
            }
        }

        EditorGUILayout.EndHorizontal();

        // 展示预设内容列表
        leftScrollPos = EditorGUILayout.BeginScrollView(leftScrollPos, GUI.skin.box);
        {
            for (int i = 0; i < storedPrefabs.Count; i++)
            {
                SVNToolPrefab currentPrefab = storedPrefabs[i];
                if (null != m_SelectedPrefab && m_SelectedPrefab.ID == currentPrefab.ID)
                {
                    SetOnSelectedBackgroundColor();
                }

                EditorGUILayout.BeginHorizontal(GUI.skin.box);
                {
                    GUI.backgroundColor = Color.white;

                    Boolean preSelected = currentPrefab.ifSelected;
                    Boolean ifChanged   = false;
                    currentPrefab.ifSelected = GUILayout.Toggle(currentPrefab.ifSelected, "同步", GUILayout.Width(40));
                    if (preSelected != currentPrefab.ifSelected)
                    {
                        // 如果选择了不同的同步规则,则保存
                        SaveSVNToolPrefabs();
                        // 刷新已选Data
                        ifChooseDataDirty = true;
                        ifChanged         = true;

                        if (currentPrefab.ifSelected)
                        {
                            DoSyncSVNToolPrefabStatus(currentPrefab, false);
                        }
                    }

                    // 预设名
                    if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
                    {
                        currentPrefab.name = EditorGUILayout.TextField(currentPrefab.name, GUILayout.Width(120));
                    }
                    else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW)
                    {
                        EditorGUILayout.LabelField(currentPrefab.name, GUILayout.Width(120));
                    }

                    if (ifChanged)
                    {
                        GUI.FocusControl("zero");
                    }

                    GUILayout.FlexibleSpace();
                    if (null != currentPrefab.name && currentPrefab.name.Equals("Global") &&
                        null != m_SvnToolUserID &&
                        !m_SvnToolUserID.Equals("Global") &&
                        m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
                    {
                        if (GUILayout.Button("恢复", GUILayout.Width(40)))
                        {
                            DoRestoreGlobalPrefab(currentPrefab);
                        }
                    }
                    if (GUILayout.Button("查看", GUILayout.Width(40)))
                    {
                        SelectCurrentSVNToolPrefab(currentPrefab);
                    }
                }

                EditorGUILayout.EndHorizontal();

                SetDefaultSVNToolBackgroundColor();
            }
        }
        EditorGUILayout.EndScrollView();
        EditorGUILayout.EndVertical();

        #endregion

        #region 预设与配置主体

        EditorGUILayout.BeginVertical(GUI.skin.box);

        EditorGUILayout.BeginHorizontal();

        GUIStyle redGUISkin = new GUIStyle();
        redGUISkin.fontSize         = 14;
        redGUISkin.normal.textColor = Color.red;
        if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
        {
            EditorGUILayout.LabelField("预设配置");
            GUILayout.Label(null == m_SelectedPrefab ? "需要左侧选择目标预设" : "拖拽文件/文件夹到下方即可添加", redGUISkin);
        }
        else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW)
        {
            EditorGUILayout.LabelField("配置文件");
            GUILayout.FlexibleSpace();
            if (CheckIfSelectedPrefabSyncing())
            {
                GUILayout.Label("同步中...", redGUISkin);
            }

            GUI.enabled = !CheckIfSelectedPrefabSyncing();
            if (GUILayout.Button("刷新同步"))
            {
                m_SelectedPrefab.initedFileStatus = false;
                DoSyncSVNToolPrefabStatus(m_SelectedPrefab);
            }

            GUI.enabled = true;
        }
        EditorGUILayout.EndHorizontal();

        // 设定ScrollView为一个Control对象
        GUI.SetNextControlName("text:");
        rightScrollPos = EditorGUILayout.BeginScrollView(rightScrollPos, GUI.skin.box);
        {
            if (null != m_SelectedPrefab)
            {
                // 当前是否在进行同步
                if (CheckIfSelectedPrefabSyncing())
                {
                    GUILayout.Label("加载中");
                }
                else
                {
                    #region 显示文件夹

                    for (int i = 0; i < m_SelectedPrefab.contentFolderPath.Count; i++)
                    {
                        SVNToolFolder folder = m_SelectedPrefab.contentFolderPath[i];
                        EditorGUILayout.BeginVertical(GUI.skin.box);
                        {
                            EditorGUILayout.BeginHorizontal();
                            {
                                // 配置状态
                                if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
                                {
                                    EditorGUILayout.LabelField("【文件夹】\t" + folder.name, GUILayout.Width(m_RightPathTextLength));
                                    GUILayout.FlexibleSpace();
                                    if (GUILayout.Button("打开文件夹", GUILayout.Width(100)))
                                    {
                                        UESvnOperation.GetSvnOperation().ShowFileInExplorer(folder.path);
                                    }
                                    if (GUILayout.Button("Del", GUILayout.Width(30)))
                                    {
                                        m_SelectedPrefab.contentFolderPath.Remove(folder);
                                    }
                                }
                                else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW)
                                {
                                    GUI.enabled = folder.contentNeedSyncFiles.Count > 0;
                                    if (folder.existNewFileOrFolder)
                                    {
                                        SetSVNToolFolderSelectedParyColor();
                                        if (GUILayout.Button("存在新建,以及文件夹操作,请点击此处", GUILayout.Width(220)))
                                        {
                                            UESvnOperation.GetSvnOperation().CommitFile(folder.path);
                                            InitSyncSVNToolPrefabStatus();
                                        }
                                        SetDefaultSVNToolBackgroundColor();
                                    }

                                    // 浏览模式 - 仅展示需同步文件
                                    if (folder.GetSVNToolFileCurrentSyncState() == EnumSVNToolFolderNeedSyncState.SELECTED_ALL)
                                    {
                                        SetSVNToolFileCanBeCommitColor();
                                    }
                                    else if (folder.GetSVNToolFileCurrentSyncState() == EnumSVNToolFolderNeedSyncState.SELECTED_PART)
                                    {
                                        SetSVNToolFolderSelectedParyColor();
                                    }

                                    Int32 selectedFolderFileCount = folder.GetTotalSelectedSVNToolFiles().Count;

                                    if (GUILayout.Button(selectedFolderFileCount == 0 ? "全选" : "取消选择", GUILayout.Width(60)))
                                    {
                                        // 全选
                                        if (selectedFolderFileCount == 0)
                                        {
                                            foreach (SVNToolFile file in folder.contentNeedSyncFiles)
                                            {
                                                file.ifSelected = true;
                                            }
                                        }
                                        else
                                        {
                                            foreach (SVNToolFile file in folder.contentNeedSyncFiles)
                                            {
                                                file.ifSelected = false;
                                            }
                                        }

                                        ifChooseDataDirty = true;
                                        GUI.FocusControl("zero");    // 取消聚焦,防止选中“当前已选择”后不刷新
                                    }

                                    EditorGUILayout.LabelField("已选 " + selectedFolderFileCount + "/" + folder.contentNeedSyncFiles.Count, GUILayout.Width(70));
                                    SetDefaultSVNToolBackgroundColor();
                                    folder.openFolder = EditorGUILayout.Foldout(folder.openFolder, folder.name, true);

                                    GUI.enabled = true;

                                    if (GUILayout.Button("打开文件夹", GUILayout.Width(100)))
                                    {
                                        UESvnOperation.GetSvnOperation().ShowFileInExplorer(folder.path);
                                    }
                                }
                            }
                            EditorGUILayout.EndHorizontal();

                            if (folder.openFolder)
                            {
                                EditorGUILayout.BeginVertical();
                                {
                                    //折叠开关开启时需要显示的内容
                                    foreach (SVNToolFile file in folder.contentNeedSyncFiles)
                                    {
                                        EditorGUILayout.BeginHorizontal(GUI.skin.box);
                                        {
                                            SVNToolWindowWriteFileField(file);
                                        }
                                        EditorGUILayout.EndHorizontal();
                                    }
                                }
                                EditorGUILayout.EndVertical();
                            }
                        }
                        EditorGUILayout.EndVertical();
                    }

                    #endregion

                    #region 显示文件

                    for (int i = 0; i < m_SelectedPrefab.contentFilePath.Count; i++)
                    {
                        SVNToolFile file = m_SelectedPrefab.contentFilePath[i];
                        if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW && !file.CanBeCommit)
                        {
                            continue;
                        }

                        EditorGUILayout.BeginHorizontal(GUI.skin.box);
                        {
                            // 编辑模式
                            if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
                            {
                                EditorGUILayout.LabelField("【 文 件 】\t" + file.name, GUILayout.Width(m_RightPathTextLength));
                                GUILayout.FlexibleSpace();
                                if (GUILayout.Button("Del", GUILayout.Width(30)))
                                {
                                    m_SelectedPrefab.contentFilePath.Remove(file);
                                }
                            }
                            // 浏览模式
                            else if (m_CurrentEditState == EnumSVNToolWindowEditState.VIEW)
                            {
                                SVNToolWindowWriteFileField(file);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    #endregion
                }
            }
        }
        EditorGUILayout.EndScrollView();

        #region 添加拖拽事件

        var rect = GUILayoutUtility.GetLastRect();
        //如果鼠标正在拖拽中或拖拽结束时,并且鼠标所在位置在文本输入框内
        if ((Event.current.type == EventType.DragUpdated || Event.current.type == EventType.DragPerform) &&
            m_CurrentEditState == EnumSVNToolWindowEditState.EDIT &&
            null != m_SelectedPrefab &&
            rect.Contains(Event.current.mousePosition)
            )
        {
            //改变鼠标的外表
            DragAndDrop.visualMode = DragAndDropVisualMode.Generic;
            if (Event.current.type == EventType.DragPerform &&
                DragAndDrop.paths != null &&
                DragAndDrop.paths.Length > 0
                )
            {
                AddNewSVNToolPath(DragAndDrop.paths);
                // 保存
                //                SaveSVNToolPrefabs();
            }
        }

        #endregion

        EditorGUILayout.EndVertical();

        #endregion

        EditorGUILayout.EndHorizontal();

        #region 结果列表

        if (CheckIfSelectedPrefabSyncing())
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                GUILayout.Label("加载中");
            }
            EditorGUILayout.EndVertical();
        }
        else if (m_CurrentEditState == EnumSVNToolWindowEditState.EDIT)
        {
            EditorGUILayout.BeginVertical(GUI.skin.box);
            {
                GUILayout.Label("编辑中");
            }
            EditorGUILayout.EndVertical();
        }
        else
        {
            // TODO 刷新值修改为 - 当做了选择后进行的刷新
            if (ifChooseDataDirty)
            {
                RefreshAllSelectedSVNToolFiles();    // 刷新值
            }

            #region 未选择结果列表

            GUILayout.Label("配置文件未选择");

            hideScrollPos = EditorGUILayout.BeginScrollView(hideScrollPos, GUI.skin.box, GUILayout.MaxHeight(100));
            {
                EditorGUILayout.TextArea(hideChooseResult, GUILayout.Height(100));
            }
            EditorGUILayout.EndScrollView();

            #endregion

            #region 已选结果列表

            GUILayout.Label("当前已选择");

            showScrollPos = EditorGUILayout.BeginScrollView(showScrollPos, GUI.skin.box, GUILayout.MaxHeight(300));
            {
                EditorGUILayout.TextArea(showChooseResult, GUILayout.Height(300));
            }
            EditorGUILayout.EndScrollView();

            #endregion
        }

        #endregion

        #region 操作组

        // 控制提交按钮的可控
        GUI.enabled = m_CurrentEditState != EnumSVNToolWindowEditState.EDIT && !CheckIfSelectedPrefabSyncing();

        EditorGUILayout.BeginHorizontal();
        {
            if (GUILayout.Button("提交"))
            {
                StringBuilder stringBuilder = new StringBuilder();
                foreach (SVNToolFile file in showResult)
                {
                    stringBuilder.Append(file.path).Append("*");
                }
                UESvnOperation.GetSvnOperation().CommitFile(stringBuilder.ToString());
                InitSyncSVNToolPrefabStatus();
            }
        }
        EditorGUILayout.EndHorizontal();

        GUI.enabled = true;

        #endregion
    }
Example #7
0
 /// <summary>
 /// 刷新同步状态
 /// </summary>
 public void RefreshSVNToolFolderNeedSyncFiles()
 {
     UESvnOperation.GetSvnOperation().FolderStatus(path);
 }
Example #8
0
 /// <summary>
 /// 检查路径下文件/文件夹是否可被Commit
 /// </summary>
 /// <param name="path"></param>
 /// <returns></returns>
 public static Boolean GetSVNToolFileStateJob(String path)
 {
     return(UESvnOperation.GetSvnOperation().FileStatus(path));
 }