diff options
author | George Hazan <george.hazan@gmail.com> | 2012-06-26 16:50:14 +0000 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2012-06-26 16:50:14 +0000 |
commit | c992cb2fdc11f1cac4bc5cbce26e8e2bb3b57da0 (patch) | |
tree | 697bdbf38a8a1f6b828a8bfbd08a478e19a82c6b /src/modules/utils | |
parent | f616294363c642d138f9dc0ef6eceae639e2434c (diff) |
- microkernel addded;
- version bumped to 0.92.2
git-svn-id: http://svn.miranda-ng.org/main/trunk@641 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c
Diffstat (limited to 'src/modules/utils')
-rw-r--r-- | src/modules/utils/bmpfilter.cpp | 4 | ||||
-rw-r--r-- | src/modules/utils/colourpicker.cpp | 4 | ||||
-rw-r--r-- | src/modules/utils/hyperlink.cpp | 2 | ||||
-rw-r--r-- | src/modules/utils/path.cpp | 205 | ||||
-rw-r--r-- | src/modules/utils/timezones.cpp | 6 | ||||
-rw-r--r-- | src/modules/utils/utils.cpp | 94 |
6 files changed, 23 insertions, 292 deletions
diff --git a/src/modules/utils/bmpfilter.cpp b/src/modules/utils/bmpfilter.cpp index 2e656dbf63..46db86baaf 100644 --- a/src/modules/utils/bmpfilter.cpp +++ b/src/modules/utils/bmpfilter.cpp @@ -36,7 +36,7 @@ static INT_PTR sttBitmapLoader(const TCHAR* ptszFileName) short picType;
TCHAR szFilename[MAX_PATH];
- if ( !pathToAbsoluteT(ptszFileName, szFilename, NULL))
+ if ( !PathToAbsoluteT(ptszFileName, szFilename, NULL))
mir_sntprintf(szFilename, SIZEOF(szFilename), _T("%s"), ptszFileName);
int filenameLen = lstrlen(szFilename);
@@ -48,7 +48,7 @@ static INT_PTR sttBitmapLoader(const TCHAR* ptszFileName) if ( !lstrcmpi(pszExt, _T(".bmp")) || !lstrcmpi(pszExt, _T(".rle"))) {
//LoadImage can do this much faster
- return (INT_PTR)LoadImage(hMirandaInst, szFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
+ return (INT_PTR)LoadImage(hInst, szFilename, IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE);
}
if ( !lstrcmpi(pszExt, _T(".png"))) {
diff --git a/src/modules/utils/colourpicker.cpp b/src/modules/utils/colourpicker.cpp index 731f61f1e1..dd31bf7155 100644 --- a/src/modules/utils/colourpicker.cpp +++ b/src/modules/utils/colourpicker.cpp @@ -47,7 +47,7 @@ static LRESULT CALLBACK ColourPickerWndProc(HWND hwnd, UINT message, WPARAM wPar custColours[0]=GetWindowLongPtr(hwnd, sizeof(COLORREF));
cc.lStructSize=sizeof(CHOOSECOLOR);
cc.hwndOwner=hwnd;
- cc.hInstance=(HWND)hMirandaInst;
+ cc.hInstance=(HWND)hInst;
cc.rgbResult=GetWindowLongPtr(hwnd, 0);
cc.lpCustColors=custColours;
cc.Flags=CC_ANYCOLOR|CC_FULLOPEN|CC_RGBINIT;
@@ -95,7 +95,7 @@ int InitColourPicker(void) wcl.lpfnWndProc=ColourPickerWndProc;
wcl.cbClsExtra=0;
wcl.cbWndExtra=sizeof(COLORREF)*2;
- wcl.hInstance=hMirandaInst;
+ wcl.hInstance=hInst;
wcl.hCursor=NULL;
wcl.lpszClassName=WNDCLASS_COLOURPICKER;
wcl.hbrBackground=(HBRUSH)(COLOR_BTNFACE+1);
diff --git a/src/modules/utils/hyperlink.cpp b/src/modules/utils/hyperlink.cpp index 2705347f36..ae372a9017 100644 --- a/src/modules/utils/hyperlink.cpp +++ b/src/modules/utils/hyperlink.cpp @@ -261,7 +261,7 @@ int InitHyperlink(void) wcl.lpfnWndProc=HyperlinkWndProc;
wcl.cbClsExtra=0;
wcl.cbWndExtra=sizeof(struct HyperlinkWndData*);
- wcl.hInstance=hMirandaInst;
+ wcl.hInstance=hInst;
if (IsWinVer2000Plus()) wcl.hCursor=NULL;
else wcl.hCursor=LoadCursor(wcl.hInstance, MAKEINTRESOURCE(IDC_HYPERLINKHAND));
wcl.lpszClassName=WNDCLASS_HYPERLINK;
diff --git a/src/modules/utils/path.cpp b/src/modules/utils/path.cpp index b31267ad2a..bf875f9d74 100644 --- a/src/modules/utils/path.cpp +++ b/src/modules/utils/path.cpp @@ -26,99 +26,16 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. extern TCHAR g_profileDir[MAX_PATH];
-static char szMirandaPath[MAX_PATH];
-static char szMirandaPathLower[MAX_PATH];
-
static INT_PTR replaceVars(WPARAM wParam, LPARAM lParam);
-static int pathIsAbsolute(const char *path)
-{
- if (strlen(path) <= 2)
- return 0;
- if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\'))
- return 1;
- return 0;
-}
-
static INT_PTR pathToRelative(WPARAM wParam, LPARAM lParam)
{
- char *pSrc = (char*)wParam;
- char *pOut = (char*)lParam;
- if ( !pSrc || !strlen(pSrc) || strlen(pSrc)>MAX_PATH) return 0;
- if ( !pathIsAbsolute(pSrc)) {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc);
- return strlen(pOut);
- }
- else {
- char szTmp[MAX_PATH];
-
- mir_snprintf(szTmp, SIZEOF(szTmp), "%s", pSrc);
- _strlwr(szTmp);
- if (strstr(szTmp, szMirandaPathLower)) {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc+strlen(szMirandaPathLower));
- return strlen(pOut);
- }
- else {
- mir_snprintf(pOut, MAX_PATH, "%s", pSrc);
- return strlen(pOut);
- }
- }
-}
-
-int pathToAbsolute(const char *pSrc, char *pOut, char* base)
-{
- if ( !pSrc || !strlen(pSrc) || strlen(pSrc) > MAX_PATH)
- return 0;
-
- if (base == NULL)
- base = szMirandaPath;
-
- char buf[MAX_PATH];
- if (pSrc[0] < ' ')
- return mir_snprintf(pOut, MAX_PATH, "%s", pSrc);
- else if (pathIsAbsolute(pSrc))
- return GetFullPathNameA(pSrc, MAX_PATH, pOut, NULL);
- else if (pSrc[0] != '\\')
- mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc);
- else
- mir_snprintf(buf, MAX_PATH, "%s%s", base, pSrc+1);
-
- return GetFullPathNameA(buf, MAX_PATH, pOut, NULL);
+ return PathToRelative((char*)wParam, (char*)lParam);
}
static INT_PTR pathToAbsolute(WPARAM wParam, LPARAM lParam)
{
- return pathToAbsolute((char*)wParam, (char*)lParam, szMirandaPath);
-}
-
-void CreatePathToFile(char* szFilePath)
-{
- char* pszLastBackslash = strrchr(szFilePath, '\\');
- if (pszLastBackslash == NULL)
- return;
-
- *pszLastBackslash = '\0';
- CreateDirectoryTree(szFilePath);
- *pszLastBackslash = '\\';
-}
-
-int CreateDirectoryTree(const char *szDir)
-{
- DWORD dwAttributes;
- char *pszLastBackslash, szTestDir[ MAX_PATH ];
-
- lstrcpynA(szTestDir, szDir, SIZEOF(szTestDir));
- if ((dwAttributes = GetFileAttributesA(szTestDir)) != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
- return 0;
-
- pszLastBackslash = strrchr(szTestDir, '\\');
- if (pszLastBackslash == NULL)
- return 0;
-
- *pszLastBackslash = '\0';
- CreateDirectoryTree(szTestDir);
- *pszLastBackslash = '\\';
- return (CreateDirectoryA(szTestDir, NULL) == 0) ? GetLastError() : 0;
+ return PathToAbsolute((char*)wParam, (char*)lParam, NULL);
}
static INT_PTR createDirTree(WPARAM, LPARAM lParam)
@@ -129,94 +46,14 @@ static INT_PTR createDirTree(WPARAM, LPARAM lParam) return CreateDirectoryTree((char*)lParam);
}
-static TCHAR szMirandaPathW[MAX_PATH];
-static TCHAR szMirandaPathWLower[MAX_PATH];
-
-static int pathIsAbsoluteW(const TCHAR *path)
-{
- if (lstrlen(path) <= 2)
- return 0;
- if ((path[1] == ':' && path[2] == '\\') || (path[0] == '\\' && path[1] == '\\'))
- return 1;
- return 0;
-}
-
static INT_PTR pathToRelativeW(WPARAM wParam, LPARAM lParam)
{
- TCHAR *pSrc = (TCHAR*)wParam;
- TCHAR *pOut = (TCHAR*)lParam;
- if ( !pSrc || !lstrlen(pSrc) || lstrlen(pSrc) > MAX_PATH)
- return 0;
-
- if ( !pathIsAbsoluteW(pSrc))
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- else {
- TCHAR szTmp[MAX_PATH];
-
- mir_sntprintf(szTmp, SIZEOF(szTmp), _T("%s"), pSrc);
- _tcslwr(szTmp);
- if (_tcsstr(szTmp, szMirandaPathWLower))
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc+lstrlen(szMirandaPathWLower));
- else
- mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- }
- return lstrlen(pOut);
-}
-
-int pathToAbsoluteW(const TCHAR *pSrc, TCHAR *pOut, TCHAR* base)
-{
- if ( !pSrc || !wcslen(pSrc) || wcslen(pSrc) > MAX_PATH)
- return 0;
-
- if (base == NULL)
- base = szMirandaPathW;
-
- TCHAR buf[MAX_PATH];
- if (pSrc[0] < ' ')
- return mir_sntprintf(pOut, MAX_PATH, _T("%s"), pSrc);
- else if (pathIsAbsoluteW(pSrc))
- return GetFullPathName(pSrc, MAX_PATH, pOut, NULL);
- else if (pSrc[0] != '\\')
- mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc);
- else
- mir_sntprintf(buf, MAX_PATH, _T("%s%s"), base, pSrc+1);
-
- return GetFullPathName(buf, MAX_PATH, pOut, NULL);
+ return PathToRelativeW((WCHAR*)wParam, (WCHAR*)lParam );
}
static INT_PTR pathToAbsoluteW(WPARAM wParam, LPARAM lParam)
{
- return pathToAbsoluteW((TCHAR*)wParam, (TCHAR*)lParam, szMirandaPathW);
-}
-
-void CreatePathToFileW(WCHAR* wszFilePath)
-{
- WCHAR* pszLastBackslash = wcsrchr(wszFilePath, '\\');
- if (pszLastBackslash == NULL)
- return;
-
- *pszLastBackslash = '\0';
- CreateDirectoryTreeW(wszFilePath);
- *pszLastBackslash = '\\';
-}
-
-int CreateDirectoryTreeW(const WCHAR* szDir)
-{
- DWORD dwAttributes;
- WCHAR* pszLastBackslash, szTestDir[ MAX_PATH ];
-
- lstrcpynW(szTestDir, szDir, SIZEOF(szTestDir));
- if ((dwAttributes = GetFileAttributesW(szTestDir)) != INVALID_FILE_ATTRIBUTES && (dwAttributes & FILE_ATTRIBUTE_DIRECTORY))
- return 0;
-
- pszLastBackslash = wcsrchr(szTestDir, '\\');
- if (pszLastBackslash == NULL)
- return 0;
-
- *pszLastBackslash = '\0';
- CreateDirectoryTreeW(szTestDir);
- *pszLastBackslash = '\\';
- return (CreateDirectoryW(szTestDir, NULL) == 0) ? GetLastError() : 0;
+ return PathToAbsoluteW((WCHAR*)wParam, (WCHAR*)lParam, NULL);
}
static INT_PTR createDirTreeW(WPARAM, LPARAM lParam)
@@ -227,20 +64,6 @@ static INT_PTR createDirTreeW(WPARAM, LPARAM lParam) return CreateDirectoryTreeW((WCHAR*)lParam);
}
-int InitPathUtilsW(void)
-{
- GetModuleFileName(hMirandaInst, szMirandaPathW, SIZEOF(szMirandaPathW));
- TCHAR *p = _tcsrchr(szMirandaPathW, '\\');
- if (p)
- p[1] = 0;
- mir_sntprintf(szMirandaPathWLower, SIZEOF(szMirandaPathWLower), _T("%s"), szMirandaPathW);
- _tcslwr(szMirandaPathWLower);
- CreateServiceFunction(MS_UTILS_PATHTORELATIVEW, pathToRelativeW);
- CreateServiceFunction(MS_UTILS_PATHTOABSOLUTEW, pathToAbsoluteW);
- CreateServiceFunction(MS_UTILS_CREATEDIRTREEW, createDirTreeW);
- return 0;
-}
-
TCHAR *GetContactID(HANDLE hContact)
{
TCHAR *theValue = {0};
@@ -251,7 +74,7 @@ TCHAR *GetContactID(HANDLE hContact) theValue = (TCHAR *)mir_tstrdup(dbv.ptszVal);
DBFreeVariant(&dbv);
return theValue;
- } }
+ } }
else {
CONTACTINFO ci = {0};
ci.cbSize = sizeof(ci);
@@ -266,7 +89,7 @@ TCHAR *GetContactID(HANDLE hContact) case CNFT_DWORD:
return _itot(ci.dVal, (TCHAR *)mir_alloc(sizeof(TCHAR)*32), 10);
break;
- } } }
+ } } }
return NULL;
}
@@ -574,17 +397,15 @@ static INT_PTR replaceVars(WPARAM wParam, LPARAM lParam) int InitPathUtils(void)
{
- char *p = 0;
- GetModuleFileNameA(hMirandaInst, szMirandaPath, SIZEOF(szMirandaPath));
- p = strrchr(szMirandaPath, '\\');
- if (p)
- p[1] = 0;
- mir_snprintf(szMirandaPathLower, MAX_PATH, "%s", szMirandaPath);
- _strlwr(szMirandaPathLower);
CreateServiceFunction(MS_UTILS_PATHTORELATIVE, pathToRelative);
+ CreateServiceFunction(MS_UTILS_PATHTORELATIVEW, pathToRelativeW);
+
CreateServiceFunction(MS_UTILS_PATHTOABSOLUTE, pathToAbsolute);
+ CreateServiceFunction(MS_UTILS_PATHTOABSOLUTEW, pathToAbsoluteW);
+
CreateServiceFunction(MS_UTILS_CREATEDIRTREE, createDirTree);
- CreateServiceFunction(MS_UTILS_REPLACEVARS, replaceVars);
+ CreateServiceFunction(MS_UTILS_CREATEDIRTREEW, createDirTreeW);
- return InitPathUtilsW();
+ CreateServiceFunction(MS_UTILS_REPLACEVARS, replaceVars);
+ return 0;
}
diff --git a/src/modules/utils/timezones.cpp b/src/modules/utils/timezones.cpp index 05e83afa51..d90a303e49 100644 --- a/src/modules/utils/timezones.cpp +++ b/src/modules/utils/timezones.cpp @@ -169,7 +169,7 @@ static HANDLE timeapiGetInfoByName(LPCTSTR tszName, DWORD dwFlags) return (dwFlags & TZF_DIFONLY) ? NULL : &myInfo.myTZ;
MIM_TIMEZONE tzsearch;
- tzsearch.hash = hashstr(tszName);
+ tzsearch.hash = mir_hashstrT(tszName);
MIM_TIMEZONE *tz = g_timezones.find(&tzsearch);
if (tz == NULL)
@@ -381,7 +381,7 @@ static int timeapiSelectListItem(HANDLE hContact, HWND hWnd, DWORD dwFlags) DBVARIANT dbv;
if ( !DBGetContactSettingTString(hContact, "UserInfo", "TzName", &dbv))
{
- unsigned hash = hashstr(dbv.ptszVal);
+ unsigned hash = mir_hashstrT(dbv.ptszVal);
for (int i = 0; i < g_timezonesBias.getCount(); ++i)
{
if (hash == g_timezonesBias[i]->hash)
@@ -607,7 +607,7 @@ void InitTimeZones(void) tz->tzi.DaylightBias = tzi.DaylightBias;
_tcscpy(tz->tszName, tszName);
- tz->hash = hashstr(tszName);
+ tz->hash = mir_hashstrT(tszName);
tz->offset = INT_MIN;
GetLocalizedString(hSubKey, _T("Display"), tz->szDisplay, SIZEOF(tz->szDisplay));
diff --git a/src/modules/utils/utils.cpp b/src/modules/utils/utils.cpp index c9c1e3a65e..964e9a920f 100644 --- a/src/modules/utils/utils.cpp +++ b/src/modules/utils/utils.cpp @@ -25,6 +25,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. INT_PTR ResizeDialog(WPARAM wParam, LPARAM lParam);
int InitOpenUrl(void);
int InitWindowList(void);
+int InitPathUtils(void);
void FreeWindowList(void);
int InitHyperlink(void);
int InitColourPicker(void);
@@ -461,98 +462,6 @@ static INT_PTR GenerateRandom(WPARAM wParam, LPARAM lParam) /////////////////////////////////////////////////////////////////////////////////////////
-char* __fastcall rtrim(char* str)
-{
- if (str == NULL) return NULL;
- char* p = strchr(str, 0);
- while (--p >= str)
- {
- switch (*p)
- {
- case ' ': case '\t': case '\n': case '\r':
- *p = 0; break;
- default:
- return str;
- }
- }
- return str;
-}
-
-TCHAR* __fastcall rtrim(TCHAR *str)
-{
- if (str == NULL) return NULL;
- TCHAR* p = _tcschr(str, 0);
- while (--p >= str)
- {
- switch (*p)
- {
- case ' ': case '\t': case '\n': case '\r':
- *p = 0; break;
- default:
- return str;
- }
- }
- return str;
-}
-
-char* __fastcall ltrim(char* str)
-{
- if (str == NULL) return NULL;
- char* p = str;
-
- for (;;)
- {
- switch (*p)
- {
- case ' ': case '\t': case '\n': case '\r':
- ++p; break;
- default:
- memmove(str, p, strlen(p) + 1);
- return str;
- }
- }
-}
-
-char* __fastcall ltrimp(char* str)
-{
- if (str == NULL) return NULL;
- char* p = str;
-
- for (;;)
- {
- switch (*p)
- {
- case ' ': case '\t': case '\n': case '\r':
- ++p; break;
- default:
- return p;
- }
- }
-}
-
-bool __fastcall wildcmp(char * name, char * mask)
-{
- char * last='\0';
- for (;; mask++, name++)
- {
- if (*mask != '?' && *mask != *name) break;
- if (*name == '\0') return ((BOOL)!*mask);
- }
- if (*mask != '*') return FALSE;
- for (;; mask++, name++)
- {
- while (*mask == '*')
- {
- last = mask++;
- if (*mask == '\0') return ((BOOL)!*mask); /* true */
- }
- if (*name == '\0') return ((BOOL)!*mask); /* *mask == EOS */
- if (*mask != '?' && *mask != *name) name -= (size_t)(mask - last) - 1, mask = last;
- }
-}
-
-/////////////////////////////////////////////////////////////////////////////////////////
-
int LoadUtilsModule(void)
{
bModuleInitialized = TRUE;
@@ -570,6 +479,7 @@ int LoadUtilsModule(void) InitOpenUrl();
InitWindowList();
InitHyperlink();
+ InitPathUtils();
InitColourPicker();
InitBitmapFilter();
InitXmlApi();
|