Develop and Download Open Source Software

Browse CVS Repository

Contents of /tombo/Tombo/Src/Repository.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.22 - (show annotations) (download) (as text)
Wed Aug 23 15:31:54 2006 UTC (17 years, 7 months ago) by hirami
Branch: MAIN
CVS Tags: B231, B230, Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B222, B223, HEAD
Changes since 1.21: +211 -39 lines
File MIME type: text/x-c++src
- Multi repository support(yet completed)
- Fixes to YAE
	* Hang up when *.tdt points invalid position.

1 #include <windows.h>
2 #include <tchar.h>
3
4 #include "Tombo.h"
5 #include "message.h"
6 #include "TString.h"
7 #include "Uniconv.h"
8 #include "TomboURI.h"
9 #include "Repository.h"
10 #include "Property.h"
11
12 #include "AutoPtr.h"
13
14 #include "RepositoryImpl.h"
15
16 // At this time, Repository is only proxy to RepositoryImpl.
17 // This class will choose repository implementations in future.
18
19 /////////////////////////////////////////
20 // Global definition
21 /////////////////////////////////////////
22
23 Repository g_Repository;
24
25 /////////////////////////////////////////
26 // Repository ctor & dtor, initializer
27 /////////////////////////////////////////
28
29 Repository::Repository() : pDefaultImpl(NULL)
30 {
31 }
32
33 Repository::~Repository()
34 {
35 }
36
37 BOOL Repository::Init()
38 {
39 if (!vSubRepository.Init(10, 10)) return FALSE;
40 return ClearSubRepository();
41 }
42
43 BOOL Repository::ClearSubRepository()
44 {
45 for (DWORD i = 0; i < vSubRepository.NumItems(); i++) {
46 RepositoryImpl *p = *vSubRepository.GetUnit(i);
47 delete p;
48 }
49 vSubRepository.Clear(FALSE);
50
51 pDefaultImpl = NULL;
52 return TRUE;
53 }
54
55 BOOL Repository::AddSubRepository(RepositoryImpl *pImpl)
56 {
57 if (!vSubRepository.Add(&pImpl)) return FALSE;
58
59 pDefaultImpl = *vSubRepository.GetUnit(0);
60 return TRUE;
61 }
62
63 BOOL Repository::GetAttachURI(const TomboURI *pBase, TomboURI *pAttached)
64 {
65 if (pBase->IsLeaf()) {
66 if (!pBase->GetParent(pAttached)) return FALSE;
67 } else {
68 if (!pAttached->Init(pBase->GetFullURI())) return FALSE;
69 }
70 return TRUE;
71 }
72
73 RepositoryImpl *Repository::GetAssocSubRepository(const TomboURI *pURI)
74 {
75 DWORD n = vSubRepository.NumItems();
76 for (DWORD i = 0; i < n; i++) {
77 RepositoryImpl *pImpl = *vSubRepository.GetUnit(i);
78 if (_tcsncmp(pImpl->GetRootURI()->GetFullURI() + 8, pURI->GetFullURI() + 8, pImpl->GetRepNameLen() + 1) == 0) {
79 return pImpl;
80 }
81 }
82 return NULL;
83 }
84
85 /////////////////////////////////////////
86 // delegated methods
87 /////////////////////////////////////////
88
89 BOOL Repository::Update(const TomboURI *pCurrentURI,
90 LPCTSTR pData,
91 TomboURI *pNewURI, TString *pNewHeadLine)
92 {
93 // pNewURI is in same sub repository
94 RepositoryImpl *pImpl = GetAssocSubRepository(pCurrentURI);
95 if (pImpl == NULL) return FALSE;
96 return pImpl->Update(pCurrentURI, pData, pNewURI, pNewHeadLine);
97 }
98
99 BOOL Repository::GetHeadLine(const TomboURI *pURI, TString *pHeadLine)
100 {
101 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
102 if (pImpl == NULL) return FALSE;
103 return pImpl->GetHeadLine(pURI, pHeadLine);
104 }
105
106 BOOL Repository::GetOption(const TomboURI *pURI, URIOption *pOption)
107 {
108 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
109 if (pImpl == NULL) return FALSE;
110 return pImpl->GetOption(pURI, pOption);
111 }
112
113 BOOL Repository::SetOption(const TomboURI *pCurrentURI, URIOption *pOption)
114 {
115 RepositoryImpl *pImpl = GetAssocSubRepository(pCurrentURI);
116 if (pImpl == NULL) return FALSE;
117 return pImpl->SetOption(pCurrentURI, pOption);
118 }
119
120 BOOL Repository::IsEncrypted(const TomboURI *pURI)
121 {
122 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
123 if (pImpl == NULL) return FALSE;
124 return pImpl->IsEncrypted(pURI);
125 }
126
127 BOOL Repository::Delete(const TomboURI *pURI, URIOption *pOption)
128 {
129 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
130 if (pImpl == NULL) return FALSE;
131 return pImpl->Delete(pURI, pOption);
132 }
133
134 BOOL Repository::Copy(const TomboURI *pCopyFrom, const TomboURI *pCopyTo, URIOption *pOption)
135 {
136 // XXXX over subrepository is not supported yet.
137 RepositoryImpl *pImpl = GetAssocSubRepository(pCopyFrom);
138 if (pImpl == NULL) return FALSE;
139 return pImpl->Copy(pCopyFrom, pCopyTo, pOption);
140 }
141
142 BOOL Repository::Move(const TomboURI *pMoveFrom, const TomboURI *pMoveTo, URIOption *pOption)
143 {
144 // XXXX over subrepository is not supported yet.
145 RepositoryImpl *pImpl = GetAssocSubRepository(pMoveFrom);
146 if (pImpl == NULL) return FALSE;
147 return pImpl->Move(pMoveFrom, pMoveTo, pOption);
148 }
149
150 BOOL Repository::GetPhysicalPath(const TomboURI *pURI, TString *pFullPath)
151 {
152 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
153 if (pImpl == NULL) return FALSE;
154 return pImpl->GetPhysicalPath(pURI, pFullPath);
155 }
156
157 BOOL Repository::ChangeHeadLine(const TomboURI *pURI, LPCTSTR pReqNewHeadLine, URIOption *pOption)
158 {
159 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
160 if (pImpl == NULL) return FALSE;
161 return pImpl->ChangeHeadLine(pURI, pReqNewHeadLine, pOption);
162 }
163
164
165 URIList *Repository::GetChild(const TomboURI *pFolder, BOOL bSkipEncrypt, BOOL bLooseDecrypt, BOOL *pLoose)
166 {
167 RepositoryImpl *pImpl = GetAssocSubRepository(pFolder);
168 if (pImpl == NULL) return FALSE;
169 return pImpl->GetChild(pFolder, bSkipEncrypt, bLooseDecrypt, pLoose);
170 }
171
172 BOOL Repository::RequestAllocateURI(const TomboURI *pBaseURI, LPCTSTR pText, TString *pHeadLine, TomboURI *pURI, const TomboURI *pTemplateURI)
173 {
174 RepositoryImpl *pImpl = GetAssocSubRepository(pBaseURI);
175 if (pImpl == NULL) return FALSE;
176 return pImpl->RequestAllocateURI(pBaseURI, pText, pHeadLine, pURI, pTemplateURI);
177 }
178
179 BOOL Repository::GetAttribute(const TomboURI *pURI, NoteAttribute *pAttribute)
180 {
181 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
182 if (pImpl == NULL) return FALSE;
183 return pImpl->GetAttribute(pURI, pAttribute);
184 }
185
186 BOOL Repository::GetNoteAttribute(const TomboURI *pURI, UINT64 *pLastUpdate, UINT64 *pCreateDate, UINT64 *pFileSize)
187 {
188 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
189 if (pImpl == NULL) return FALSE;
190 return pImpl->GetNoteAttribute(pURI, pLastUpdate, pCreateDate, pFileSize);
191 }
192
193 BOOL Repository::SetAttribute(const TomboURI *pURI, const NoteAttribute *pAttribute)
194 {
195 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
196 if (pImpl == NULL) return FALSE;
197 return pImpl->SetAttribute(pURI, pAttribute);
198 }
199
200 LPTSTR Repository::GetNoteData(const TomboURI *pURI)
201 {
202 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
203 if (pImpl == NULL) return FALSE;
204 return pImpl->GetNoteData(pURI);
205 }
206
207 LPBYTE Repository::GetNoteDataNative(const TomboURI *pURI, LPDWORD pSize)
208 {
209 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
210 if (pImpl == NULL) return FALSE;
211 return pImpl->GetNoteDataNative(pURI, pSize);
212 }
213
214 BOOL Repository::ExecuteAssoc(const TomboURI *pURI, ExeAppType nType)
215 {
216 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
217 if (pImpl == NULL) return FALSE;
218 return pImpl->ExecuteAssoc(pURI, nType);
219 }
220
221 BOOL Repository::MakeFolder(const TomboURI *pParent, LPCTSTR pFolderName)
222 {
223 RepositoryImpl *pImpl = GetAssocSubRepository(pParent);
224 if (pImpl == NULL) return FALSE;
225 return pImpl->MakeFolder(pParent, pFolderName);
226 }
227
228 BOOL Repository::GetFileName(const TomboURI *pURI, TString *pName)
229 {
230 RepositoryImpl *pImpl = GetAssocSubRepository(pURI);
231 if (pImpl == NULL) return FALSE;
232 return pURI->GetBaseName(pName);
233 }
234
235 /////////////////////////////////////////
236 // sub repository IF
237 /////////////////////////////////////////
238
239 DWORD Repository::GetNumOfSubRepository()
240 {
241 return vSubRepository.NumItems();
242 }
243
244 DWORD Repository::GetSubRepositoryType(DWORD nIndex)
245 {
246 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
247 if (pImpl == NULL) return NULL;
248
249 return pImpl->GetRepositoryType();
250 }
251
252 LPCTSTR Repository::GetSubRepositoryName(DWORD nIndex)
253 {
254 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
255 if (pImpl == NULL) return NULL;
256
257 return pImpl->GetDisplayName();
258 }
259
260 const TomboURI *Repository::GetSubRepositoryRootURI(DWORD nIndex)
261 {
262 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
263 if (pImpl == NULL) return NULL;
264 return pImpl->GetRootURI();
265 }
266
267 LPTSTR Repository::GetSubRepoXMLSaveString(DWORD nIndex)
268 {
269 RepositoryImpl *pImpl = *vSubRepository.GetUnit(nIndex);
270 if (pImpl == NULL) return NULL;
271 return pImpl->GetXMLSaveString();
272 }
273
274 // factory methods for RepositoryImpl
275 RepositoryImpl *Repository::CreateSubRepo(LPCWSTR pName, const WCHAR **atts)
276 {
277 if (wcscmp(pName, L"localfile") == 0) {
278 DWORD i = 0;
279 LPTSTR pDispName = NULL;
280 LPTSTR pRepName = NULL;
281 LPTSTR pTopDir = NULL;
282 BOOL bKeepTitle = FALSE;
283 BOOL bKeepCaret = FALSE;
284 BOOL bSafeFileName = FALSE;
285
286 while (atts[i] != L'\0') {
287 if (wcscmp(atts[i], L"name") == 0) {
288 pRepName = ConvWCharToTChar(atts[i + 1]);
289 } else if (wcscmp(atts[i], L"dispname") == 0) {
290 pDispName = ConvWCharToTChar(atts[i + 1]);
291 } else if (wcscmp(atts[i], L"path") == 0) {
292 pTopDir = ConvWCharToTChar(atts[i + 1]);
293 } else if (wcscmp(atts[i], L"keeptitle") == 0) {
294 bKeepTitle = (wcscmp(atts[i + 1], L"1") == 0);
295 } else if (wcscmp(atts[i], L"keepcaret") == 0) {
296 bKeepCaret = (wcscmp(atts[i + 1], L"1") == 0);
297 } else if (wcscmp(atts[i], L"safefilename") == 0) {
298 bSafeFileName = (wcscmp(atts[i + 1], L"1") == 0);
299 }
300 i+= 2;
301 }
302 ArrayAutoPointer<TCHAR> ap1(pDispName), ap2(pRepName), ap3(pTopDir);
303
304 if (pRepName == NULL || pDispName == NULL || pTopDir == NULL) {
305 SetLastError(ERROR_INVALID_PARAMETER);
306 return NULL;
307 }
308
309 LocalFileRepository *pImpl = new LocalFileRepository();
310 if (pImpl == NULL) {
311 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
312 return NULL;
313 }
314 if (!pImpl->Init(pRepName, pDispName, pTopDir, bKeepTitle, bKeepCaret, bSafeFileName)) {
315 delete[] pImpl;
316 return NULL;
317 }
318 return pImpl;
319 } else if (wcscmp(pName, L"vfolder") == 0) {
320 LPTSTR pDispName = NULL;
321 LPTSTR pRepName = NULL;
322 DWORD i = 0;
323 while (atts[i] != L'\0') {
324 if (wcscmp(atts[i], L"name") == 0) {
325 pRepName = ConvWCharToTChar(atts[i + 1]);
326 } else if (wcscmp(atts[i], L"dispname") == 0) {
327 pDispName = ConvWCharToTChar(atts[i + 1]);
328 }
329 i += 2;
330 }
331 ArrayAutoPointer<TCHAR> ap1(pDispName), ap2(pRepName);
332
333 VFolderRepository *pImpl = new VFolderRepository();
334 if (pImpl == NULL) {
335 SetLastError(ERROR_NOT_ENOUGH_MEMORY);
336 return NULL;
337 }
338 if (!pImpl->Init(pRepName, pDispName)) {
339 delete[] pImpl;
340 return NULL;
341 }
342 return pImpl;
343 } else {
344 return NULL;
345 }
346 }

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26