6 #include "TomboURI.h"
\r
7 #include "VarBuffer.h"
\r
8 #include "URIScanner.h"
\r
9 #include "Repository.h"
\r
11 #define URILIST_INITSIZE 20
\r
12 #define URILIST_DELTASIZE 10
\r
14 /////////////////////////////////////////////////
\r
15 //////////////////////////////////////////////////
\r
16 // URIList implementation
\r
17 //////////////////////////////////////////////////
\r
18 //////////////////////////////////////////////////
\r
26 for (DWORD i = 0; i < liList.NumItems(); i++) {
\r
27 URIListItem *pItem = liList.GetUnit(i);
\r
29 delete [] pItem->pTitle;
\r
33 BOOL URIList::Init()
\r
35 if (!liList.Init(URILIST_INITSIZE, URILIST_DELTASIZE)) return FALSE;
\r
39 BOOL URIList::Add(const TomboURI *pURI, LPCTSTR pTitle)
\r
43 item.pURI = new TomboURI(*pURI);
\r
44 if (item.pURI == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; }
\r
48 item.pTitle = StringDup(pTitle);
\r
49 if (item.pTitle == NULL) return FALSE;
\r
52 if (!liList.Add(&item)) return FALSE;
\r
57 /////////////////////////////////////////////////
\r
58 //////////////////////////////////////////////////
\r
59 // URIScanner implementation
\r
60 //////////////////////////////////////////////////
\r
61 //////////////////////////////////////////////////
\r
63 //////////////////////////////////////////////////
\r
64 // ctor & Initialize
\r
65 //////////////////////////////////////////////////
\r
67 URIScanner::URIScanner() : pBaseURI(NULL), pCurrentURI(NULL), pTop(NULL), pBaseTitle(NULL)
\r
71 BOOL URIScanner::Init(IEnumRepository *pRepo, const TomboURI *pURI, BOOL bSKE)
\r
74 pRepository = pRepo;
\r
75 bSkipEncrypt = bSKE;
\r
79 URIOption opt(NOTE_OPTIONMASK_VALID);
\r
80 if (!pRepository->GetOption(pURI, &opt)) return FALSE;
\r
83 SetLastError(ERROR_INVALID_PARAMETER);
\r
88 pBaseURI = new TomboURI(*pURI);
\r
93 //////////////////////////////////////////////////
\r
95 //////////////////////////////////////////////////
\r
97 URIScanner::~URIScanner()
\r
104 //////////////////////////////////////////////////
\r
105 // treat stack frame
\r
106 //////////////////////////////////////////////////
\r
108 void URIScanner::ClearStack()
\r
115 void URIScanner::LeaveFrame()
\r
117 StackFrame *pSF = pTop;
\r
124 BOOL URIScanner::PushFrame(const TomboURI *pURI)
\r
126 StackFrame *pSF = new StackFrame();
\r
127 if (pSF == NULL) { SetLastError(ERROR_NOT_ENOUGH_MEMORY); return FALSE; }
\r
130 pSF->pList = pRepository->GetChild(pCurrentURI, bSkipEncrypt, FALSE, &bLoose);
\r
131 if (pSF->pList == NULL) {
\r
132 DWORD n = GetLastError();
\r
133 if (GetLastError() == ERROR_CANCELLED) {
\r
140 if (iDirection == 1) {
\r
143 pSF->nPos = pSF->pList->GetSize() - 1;
\r
152 //////////////////////////////////////////////////
\r
153 // cutomisable methods
\r
154 //////////////////////////////////////////////////
\r
156 void URIScanner::InitialScan() {}
\r
157 void URIScanner::AfterScan() {}
\r
158 void URIScanner::PreFolder() {}
\r
159 void URIScanner::PostFolder() {}
\r
160 void URIScanner::Node() {}
\r
162 //////////////////////////////////////////////////
\r
164 //////////////////////////////////////////////////
\r
166 BOOL URIScanner::FullScan()
\r
168 return Scan(NULL, FALSE);
\r
171 //////////////////////////////////////////////////
\r
173 //////////////////////////////////////////////////
\r
175 BOOL URIScanner::Scan(const TomboURI *pStartURI, BOOL bReverse)
\r
184 pBaseTitle = new TString();
\r
185 if (!pRepository->GetHeadLine(pBaseURI, pBaseTitle)) return FALSE;
\r
187 // set marker and call initialize method
\r
188 pCurrentURI = pBaseURI;
\r
189 pTitle = pBaseTitle->Get();
\r
193 // create stack frame
\r
194 if (pStartURI == NULL || _tcscmp(pStartURI->GetFullURI(), pBaseURI->GetFullURI()) == 0) {
\r
195 if (!PushFrame(pCurrentURI)) return FALSE;
\r
202 // if pStartURI is passed, traverse the tree to create stack frame.
\r
203 if (!MakeFrame(pStartURI)) {
\r
209 // enum current frame
\r
210 while (pTop->nPos >= 0 && pTop->nPos < pTop->pList->GetSize()) {
\r
212 if (bStopScan) break;
\r
215 pCurrentURI = pTop->pList->GetURI(pTop->nPos);
\r
216 pTitle = pTop->pList->GetTitle(pTop->nPos);
\r
218 // check folder or not
\r
219 URIOption opt(NOTE_OPTIONMASK_VALID);
\r
220 if (!pRepository->GetOption(pCurrentURI, &opt)) return FALSE;
\r
223 // create new frame
\r
224 if (!PushFrame(pCurrentURI)) return FALSE;
\r
225 if (bStopScan) break;
\r
231 pTop->nPos += iDirection;
\r
234 // when enumeration finished,
\r
237 pCurrentURI = pTop->pList->GetURI(pTop->nPos);
\r
238 pTitle = pTop->pList->GetTitle(pTop->nPos);
\r
240 pCurrentURI = pBaseURI;
\r
241 pTitle = pBaseTitle->Get();
\r
245 pTop->nPos += iDirection;
\r
249 // call finalize method
\r
255 //////////////////////////////////////////////////
\r
257 //////////////////////////////////////////////////
\r
259 BOOL URIScanner::MakeFrame(const TomboURI *pStartURI)
\r
261 // check base uri and start uri
\r
262 TString repB, repS;
\r
263 if (!pBaseURI->GetRepositoryName(&repB) || !pStartURI->GetRepositoryName(&repS) ||
\r
264 _tcscmp(repB.Get(), repS.Get()) != 0) return FALSE;
\r
266 TomboURIItemIterator itrB(pBaseURI);
\r
267 TomboURIItemIterator itrS(pStartURI);
\r
268 if (!itrB.Init() || !itrS.Init()) return FALSE;
\r
269 itrB.First(); itrS.First();
\r
271 LPCTSTR pB = itrB.Current();
\r
272 LPCTSTR pS = itrS.Current();
\r
274 if (pB == NULL || pS == NULL) {
\r
275 if (pS == NULL && pB != NULL) return FALSE;
\r
279 if (_tcscmp(pB, pS) != 0) return FALSE;
\r
285 // OK, stack frames.
\r
287 const TomboURI *pURI = pCurrentURI;
\r
289 pTitle = pBaseTitle->Get();
\r
291 // stack first frame
\r
292 if (!PushFrame(pURI)) return FALSE;
\r
297 LPCTSTR pElement = itrS.Current();
\r
301 // get each element
\r
302 if (itrS.IsLeaf()) {
\r
303 if (!pRepository->GetHeadLine(pStartURI, &shl)) return FALSE;
\r
304 pHeadLine = shl.Get();
\r
307 pHeadLine = pElement;
\r
311 while (pTop->nPos >= 0 && pTop->nPos < pTop->pList->GetSize()) {
\r
312 LPCTSTR pElem = pTop->pList->GetTitle(pTop->nPos);
\r
314 if (_tcscmp(pHeadLine, pElem) == 0) {
\r
315 // path is matched.
\r
317 pCurrentURI = pTop->pList->GetURI(pTop->nPos);
\r
320 URIOption opt(NOTE_OPTIONMASK_VALID);
\r
321 if (!pRepository->GetOption(pCurrentURI, &opt)) return FALSE;
\r
323 if (!PushFrame(pCurrentURI)) return FALSE;
\r
324 if (bStopScan) break;
\r
332 pTop->nPos += iDirection;
\r
336 } while((pElement = itrS.Current()) != NULL);
\r