Repository navigation
Expand file tree
/
Copy pathVCXProjSync.cpp
More file actions
222 lines (175 loc) · 5.63 KB
/
Copy pathVCXProjSync.cpp
File metadata and controls
222 lines (175 loc) · 5.63 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
210
211
212
213
214
215
216
217
218
219
220
221
222
#include "VCXProjSync.h"
#include "Common.h"
#include <iostream>
using namespace std;
#define REJECT_FILETYPE_LIST "sln, sdf, opensdf, dsp, ncb, vcproj, user, suo, aps, filters, vcxproj, vcproj"
#define REJECT_FOLDERTYPE_LIST "%"
VCXProjSync::VCXProjSync(ConfigFile* pConfigFile)
{
m_pConfig = pConfigFile;
m_pConfig->add2RejectFolderTypeList(REJECT_FOLDERTYPE_LIST);
m_pConfig->add2List(pConfigFile->m_pRejectFileType, REJECT_FILETYPE_LIST); // VCX定义的拒绝接受的“文件类型”
bVCProj = m_pConfig->checkFileType(m_pConfig->m_strTargetName, ".vcproj");
if(bVCProj)
{
m_pVC = new VC(m_pConfig->m_strTargetFile);
}
else
{
m_pVCX = new VCX(m_pConfig->m_strTargetFile);
m_pVCXFilter = new VCXFilter(m_pConfig->m_strTargetFile + ".filters");
}
}
VCXProjSync::~VCXProjSync(void)
{
if(bVCProj)
{
delete m_pVC;
m_pVC->save();
cout << "Synchronise " << m_pVC->m_strFile << " successfully!" << endl;
}else{
m_pVCX->save();
m_pVCXFilter->save();
cout << "Synchronise " << m_pVCX->m_strFile << " successfully!" << endl;
cout << "Synchronise " << m_pVCXFilter->m_strFile << " successfully!" << endl;
delete m_pVCX;
delete m_pVCXFilter;
}
}
void VCXProjSync::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 = "";
m_strCurRelativeFilter = "";
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())
{
m_strCurRelativeFilter = strCurRootPath;
m_strCurRelativeFilter.Delete(0, len);
m_strCurRelativePath += m_strCurRelativeFilter;
m_strCurRelativeFilter.Delete(m_strCurRelativeFilter.GetLength()-1, 1);
}
EXIT:
cout << "Current Root Path is: " << strCurRootPath << endl;
cout << "Current Relative Path is: " << m_strCurRelativePath << "\n\n";
}
MSXML2::IXMLDOMElementPtr VCXProjSync::addFile(MSXML2::IXMLDOMElementPtr pParentElement, CString strRelativePath, CString strRelativeFilter)
{
if(bVCProj)
return m_pVC->addFile(pParentElement, strRelativePath);
m_pVCX->addFile(strRelativePath);
MSXML2::IXMLDOMElementPtr pFile = m_pVCXFilter->addFile(strRelativePath, strRelativeFilter);
return pFile;
}
MSXML2::IXMLDOMElementPtr VCXProjSync::addFilter(MSXML2::IXMLDOMElementPtr pParentElement, const _variant_t attributeVal, CString strRelativeFilter)
{
if(bVCProj)
return m_pVC->addFilter(pParentElement, attributeVal);
return m_pVCXFilter->addFilter(strRelativeFilter);
}
int VCXProjSync::addAllFiles(MSXML2::IXMLDOMElementPtr pParentElement, const CString strCurPath, const CString strCurRelativePath, const CString strCurRelativeFilter)
{
int iChildren = 0; // 用于记录子节点的个数,如果为0,则删除父节点
MSXML2::IXMLDOMElementPtr pNode;
CString strPath, strRelativePath, strRelativeFilter, FilterName;
strPath = strCurPath + _T("*.*");
HANDLE hFind = FindFirstFile(strPath, &m_stFindFileData);
if(hFind == INVALID_HANDLE_VALUE)
return 0;
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 + "\\";
strRelativePath = strCurRelativePath + m_stFindFileData.cFileName + "\\";
if(m_pConfig->checkPath(m_pCurAcceptPath, strPath)) // 检查strPath是否为“拒绝路径”
{
if(strCurRelativeFilter.GetLength() == 0)
strRelativeFilter = m_stFindFileData.cFileName;
else
strRelativeFilter = strCurRelativeFilter + "\\" + m_stFindFileData.cFileName;
pNode = addFilter(pParentElement, m_stFindFileData.cFileName, strRelativeFilter);
if(addAllFiles(pNode, strPath, strRelativePath, strRelativeFilter))
iChildren++;
}
}
else
{
if(m_pConfig->checkFile(m_pCurAcceptPath, strCurPath, m_stFindFileData.cFileName))
{
iChildren++;
strPath = strCurRelativePath + m_stFindFileData.cFileName;
addFile(pParentElement, strPath, strCurRelativeFilter);
}
}
FIND_NEXT:
if(!FindNextFile(hFind, &m_stFindFileData))
break;
}
FindClose(hFind);
if(iChildren == 0)
CXMLParser::DeleteNode(pParentElement);
return iChildren;
}
void VCXProjSync::run()
{
cout << "\nStart synchronising..." << endl;
MSXML2::IXMLDOMElementPtr pNode;
UNIT* FilePtr = m_pConfig->m_pAcceptFile;
while(FilePtr && FilePtr->strData != "")
{
setRelativePath(FilePtr->strData);
addFile(m_pVC->m_pFilesElement, m_strCurRelativePath, m_strCurRelativeFilter);
FilePtr = FilePtr->pNext;
}
m_pCurAcceptPath = m_pConfig->m_pAcceptPath;
while(m_pCurAcceptPath && m_pCurAcceptPath->strData != "")
{
m_strCurRootPath = m_pCurAcceptPath->strData;
addPathSep(m_strCurRootPath);
setRelativePath(m_strCurRootPath);
if(bVCProj)
addAllFiles(m_pVC->m_pFilesElement, m_strCurRootPath, m_strCurRelativePath, m_strCurRelativeFilter);
else if(addAllFiles(m_pVCXFilter->m_pFilesGroup, m_strCurRootPath, m_strCurRelativePath, m_strCurRelativeFilter))
m_pVCXFilter->addFilterX(m_strCurRelativeFilter);
m_pCurAcceptPath = m_pCurAcceptPath->pNext;
}
}