Index: src/libchcore/TFileFilter.cpp =================================================================== diff -u -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/TFileFilter.cpp (.../TFileFilter.cpp) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) +++ src/libchcore/TFileFilter.cpp (.../TFileFilter.cpp) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -143,69 +143,35 @@ TString TFileFilter::GetCombinedMask() const { - TString strMask; - size_t stCount = m_astrMask.Get().GetCount(); - if (stCount > 0) - { - strMask = m_astrMask.Get().GetAt(0).ToSerializedString(); - for (size_t stIndex = 1; stIndex < stCount; stIndex++) - { - strMask += _T("|") + m_astrMask.Get().GetAt(stIndex).ToSerializedString(); - } - } - - return strMask; + return m_astrMask.Get().ToString(); } void TFileFilter::SetCombinedMask(const TString& strMask) { - TStringArray arrMasks; - strMask.Split(_T("|"), arrMasks); - TStringPatternArray& rPatterns = m_astrMask.Modify(); rPatterns.Clear(); - for (size_t stIndex = 0; stIndex < arrMasks.GetCount(); ++stIndex) - { - rPatterns.Add(TStringPattern::CreateFromSerializedString(arrMasks.GetAt(stIndex))); - } + rPatterns.FromString(strMask); } TString TFileFilter::GetCombinedExcludeMask() const { - TString strMask; - size_t stCount = m_astrExcludeMask.Get().GetCount(); - if (stCount > 0) - { - strMask = m_astrExcludeMask.Get().GetAt(0).ToSerializedString(); - for (size_t stIndex = 1; stIndex < stCount; stIndex++) - { - strMask += _T("|") + m_astrExcludeMask.Get().GetAt(stIndex).ToSerializedString(); - } - } - - return strMask; + return m_astrExcludeMask.Get().ToString(); } void TFileFilter::SetCombinedExcludeMask(const TString& strMask) { - TStringArray arrMasks; - strMask.Split(_T("|"), arrMasks); - TStringPatternArray& rPatterns = m_astrExcludeMask.Modify(); rPatterns.Clear(); - for (size_t stIndex = 0; stIndex < arrMasks.GetCount(); ++stIndex) - { - rPatterns.Add(TStringPattern::CreateFromSerializedString(arrMasks.GetAt(stIndex))); - } + rPatterns.FromString(strMask); } void TFileFilter::StoreInConfig(TConfig& rConfig) const { SetConfigValue(rConfig, _T("IncludeMask.Use"), m_bUseMask.Get()); - SetConfigValue(rConfig, _T("IncludeMask.MaskList.Mask"), m_astrMask.Get().ToStringArray()); + SetConfigValue(rConfig, _T("IncludeMask.MaskList.Mask"), m_astrMask.Get().ToSerializedStringArray()); SetConfigValue(rConfig, _T("ExcludeMask.Use"), m_bUseExcludeMask.Get()); - SetConfigValue(rConfig, _T("ExcludeMask.MaskList.Mask"), m_astrExcludeMask.Get().ToStringArray()); + SetConfigValue(rConfig, _T("ExcludeMask.MaskList.Mask"), m_astrExcludeMask.Get().ToSerializedStringArray()); SetConfigValue(rConfig, _T("SizeA.Use"), m_bUseSize1.Get()); SetConfigValue(rConfig, _T("SizeA.FilteringType"), m_eSizeCmpType1.Get()); @@ -243,14 +209,14 @@ TStringArray arrMask; m_astrMask.Modify().Clear(); GetConfigValue(rConfig, _T("IncludeMask.MaskList.Mask"), arrMask); - m_astrMask.Modify().FromStringArray(arrMask); + m_astrMask.Modify().FromSerializedStringArray(arrMask); if (!GetConfigValue(rConfig, _T("ExcludeMask.Use"), m_bUseExcludeMask.Modify())) m_bUseExcludeMask = false; m_astrExcludeMask.Modify().Clear(); GetConfigValue(rConfig, _T("ExcludeMask.MaskList.Mask"), arrMask); - m_astrExcludeMask.Modify().FromStringArray(arrMask); + m_astrExcludeMask.Modify().FromSerializedStringArray(arrMask); if (!GetConfigValue(rConfig, _T("SizeA.Use"), m_bUseSize1.Modify())) m_bUseSize1 = false; @@ -491,12 +457,12 @@ rColumns.AddColumn(_T("date_compare_type_1"), IColumnsDefinition::eType_int); rColumns.AddColumn(_T("use_date_1"), IColumnsDefinition::eType_bool); rColumns.AddColumn(_T("use_time_1"), IColumnsDefinition::eType_bool); - rColumns.AddColumn(_T("datetime_1"), IColumnsDefinition::eType_ulonglong); + rColumns.AddColumn(_T("datetime_1"), IColumnsDefinition::eType_longlong); rColumns.AddColumn(_T("use_date_time_2"), IColumnsDefinition::eType_bool); rColumns.AddColumn(_T("date_compare_type_2"), IColumnsDefinition::eType_int); rColumns.AddColumn(_T("use_date_2"), IColumnsDefinition::eType_bool); rColumns.AddColumn(_T("use_time_2"), IColumnsDefinition::eType_bool); - rColumns.AddColumn(_T("datetime_2"), IColumnsDefinition::eType_ulonglong); + rColumns.AddColumn(_T("datetime_2"), IColumnsDefinition::eType_longlong); rColumns.AddColumn(_T("use_attributes"), IColumnsDefinition::eType_bool); rColumns.AddColumn(_T("attr_archive"), IColumnsDefinition::eType_int); rColumns.AddColumn(_T("attr_ro"), IColumnsDefinition::eType_int); @@ -543,7 +509,7 @@ if (bAdded || m_setModifications[eMod_UseTime1]) rRow.SetValue(_T("use_time_1"), m_bUseTime1); if (bAdded || m_setModifications[eMod_DateTime1]) - rRow.SetValue(_T("datetime_1"), m_tDateTime1.Get().GetAsTimeT()); + rRow.SetValue(_T("datetime_1"), (long long)m_tDateTime1.Get().GetAsTimeT()); if (bAdded || m_setModifications[eMod_UseDateTime2]) rRow.SetValue(_T("use_date_time_2"), m_bUseDateTime2); if (bAdded || m_setModifications[eMod_DateCmpType2]) @@ -553,7 +519,7 @@ if (bAdded || m_setModifications[eMod_UseTime2]) rRow.SetValue(_T("use_time_2"), m_bUseTime2); if (bAdded || m_setModifications[eMod_DateTime2]) - rRow.SetValue(_T("datetime_2"), m_tDateTime2.Get().GetAsTimeT()); + rRow.SetValue(_T("datetime_2"), (long long)m_tDateTime2.Get().GetAsTimeT()); if (bAdded || m_setModifications[eMod_UseAttributes]) rRow.SetValue(_T("use_attributes"), m_bUseAttributes); if (bAdded || m_setModifications[eMod_AttrArchive]) Index: src/libchcore/TStringPattern.cpp =================================================================== diff -u -re8f31b0f922b402878356e130c866c4f3682a7f5 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision e8f31b0f922b402878356e130c866c4f3682a7f5) +++ src/libchcore/TStringPattern.cpp (.../TStringPattern.cpp) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -26,14 +26,32 @@ { } - TString TStringPattern::ToSerializedString() const + TStringPattern TStringPattern::CreateFromString(const TString& strPattern, EPatternType eDefaultPatternType) { + TStringPattern pattern; + pattern.FromString(strPattern, eDefaultPatternType); + return pattern; + } + + void TStringPattern::FromString(const TString& strPattern, EPatternType eDefaultPatternType) + { + m_ePatternType = eDefaultPatternType; + if (strPattern.StartsWith(L"WC;")) + { + m_strPattern = strPattern.Mid(3); + m_ePatternType = EPatternType::eType_Wildcard; + } + else + m_strPattern = strPattern; + } + + chcore::TString TStringPattern::ToString() const + { TString strPrefix; switch (m_ePatternType) { case EPatternType::eType_Wildcard: - strPrefix = L"WC;"; - break; + break; // wildcard won't have any prefix (it's implicit) default: throw TCoreException(eErr_UnhandledCase, L"Pattern type not supported", LOCATION); @@ -42,27 +60,9 @@ return TString(strPrefix + m_strPattern); } - void TStringPattern::FromSerializedString(const TString& strSerializedPattern) - { - if (strSerializedPattern.StartsWith(L"WC;")) - { - m_ePatternType = EPatternType::eType_Wildcard; - m_strPattern = strSerializedPattern.Mid(3); - } - else - throw TCoreException(eErr_UnhandledCase, L"Pattern type not supported", LOCATION); - } - - TStringPattern TStringPattern::CreateFromSerializedString(const TString& strSerializedPattern) - { - TStringPattern pattern; - pattern.FromSerializedString(strSerializedPattern); - return pattern; - } - bool TStringPattern::MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const { - bool bMatch = 1; + bool bMatch = true; //iterate and delete '?' and '*' one by one while (*lpszMask != _T('\0') && bMatch && *lpszString != _T('\0')) Index: src/libchcore/TStringPattern.h =================================================================== diff -u -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/TStringPattern.h (.../TStringPattern.h) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) +++ src/libchcore/TStringPattern.h (.../TStringPattern.h) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -42,11 +42,11 @@ EPatternType GetPatternType() const { return m_ePatternType; } TString GetPattern() const { return m_strPattern; } - // serialization - static TStringPattern CreateFromSerializedString(const TString& strSerializedPattern); + // string parsing + static TStringPattern CreateFromString(const TString& strPattern, EPatternType eDefaultPatternType = EPatternType::eType_Wildcard); - void FromSerializedString(const TString& strSerializedPattern); - TString ToSerializedString() const; + void FromString(const TString& strPattern, EPatternType eDefaultPatternType = EPatternType::eType_Wildcard); + TString ToString() const; private: bool MatchMask(LPCTSTR lpszMask, LPCTSTR lpszString) const; Index: src/libchcore/TStringPatternArray.cpp =================================================================== diff -u -re8f31b0f922b402878356e130c866c4f3682a7f5 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision e8f31b0f922b402878356e130c866c4f3682a7f5) +++ src/libchcore/TStringPatternArray.cpp (.../TStringPatternArray.cpp) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -101,22 +101,53 @@ return true; } - void TStringPatternArray::FromStringArray(const TStringArray& arrSerializedPatterns) + void TStringPatternArray::FromString(const TString& strPatterns, TStringPattern::EPatternType eDefaultPatternType) { + TStringArray arrPatterns; + strPatterns.Split(_T("|"), arrPatterns); + FromStringArray(arrPatterns, eDefaultPatternType); + } + + void TStringPatternArray::FromSerializedStringArray(const TStringArray& arrSerializedPatterns) + { m_vPatterns.clear(); for (size_t stIndex = 0; stIndex < arrSerializedPatterns.GetCount(); ++stIndex) { - m_vPatterns.push_back(TStringPattern::CreateFromSerializedString(arrSerializedPatterns.GetAt(stIndex))); + m_vPatterns.push_back(TStringPattern::CreateFromString(arrSerializedPatterns.GetAt(stIndex))); } } - TStringArray TStringPatternArray::ToStringArray() const + void TStringPatternArray::FromStringArray(const TStringArray& arrPatterns, TStringPattern::EPatternType eDefaultPatternType) { + for (size_t stIndex = 0; stIndex < arrPatterns.GetCount(); ++stIndex) + { + Add(TStringPattern::CreateFromString(arrPatterns.GetAt(stIndex), eDefaultPatternType)); + } + } + + TString TStringPatternArray::ToString() const + { + TString strMask; + size_t stCount = GetCount(); + if (stCount > 0) + { + strMask = GetAt(0).ToString(); + for (size_t stIndex = 1; stIndex < stCount; stIndex++) + { + strMask += _T("|") + GetAt(stIndex).ToString(); + } + } + + return strMask; + } + + TStringArray TStringPatternArray::ToSerializedStringArray() const + { TStringArray arrSerialized; for (const TStringPattern& pattern : m_vPatterns) { - arrSerialized.Add(pattern.ToSerializedString()); + arrSerialized.Add(pattern.ToString()); } return arrSerialized; Index: src/libchcore/TStringPatternArray.h =================================================================== diff -u -re96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/TStringPatternArray.h (.../TStringPatternArray.h) (revision e96806b7f8ff7ca7e9f4afbea603e6351a3dc3e3) +++ src/libchcore/TStringPatternArray.h (.../TStringPatternArray.h) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -44,9 +44,14 @@ bool MatchesAny(const TString& strTextToMatch) const; bool MatchesAll(const TString& strTextToMatch) const; + // string parsing + void FromString(const TString& strPatterns, TStringPattern::EPatternType eDefaultPatternType = TStringPattern::EPatternType::eType_Wildcard); + void FromStringArray(const TStringArray& strPatterns, TStringPattern::EPatternType eDefaultPatternType = TStringPattern::EPatternType::eType_Wildcard); + TString ToString() const; + // serialization - void FromStringArray(const TStringArray& arrSerializedPatterns); - TStringArray ToStringArray() const; + void FromSerializedStringArray(const TStringArray& arrSerializedPatterns); + TStringArray ToSerializedStringArray() const; private: #pragma warning(push) Index: src/libchcore/Tests/TestsTStringPattern.cpp =================================================================== diff -u -r2755e12daeccb1935f569e7235e685e566b0b098 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/Tests/TestsTStringPattern.cpp (.../TestsTStringPattern.cpp) (revision 2755e12daeccb1935f569e7235e685e566b0b098) +++ src/libchcore/Tests/TestsTStringPattern.cpp (.../TestsTStringPattern.cpp) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -8,15 +8,15 @@ TEST(TestsTStringPattern, DefaultConstruction) { TStringPattern patternEmpty; - EXPECT_STREQ(L"WC;", patternEmpty.ToSerializedString().c_str()); + EXPECT_STREQ(L"", patternEmpty.ToString().c_str()); EXPECT_STREQ(L"", patternEmpty.GetPattern().c_str()); EXPECT_EQ(TStringPattern::EPatternType::eType_Wildcard, patternEmpty.GetPatternType()); } TEST(TestsTStringPattern, PatternConstruction) { TStringPattern patternEmpty(L"*.*", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_STREQ(L"WC;*.*", patternEmpty.ToSerializedString().c_str()); + EXPECT_STREQ(L"*.*", patternEmpty.ToString().c_str()); EXPECT_STREQ(L"*.*", patternEmpty.GetPattern().c_str()); EXPECT_EQ(TStringPattern::EPatternType::eType_Wildcard, patternEmpty.GetPatternType()); } @@ -27,26 +27,26 @@ patternEmpty.SetPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard); - EXPECT_STREQ(L"WC;*.bat", patternEmpty.ToSerializedString().c_str()); + EXPECT_STREQ(L"*.bat", patternEmpty.ToString().c_str()); EXPECT_STREQ(L"*.bat", patternEmpty.GetPattern().c_str()); EXPECT_EQ(TStringPattern::EPatternType::eType_Wildcard, patternEmpty.GetPatternType()); } TEST(TestsTStringPattern, CreateFromSerializedString) { - TStringPattern patternEmpty = TStringPattern::CreateFromSerializedString(L"WC;*.*"); + TStringPattern patternEmpty = TStringPattern::CreateFromString(L"WC;*.*"); - EXPECT_STREQ(L"WC;*.*", patternEmpty.ToSerializedString().c_str()); + EXPECT_STREQ(L"*.*", patternEmpty.ToString().c_str()); EXPECT_STREQ(L"*.*", patternEmpty.GetPattern().c_str()); EXPECT_EQ(TStringPattern::EPatternType::eType_Wildcard, patternEmpty.GetPatternType()); } -TEST(TestsTStringPattern, FromSerializedString) +TEST(TestsTStringPattern, FromStringString) { TStringPattern patternEmpty; - patternEmpty.FromSerializedString(L"WC;*.*"); + patternEmpty.FromString(L"WC;*.*"); - EXPECT_STREQ(L"WC;*.*", patternEmpty.ToSerializedString().c_str()); + EXPECT_STREQ(L"*.*", patternEmpty.ToString().c_str()); EXPECT_STREQ(L"*.*", patternEmpty.GetPattern().c_str()); EXPECT_EQ(TStringPattern::EPatternType::eType_Wildcard, patternEmpty.GetPatternType()); } Index: src/libchcore/Tests/TestsTStringPatternArray.cpp =================================================================== diff -u -r2755e12daeccb1935f569e7235e685e566b0b098 -rfcf6698a5e67445b1a68627fa94837b1ad97284e --- src/libchcore/Tests/TestsTStringPatternArray.cpp (.../TestsTStringPatternArray.cpp) (revision 2755e12daeccb1935f569e7235e685e566b0b098) +++ src/libchcore/Tests/TestsTStringPatternArray.cpp (.../TestsTStringPatternArray.cpp) (revision fcf6698a5e67445b1a68627fa94837b1ad97284e) @@ -21,8 +21,8 @@ arrPatterns.Add(TStringPattern(L"*.exe", TStringPattern::EPatternType::eType_Wildcard)); EXPECT_EQ(2, arrPatterns.GetCount()); - EXPECT_STREQ(L"WC;*.bat", arrPatterns.GetAt(0).ToSerializedString().c_str()); - EXPECT_STREQ(L"WC;*.exe", arrPatterns.GetAt(1).ToSerializedString().c_str()); + EXPECT_STREQ(L"*.bat", arrPatterns.GetAt(0).ToString().c_str()); + EXPECT_STREQ(L"*.exe", arrPatterns.GetAt(1).ToString().c_str()); } TEST(TestsTStringPatternArray, InsertAt) @@ -33,8 +33,8 @@ arrPatterns.InsertAt(0, TStringPattern(L"*.exe", TStringPattern::EPatternType::eType_Wildcard)); EXPECT_EQ(2, arrPatterns.GetCount()); - EXPECT_STREQ(L"WC;*.bat", arrPatterns.GetAt(1).ToSerializedString().c_str()); - EXPECT_STREQ(L"WC;*.exe", arrPatterns.GetAt(0).ToSerializedString().c_str()); + EXPECT_STREQ(L"*.bat", arrPatterns.GetAt(1).ToString().c_str()); + EXPECT_STREQ(L"*.exe", arrPatterns.GetAt(0).ToString().c_str()); } TEST(TestsTStringPatternArray, SetAt) @@ -47,8 +47,8 @@ arrPatterns.SetAt(0, TStringPattern(L"*.com", TStringPattern::EPatternType::eType_Wildcard)); EXPECT_EQ(2, arrPatterns.GetCount()); - EXPECT_STREQ(L"WC;*.com", arrPatterns.GetAt(0).ToSerializedString().c_str()); - EXPECT_STREQ(L"WC;*.exe", arrPatterns.GetAt(1).ToSerializedString().c_str()); + EXPECT_STREQ(L"*.com", arrPatterns.GetAt(0).ToString().c_str()); + EXPECT_STREQ(L"*.exe", arrPatterns.GetAt(1).ToString().c_str()); } TEST(TestsTStringPatternArray, RemoveAt) @@ -61,7 +61,7 @@ arrPatterns.RemoveAt(0); EXPECT_EQ(1, arrPatterns.GetCount()); - EXPECT_STREQ(L"WC;*.exe", arrPatterns.GetAt(0).ToSerializedString().c_str()); + EXPECT_STREQ(L"*.exe", arrPatterns.GetAt(0).ToString().c_str()); } TEST(TestsTStringPatternArray, Clear) @@ -129,21 +129,21 @@ arrPatterns.Add(TStringPattern(L"*.bat", TStringPattern::EPatternType::eType_Wildcard)); arrPatterns.Add(TStringPattern(L"autostart.*", TStringPattern::EPatternType::eType_Wildcard)); - TStringArray arrElements = arrPatterns.ToStringArray(); + TStringArray arrElements = arrPatterns.ToSerializedStringArray(); EXPECT_EQ(2, arrElements.GetCount()); - EXPECT_STREQ(L"WC;*.bat", arrElements.GetAt(0).c_str()); - EXPECT_STREQ(L"WC;autostart.*", arrElements.GetAt(1).c_str()); + EXPECT_STREQ(L"*.bat", arrElements.GetAt(0).c_str()); + EXPECT_STREQ(L"autostart.*", arrElements.GetAt(1).c_str()); } TEST(TestsTStringPatternArray, FromStringArray) { TStringArray arrElements; - arrElements.Add(L"WC;*.bat"); - arrElements.Add(L"WC;autostart.*"); + arrElements.Add(L"*.bat"); + arrElements.Add(L"autostart.*"); TStringPatternArray arrPatterns; arrPatterns.FromStringArray(arrElements); - EXPECT_STREQ(L"WC;*.bat", arrPatterns.GetAt(0).ToSerializedString().c_str()); - EXPECT_STREQ(L"WC;autostart.*", arrPatterns.GetAt(1).ToSerializedString().c_str()); + EXPECT_STREQ(L"*.bat", arrPatterns.GetAt(0).ToString().c_str()); + EXPECT_STREQ(L"autostart.*", arrPatterns.GetAt(1).ToString().c_str()); }