尊重原创,转载请在文首注明出处:http://blog.csdn.net/cai612781/article/details/79015085
一,语法
项目开发中通常都会使用Subversion(SVN)作为版本控制系统,同时会使用SVN的客户端软件TortoiseSVN。
我们通过TortoiseSVN的TortoiseProc.exe程序添加参数,来实现在C#或bat批处理脚本中调用SVN。
举个栗子: TortoiseProc.exe /command:update /path:xxx /closeonend:0
/command表示SVN的操作命令
/path表示操作的路径,可以有多个,用*分隔
/closeonend用于在执行完毕后关闭对话框:
/closeonend:0不自动关闭对话框
/closeonend:1没有错误,则自动关闭对话框
/closeonend:2没有错误、冲突,则自动关闭对话框
/closeonend:3没有错误、冲突、合并,自动关闭对话框
二,代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using UnityEditor;
namespace Assets.Editor.Svn
{
public class SvnUtil : UnityEditor.Editor
{
private static string _svnPath = "";
public static void DelAndUpdateSvnFile(string path)
{
if (File.Exists(path))
{
File.Delete(path);
}
ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
}
public static void RevertAndUpdateSvnDirectory(string path)
{
ExecuteProcess(GetSvnProcPath(), string.Format("/command:revert -r /path:{0} /closeonend:2", path));
ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
}
public static void UpdateSvnDirectory(string path)
{
ExecuteProcess(GetSvnProcPath(), string.Format("/command:update /path:{0} /closeonend:2", path));
}
public static void CommitSvnDirectory(string path)
{
ExecuteProcess(GetSvnProcPath(), string.Format("/command:commit /path:{0} /closeonend:0", path));
}
public static void ProcessSvnCommand(string command)
{
ExecuteProcess(GetSvnProcPath(), command);
}
private static List<string> drives = new List<string>() { "c:", "d:", "e:", "f:"};
private static string svnPath = @"\Program Files\TortoiseSVN\bin\";
private static string svnProc = @"TortoiseProc.exe";
private static string svnProcPath = "";
private static string GetSvnProcPath()
{
if (_svnPath != string.Empty)
{
return _svnPath;
}
foreach (string item in drives)
{
string path = string.Concat(item, svnPath, svnProc);
if (File.Exists(path))
{
_svnPath = path;
break;
}
}
if (_svnPath == string.Empty)
{
_svnPath = EditorUtility.OpenFilePanel("Select TortoiseProc.exe", "c:\\", "exe");
}
//可将路径存到本地注册表
return _svnPath;
}
private static void ExecuteProcess(string filePath, string command, int seconds = 0)
{
EditorUtil.ExecuteProcess(filePath, command, "", seconds);//参见文末另一篇:C#调用可执行文件
}
}
}
EditorUtil.ExecuteProcess 参见另一篇:C#调用可执行文件