Repository navigation
Expand file tree
/
Copy pathVCProjSync.cpp
More file actions
209 lines (166 loc) · 4.62 KB
/
Copy pathVCProjSync.cpp
File metadata and controls
209 lines (166 loc) · 4.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#include "VCProjSync.h"
#include "Common.h"
#include <iostream>
using namespace std;
#define REJECT_FILETYPE_LIST "dsp, ncb, vcproj, user, suo, aps"
/*
.vcproj 文件的 XML 结构如下:
<VisualStudioProject ...>
<Files>
<Filter Name="+Classifier">
<Filter Name="+RSC">
<File RelativePath="..\FaceRecognition\Main\+Classifier\+RSC\Demo_RSC_AR_disguise.m">
</File>
</Filter>
</Filter>
</Files>
</VisualStudioProject>
*/
VCProjSync::VCProjSync(ConfigFile* pConfigFile) : CXMLParser((TCHAR*)pConfigFile->m_strTargetFile.GetString())
{
if(!m_pRootElement)
throw "Error .vcproj file";
m_pConfig = pConfigFile;
// 处理节点
DeleteNode(m_pRootElement, _T("Files"));
DeleteNode(m_pRootElement, _T("Globals"));
m_pFilesElement = AddNode(m_pRootElement, _T("Files"), _T(""));
AddNode(m_pRootElement, _T("Globals"), _T(""));
pConfigFile->add2List(pConfigFile->m_pRejectFileType, REJECT_FILETYPE_LIST);
}
VCProjSync::~VCProjSync(void)
{
m_pDoc->save(m_lpXMLFile);
cout << "Synchronise " << m_pConfig->m_strTargetName << " successfully!" << endl;
}
void VCProjSync::run()
{
cout << "\nStart synchronising..." << endl;
MSXML2::IXMLDOMElementPtr pFilter;
UNIT* FilePtr = m_pConfig->m_pAcceptFile;
while(FilePtr && FilePtr->strData != "")
{
setRelativePath(FilePtr->strData);
MSXML2::IXMLDOMElementPtr pFile = AddNode(m_pFilesElement, "File", "");
pFile->setAttribute("RelativePath", m_strCurRelativePath.GetString());
FilePtr = FilePtr->pNext;
}
m_pCurAcceptPath = m_pConfig->m_pAcceptPath;
while(m_pCurAcceptPath && m_pCurAcceptPath->strPath != "")
{
m_strCurRootPath = m_pCurAcceptPath->strPath;
addPathSep(m_strCurRootPath);
setRelativePath(m_strCurRootPath);
addAllFiles(m_strCurRootPath, m_pFilesElement);
m_pCurAcceptPath = m_pCurAcceptPath->pNext;
}
}
void VCProjSync::setRelativePath(CString strCurRootPath)
{
if(strCurRootPath == "") return;
CString strVCPath = m_pConfig->m_strTargetPath + "\\";
if( strCurRootPath == strVCPath )
{
m_strCurRelativePath = _T(".\\");
goto EXIT;
}
int i = 0, len = 0, nSepCount = 0;
while(strCurRootPath.GetAt(i) == strVCPath.GetAt(i))
{
if(strCurRootPath.GetAt(i) == '\\')
{
len = i + 1;
nSepCount++;
}
i++;
}
// 如果第二个 '\\' 前的路径不同,则直接把相对路径置为 strCurRootPath
if(nSepCount < 2)
{
m_strCurRelativePath = strCurRootPath;
goto EXIT;
}
m_strCurRelativePath = "";
if(len < strVCPath.GetLength())
{
CString strRes = m_pConfig->m_strTargetPath;
strRes.Delete(0, len-1);
int i = -1;
while(true)
{
i = strRes.Find('\\', i+1);
if(i == -1)
break;
m_strCurRelativePath += _T("..\\");
}
}
if(len < strCurRootPath.GetLength())
{
CString strRes = strCurRootPath;
strRes.Delete(0, len);
m_strCurRelativePath += strRes;
}
EXIT:
cout << "Current Root Path is: " << strCurRootPath << endl;
cout << "Current Relative Path is: " << m_strCurRelativePath << "\n\n";
}
/*
.vcproj 文件的<Filter>节点的 XML 结构如下:
<Filter Name="+Classifier">
<Filter Name="+RSC">
<File RelativePath="..\FaceRecognition\Main\+Classifier\+RSC\Demo_RSC_AR_disguise.m">
</File>
</Filter>
</Filter>
*/
void VCProjSync::addAllFiles(const CString strCurPath, MSXML2::IXMLDOMElementPtr pParentElement)
{
int iChildren = 0;
MSXML2::IXMLDOMElementPtr pFilter;
CString strPath, strCurRelativePath;
strPath = strCurPath + _T("*.*");
strCurRelativePath = m_strCurRelativePath;
if(strCurPath.GetLength() > m_strCurRootPath.GetLength())
{
CString strRes = strCurPath;
strRes.Delete(0, m_strCurRootPath.GetLength());
strCurRelativePath += strRes;
}
HANDLE hFind = FindFirstFile(strPath, &m_stFindFileData);
if(hFind == INVALID_HANDLE_VALUE)
return;
while(TRUE)
{
if(m_stFindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
{
if(m_stFindFileData.cFileName[0] == '.')
goto FIND_NEXT;
if(m_pConfig->isOneRejectFolder(m_stFindFileData.cFileName))
goto FIND_NEXT;
strPath = strCurPath + m_stFindFileData.cFileName;
strPath += "\\";
if(m_pConfig->checkPath(m_pCurAcceptPath, strPath))
{
iChildren++;
pFilter = AddNode(pParentElement, "Filter", "");
pFilter->setAttribute("Name", m_stFindFileData.cFileName);
addAllFiles(strPath, pFilter);
}
}
else
{
if(m_pConfig->checkFile(m_pCurAcceptPath, strCurPath, m_stFindFileData.cFileName))
{
iChildren++;
strPath = strCurRelativePath + m_stFindFileData.cFileName;
AddNode(pParentElement, "File", "")->setAttribute("RelativePath", strPath.GetString());
}
}
FIND_NEXT:
if(!FindNextFile(hFind, &m_stFindFileData))
break;
}
FindClose(hFind);
if(iChildren == 0)
DeleteNode(pParentElement);
}