Exemplo n.º 1
0
    public static bool Add(SVNConfig config, string filePath, out string message)
    {
        // Run an svn add
        System.Diagnostics.Process process = CreateSVNProcess(config);
        process.StartInfo.Arguments = "add --username " + config.username + " --password " + config.password + " " + filePath;

        string stdout, stderr;
        StartProcess(config, process, out stdout, out stderr);

        if(stderr.Length != 0)
        {
            message = stderr;
            return false;
        }

        message = stdout;
        return true;
    }
Exemplo n.º 2
0
    public static SVNFileInfo GetStatus(SVNConfig config, string filePath)
    {
        // Run an svn status
        System.Diagnostics.Process process = CreateSVNProcess(config);
        process.StartInfo.Arguments = "status -v -u " + filePath;

        string statusOutput, stderr;
        StartProcess(config, process, out statusOutput, out stderr);

        if(stderr.Length > 0)
        {
            return null;
        }

        SVNFileInfo status = new SVNFileInfo();
        status.filePath = filePath;

        if(statusOutput.Length > 9)
        {
            char[] fileFlags = statusOutput.ToCharArray(0, 9);
            status.status = GetChangeStatus(fileFlags[0]);
            status.outOfDate = fileFlags[8] == '*';
        }

        if(status.status == ChangeStatus.Unversioned || status.status == ChangeStatus.Added)
        {
            status.info = new Dictionary<string, string>();
        }
        else
        {
            status.info = GetSVNInfo(config, filePath);

            if(status.info.ContainsKey("URL"))
            {
                status.info = GetSVNInfo(config, status.info["URL"]);
            }
        }

        return status;
    }
Exemplo n.º 3
0
    void OnGUI()
    {
        if(_config == null)
        {
            _config = Resources.Load("SVNConfig", typeof(SVNConfig)) as SVNConfig;

            if(_config == null)
            {
                _config = ScriptableObject.CreateInstance<SVNConfig>();

                System.IO.DirectoryInfo resourcesDirectory = new System.IO.DirectoryInfo("Assets/Editor/Resources");
                if(!resourcesDirectory.Exists)
                {
                    resourcesDirectory.Create();
                }
                AssetDatabase.CreateAsset(_config, "Assets/Editor/Resources/SVNConfig.asset");
                AssetDatabase.SaveAssets();
            }
        }

        string sceneName = GetSceneName();

        if(GUILayout.Button("Refresh"))
        {
            UpdateSceneInfo();
            UpdateSelectionInfo();
        }

        if(_errorConnecting)
        {
            EditorGUILayout.HelpBox("There was an error connecting to the subversion system", MessageType.Error, true);
        }
        else if(EditorApplication.currentScene == "")
        {
            _sceneInfo = null;
            EditorGUILayout.HelpBox("No subversion meta-data is available until the scene is saved", MessageType.Warning, true);
        }
        else
        {
            if(_sceneInfo == null || _sceneInfo.filePath != sceneName)
            {
                UpdateSceneInfo();
                UpdateSelectionInfo();
            }

            if(_sceneInfo != null)
            {
                if(_sceneInfo.outOfDate)
                {
                    EditorGUILayout.HelpBox("This scene is out of date and should be updated. Last modified by " + _sceneInfo.lastChangedAuthor, MessageType.Error, true);
                }
                else if(_sceneInfo.locked)
                {
                    string unlockButtonText = "Unlock scene";

                    if(_sceneInfo.lockOwner != _config.username)
                    {
                        EditorGUILayout.HelpBox("This scene is currently locked by " + _sceneInfo.lockOwner, MessageType.Error, true);
                        unlockButtonText = "Force unlock scene";
                    }
                    else
                    {
                        EditorGUILayout.HelpBox("You have locked this scene", MessageType.Info, true);
                    }

                    if(GUILayout.Button(unlockButtonText))
                    {
                        string message = "";
                        bool result = SVNUtils.Unlock(_config, sceneName, out message);

                        if(!result)
                        {
                            EditorUtility.DisplayDialog("Unlock failed", "Unlock failed with the following message: " + message, "OK");
                        }
                        else
                        {
                            if(message != "")
                            {
                                EditorUtility.DisplayDialog("Unlock successful", "Unlock succeeded with the following message: " + message, "OK");
                            }
                        }

                        UpdateSceneInfo();
                    }
                }
                else
                {
                    bool allowLock = false;

                    switch(_sceneInfo.status)
                    {
                    case SVNUtils.ChangeStatus.Modified:
                        EditorGUILayout.HelpBox("Scene is modified but not locked It is recommended to lock the scene",  MessageType.Warning, true);
                        allowLock = true;
                        break;
                    case SVNUtils.ChangeStatus.NoModifications:
                        EditorGUILayout.HelpBox("It is recommended to lock the scene if you are planning on changing anything",  MessageType.Info, true);
                        allowLock = true;
                        break;
                    case SVNUtils.ChangeStatus.Conflicted:
                        EditorGUILayout.HelpBox("Scene is in a conflicted state!",  MessageType.Error, true);
                        break;
                    case SVNUtils.ChangeStatus.Unversioned:
                        EditorGUILayout.HelpBox("Scene has not been added to the respository",  MessageType.Warning, true);
                        if(GUILayout.Button("Add scene to repository"))
                        {
                            string message = "";
                            bool result = SVNUtils.Add(_config, sceneName, out message);

                            if(!result)
                            {
                                EditorUtility.DisplayDialog("Add failed", "Add failed with the following message: " + message, "OK");
                            }
                            else
                            {
                                if(message != "")
                                {
                                    EditorUtility.DisplayDialog("Add successful", "Add succeeded with the following message: " + message, "OK");
                                }
                            }

                            UpdateSceneInfo();
                            Repaint();
                        }
                        break;
                    case SVNUtils.ChangeStatus.Added:
                        EditorGUILayout.HelpBox("Scene has been marked for add",  MessageType.Info, true);
                        break;
                    }

                    if(allowLock && GUILayout.Button("Lock scene"))
                    {
                        string message = "";
                        bool result = SVNUtils.Lock(_config, sceneName, out message);

                        if(!result)
                        {
                            EditorUtility.DisplayDialog("Lock failed", "Lock failed with the following message: " + message, "OK");
                        }
                        else
                        {
                            if(message != "")
                            {
                                EditorUtility.DisplayDialog("Lock successful", "Lock succeeded with the following message: " + message, "OK");
                            }
                        }

                        UpdateSceneInfo();
                    }
                }

                if(_sceneInfo.status != SVNUtils.ChangeStatus.Unversioned && _sceneInfo.status != SVNUtils.ChangeStatus.Added)
                {
                    EditorGUILayout.LabelField("Scene was last modified by " + _sceneInfo.lastChangedAuthor);
                }
            }
            else
            {
                EditorGUILayout.HelpBox("No subversion meta-data found for this scene file or error connecting to the server", MessageType.Error, true);
            }

        }

        if(!_errorConnecting)
        {
            if(_selectionInfo == null)
            {
                UpdateSelectionInfo();
            }
        }
        else
        {
            _selectionInfo = new List<SVNUtils.SVNFileInfo>();
        }

        foreach(SVNUtils.SVNFileInfo prefabInfo in _selectionInfo)
        {
            if(prefabInfo.outOfDate)
            {
                string prefabName = prefabInfo.filePath;

                if(prefabInfo.status == SVNUtils.ChangeStatus.Modified)
                {
                    EditorGUILayout.HelpBox("You have made changes to the prefab '" + prefabName + "' and it is out of date. Next update will be a conflict. Last modified by " + prefabInfo.lastChangedAuthor,  MessageType.Error, true);
                }
                else
                {
                    EditorGUILayout.HelpBox("Prefab '" + prefabName + "' is out of date. Last modified by " + prefabInfo.lastChangedAuthor,  MessageType.Warning, true);
                }
            }
        }

        EditorGUILayout.BeginVertical("Box");
        _showConfig = EditorGUILayout.Foldout(_showConfig, "SVN Configuration");

        if(_showConfig)
        {
            // Username / password
            GUILayout.Label("Username:"******"Password:"******"Select SVN executable"))
            {
                string extension = "";
                if(Application.platform == RuntimePlatform.WindowsEditor)
                {
                    extension = "exe";
                }
                _config.svnPath = EditorUtility.OpenFilePanel("Select SVN executable", _config.svnPath, extension);
            }

            _config.enableDebugging = GUILayout.Toggle(_config.enableDebugging, "Enable debugging");
        }
        EditorGUILayout.EndVertical();

        EditorUtility.SetDirty(_config);
    }
Exemplo n.º 4
0
    private static bool StartProcess(SVNConfig config, System.Diagnostics.Process process, out string stdout, out string stderr)
    {
        if(config.enableDebugging)
        {
            Debug.Log(process.StartInfo.FileName + " " + process.StartInfo.Arguments);
        }

        bool result = false;

        try
        {
            result = process.Start();
        }
        catch(System.Exception e)
        {
            Debug.LogError(e.Message);
            stdout = "";
            stderr = e.Message;
            return false;
        }

        stdout = process.StandardOutput.ReadToEnd();
        stderr = process.StandardError.ReadToEnd();

        if(config.enableDebugging && stdout != "")
        {
            Debug.Log(stdout);
        }

        if(stderr != "")
        {
            Debug.LogError(stderr);
        }

        process.WaitForExit();

        return result;
    }
Exemplo n.º 5
0
    private static Dictionary<string, string> GetSVNInfo(SVNConfig config, string filePath)
    {
        // Run an svn info
        System.Diagnostics.Process infoProcess = CreateSVNProcess(config);
        infoProcess.StartInfo.Arguments = "info " + filePath;

        string stdout, stderr;
        StartProcess(config, infoProcess, out stdout, out stderr);

        stdout = stdout.Replace("\r", "");
        string[] infoLines = stdout.Split('\n');
        Dictionary<string, string> output = new Dictionary<string, string>();
        string lastEntry = "";

        foreach(string line in infoLines)
        {
            int seperator = line.IndexOf(':');

            if(seperator == -1 && lastEntry != "")
            {
                output[lastEntry] += line;
            }
            else if(seperator != -1 && seperator + 2 < line.Length)
            {
                string key = line.Substring(0, seperator);
                string val = line.Substring(seperator + 2);

                output[key] = val;

                lastEntry = key;
            }
        }

        return output;
    }
Exemplo n.º 6
0
    private static System.Diagnostics.Process CreateSVNProcess(SVNConfig config)
    {
        if(config.svnPath == "")
        {
            if(Application.platform == RuntimePlatform.WindowsEditor)
            {
                config.svnPath = "svn.exe";
            }
            else
            {
                config.svnPath = "svn";
            }
        }

        System.Diagnostics.Process process = new System.Diagnostics.Process();
        process.StartInfo.FileName = config.svnPath;
        process.StartInfo.RedirectStandardOutput = true;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.UseShellExecute = false;
        process.StartInfo.CreateNoWindow = true;
        return process;
    }