[go: up one dir, main page]

Menu

[r1]: / Token.cpp  Maximize  Restore  History

Download this file

120 lines (105 with data), 3.2 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
// Token.cpp: implementation of the Token class.
//
//////////////////////////////////////////////////////////////////////
#include "Token.h"
#include <shlwapi.h>
#include "Helpers.h"
//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////
CToken::CToken(LPCTSTR mask, bool relaxed):
count(0),token(NULL), intval(0)
{
LPTSTR tmp;
int ln, i, last =0;
for (ln=0, i=0; mask[ln] !=0; ln++) if (mask[ln]=='*') i++;
token = new TOKEN[i+1];
for (i=0; i<= ln; i++) {
if (mask[i]=='*' || mask[i]==0) {
if ((i-last)>0) {
token[count].disp = (last>0)?( (mask[i]==0)? TOKEN::END: TOKEN::ENTIRE ): TOKEN::START;
token[count].len = i-last;
token[count].ptr = new TCHAR[i-last+1];
tmp = StrNCopy(token[count].ptr, mask+last, i-last-1);
*tmp=0;
count++;
}
last = i+1;
}
}
if (count==1 && relaxed) token[0].disp = TOKEN::ENTIRE;
if (count>0) intval = StrToInt(token[0].ptr);
}
CToken::~CToken()
{
while(count--) delete token[count].ptr;
delete token;
}
bool CToken::IsMatch(LPCTSTR string)
{
//if (this==NULL) return true;
unsigned ln = StrLen(string);
int i, res = 0;
LPCTSTR end=string+ln;
for (i = 0; i< count; i++) {
if (*string==0) return false;
if (token[i].disp==TOKEN::END) {
res = CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
end-token[i].len, token[i].len,
token[i].ptr, token[i].len);
if (res!=CSTR_EQUAL) return false;
} else {
while (*string) {
res = CompareString(LOCALE_USER_DEFAULT, NORM_IGNORECASE,
string, token[i].len,
token[i].ptr, token[i].len);
if (res==CSTR_EQUAL) {
string+=token[i].len;
break;
}
if (token[i].disp==TOKEN::START) return false;
if ((--ln) < token[i].len) return false;
string++;
}
}
}
return (*string)!=0 || (res==CSTR_EQUAL);//;
}
int CToken::IntCompare(int number)
{
return (number - intval);
}
/***************************************************************************************
*
*
***************************************************************************************/
CTokenFile::CTokenFile(LPCTSTR mask, DWORD minSizeMB, DWORD maxSizeMB):
CToken(mask)
{
minmax.min = minSizeMB;
minmax.max = maxSizeMB;
}
CTokenFile::~CTokenFile()
{
}
bool CTokenFile::IsMatch(WIN32_FIND_DATA &wfd)
{
if (*(long*)wfd.cFileName == 0x2e || *(long*)wfd.cFileName == 0x002e002e) return false;
if ((wfd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)==0 && !ValidSize(wfd)) return false;
// if (StrCmp(wfd.cFileName,TEXT("CRUSH"))==0) {
// wfd.dwFileAttributes = wfd.dwFileAttributes;
// }
return CToken::IsMatch(wfd.cFileName);
}
bool CTokenFile::ValidSize(WIN32_FIND_DATA &wfd)
{
if ((minmax.min | minmax.max)==0) return true;
ULARGE_INTEGER ul;
ul.LowPart = wfd.nFileSizeLow;
ul.HighPart = wfd.nFileSizeHigh;
ul.QuadPart >>= 10;
if (minmax.min && minmax.min*1024 > ul.LowPart) return false;
if (minmax.max && minmax.max*1024 < ul.LowPart) return false;
//if ()) {
return true;
}