summaryrefslogtreecommitdiff
path: root/plugins/CountryFlags/src
diff options
context:
space:
mode:
authorMataes <mataes2007@gmail.com>2018-05-16 21:12:31 +0300
committerMataes <mataes2007@gmail.com>2018-05-16 21:12:31 +0300
commit1fc8e65dd319abf0bac6ce753bb87ecbabd8b177 (patch)
tree94aaf74e14515883aea9da6752ccacca6007fa47 /plugins/CountryFlags/src
parentaba882ecf1f570400c301493725fcb31270e0fd5 (diff)
Flags, CrashDumper, CryptoPP, CSList, Db_autobackups, DbEditorPP: cmplugin adaptation
Diffstat (limited to 'plugins/CountryFlags/src')
-rw-r--r--plugins/CountryFlags/src/icons.cpp86
-rw-r--r--plugins/CountryFlags/src/ip2country.cpp195
-rw-r--r--plugins/CountryFlags/src/main.cpp16
-rw-r--r--plugins/CountryFlags/src/options.cpp36
-rw-r--r--plugins/CountryFlags/src/stdafx.h9
5 files changed, 170 insertions, 172 deletions
diff --git a/plugins/CountryFlags/src/icons.cpp b/plugins/CountryFlags/src/icons.cpp
index e0d145dfe7..c295ddebb1 100644
--- a/plugins/CountryFlags/src/icons.cpp
+++ b/plugins/CountryFlags/src/icons.cpp
@@ -24,7 +24,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
static HANDLE *phIconHandles;
/* country number indices (same order as in flags.bmp) */
-const int BitmapIndexMap[232]={
+const int BitmapIndexMap[232] = {
0, 1, 7, 20, 27, 30, 31, 32, 33, 34, 36, 39, 40, 41, 43, 44, 45, 46, 47, 48,
49, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, 64, 65, 66, 81, 82, 84, 86,
90, 91, 92, 93, 94, 95, 98, 101, 102, 103, 104, 105, 106, 107, 178, 108, 109, 110, 111, 112,
@@ -42,7 +42,7 @@ const int BitmapIndexMap[232]={
static int __fastcall CountryNumberToBitmapIndex(int countryNumber)
{
/* shared flags by multiple countries */
- switch(countryNumber) {
+ switch (countryNumber) {
case 262: /* Reunion Island */
case 594: /* French Guiana */
case 5901: /* French Antilles */
@@ -70,17 +70,17 @@ static int __fastcall CountryNumberToBitmapIndex(int countryNumber)
}
/* binary search in index array */
- int low = 0, i, high = _countof(BitmapIndexMap)-1;
+ int low = 0, i, high = _countof(BitmapIndexMap) - 1;
if (countryNumber <= BitmapIndexMap[high])
while (low <= high) {
- i = low+((high-low)/2);
+ i = low + ((high - low) / 2);
if (BitmapIndexMap[i] == countryNumber)
return i;
- if (countryNumber >BitmapIndexMap[i])
- low=i+1;
+ if (countryNumber > BitmapIndexMap[i])
+ low = i + 1;
else
- high=i-1;
+ high = i - 1;
}
/* Other,Unknown,Unspecified */
@@ -89,43 +89,43 @@ static int __fastcall CountryNumberToBitmapIndex(int countryNumber)
// return value needs to be released using DestroyIcon()
// only operates on color icons, which isn't a problem here
-static HICON __fastcall ResizeIconCentered(HICON hIcon,int cx,int cy)
+static HICON __fastcall ResizeIconCentered(HICON hIcon, int cx, int cy)
{
HICON hResIcon = nullptr;
HDC hdc = CreateCompatibleDC(nullptr);
if (hdc != nullptr) {
ICONINFO icoi;
- if ( GetIconInfo(hIcon,&icoi)) {
+ if (GetIconInfo(hIcon, &icoi)) {
BITMAP bm;
- if (GetObject(icoi.hbmColor,sizeof(bm),&bm) && bm.bmWidth<=cx && bm.bmHeight<=cy) {
+ if (GetObject(icoi.hbmColor, sizeof(bm), &bm) && bm.bmWidth <= cx && bm.bmHeight <= cy) {
POINT pt;
- pt.x = (cx-bm.bmWidth)/2;
- pt.y = (cy-bm.bmHeight)/2;
+ pt.x = (cx - bm.bmWidth) / 2;
+ pt.y = (cy - bm.bmHeight) / 2;
HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, icoi.hbmColor);
if (hbmPrev != nullptr) { /* error on select? */
HBITMAP hbm = icoi.hbmColor;
- icoi.hbmColor = CreateCompatibleBitmap(hdc,cx,cy);
+ icoi.hbmColor = CreateCompatibleBitmap(hdc, cx, cy);
if (icoi.hbmColor != nullptr)
- if (SelectObject(hdc,icoi.hbmColor) != nullptr) { /* error on select? */
+ if (SelectObject(hdc, icoi.hbmColor) != nullptr) { /* error on select? */
DeleteObject(hbm); /* delete prev color (XOR) */
- if (BitBlt(hdc,0,0,cx,cy,nullptr,0,0,BLACKNESS)) /* transparency: AND=0, XOR=1 */
- if (DrawIconEx(hdc,pt.x,pt.y,hIcon,bm.bmWidth,bm.bmHeight,0,nullptr,DI_IMAGE|DI_NOMIRROR)) {
- if (SelectObject(hdc,icoi.hbmMask) != nullptr) { /* error on select? */
+ if (BitBlt(hdc, 0, 0, cx, cy, nullptr, 0, 0, BLACKNESS)) /* transparency: AND=0, XOR=1 */
+ if (DrawIconEx(hdc, pt.x, pt.y, hIcon, bm.bmWidth, bm.bmHeight, 0, nullptr, DI_IMAGE | DI_NOMIRROR)) {
+ if (SelectObject(hdc, icoi.hbmMask) != nullptr) { /* error on select? */
hbm = icoi.hbmMask;
- icoi.hbmMask = CreateBitmap(cx,cy,1,1,nullptr); /* mono */
+ icoi.hbmMask = CreateBitmap(cx, cy, 1, 1, nullptr); /* mono */
if (icoi.hbmMask != nullptr)
- if (SelectObject(hdc,icoi.hbmMask) != nullptr) { /* error on select? */
+ if (SelectObject(hdc, icoi.hbmMask) != nullptr) { /* error on select? */
DeleteObject(hbm); /* delete prev mask (AND) */
- if (BitBlt(hdc,0,0,cx,cy,nullptr,0,0,WHITENESS)) /* transparency: AND=0, XOR=1 */
- if (DrawIconEx(hdc,pt.x,pt.y,hIcon,0,0,0,nullptr,DI_MASK|DI_NOMIRROR)) {
- SelectObject(hdc,hbmPrev);
+ if (BitBlt(hdc, 0, 0, cx, cy, nullptr, 0, 0, WHITENESS)) /* transparency: AND=0, XOR=1 */
+ if (DrawIconEx(hdc, pt.x, pt.y, hIcon, 0, 0, 0, nullptr, DI_MASK | DI_NOMIRROR)) {
+ SelectObject(hdc, hbmPrev);
hResIcon = CreateIconIndirect(&icoi); /* bitmaps must not be selected */
}
}
}
}
}
- SelectObject(hdc,hbmPrev);
+ SelectObject(hdc, hbmPrev);
}
}
DeleteObject(icoi.hbmColor);
@@ -152,8 +152,8 @@ HICON __fastcall LoadFlagIcon(int countryNumber)
int __fastcall CountryNumberToIndex(int countryNumber)
{
- int nf=0;
- for(int i=0; i < nCountriesCount; ++i) {
+ int nf = 0;
+ for (int i = 0; i < nCountriesCount; ++i) {
if (countries[i].id == countryNumber)
return i;
if (countries[i].id == 0xFFFF)
@@ -164,7 +164,7 @@ int __fastcall CountryNumberToIndex(int countryNumber)
/************************* Services *******************************/
-static INT_PTR ServiceLoadFlagIcon(WPARAM wParam,LPARAM lParam)
+static INT_PTR ServiceLoadFlagIcon(WPARAM wParam, LPARAM lParam)
{
/* return handle */
if ((BOOL)lParam) {
@@ -177,15 +177,15 @@ static INT_PTR ServiceLoadFlagIcon(WPARAM wParam,LPARAM lParam)
return (INT_PTR)LoadFlagIcon(wParam);
}
-static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam,LPARAM lParam)
+static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam, LPARAM lParam)
{
HICON hIcon = nullptr;
/* load both icons */
- HICON hLowerIcon = (HICON)ServiceLoadFlagIcon((WPARAM)lParam,0);
+ HICON hLowerIcon = (HICON)ServiceLoadFlagIcon((WPARAM)lParam, 0);
if (hLowerIcon == nullptr)
return 0;
- HICON hUpperIcon = (HICON)ServiceLoadFlagIcon(wParam,0);
+ HICON hUpperIcon = (HICON)ServiceLoadFlagIcon(wParam, 0);
/* merge them */
ICONINFO icoi;
@@ -195,18 +195,18 @@ static INT_PTR ServiceCreateMergedFlagIcon(WPARAM wParam,LPARAM lParam)
HDC hdc = CreateCompatibleDC(nullptr);
if (hdc != nullptr) {
POINT aptTriangle[3] = { 0 };
- aptTriangle[1].y = bm.bmHeight-1;
- aptTriangle[2].x = bm.bmWidth-1;
- HRGN hrgn = CreatePolygonRgn(aptTriangle,_countof(aptTriangle),WINDING);
+ aptTriangle[1].y = bm.bmHeight - 1;
+ aptTriangle[2].x = bm.bmWidth - 1;
+ HRGN hrgn = CreatePolygonRgn(aptTriangle, _countof(aptTriangle), WINDING);
if (hrgn != nullptr) {
- SelectClipRgn(hdc,hrgn);
+ SelectClipRgn(hdc, hrgn);
DeleteObject(hrgn);
HBITMAP hbmPrev = (HBITMAP)SelectObject(hdc, icoi.hbmColor);
if (hbmPrev != nullptr) { /* error on select? */
- if ( DrawIconEx(hdc,0,0,hUpperIcon,bm.bmWidth,bm.bmHeight,0,nullptr,DI_NOMIRROR|DI_IMAGE))
- if ( SelectObject(hdc,icoi.hbmMask) != nullptr) /* error on select? */
- DrawIconEx(hdc,0,0,hUpperIcon,bm.bmWidth,bm.bmHeight,0,nullptr,DI_NOMIRROR|DI_MASK);
- SelectObject(hdc,hbmPrev);
+ if (DrawIconEx(hdc, 0, 0, hUpperIcon, bm.bmWidth, bm.bmHeight, 0, nullptr, DI_NOMIRROR | DI_IMAGE))
+ if (SelectObject(hdc, icoi.hbmMask) != nullptr) /* error on select? */
+ DrawIconEx(hdc, 0, 0, hUpperIcon, bm.bmWidth, bm.bmHeight, 0, nullptr, DI_NOMIRROR | DI_MASK);
+ SelectObject(hdc, hbmPrev);
}
}
DeleteDC(hdc);
@@ -236,20 +236,20 @@ void InitIcons(void)
/* all those flag icons do not need any transparency mask (flags are always opaque),
* storing them in a large bitmap to reduce file size */
- HIMAGELIST himl = ImageList_LoadImage(hInst,MAKEINTRESOURCE(IDB_FLAGS),sid.cx,0,CLR_NONE,IMAGE_BITMAP,LR_CREATEDIBSECTION);
+ HIMAGELIST himl = ImageList_LoadImage(g_plugin.getInst(), MAKEINTRESOURCE(IDB_FLAGS), sid.cx, 0, CLR_NONE, IMAGE_BITMAP, LR_CREATEDIBSECTION);
if (himl != nullptr) {
- phIconHandles = (HANDLE*)mir_alloc(nCountriesCount*sizeof(HANDLE));
+ phIconHandles = (HANDLE*)mir_alloc(nCountriesCount * sizeof(HANDLE));
if (phIconHandles != nullptr) {
- for (int i=0; i < nCountriesCount; ++i) {
+ for (int i = 0; i < nCountriesCount; ++i) {
sid.description.a = (char*)countries[i].szName;
/* create identifier */
- mir_snprintf(szId, (countries[i].id == 0xFFFF) ? "%s0x%X" : "%s%i","flags_", countries[i].id); /* buffer safe */
+ mir_snprintf(szId, (countries[i].id == 0xFFFF) ? "%s0x%X" : "%s%i", "flags_", countries[i].id); /* buffer safe */
int index = CountryNumberToBitmapIndex(countries[i].id);
/* create icon */
- HICON hIcon = ImageList_GetIcon(himl,index,ILD_NORMAL);
+ HICON hIcon = ImageList_GetIcon(himl, index, ILD_NORMAL);
if (hIcon) {
- sid.hDefaultIcon = ResizeIconCentered(hIcon,sid.cx,sid.cy);
+ sid.hDefaultIcon = ResizeIconCentered(hIcon, sid.cx, sid.cy);
DestroyIcon(hIcon);
}
else sid.hDefaultIcon = nullptr;
diff --git a/plugins/CountryFlags/src/ip2country.cpp b/plugins/CountryFlags/src/ip2country.cpp
index ce4c45e020..2e8bae93db 100644
--- a/plugins/CountryFlags/src/ip2country.cpp
+++ b/plugins/CountryFlags/src/ip2country.cpp
@@ -19,7 +19,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "stdafx.h"
-extern HINSTANCE hInst;
extern int nCountriesCount;
extern struct CountryListEntry *countries;
@@ -28,24 +27,24 @@ extern struct CountryListEntry *countries;
#define DATARECORD_SIZE (sizeof(DWORD)+sizeof(DWORD)+sizeof(WORD))
// mir_free() the return value
-static BYTE* GetDataHeader(BYTE *data,DWORD cbDataSize,DWORD *pnDataRecordCount)
+static BYTE* GetDataHeader(BYTE *data, DWORD cbDataSize, DWORD *pnDataRecordCount)
{
BYTE *recordData;
/* uncompressed size stored in first DWORD */
- *pnDataRecordCount=(*(DWORD*)data)/DATARECORD_SIZE;
- recordData=(BYTE*)mir_alloc(*(DWORD*)data);
+ *pnDataRecordCount = (*(DWORD*)data) / DATARECORD_SIZE;
+ recordData = (BYTE*)mir_alloc(*(DWORD*)data);
if (recordData != nullptr)
- Huffman_Uncompress(data+sizeof(DWORD),recordData,cbDataSize-sizeof(DWORD),*(DWORD*)data);
+ Huffman_Uncompress(data + sizeof(DWORD), recordData, cbDataSize - sizeof(DWORD), *(DWORD*)data);
return recordData;
}
-static int GetDataRecord(BYTE *data,DWORD index,DWORD *pdwFrom,DWORD *pdwTo)
+static int GetDataRecord(BYTE *data, DWORD index, DWORD *pdwFrom, DWORD *pdwTo)
{
- data+=index*DATARECORD_SIZE;
- *pdwFrom=*(DWORD*)data;
- data+=sizeof(DWORD);
- if (pdwTo != nullptr) *pdwTo=*(DWORD*)data;
- data+=sizeof(DWORD);
+ data += index * DATARECORD_SIZE;
+ *pdwFrom = *(DWORD*)data;
+ data += sizeof(DWORD);
+ if (pdwTo != nullptr) *pdwTo = *(DWORD*)data;
+ data += sizeof(DWORD);
return (int)*(WORD*)data;
}
@@ -61,36 +60,36 @@ static void CALLBACK UnloadRecordCache(LPARAM)
{
mir_cslock lck(csRecordCache);
mir_free(dataRecords);
- dataRecords=nullptr;
+ dataRecords = nullptr;
}
// function assumes it has got the csRecordCache mutex
-static BOOL EnsureRecordCacheLoaded(BYTE **pdata,DWORD *pcount)
+static BOOL EnsureRecordCacheLoaded(BYTE **pdata, DWORD *pcount)
{
HRSRC hrsrc;
DWORD cb;
mir_cslock lck(csRecordCache);
if (dataRecords == nullptr) {
/* load record data list from resources */
- hrsrc=FindResource(hInst,MAKEINTRESOURCE(IDR_IPTOCOUNTRY),L"BIN");
- cb=SizeofResource(hInst,hrsrc);
- dataRecords=(BYTE*)LockResource(LoadResource(hInst,hrsrc));
- if (cb<=sizeof(DWORD) || dataRecords == nullptr)
+ hrsrc = FindResource(g_plugin.getInst(), MAKEINTRESOURCE(IDR_IPTOCOUNTRY), L"BIN");
+ cb = SizeofResource(g_plugin.getInst(), hrsrc);
+ dataRecords = (BYTE*)LockResource(LoadResource(g_plugin.getInst(), hrsrc));
+ if (cb <= sizeof(DWORD) || dataRecords == nullptr)
return FALSE;
/* uncompress record data */
- dataRecords=GetDataHeader(dataRecords,cb,&nDataRecordsCount);
+ dataRecords = GetDataHeader(dataRecords, cb, &nDataRecordsCount);
if (dataRecords == nullptr || !nDataRecordsCount)
return FALSE;
}
- *pdata=dataRecords;
- *pcount=nDataRecordsCount;
+ *pdata = dataRecords;
+ *pcount = nDataRecordsCount;
return TRUE;
}
static void LeaveRecordCache(void)
{
/* mark for unload */
- CallFunctionBuffered(UnloadRecordCache,0,FALSE,UNLOADDELAY);
+ CallFunctionBuffered(UnloadRecordCache, 0, FALSE, UNLOADDELAY);
}
/************************* Services *******************************/
@@ -99,21 +98,21 @@ static void LeaveRecordCache(void)
INT_PTR ServiceIpToCountry(WPARAM wParam, LPARAM)
{
BYTE *data;
- DWORD dwFrom,dwTo;
- DWORD low=0,i,high;
+ DWORD dwFrom, dwTo;
+ DWORD low = 0, i, high;
int id;
- if (EnsureRecordCacheLoaded(&data,&high)) {
+ if (EnsureRecordCacheLoaded(&data, &high)) {
/* binary search in record data */
- GetDataRecord(data,low,&dwFrom,nullptr);
+ GetDataRecord(data, low, &dwFrom, nullptr);
--high;
- if (wParam>=dwFrom) /* only search if wParam valid */
- while (low<=high) {
- i=low+((high-low)/2);
- /* analyze record */
- id=GetDataRecord(data,i,&dwFrom,&dwTo);
- if (dwFrom<=wParam && dwTo>=wParam) { LeaveRecordCache(); return id; }
- if (wParam>dwTo) low=i+1;
- else high=i-1;
+ if (wParam >= dwFrom) /* only search if wParam valid */
+ while (low <= high) {
+ i = low + ((high - low) / 2);
+ /* analyze record */
+ id = GetDataRecord(data, i, &dwFrom, &dwTo);
+ if (dwFrom <= wParam && dwTo >= wParam) { LeaveRecordCache(); return id; }
+ if (wParam > dwTo) low = i + 1;
+ else high = i - 1;
}
LeaveRecordCache();
}
@@ -129,7 +128,7 @@ INT_PTR ServiceIpToCountry(WPARAM wParam, LPARAM)
struct {
const char *szMir;
const char *szCSV;
-} static const differentCountryNames[]={
+} static const differentCountryNames[] = {
{"British Virgin Islands","VIRGIN ISLANDS, BRITISH"},
{"Brunei","BRUNEI DARUSSALAM"},
{"Cape Verde Islands","CAPE VERDE"},
@@ -164,82 +163,82 @@ struct {
struct ResizableByteBuffer {
BYTE *buf;
- DWORD cbLength,cbAlloced;
+ DWORD cbLength, cbAlloced;
};
-static void AppendToByteBuffer(struct ResizableByteBuffer *buffer,const void *append,DWORD cbAppendSize)
+static void AppendToByteBuffer(struct ResizableByteBuffer *buffer, const void *append, DWORD cbAppendSize)
{
- if (buffer->cbAlloced<=buffer->cbLength+cbAppendSize) {
- BYTE* buf=(BYTE*)mir_realloc(buffer->buf,buffer->cbAlloced+ALLOC_STEP+cbAppendSize);
+ if (buffer->cbAlloced <= buffer->cbLength + cbAppendSize) {
+ BYTE* buf = (BYTE*)mir_realloc(buffer->buf, buffer->cbAlloced + ALLOC_STEP + cbAppendSize);
if (buf == NULL) return;
- buffer->buf=buf;
- buffer->cbAlloced+=ALLOC_STEP+cbAppendSize;
+ buffer->buf = buf;
+ buffer->cbAlloced += ALLOC_STEP + cbAppendSize;
OutputDebugStringA("reallocating memory...\n"); /* all ascii */
}
- memcpy(&buffer->buf[buffer->cbLength],append,cbAppendSize);
- buffer->cbLength+=cbAppendSize;
+ memcpy(&buffer->buf[buffer->cbLength], append, cbAppendSize);
+ buffer->cbLength += cbAppendSize;
}
-static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
+static int EnumIpDataLines(const char *pszFileCSV, const char *pszFileOut)
{
FILE *fp;
- char line[1024],out[512],*pszFrom,*pszTo,*pszTwo,*pszCountry,*buf;
- int i,j;
+ char line[1024], out[512], *pszFrom, *pszTo, *pszTwo, *pszCountry, *buf;
+ int i, j;
DWORD dwOut;
WORD wOut;
struct ResizableByteBuffer buffer;
memset(&buffer, 0, sizeof(buffer));
- fp=fopen(pszFileCSV,"rt");
+ fp = fopen(pszFileCSV, "rt");
if (fp != NULL) {
OutputDebugStringA("Running IP data convert...\n"); /* all ascii */
while (!feof(fp)) {
- if (fgets(line,sizeof(line),fp) == NULL) break;
+ if (fgets(line, sizeof(line), fp) == NULL) break;
/* get line data */
- pszFrom=line+1;
- pszTo=strchr(pszFrom,',');
- *(pszTo-1)='\0'; pszTo+=2;
- pszTwo=strchr(pszTo,',');
- *(pszTwo-1)='\0'; pszTwo+=2;
- pszCountry=strchr(pszTwo,',')+1;
- pszCountry=strchr(pszCountry,',')+2;
- buf=strchr(pszCountry,'"');
- *buf=pszTwo[2]='\0';
+ pszFrom = line + 1;
+ pszTo = strchr(pszFrom, ',');
+ *(pszTo - 1) = '\0'; pszTo += 2;
+ pszTwo = strchr(pszTo, ',');
+ *(pszTwo - 1) = '\0'; pszTwo += 2;
+ pszCountry = strchr(pszTwo, ',') + 1;
+ pszCountry = strchr(pszCountry, ',') + 2;
+ buf = strchr(pszCountry, '"');
+ *buf = pszTwo[2] = '\0';
/* corrections */
- if (!mir_wstrcmpi(pszCountry,"ANTARCTICA")) continue;
- if (!mir_wstrcmpi(pszCountry,"TIMOR-LESTE")) continue;
- if (!mir_wstrcmpi(pszCountry,"PALESTINIAN TERRITORY, OCCUPIED"))
- mir_wstrcpy(pszCountry,"ISRAEL");
- else if (!mir_wstrcmpi(pszCountry,"UNITED STATES MINOR OUTLYING ISLANDS"))
- mir_wstrcpy(pszCountry,"UNITED STATES");
- else if (!mir_wstrcmpi(pszCountry,"SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"))
- mir_wstrcpy(pszCountry,"UNITED KINGDOM");
- else if (!mir_wstrcmpi(pszTwo,"JE")) /* map error */
- mir_wstrcpy(pszCountry,"UNITED KINGDOM");
- else if (!mir_wstrcmpi(pszTwo,"AX")) /* Еland Island belongs to Finland */
- mir_wstrcpy(pszCountry,"FINLAND");
- else if (!mir_wstrcmpi(pszTwo,"ME"))
- mir_wstrcpy(pszCountry,"MONTENEGRO");
- else if (!mir_wstrcmpi(pszTwo,"RS") || !mir_wstrcmpi(pszTwo,"CS"))
- mir_wstrcpy(pszCountry,"SERBIA");
+ if (!mir_wstrcmpi(pszCountry, "ANTARCTICA")) continue;
+ if (!mir_wstrcmpi(pszCountry, "TIMOR-LESTE")) continue;
+ if (!mir_wstrcmpi(pszCountry, "PALESTINIAN TERRITORY, OCCUPIED"))
+ mir_wstrcpy(pszCountry, "ISRAEL");
+ else if (!mir_wstrcmpi(pszCountry, "UNITED STATES MINOR OUTLYING ISLANDS"))
+ mir_wstrcpy(pszCountry, "UNITED STATES");
+ else if (!mir_wstrcmpi(pszCountry, "SOUTH GEORGIA AND THE SOUTH SANDWICH ISLANDS"))
+ mir_wstrcpy(pszCountry, "UNITED KINGDOM");
+ else if (!mir_wstrcmpi(pszTwo, "JE")) /* map error */
+ mir_wstrcpy(pszCountry, "UNITED KINGDOM");
+ else if (!mir_wstrcmpi(pszTwo, "AX")) /* Еland Island belongs to Finland */
+ mir_wstrcpy(pszCountry, "FINLAND");
+ else if (!mir_wstrcmpi(pszTwo, "ME"))
+ mir_wstrcpy(pszCountry, "MONTENEGRO");
+ else if (!mir_wstrcmpi(pszTwo, "RS") || !mir_wstrcmpi(pszTwo, "CS"))
+ mir_wstrcpy(pszCountry, "SERBIA");
/* convert */
- for(i=0;i<nCountriesCount;i++) {
+ for (i = 0; i < nCountriesCount; i++) {
/* map different writings */
- for(j=0;j<_countof(differentCountryNames);j++)
- if (!mir_wstrcmpi(countries[i].szName,differentCountryNames[j].szMir)) {
- buf=(char*)differentCountryNames[j].szCSV;
+ for (j = 0; j < _countof(differentCountryNames); j++)
+ if (!mir_wstrcmpi(countries[i].szName, differentCountryNames[j].szMir)) {
+ buf = (char*)differentCountryNames[j].szCSV;
break;
}
if (j == _countof(differentCountryNames))
- buf=(char*)countries[i].szName;
+ buf = (char*)countries[i].szName;
/* check country */
- if (!mir_strcmpi(pszCountry,buf)) {
- dwOut=(DWORD)atoi(pszFrom);
- AppendToByteBuffer(&buffer,(void*)&dwOut,sizeof(DWORD));
- dwOut=(DWORD)atoi(pszTo);
- AppendToByteBuffer(&buffer,(void*)&dwOut,sizeof(DWORD));
- wOut=(WORD)countries[i].id;
- AppendToByteBuffer(&buffer,(void*)&wOut,sizeof(WORD));
+ if (!mir_strcmpi(pszCountry, buf)) {
+ dwOut = (DWORD)atoi(pszFrom);
+ AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(DWORD));
+ dwOut = (DWORD)atoi(pszTo);
+ AppendToByteBuffer(&buffer, (void*)&dwOut, sizeof(DWORD));
+ wOut = (WORD)countries[i].id;
+ AppendToByteBuffer(&buffer, (void*)&wOut, sizeof(WORD));
break;
}
}
@@ -253,23 +252,23 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
OutputDebugStringA("Done!\n"); /* all ascii */
if (buffer.buf != NULL) {
HANDLE hFileOut;
- DWORD cbWritten=0;
+ DWORD cbWritten = 0;
BYTE *compressed;
DWORD cbCompressed;
/* compress whole data */
OutputDebugStringA("Compressing...\n"); /* all ascii */
- compressed=(BYTE*)mir_alloc(buffer.cbAlloced+384);
+ compressed = (BYTE*)mir_alloc(buffer.cbAlloced + 384);
if (compressed != NULL) {
- cbCompressed=Huffman_Compress(buffer.buf,compressed,buffer.cbLength);
+ cbCompressed = Huffman_Compress(buffer.buf, compressed, buffer.cbLength);
OutputDebugStringA("Done!\n"); /* all ascii */
OutputDebugStringA("Writing to file...\n"); /* all ascii */
- hFileOut=CreateFile(pszFileOut,GENERIC_WRITE,FILE_SHARE_READ,NULL,CREATE_ALWAYS,FILE_ATTRIBUTE_NORMAL,NULL);
+ hFileOut = CreateFile(pszFileOut, GENERIC_WRITE, FILE_SHARE_READ, NULL, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
if (hFileOut != INVALID_HANDLE_VALUE) {
/* store data length count at beginning */
- dwOut=buffer.cbLength;
- WriteFile(hFileOut,&dwOut,sizeof(DWORD),&cbWritten,NULL);
+ dwOut = buffer.cbLength;
+ WriteFile(hFileOut, &dwOut, sizeof(DWORD), &cbWritten, NULL);
/* store compressed data records */
- WriteFile(hFileOut,compressed,cbCompressed,&cbWritten,NULL);
+ WriteFile(hFileOut, compressed, cbCompressed, &cbWritten, NULL);
CloseHandle(hFileOut);
}
OutputDebugStringA("Done!\n"); /* all ascii */
@@ -285,12 +284,12 @@ static int EnumIpDataLines(const char *pszFileCSV,const char *pszFileOut)
static void BinConvThread(void *unused)
{
/* debug version only */
- if (MessageBox(NULL,_T("Looking for 'ip-to-country.csv' in current directory.\n"
+ if (MessageBox(NULL, _T("Looking for 'ip-to-country.csv' in current directory.\n"
"It will be converted into 'ip-to-country.bin'.\n"
"See debug output for more details.\n"
- "This process may take very long."),L"Bin Converter",MB_OKCANCEL|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL) == IDOK) {
- EnumIpDataLines("ip-to-country.csv","ip-to-country.bin");
- MessageBox(NULL,L"Done!\n'ip-to-country.bin' has been created in current directory.",L"Bin Converter",MB_OK|MB_ICONINFORMATION|MB_SETFOREGROUND|MB_TOPMOST|MB_TASKMODAL);
+ "This process may take very long."), L"Bin Converter", MB_OKCANCEL | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL) == IDOK) {
+ EnumIpDataLines("ip-to-country.csv", "ip-to-country.bin");
+ MessageBox(NULL, L"Done!\n'ip-to-country.bin' has been created in current directory.", L"Bin Converter", MB_OK | MB_ICONINFORMATION | MB_SETFOREGROUND | MB_TOPMOST | MB_TASKMODAL);
}
}
@@ -300,10 +299,10 @@ static void BinConvThread(void *unused)
void InitIpToCountry(void)
{
- nDataRecordsCount=0;
- dataRecords=nullptr;
+ nDataRecordsCount = 0;
+ dataRecords = nullptr;
/* Services */
- CreateServiceFunction(MS_FLAGS_IPTOCOUNTRY,ServiceIpToCountry);
+ CreateServiceFunction(MS_FLAGS_IPTOCOUNTRY, ServiceIpToCountry);
#ifdef BINCONV
mir_forkthread(BinConvThread);
#endif
diff --git a/plugins/CountryFlags/src/main.cpp b/plugins/CountryFlags/src/main.cpp
index e34ff660be..78525158be 100644
--- a/plugins/CountryFlags/src/main.cpp
+++ b/plugins/CountryFlags/src/main.cpp
@@ -22,10 +22,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
int nCountriesCount;
CountryListEntry *countries;
-HINSTANCE hInst;
+CMPlugin g_plugin;
int hLangpack;
-static PLUGININFOEX pluginInfo={
+static PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_NAME,
PLUGIN_MAKE_VERSION(__MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM),
@@ -38,12 +38,6 @@ static PLUGININFOEX pluginInfo={
{0x68c36842, 0x3d95, 0x4f4a, {0xab, 0x81, 0x1, 0x4d, 0x65, 0x93, 0x86, 0x3b}}
};
-BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD, LPVOID)
-{
- hInst = hinstDLL;
- return TRUE;
-}
-
extern "C" __declspec(dllexport) const PLUGININFOEX* MirandaPluginInfoEx(DWORD)
{
return &pluginInfo;
@@ -54,12 +48,12 @@ extern "C" __declspec(dllexport) int Load(void)
mir_getLP(&pluginInfo);
PrepareBufferedFunctions();
- if ( CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&nCountriesCount, (LPARAM)&countries))
+ if (CallService(MS_UTILS_GETCOUNTRYLIST, (WPARAM)&nCountriesCount, (LPARAM)&countries))
nCountriesCount = 0;
bShowStatusIcon = db_get_b(NULL, MODULENAME, "ShowStatusIconFlag", SETTING_SHOWSTATUSICONFLAG_DEFAULT) != 0;
- bShowExtraIcon = db_get_b(NULL, MODULENAME, "ShowExtraImgFlag", SETTING_SHOWEXTRAIMGFLAG_DEFAULT) != 0;
- bUseUnknown = db_get_b(NULL, MODULENAME, "UseUnknownFlag", SETTING_USEUNKNOWNFLAG_DEFAULT) != 0;
+ bShowExtraIcon = db_get_b(NULL, MODULENAME, "ShowExtraImgFlag", SETTING_SHOWEXTRAIMGFLAG_DEFAULT) != 0;
+ bUseUnknown = db_get_b(NULL, MODULENAME, "UseUnknownFlag", SETTING_USEUNKNOWNFLAG_DEFAULT) != 0;
bUseIpToCountry = db_get_b(NULL, MODULENAME, "UseIpToCountry", SETTING_USEIPTOCOUNTRY_DEFAULT) != 0;
InitIcons();
diff --git a/plugins/CountryFlags/src/options.cpp b/plugins/CountryFlags/src/options.cpp
index 01b0e31a5c..d47bf75963 100644
--- a/plugins/CountryFlags/src/options.cpp
+++ b/plugins/CountryFlags/src/options.cpp
@@ -23,38 +23,38 @@ bool bUseUnknown, bShowStatusIcon, bShowExtraIcon, bUseIpToCountry;
#define M_ENABLE_SUBCTLS (WM_APP+1)
-static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM,LPARAM lParam)
+static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg, UINT msg, WPARAM, LPARAM lParam)
{
- switch(msg) {
+ switch (msg) {
case WM_INITDIALOG:
TranslateDialogDefault(hwndDlg);
CheckDlgButton(hwndDlg, IDC_CHECK_SHOWSTATUSICONFLAG, bShowStatusIcon ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHECK_SHOWEXTRAIMGFLAG, bShowExtraIcon ? BST_CHECKED : BST_UNCHECKED);
CheckDlgButton(hwndDlg, IDC_CHECK_USEUNKNOWNFLAG, bUseUnknown ? BST_CHECKED : BST_UNCHECKED);
- CheckDlgButton(hwndDlg,IDC_CHECK_USEIPTOCOUNTRY, bUseIpToCountry ? BST_CHECKED : BST_UNCHECKED);
-
- SendMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
+ CheckDlgButton(hwndDlg, IDC_CHECK_USEIPTOCOUNTRY, bUseIpToCountry ? BST_CHECKED : BST_UNCHECKED);
+
+ SendMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
return TRUE; /* default focus */
case M_ENABLE_SUBCTLS:
- {
- BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWEXTRAIMGFLAG);
- EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_EXTRAIMGFLAGCOLUMN), checked);
- if (!checked)
- checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWSTATUSICONFLAG);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_USEUNKNOWNFLAG), checked);
- EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_USEIPTOCOUNTRY), checked);
- }
- return TRUE;
+ {
+ BOOL checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWEXTRAIMGFLAG);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_TEXT_EXTRAIMGFLAGCOLUMN), checked);
+ if (!checked)
+ checked = IsDlgButtonChecked(hwndDlg, IDC_CHECK_SHOWSTATUSICONFLAG);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_USEUNKNOWNFLAG), checked);
+ EnableWindow(GetDlgItem(hwndDlg, IDC_CHECK_USEIPTOCOUNTRY), checked);
+ }
+ return TRUE;
case WM_COMMAND:
- PostMessage(hwndDlg,M_ENABLE_SUBCTLS,0,0);
- PostMessage(GetParent(hwndDlg),PSM_CHANGED,0,0); /* enable apply */
+ PostMessage(hwndDlg, M_ENABLE_SUBCTLS, 0, 0);
+ PostMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); /* enable apply */
return FALSE;
case WM_NOTIFY:
- switch(((NMHDR*)lParam)->code) {
+ switch (((NMHDR*)lParam)->code) {
case PSN_APPLY: /* setting change hook will pick these up */
bool bChanged = false, bTemp;
@@ -83,7 +83,7 @@ static INT_PTR CALLBACK ExtraImgOptDlgProc(HWND hwndDlg,UINT msg,WPARAM,LPARAM l
int OnOptionsInit(WPARAM wParam, LPARAM)
{
OPTIONSDIALOGPAGE odp = { 0 };
- odp.hInstance = hInst;
+ odp.hInstance = g_plugin.getInst();
odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_EXTRAIMG);
odp.position = 900000002;
odp.szGroup.a = LPGEN("Icons"); /* autotranslated */
diff --git a/plugins/CountryFlags/src/stdafx.h b/plugins/CountryFlags/src/stdafx.h
index 5ca2c565f3..894510b513 100644
--- a/plugins/CountryFlags/src/stdafx.h
+++ b/plugins/CountryFlags/src/stdafx.h
@@ -26,7 +26,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include <win2k.h>
-#define __NO_CMPLUGIN_NEEDED
#include <newpluginapi.h>
#include <m_langpack.h>
#include <m_icolib.h>
@@ -44,7 +43,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#include "resource.h"
#include "version.h"
-extern HINSTANCE hInst;
+struct CMPlugin : public PLUGIN<CMPlugin>
+{
+ CMPlugin() :
+ PLUGIN<CMPlugin>(MODULENAME)
+ {}
+};
+
extern int nCountriesCount;
extern CountryListEntry *countries;