|
@@ -1,38 +1,126 @@
|
|
|
#include "StdAfx.h"
|
|
|
#include "SVNProc.h"
|
|
|
#include <afxinet.h>
|
|
|
+#include "CharEncoding.h"
|
|
|
|
|
|
-CSVNProc::CSVNProc(void)
|
|
|
+IMPLEMENT_SERIAL(CSVNProc, CObject, 0)
|
|
|
+
|
|
|
+CSVNProc::CSVNProc(void) :CObject()
|
|
|
{
|
|
|
+ m_bNeedUpdate = FALSE;
|
|
|
+ m_strSVNAddress = _T("");
|
|
|
+ m_strSVNSavePath = _T("");
|
|
|
+ m_dwSVNVersion = 0;
|
|
|
+ m_svnpath = PATH_RES;
|
|
|
}
|
|
|
|
|
|
CSVNProc::~CSVNProc(void)
|
|
|
{
|
|
|
}
|
|
|
|
|
|
-void CSVNProc::SVNProcess(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion, SVNTYPE type)
|
|
|
+CSVNProc& CSVNProc::operator=(CSVNProc& obj)
|
|
|
+{
|
|
|
+ // TODO: 在此处插入 return 语句
|
|
|
+ m_bNeedUpdate = obj.m_bNeedUpdate;
|
|
|
+ m_strSVNAddress = obj.m_strSVNAddress;
|
|
|
+ m_strSVNSavePath = obj.m_strSVNSavePath;
|
|
|
+ m_dwSVNVersion = obj.m_dwSVNVersion;
|
|
|
+
|
|
|
+ return *this;
|
|
|
+}
|
|
|
+
|
|
|
+void CSVNProc::Serialize(CArchive& ar)
|
|
|
{
|
|
|
+ CObject::Serialize(ar);
|
|
|
+ // 读写判断
|
|
|
+ if(ar.IsStoring())
|
|
|
+ {// 保存;
|
|
|
+ ar << m_bNeedUpdate;
|
|
|
+ ar << m_strSVNAddress;
|
|
|
+ ar << m_strSVNSavePath;
|
|
|
+ ar << m_dwSVNVersion;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {// 加载;
|
|
|
+ ar >> m_bNeedUpdate;
|
|
|
+ ar >> m_strSVNAddress;
|
|
|
+ ar >> m_strSVNSavePath;
|
|
|
+ ar >> m_dwSVNVersion;
|
|
|
+ }
|
|
|
+}
|
|
|
|
|
|
+void CSVNProc::SVNProcess(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion, SVNTYPE type)
|
|
|
+{
|
|
|
TCHAR szCommand[MAX_PATH] = { 0 };
|
|
|
if ( type == SVN_EXPORT ) {
|
|
|
// 先删除要导出的路径;
|
|
|
_stprintf_s(szCommand, _T("/c rd /s /q %s"), strSavePath.c_str());
|
|
|
ShellExecute(NULL, _T("open"), _T("cmd"), szCommand, NULL, SW_HIDE);
|
|
|
// 再执行导出;
|
|
|
- _stprintf_s(szCommand, _T("/c svn export -r %d %s %s &pause"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str());
|
|
|
+ //_stprintf_s(szCommand, _T("/c svn export -r %d %s %s > data.jg &pause"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str());
|
|
|
+ _stprintf_s(szCommand, _T("/c svn export -r %d %s %s > %d"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str(), m_svnpath);
|
|
|
}
|
|
|
else if ( type == SVN_CHECKOUT ) {
|
|
|
// 先删除要导出的路径;
|
|
|
_stprintf_s(szCommand, _T("/c rd /s /q %s"), strSavePath.c_str());
|
|
|
ShellExecute(NULL, _T("open"), _T("cmd"), szCommand, NULL, SW_HIDE);
|
|
|
// 再执行导出;
|
|
|
- _stprintf_s(szCommand, _T("/c svn checkout -r %d %s %s &pause"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str());
|
|
|
+ //_stprintf_s(szCommand, _T("/c svn checkout -r %d %s %s > data.jg &pause"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str());
|
|
|
+ _stprintf_s(szCommand, _T("/c svn checkout -r %d %s %s > %d"), dwSVNVersion, strSVNAddress.c_str(), strSavePath.c_str(), m_svnpath);
|
|
|
}
|
|
|
else if ( type == SVN_ROLLBACK ) {
|
|
|
- _stprintf_s(szCommand, _T("/c svn update -r %d %s &pause"), dwSVNVersion, strSavePath.c_str());
|
|
|
+ //_stprintf_s(szCommand, _T("/c svn update -r %d %s > data.jg &pause"), dwSVNVersion, strSavePath.c_str());
|
|
|
+ _stprintf_s(szCommand, _T("/c svn update -r %d %s > %d"), dwSVNVersion, strSavePath.c_str(), m_svnpath);
|
|
|
+ }
|
|
|
+
|
|
|
+ SHELLEXECUTEINFO sei;
|
|
|
+ memset(&sei, 0, sizeof(SHELLEXECUTEINFO));
|
|
|
+ sei.cbSize = sizeof(SHELLEXECUTEINFO);
|
|
|
+ sei.hwnd = NULL;
|
|
|
+ sei.lpVerb = _T("open");
|
|
|
+ sei.fMask = SEE_MASK_NOCLOSEPROCESS | SEE_MASK_FLAG_NO_UI;
|
|
|
+ sei.lpFile = "cmd";
|
|
|
+ sei.lpParameters = szCommand;
|
|
|
+ sei.lpDirectory = NULL;
|
|
|
+ sei.nShow = SW_HIDE;
|
|
|
+ sei.hInstApp = NULL;
|
|
|
+
|
|
|
+ if (!ShellExecuteEx(&sei)) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (sei.hProcess != NULL) {
|
|
|
+ WaitForSingleObject(sei.hProcess, INFINITE);
|
|
|
+ if (sei.hProcess)
|
|
|
+ CloseHandle(sei.hProcess);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 结束后进入文本结果识别;
|
|
|
+ CString str;
|
|
|
+ CStdioFile file;
|
|
|
+ _stprintf_s(szCommand, _T("%d"), m_svnpath);
|
|
|
+ if (file.Open(szCommand, CFile::modeRead)) {
|
|
|
+ // 文件大小;
|
|
|
+ ULONGLONG ulSize = file.SeekToEnd();
|
|
|
+ file.SeekToBegin();
|
|
|
+ if ( ulSize > 60)
|
|
|
+ file.Seek(ulSize - 60, CFile::begin);
|
|
|
+ while (file.GetPosition() != ulSize) {
|
|
|
+ file.ReadString(str);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 关闭文件;
|
|
|
+ file.Close();
|
|
|
}
|
|
|
|
|
|
- ShellExecute(NULL, _T("open"), _T("cmd"), szCommand, NULL, SW_SHOW);
|
|
|
+ // 目前只针对更新指定版本;
|
|
|
+ TCHAR szCommand2[MAX_PATH] = { 0 };
|
|
|
+ _stprintf_s(szCommand, _T("At revision %ld."), dwSVNVersion);
|
|
|
+ _stprintf_s(szCommand, _T("Updated to revision %ld."), dwSVNVersion);
|
|
|
+ if (!str.IsEmpty() && (str.CompareNoCase(szCommand) == 0 || str.CompareNoCase(szCommand2) == 0)) {
|
|
|
+ // 表示更新成功;
|
|
|
+ m_bNeedUpdate = FALSE;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void CSVNProc::Export(std::string strSVNAddress, std::string strSavePath, DWORD dwSVNVersion)
|
|
@@ -50,7 +138,78 @@ void CSVNProc::Rollback(std::string strSVNAddress, std::string strSavePath, DWOR
|
|
|
SVNProcess(strSVNAddress, strSavePath, dwSVNVersion, SVN_ROLLBACK);
|
|
|
}
|
|
|
|
|
|
-BOOL CSVNProc::CheckNewVersion(std::string url, std::string strContent)
|
|
|
+BOOL CSVNMgr::ParseJson(std::string json)
|
|
|
+{
|
|
|
+ cJSON* pRoot = cJSON_Parse(json.c_str());
|
|
|
+ if (pRoot) {
|
|
|
+ cJSON* pMsg = cJSON_GetObjectItem(pRoot, "responseMsg");
|
|
|
+ if (pMsg) {
|
|
|
+ std::string data;
|
|
|
+ std::string code = cJSON_GetObjectItem(pMsg, "code") ? cJSON_GetObjectItem(pMsg, "code")->valuestring : "";
|
|
|
+ std::string msg = cJSON_GetObjectItem(pMsg, "message") ? cJSON_GetObjectItem(pMsg, "message")->valuestring : "";
|
|
|
+
|
|
|
+ if (code == "00") {
|
|
|
+ cJSON* pObj = cJSON_GetObjectItem(pMsg, "data");
|
|
|
+ if (pObj != NULL) {
|
|
|
+ int nSise = cJSON_GetArraySize(pObj);
|
|
|
+ for (int i = 0; i < nSise; i++) {
|
|
|
+ cJSON* pInfo = cJSON_GetArrayItem(pObj, i);
|
|
|
+ if (pInfo) {
|
|
|
+ std::string type = cJSON_GetObjectItem(pInfo, "type") ? cJSON_GetObjectItem(pInfo, "type")->valuestring : "";
|
|
|
+ std::string path = cJSON_GetObjectItem(pInfo, "svnPath") ? cJSON_GetObjectItem(pInfo, "svnPath")->valuestring : "";
|
|
|
+ std::string version = cJSON_GetObjectItem(pInfo, "svnVersion") ? cJSON_GetObjectItem(pInfo, "svnVersion")->valuestring : "";
|
|
|
+
|
|
|
+ CSVNProc* pSVN = NULL;
|
|
|
+ // 查找该地址是否存在;
|
|
|
+ if ((pSVN = IsSVNExist(path)) != NULL) {
|
|
|
+ UpdatedSVN(pSVN, _tstol(version.c_str()));
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pSVN = new CSVNProc();
|
|
|
+ pSVN->m_bNeedUpdate = TRUE;
|
|
|
+ pSVN->m_strSVNAddress = path.c_str();
|
|
|
+ pSVN->m_dwSVNVersion = _tstol(version.c_str());
|
|
|
+ if (type == "SatTest") {
|
|
|
+ pSVN->m_svnpath = PATH_TESTER;
|
|
|
+ pSVN->m_strSVNSavePath = _T("D:\\SAT\\Tester");
|
|
|
+ }
|
|
|
+ else if (type == "SatScript") {
|
|
|
+ pSVN->m_svnpath = PATH_SCRIPT;
|
|
|
+ pSVN->m_strSVNSavePath = _T("D:\\SAT\\Script");
|
|
|
+ }
|
|
|
+ else if (type == "SatResource") {
|
|
|
+ pSVN->m_svnpath = PATH_RES;
|
|
|
+ pSVN->m_strSVNSavePath = _T("D:\\SAT\\resource");
|
|
|
+ }
|
|
|
+ else {
|
|
|
+ delete pSVN;
|
|
|
+ pSVN = NULL;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 加入数组;
|
|
|
+ if ( pSVN )
|
|
|
+ m_arySVN.Add(pSVN);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 释放内存;
|
|
|
+ cJSON_Delete(pRoot);
|
|
|
+ // 返回结果;
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 错误产生,可输出msg方便查询;
|
|
|
+ cJSON_Delete(pRoot);
|
|
|
+ }
|
|
|
+
|
|
|
+ return FALSE;
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CSVNMgr::HttpRequest(std::string url, std::string strContent, std::string& data)
|
|
|
{
|
|
|
// 分解地址;
|
|
|
DWORD dwServiceType;
|
|
@@ -63,45 +222,53 @@ BOOL CSVNProc::CheckNewVersion(std::string url, std::string strContent)
|
|
|
}
|
|
|
|
|
|
// 设置超时
|
|
|
- CInternetSession session;
|
|
|
+ CInternetSession session(_T("HTTP Session"));;
|
|
|
session.SetOption(INTERNET_OPTION_CONNECT_TIMEOUT, 2000);
|
|
|
session.SetOption(INTERNET_OPTION_CONNECT_RETRIES, 3);
|
|
|
session.SetOption(INTERNET_OPTION_SEND_TIMEOUT, 10000);
|
|
|
session.SetOption(INTERNET_OPTION_RECEIVE_TIMEOUT, 20000);
|
|
|
- // http://10.201.40.65:8580/btc_execute_se/ajaxInteractiveManage!getSvnVersion.action
|
|
|
-
|
|
|
+
|
|
|
// 打开HTTP连接
|
|
|
CHttpConnection* pHttpConnection = session.GetHttpConnection(strServer, dwServiceType == AFX_INET_SERVICE_HTTP ? INTERNET_FLAG_KEEP_CONNECTION : INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE, nPort);
|
|
|
if (NULL == pHttpConnection) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 开启一个HTTP请求
|
|
|
url.append("!" + strContent);
|
|
|
- CHttpFile* pHttpFile = pHttpConnection->OpenRequest(_T("POST"), url.c_str(), NULL, 1, NULL, NULL, dwServiceType == AFX_INET_SERVICE_HTTP ? INTERNET_FLAG_KEEP_CONNECTION : INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE);
|
|
|
+ url = CharEncoding::EnCode_UTF8URL(url.c_str());
|
|
|
+ CHttpFile* pHttpFile = pHttpConnection->OpenRequest(_T("POST"), strObject, NULL, 1, NULL, NULL, dwServiceType == AFX_INET_SERVICE_HTTP ? INTERNET_FLAG_KEEP_CONNECTION : INTERNET_FLAG_KEEP_CONNECTION | INTERNET_FLAG_SECURE);
|
|
|
if (NULL == pHttpFile) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 设置HTTP请求包头
|
|
|
std::string output;
|
|
|
- pHttpFile->AddRequestHeaders(_T("User-Agent: MYPRODUCT/1.0.0 (Windows)"));
|
|
|
- pHttpFile->AddRequestHeaders(_T("Content-Type: application/octet-stream"));
|
|
|
- pHttpFile->AddRequestHeaders(_T("Charset: UTF-8"));
|
|
|
-
|
|
|
+ TCHAR szHeaders[MAX_PATH] = { 0 };
|
|
|
+ pHttpFile->AddRequestHeaders(_T("User-Agent: PostmanRuntime/7.24.1"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Accept: */*"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Accept-Encoding: gzip, deflate, br"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Connection: keep-alive"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Content-Type: application/json;charset=utf-8"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Cache-Control: no-cache"));
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Accept-Language: zh-cn"));
|
|
|
+ _stprintf_s(szHeaders, _T("Host:%s"), strServer.GetString());
|
|
|
+ pHttpFile->AddRequestHeaders(szHeaders);
|
|
|
+ pHttpFile->AddRequestHeaders(_T("Content-Length:0"));
|
|
|
+
|
|
|
// 发送数据
|
|
|
- BOOL bResult = pHttpFile->SendRequest(NULL, 0, (LPVOID)strContent.data(), (DWORD)strContent.length());
|
|
|
+ BOOL bResult = pHttpFile->SendRequest(NULL, 0, NULL, 0);
|
|
|
if (!bResult) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 查询状态
|
|
|
DWORD dwHttpCode = 0;
|
|
|
bResult = pHttpFile->QueryInfoStatusCode(dwHttpCode);
|
|
|
if (!bResult) {
|
|
|
return FALSE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 出错的原因
|
|
|
char szBuffer[4096] = { 0 };
|
|
|
DWORD dwBufferSize;
|
|
@@ -109,10 +276,9 @@ BOOL CSVNProc::CheckNewVersion(std::string url, std::string strContent)
|
|
|
BOOL bResult = pHttpFile->QueryInfo(HTTP_QUERY_STATUS_TEXT, szBuffer, &dwBufferSize);
|
|
|
return FALSE;
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
// 接收响应
|
|
|
- std::string data;
|
|
|
- DWORD dwReadBytes;
|
|
|
+ DWORD dwReadBytes;
|
|
|
while ((dwReadBytes = pHttpFile->Read((void*)szBuffer, 4096)) > 0) {
|
|
|
data.append(szBuffer, dwReadBytes);
|
|
|
memset(szBuffer, 0, 4096 * sizeof(char));
|
|
@@ -133,5 +299,88 @@ BOOL CSVNProc::CheckNewVersion(std::string url, std::string strContent)
|
|
|
|
|
|
session.Close();
|
|
|
|
|
|
+ data = CharEncoding::DeCode_URLUTF8(data.c_str());
|
|
|
TRACE1(_T("请求结果:%s"), data.c_str());
|
|
|
+
|
|
|
+ return TRUE;
|
|
|
}
|
|
|
+
|
|
|
+CSVNProc* CSVNMgr::IsSVNExist(std::string strSVNAddress)
|
|
|
+{
|
|
|
+ CSVNProc* pSVN = NULL;
|
|
|
+ int nSize = m_arySVN.GetSize();
|
|
|
+ for ( int i = 0; i < nSize; i++ ) {
|
|
|
+ pSVN = m_arySVN.GetAt(i);
|
|
|
+ if (pSVN) {
|
|
|
+ if (pSVN->m_strSVNAddress.CompareNoCase(strSVNAddress.c_str()) == 0)
|
|
|
+ return pSVN;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+void CSVNMgr::UpdatedSVN(CSVNProc* pSVN, DWORD dwVersion)
|
|
|
+{
|
|
|
+ if (pSVN->m_dwSVNVersion != dwVersion) {
|
|
|
+ pSVN->m_dwSVNVersion = dwVersion;
|
|
|
+ pSVN->m_bNeedUpdate = TRUE;
|
|
|
+ //pSVN->Rollback(pSVN->m_strSVNAddress.GetString(), pSVN->m_strSVNSavePath.GetString(), pSVN->m_dwSVNVersion);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ pSVN->m_bNeedUpdate = FALSE;
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CSVNMgr::HasNewVersion()
|
|
|
+{
|
|
|
+ CSVNProc* pSVN = NULL;
|
|
|
+ int nSize = m_arySVN.GetSize();
|
|
|
+ for (int i = 0; i < nSize; i++) {
|
|
|
+ pSVN = m_arySVN.GetAt(i);
|
|
|
+ if (pSVN) {
|
|
|
+ if (pSVN->m_bNeedUpdate)
|
|
|
+ return TRUE;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return FALSE;
|
|
|
+}
|
|
|
+
|
|
|
+void CSVNMgr::Load(LPCTSTR lpFileName)
|
|
|
+{
|
|
|
+ CFile file;
|
|
|
+ if (!file.Open(lpFileName, CFile::modeRead)) {
|
|
|
+ CArchive ar(&file, CArchive::load);
|
|
|
+ m_arySVN.Serialize(ar);
|
|
|
+ ar.Close();
|
|
|
+ file.Close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+void CSVNMgr::Store(LPCTSTR lpFileName)
|
|
|
+{
|
|
|
+ CFile file;
|
|
|
+ if (!file.Open(lpFileName, CFile::modeWrite | CFile::modeCreate)) {
|
|
|
+ CArchive ar(&file, CArchive::store);
|
|
|
+ m_arySVN.Serialize(ar);
|
|
|
+ ar.Flush();
|
|
|
+ ar.Close();
|
|
|
+ file.Flush();
|
|
|
+ file.Close();
|
|
|
+ }
|
|
|
+}
|
|
|
+
|
|
|
+BOOL CSVNMgr::CheckNewVersion(std::string url, std::string strContent)
|
|
|
+{
|
|
|
+ std::string data;
|
|
|
+ if (!HttpRequest(url, strContent, data))
|
|
|
+ return FALSE;
|
|
|
+
|
|
|
+ // 将结果转换为结构体;
|
|
|
+ ParseJson(data);
|
|
|
+
|
|
|
+ return HasNewVersion();
|
|
|
+}
|
|
|
+
|