Browse CVS Repository
Contents of /tombo/Tombo/Src/DirList.cpp
Parent Directory
| Revision Log
| Revision Graph
Revision 1.9 -
( show annotations)
( download)
( as text)
Tue Feb 7 17:07:37 2006 UTC
(18 years, 2 months ago)
by hirami
Branch: MAIN
CVS Tags: Tombo_2_0a3, Tombo_1_17_1, B199, B200, B201, B202, B203, B205, B206, B207, B208, B213, B212, B211, B217, B216, B215, B214, B219, B218, Tombo_2_0b2, Tombo_2_0b3, Tombo_2_0b1, Tombo_2_0b4, B228, B229, B226, B227, B224, B225, B222, B223, B220, B221, B231, B230, Tombo_1_17, Tombo_1_16, HEAD
Branch point for: Tombo_1_17_1_branch
Changes since 1.8: +24 -11 lines
File MIME type: text/x-c++src
* When some *.chs crypted with another password, popup warnings and show title '???????' if crypt failed.(#7227)
* Add RegErase tool.
| 1 |
#include <windows.h> |
| 2 |
#include <tchar.h> |
| 3 |
#include "Tombo.h" |
| 4 |
#include "DirList.h" |
| 5 |
#include "MemoNote.h" |
| 6 |
#include "TString.h" |
| 7 |
#include "TomboURI.h" |
| 8 |
#include "Repository.h" |
| 9 |
|
| 10 |
static StringBufferT *pSortSB; |
| 11 |
extern "C" int SortItems(const void *e1, const void *e2) |
| 12 |
{ |
| 13 |
const DirListItem *p1 = (const DirListItem*)e1; |
| 14 |
const DirListItem *p2 = (const DirListItem*)e2; |
| 15 |
LPCTSTR q1 = pSortSB->Get(p1->nHeadLinePos); |
| 16 |
LPCTSTR q2 = pSortSB->Get(p2->nHeadLinePos); |
| 17 |
if (p1->bFolder == p2->bFolder) { |
| 18 |
return _tcsicmp(q1, q2); |
| 19 |
} else { |
| 20 |
if (p1->bFolder) { |
| 21 |
return -1; |
| 22 |
} else { |
| 23 |
return 1; |
| 24 |
} |
| 25 |
} |
| 26 |
} |
| 27 |
|
| 28 |
BOOL DirList::Init(LPCTSTR pUB) |
| 29 |
{ |
| 30 |
pURIBase = pUB; |
| 31 |
|
| 32 |
if (!vDirList.Init(50, 10)) return FALSE; |
| 33 |
if (!sbDirList.Init(400, 20)) return FALSE; |
| 34 |
return TRUE; |
| 35 |
} |
| 36 |
|
| 37 |
DirList::~DirList() |
| 38 |
{ |
| 39 |
} |
| 40 |
|
| 41 |
DWORD DirList::GetList(LPCTSTR pMatchPath, BOOL bSkipEncrypt, BOOL bLooseDecrypt) |
| 42 |
{ |
| 43 |
BOOL bPartial = FALSE; |
| 44 |
|
| 45 |
// make folder/file list |
| 46 |
WIN32_FIND_DATA wfd; |
| 47 |
HANDLE hHandle = FindFirstFile(pMatchPath, &wfd); |
| 48 |
if (hHandle != INVALID_HANDLE_VALUE) { |
| 49 |
struct DirListItem di; |
| 50 |
|
| 51 |
do { |
| 52 |
if (_tcscmp(wfd.cFileName, TEXT(".")) == 0 || _tcscmp(wfd.cFileName, TEXT("..")) == 0) continue; |
| 53 |
|
| 54 |
DWORD l = _tcslen(wfd.cFileName); |
| 55 |
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 56 |
// folder |
| 57 |
di.bFolder = TRUE; |
| 58 |
} else { |
| 59 |
// file |
| 60 |
DWORD n = MemoNote::IsNote(wfd.cFileName); |
| 61 |
if (n == NOTE_TYPE_NO || n == NOTE_TYPE_TDT) continue; |
| 62 |
|
| 63 |
di.bFolder = FALSE; |
| 64 |
} |
| 65 |
|
| 66 |
if (!sbDirList.Add(pURIBase, _tcslen(pURIBase), &(di.nURIPos))) return DIRLIST_GETLIST_RESULT_FAIL; |
| 67 |
DWORD d; |
| 68 |
if (!sbDirList.Add(wfd.cFileName, l, &d)) return DIRLIST_GETLIST_RESULT_FAIL; |
| 69 |
if (wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { |
| 70 |
if (!sbDirList.Add(TEXT("/"), 1, &d)) return DIRLIST_GETLIST_RESULT_FAIL; |
| 71 |
} |
| 72 |
if (!sbDirList.Add(TEXT(""), 1, &d)) return DIRLIST_GETLIST_RESULT_FAIL; |
| 73 |
|
| 74 |
TomboURI sURI; |
| 75 |
TString sHeadLine; |
| 76 |
if (!sURI.Init(GetFileName(di.nURIPos))) return DIRLIST_GETLIST_RESULT_FAIL; |
| 77 |
|
| 78 |
URIOption opt(NOTE_OPTIONMASK_ENCRYPTED); |
| 79 |
g_Repository.GetOption(&sURI, &opt); |
| 80 |
|
| 81 |
if (!opt.bEncrypt || !bSkipEncrypt) { |
| 82 |
if (!g_Repository.GetHeadLine(&sURI, &sHeadLine)) { |
| 83 |
if (GetLastError() == ERROR_INVALID_PASSWORD && bLooseDecrypt) { |
| 84 |
bPartial = TRUE; |
| 85 |
sHeadLine.Set(TEXT("????????")); |
| 86 |
} else { |
| 87 |
return DIRLIST_GETLIST_RESULT_FAIL; |
| 88 |
} |
| 89 |
} |
| 90 |
if (!sbDirList.Add(sHeadLine.Get(), _tcslen(sHeadLine.Get()) + 1, &(di.nHeadLinePos))) return DIRLIST_GETLIST_RESULT_FAIL; |
| 91 |
|
| 92 |
// Add file name to buffer |
| 93 |
if (!sbDirList.Add(wfd.cFileName, l + 1, &(di.nFileNamePos))) return DIRLIST_GETLIST_RESULT_FAIL; |
| 94 |
if (!vDirList.Add(&di)) return DIRLIST_GETLIST_RESULT_FAIL; |
| 95 |
} |
| 96 |
} while(FindNextFile(hHandle, &wfd)); |
| 97 |
FindClose(hHandle); |
| 98 |
} |
| 99 |
|
| 100 |
DWORD n = vDirList.NumItems(); |
| 101 |
|
| 102 |
// sort |
| 103 |
pSortSB = &sbDirList; |
| 104 |
qsort((LPBYTE)vDirList.GetBuf(), n, sizeof(struct DirListItem), SortItems); |
| 105 |
|
| 106 |
if (bPartial) { |
| 107 |
return DIRLIST_GETLIST_RESULT_PARTIAL; |
| 108 |
} else { |
| 109 |
return DIRLIST_GETLIST_RESULT_SUCCESS; |
| 110 |
} |
| 111 |
} |
| |