diff options
author | George Hazan <ghazan@miranda.im> | 2019-04-24 22:11:43 +0300 |
---|---|---|
committer | George Hazan <ghazan@miranda.im> | 2019-04-24 22:11:43 +0300 |
commit | e5e4d3f5a0c24ebdfb9b9017c421a796a82f76bc (patch) | |
tree | 0b9e1292d360b11f8927763af65b0c1bec97d1d5 /plugins | |
parent | 7dfb3eacd8f7f32a3338c28a0f9286360878dc44 (diff) |
Import now is bound to pcre16.mir
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/Import/import.vcxproj | 3 | ||||
-rw-r--r-- | plugins/Import/src/main.cpp | 7 | ||||
-rw-r--r-- | plugins/Import/src/patterns.cpp | 106 | ||||
-rw-r--r-- | plugins/Import/src/stdafx.h | 30 |
4 files changed, 144 insertions, 2 deletions
diff --git a/plugins/Import/import.vcxproj b/plugins/Import/import.vcxproj index 242b086e6a..99baa397f9 100644 --- a/plugins/Import/import.vcxproj +++ b/plugins/Import/import.vcxproj @@ -19,6 +19,9 @@ </ProjectConfiguration>
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\..\libs\Pcre16\pcre16.vcxproj">
+ <Project>{6124e997-426e-4a0b-9617-d6d577d5e7d7}</Project>
+ </ProjectReference>
<ProjectReference Include="..\..\libs\sqlite3\sqlite3.vcxproj">
<Project>{0c02e395-e73f-47e3-8b95-b7924c0c7a6a}</Project>
</ProjectReference>
diff --git a/plugins/Import/src/main.cpp b/plugins/Import/src/main.cpp index 046d463f39..0477aae3f4 100644 --- a/plugins/Import/src/main.cpp +++ b/plugins/Import/src/main.cpp @@ -46,8 +46,10 @@ static PLUGININFOEX pluginInfoEx = { };
CMPlugin::CMPlugin() :
- PLUGIN<CMPlugin>(IMPORT_MODULE, pluginInfoEx)
-{}
+ PLUGIN<CMPlugin>(IMPORT_MODULE, pluginInfoEx),
+ m_patterns(1)
+{
+}
/////////////////////////////////////////////////////////////////////////////////////////
// MirandaInterfaces - returns the protocol interface to the core
@@ -158,6 +160,7 @@ int CMPlugin::Load() icex.dwICC = ICC_DATE_CLASSES;
InitCommonControlsEx(&icex);
+ LoadPatterns();
RegisterDbrw();
RegisterMContacts();
RegisterJson();
diff --git a/plugins/Import/src/patterns.cpp b/plugins/Import/src/patterns.cpp new file mode 100644 index 0000000000..67da571557 --- /dev/null +++ b/plugins/Import/src/patterns.cpp @@ -0,0 +1,106 @@ +/* + +Import plugin for Miranda NG + +Copyright (C) 2012-19 Miranda NG team (https://miranda-ng.org) + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + +*/ + +#include "stdafx.h" + +void CMPlugin::LoadPatterns() +{ + wchar_t wszPath[MAX_PATH], wszFullPath[MAX_PATH]; + GetModuleFileNameW(m_hInst, wszPath, _countof(wszPath)); + if (auto *p = wcsrchr(wszPath, '\\')) + p[1] = 0; + + mir_snwprintf(wszFullPath, L"%s\\Import\\*.ini", wszPath); + + WIN32_FIND_DATAW fd; + HANDLE hFind = FindFirstFileW(wszFullPath, &fd); + if (hFind == INVALID_HANDLE_VALUE) + return; + + do { + mir_snwprintf(wszFullPath, L"%s\\Import\\%s", wszPath, fd.cFileName); + LoadPattern(wszFullPath); + } + while (FindNextFileW(hFind, &fd) != 0); +} + +void CMPlugin::LoadPattern(const wchar_t *pwszFileName) +{ + // [General] section + wchar_t buf[1024]; + if (!GetPrivateProfileStringW(L"General", L"Name", L"", buf, _countof(buf), pwszFileName)) + return; + + std::auto_ptr<CImportPattern> pNew(new CImportPattern()); + pNew->wszName = buf; + pNew->iType = GetPrivateProfileIntW(L"General", L"Type", 1, pwszFileName); + + if (GetPrivateProfileStringW(L"General", L"Charset", L"", buf, _countof(buf), pwszFileName)) { + if (!wcsicmp(buf, L"ANSI")) + pNew->iCodePage = GetPrivateProfileIntW(L"General", L"Codepage", CP_ACP, pwszFileName); + else if (!wcsicmp(buf, L"UCS2")) + pNew->iCodePage = 1200; + } + else return; + + pNew->iUseHeader = GetPrivateProfileIntW(L"General", L"UseHeader", 0, pwszFileName); + pNew->iUsePreMsg = GetPrivateProfileIntW(L"General", L"UsePreMsg", 0, pwszFileName); + pNew->iUseFilename = GetPrivateProfileIntW(L"General", L"UseFileName", 0, pwszFileName); + + // [Message] section + int erroffset; + const char *err; + if (GetPrivateProfileStringW(L"Message", L"Pattern", L"", buf, _countof(buf), pwszFileName)) { + if ((pNew->regMessage.pattern = pcre16_compile(buf, 0, &err, &erroffset, nullptr)) == nullptr) + return; + pNew->regMessage.extra = pcre16_study(pNew->regMessage.pattern, 0, &err); + } + else return; + + if (GetPrivateProfileStringW(L"Message", L"In", L"", buf, _countof(buf), pwszFileName)) + pNew->wszIncoming = buf; + if (GetPrivateProfileStringW(L"Message", L"Out", L"", buf, _countof(buf), pwszFileName)) + pNew->wszOutgoing = buf; + + pNew->iDirection = GetPrivateProfileIntW(L"General", L"Direction", 0, pwszFileName); + pNew->iDay = GetPrivateProfileIntW(L"General", L"Day", 0, pwszFileName); + pNew->iMonth = GetPrivateProfileIntW(L"General", L"Month", 0, pwszFileName); + pNew->iYear = GetPrivateProfileIntW(L"General", L"Year", 0, pwszFileName); + pNew->iHours = GetPrivateProfileIntW(L"General", L"Hours", 0, pwszFileName); + pNew->iMinutes = GetPrivateProfileIntW(L"General", L"Minutes", 0, pwszFileName); + pNew->iSeconds = GetPrivateProfileIntW(L"General", L"Seconds", 0, pwszFileName); + + if (pNew->iUseFilename) { + if (!GetPrivateProfileStringW(L"FileName", L"Pattern", L"", buf, _countof(buf), pwszFileName)) + return; + if ((pNew->regFilename.pattern = pcre16_compile(buf, 0, &err, &erroffset, nullptr)) == nullptr) + return; + pNew->regFilename.extra = pcre16_study(pNew->regFilename.pattern, 0, &err); + + pNew->iInNick = GetPrivateProfileIntW(L"FileName", L"InNick", 0, pwszFileName); + pNew->iInUID = GetPrivateProfileIntW(L"FileName", L"InUID", 0, pwszFileName); + pNew->iOutNick = GetPrivateProfileIntW(L"FileName", L"OutNick", 0, pwszFileName); + pNew->iOutUID = GetPrivateProfileIntW(L"FileName", L"OutUID", 0, pwszFileName); + } + + m_patterns.insert(pNew.release()); +} diff --git a/plugins/Import/src/stdafx.h b/plugins/Import/src/stdafx.h index 85e8f728d3..7ca8c6a310 100644 --- a/plugins/Import/src/stdafx.h +++ b/plugins/Import/src/stdafx.h @@ -45,6 +45,8 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <m_import.h>
#include <m_gui.h>
+#include "../../../libs/Pcre16/src/pcre.h"
+
#include "version.h"
#include "resource.h"
@@ -59,8 +61,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MS_IMPORT_SERVICE "MIMImport/Import" // Service for main menu item
#define MS_IMPORT_CONTACT "MIMImport/ImportContact" // Service for contact menu item
+struct CImportPattern : public MZeroedObject
+{
+ struct CRegexp
+ {
+ pcre16 *pattern;
+ pcre16_extra *extra;
+ };
+
+ CMStringW wszName;
+ int iType = 1;
+ int iCodePage = CP_UTF8;
+ int iUseHeader, iUsePreMsg, iUseFilename;
+
+ CRegexp regMessage;
+ CMStringW wszIncoming, wszOutgoing;
+ int iDirection, iDay, iMonth, iYear, iHours, iMinutes, iSeconds;
+
+ CRegexp regFilename;
+ int iInNick, iInUID, iOutNick, iOutUID;
+};
+
struct CMPlugin : public PLUGIN<CMPlugin>
{
+private:
+ void LoadPattern(const wchar_t *pwszFileName);
+ void LoadPatterns();
+
+ OBJLIST<CImportPattern> m_patterns;
+
+public:
CMPlugin();
int Load() override;
|