diff options
-rw-r--r-- | plugins/ExternalAPI/m_folders.h | 83 | ||||
-rw-r--r-- | plugins/Folders/src/commonheaders.h | 1 | ||||
-rw-r--r-- | plugins/Folders/src/dlg_handlers.cpp | 439 | ||||
-rw-r--r-- | plugins/Folders/src/dlg_handlers.h | 10 | ||||
-rw-r--r-- | plugins/Folders/src/events.cpp | 4 | ||||
-rw-r--r-- | plugins/Folders/src/events.h | 2 | ||||
-rw-r--r-- | plugins/Folders/src/folderItem.cpp | 227 | ||||
-rw-r--r-- | plugins/Folders/src/folderItem.h | 58 | ||||
-rw-r--r-- | plugins/Folders/src/folders.cpp | 160 | ||||
-rw-r--r-- | plugins/Folders/src/foldersList.cpp | 149 | ||||
-rw-r--r-- | plugins/Folders/src/foldersList.h | 6 | ||||
-rw-r--r-- | plugins/Folders/src/services.cpp | 252 | ||||
-rw-r--r-- | plugins/Folders/src/services.h | 22 | ||||
-rw-r--r-- | plugins/Folders/src/utils.cpp | 331 | ||||
-rw-r--r-- | plugins/Folders/src/utils.h | 44 |
15 files changed, 480 insertions, 1308 deletions
diff --git a/plugins/ExternalAPI/m_folders.h b/plugins/ExternalAPI/m_folders.h index c6d021d46d..ebf2e4baaa 100644 --- a/plugins/ExternalAPI/m_folders.h +++ b/plugins/ExternalAPI/m_folders.h @@ -34,7 +34,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MIRANDA_PATHW L"%miranda_path%"
#define MIRANDA_USERDATAW L"%miranda_userdata%"
-#ifdef _UNICODE
+#ifdef _UNICODE
#define PROFILE_PATHT PROFILE_PATHW
#define CURRENT_PROFILET CURRENT_PROFILEW
#define MIRANDA_PATHT MIRANDA_PATHW
@@ -75,15 +75,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #endif
typedef struct{
- int cbSize; //size of struct
- char szSection[FOLDERS_NAME_MAX_SIZE]; //section name, if it doesn't exist it will be created otherwise it will just add this entry to it
- char szName[FOLDERS_NAME_MAX_SIZE]; //entry name - will be shown in options
- union{
- const char *szFormat; //default string format. Fallback string in case there's no entry in the database for this folder. This should be the initial value for the path, users will be able to change it later.
- const wchar_t *szFormatW; //String is dup()'d so you can free it later. If you set the unicode string don't forget to set the flag accordingly.
- const TCHAR *szFormatT;
- };
- DWORD flags; //FF_* flags
+ int cbSize; //size of struct
+ LPCSTR szSection; //section name, if it doesn't exist it will be created otherwise it will just add this entry to it
+ LPCSTR szName; //entry name - will be shown in options
+ union {
+ const char *szFormat; //default string format. Fallback string in case there's no entry in the database for this folder. This should be the initial value for the path, users will be able to change it later.
+ const wchar_t *szFormatW; //String is dup()'d so you can free it later. If you set the unicode string don't forget to set the flag accordingly.
+ const TCHAR *szFormatT;
+ };
+ DWORD flags; //FF_* flags
} FOLDERSDATA;
/*Folders/Register/Path service
@@ -112,6 +112,7 @@ typedef struct{ wchar_t *szPathW; //unicode version of the buffer.
TCHAR *szPathT;
};
+ DWORD flags; //FF_* flags
} FOLDERSGETDATA;
/*Folders/Get/Path service
@@ -121,26 +122,6 @@ typedef struct{ */
#define MS_FOLDERS_GET_PATH "Folders/Get/Path"
-typedef struct{
- int cbSize;
- union{
- char **szPath; //address of a string variable (char *) or (wchar_t*) where the path should be stored (the last \ won't be copied).
- wchar_t **szPathW; //unicode version of string.
- TCHAR **szPathT;
- };
-} FOLDERSGETALLOCDATA;
-
-/*Folders/GetRelativePath/Alloc service
- wParam - (WPARAM) (int) - Handle to registered path
- lParam - (LPARAM) (FOLDERSALLOCDATA *) data
- This service is the same as MS_FOLDERS_GET_PATH with the difference that this service
- allocates the needed space for the buffer. It uses miranda's memory functions for that and you need
- to use those to free the resulting buffer.
- Should return 0 on success, or nonzero otherwise. Currently it only returns 0.
-*/
-#define MS_FOLDERS_GET_PATH_ALLOC "Folders/Get/Path/Alloc"
-
-
/*Folders/On/Path/Changed
wParam - (WPARAM) 0
lParam - (LPARAM) 0
@@ -153,17 +134,14 @@ typedef struct{ #ifndef M_UTILS_H__
#error The helper functions require that m_utils.h be included in the project. Please include that file if you want to use the helper functions. If you don''t want to use the functions just define FOLDERS_NO_HELPER_FUNCTIONS.
#endif
-//#include "../../../include/newpluginapi.h"
__inline static HANDLE FoldersRegisterCustomPath(const char *section, const char *name, const char *defaultPath)
{
FOLDERSDATA fd = {0};
if (!ServiceExists(MS_FOLDERS_REGISTER_PATH)) return 0;
fd.cbSize = sizeof(FOLDERSDATA);
- strncpy(fd.szSection, section, FOLDERS_NAME_MAX_SIZE);
- fd.szSection[FOLDERS_NAME_MAX_SIZE - 1] = '\0';
- strncpy(fd.szName, name, FOLDERS_NAME_MAX_SIZE);
- fd.szName[FOLDERS_NAME_MAX_SIZE - 1] = '\0';
+ fd.szSection = section;
+ fd.szName = name;
fd.szFormat = defaultPath;
return (HANDLE) CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM) &fd);
}
@@ -174,10 +152,8 @@ __inline static HANDLE FoldersRegisterCustomPathW(const char *section, const cha FOLDERSDATA fd = {0};
if (!ServiceExists(MS_FOLDERS_REGISTER_PATH)) return 0;
fd.cbSize = sizeof(FOLDERSDATA);
- strncpy(fd.szSection, section, FOLDERS_NAME_MAX_SIZE);
- fd.szSection[FOLDERS_NAME_MAX_SIZE - 1] = '\0'; //make sure it's NULL terminated
- strncpy(fd.szName, name, FOLDERS_NAME_MAX_SIZE);
- fd.szName[FOLDERS_NAME_MAX_SIZE - 1] = '\0'; //make sure it's NULL terminated
+ fd.szSection = section;
+ fd.szName = name;
fd.szFormatW = defaultPathW;
fd.flags = FF_UNICODE;
return (HANDLE) CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM) &fd);
@@ -192,8 +168,7 @@ __inline static INT_PTR FoldersGetCustomPath(HANDLE hFolderEntry, char *path, co fgd.nMaxPathSize = size;
fgd.szPath = path;
res = CallService(MS_FOLDERS_GET_PATH, (WPARAM) hFolderEntry, (LPARAM) &fgd);
- if (res)
- {
+ if (res) {
char buffer[MAX_PATH];
CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM) notFound, (LPARAM) buffer);
mir_snprintf(path, size, "%s", buffer);
@@ -210,9 +185,9 @@ __inline static INT_PTR FoldersGetCustomPathW(HANDLE hFolderEntry, wchar_t *path fgd.cbSize = sizeof(FOLDERSGETDATA);
fgd.nMaxPathSize = size;
fgd.szPathW = pathW;
+ fgd.flags = FF_UNICODE;
res = CallService(MS_FOLDERS_GET_PATH, (WPARAM) hFolderEntry, (LPARAM) &fgd);
- if (res)
- {
+ if (res) {
wchar_t buffer[MAX_PATH];
CallService(MS_UTILS_PATHTOABSOLUTEW, (WPARAM) notFoundW, (LPARAM) buffer);
mir_sntprintf(pathW, size, _T("%s"), buffer);
@@ -230,24 +205,19 @@ __inline static INT_PTR FoldersGetCustomPathEx(HANDLE hFolderEntry, char *path, fgd.nMaxPathSize = size;
fgd.szPath = path;
res = CallService(MS_FOLDERS_GET_PATH, (WPARAM) hFolderEntry, (LPARAM) &fgd);
- if (res)
- {
+ if (res) {
char buffer[MAX_PATH];
CallService(MS_UTILS_PATHTOABSOLUTE, (WPARAM) notFound, (LPARAM) buffer);
mir_snprintf(path, size, "%s", buffer);
}
+
if (strlen(path) > 0)
- {
strcat(path, "\\");
- }
- else{
+ else
path[0] = '\0';
- }
if (fileName)
- {
strcat(path, fileName);
- }
return res;
}
@@ -260,26 +230,21 @@ __inline static INT_PTR FoldersGetCustomPathExW(HANDLE hFolderEntry, wchar_t *pa fgd.cbSize = sizeof(FOLDERSGETDATA);
fgd.nMaxPathSize = size;
fgd.szPathW = pathW;
+ fgd.flags = FF_UNICODE;
res = CallService(MS_FOLDERS_GET_PATH, (WPARAM) hFolderEntry, (LPARAM) &fgd);
- if (res)
- {
+ if (res) {
wchar_t buffer[MAX_PATH];
CallService(MS_UTILS_PATHTOABSOLUTEW, (WPARAM) notFoundW, (LPARAM) buffer);
mir_sntprintf(pathW, size, _T("%s"), buffer);
}
if (wcslen(pathW) > 0)
- {
wcscat(pathW, L"\\");
- }
- else{
+ else
pathW[0] = L'\0';
- }
if (fileNameW)
- {
wcscat(pathW, fileNameW);
- }
return res;
}
diff --git a/plugins/Folders/src/commonheaders.h b/plugins/Folders/src/commonheaders.h index 52ab262421..1b5b1be6f2 100644 --- a/plugins/Folders/src/commonheaders.h +++ b/plugins/Folders/src/commonheaders.h @@ -42,6 +42,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "m_database.h"
#include "m_system.h"
+#include "m_system_cpp.h"
#include "m_skin.h"
#include "m_options.h"
#include "m_clist.h"
diff --git a/plugins/Folders/src/dlg_handlers.cpp b/plugins/Folders/src/dlg_handlers.cpp index 4d507ce31c..88f6f4ad63 100644 --- a/plugins/Folders/src/dlg_handlers.cpp +++ b/plugins/Folders/src/dlg_handlers.cpp @@ -6,179 +6,121 @@ static int bInitializing = 0; int GetCurrentItemSelection(HWND hWnd)
{
- return SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
+ return SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETCURSEL, 0, 0);
}
int GetCurrentSectionSelection(HWND hWnd)
{
- return SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
+ return SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETCURSEL, 0, 0);
}
PFolderItem GetSelectedItem(HWND hWnd)
{
- WCHAR section[MAX_FOLDER_SIZE];
- WCHAR item[MAX_FOLDER_SIZE];
+ char section[MAX_FOLDER_SIZE], item[MAX_FOLDER_SIZE];
GetCurrentItemText(hWnd, item, MAX_FOLDER_SIZE);
GetCurrentSectionText(hWnd, section, MAX_FOLDER_SIZE);
return lstRegisteredFolders.GetTranslated(section, item);
}
-int GetCurrentItemText(HWND hWnd, WCHAR *buffer, int count)
+int GetCurrentItemText(HWND hWnd, char *buffer, int count)
{
int index = GetCurrentItemSelection(hWnd);
- if (index != LB_ERR)
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
- return 1;
- }
- else{
- buffer[0] = L'\0';
- return 0;
- }
+ if (index != LB_ERR) {
+ SendDlgItemMessageA(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
+ return 1;
+ }
+
+ buffer[0] = L'\0';
+ return 0;
}
-int GetCurrentSectionText(HWND hWnd, WCHAR *buffer, int count)
+int GetCurrentSectionText(HWND hWnd, char *buffer, int count)
{
int index = GetCurrentSectionSelection(hWnd);
- if (index != LB_ERR)
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
- return 1;
- }
- else{
- buffer[0] = L'0';
- return 0;
- }
-}
+ if (index != LB_ERR) {
+ SendDlgItemMessageA(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_GETTEXT, index, (LPARAM) buffer);
+ return 1;
+ }
-//void GetEditText(HWND hWnd, char *buffer, int size)
-//{
-// GetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
-// StrTrim(buffer, "\\\t \n");
-//}
+ buffer[0] = L'0';
+ return 0;
+}
-void GetEditTextW(HWND hWnd, wchar_t *buffer, int size)
+static void GetEditText(HWND hWnd, TCHAR *buffer, int size)
{
- GetWindowTextW(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
+ GetWindowText( GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer, size);
}
-//void SetEditText(HWND hWnd, const char *buffer)
-//{
-// bInitializing = 1;
-// SetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
-// bInitializing = 0;
-//// SendDlgItemMessage(hWnd, IDC_FOLDER_EDIT, WM_SETTEXT, 0, (LPARAM) buffer);
-//}
-
-void SetEditTextW(HWND hWnd, const wchar_t *buffer)
+void SetEditText(HWND hWnd, const TCHAR *buffer)
{
bInitializing = 1;
- SetWindowTextW(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
+ SetWindowText(GetDlgItem(hWnd, IDC_FOLDER_EDIT), buffer);
bInitializing = 0;
}
int ContainsSection(HWND hWnd, const WCHAR *section)
{
- int index = SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM) section);
+ int index = SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_FINDSTRINGEXACT, -1, (LPARAM) section);
return (index != LB_ERR);
}
void LoadRegisteredFolderSections(HWND hWnd)
{
- for (int i = 0; i < lstRegisteredFolders.Count(); i++)
- {
- PFolderItem tmp = lstRegisteredFolders.Get(i + 1);
- WCHAR *translated = mir_a2u(Translate(tmp->GetSection()));
- if (!ContainsSection(hWnd, translated))
- {
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_ADDSTRING, 0, (LPARAM) translated);
- }
- mir_free(translated);
- }
+ for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
+ PFolderItem tmp = lstRegisteredFolders.Get(i + 1);
+ TCHAR *translated = mir_a2t( tmp->GetSection());
+ if (!ContainsSection(hWnd, translated))
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_SECTIONS_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(translated));
+
+ mir_free(translated);
+ }
}
void LoadRegisteredFolderItems(HWND hWnd)
{
- WCHAR buffer[MAX_FOLDER_SIZE];
+ char buffer[MAX_FOLDER_SIZE];
GetCurrentSectionText(hWnd, buffer, MAX_FOLDER_SIZE);
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_RESETCONTENT, 0, 0);
- for (int i = 0; i < lstRegisteredFolders.Count(); i++)
- {
- PFolderItem item = lstRegisteredFolders.Get(i + 1);
- WCHAR *wide = mir_a2u(Translate(item->GetSection()));
- if (wcscmp(buffer, wide) == 0)
- {
- mir_free(wide);
- wide = mir_a2u(Translate(item->GetName()));
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_ADDSTRING, 0, (LPARAM) wide);
- }
- mir_free(wide);
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_RESETCONTENT, 0, 0);
+ for (int i = 0; i < lstRegisteredFolders.Count(); i++) {
+ PFolderItem item = lstRegisteredFolders.Get(i + 1);
+ if ( !strcmp(buffer, item->GetSection()) == 0) {
+ mir_ptr<TCHAR> wide( mir_a2t( item->GetName()));
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_ADDSTRING, 0, (LPARAM)TranslateTS(wide));
}
- SendDlgItemMessageW(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_SETCURSEL, 0, 0); //select the first item
+ }
+ SendDlgItemMessage(hWnd, IDC_FOLDERS_ITEMS_LIST, LB_SETCURSEL, 0, 0); //select the first item
PostMessage(hWnd, WM_COMMAND, MAKEWPARAM(IDC_FOLDERS_ITEMS_LIST, LBN_SELCHANGE), 0); //tell the dialog to refresh the preview
}
void LoadItem(HWND hWnd, PFolderItem item)
{
- if (item)
- {
- if (item->IsUnicode())
- {
- SetEditTextW(hWnd, item->GetFormatW());
- }
- else{
- WCHAR *buffer = mir_a2u(item->GetFormat());
- SetEditTextW(hWnd, buffer);
- mir_free(buffer);
- }
- RefreshPreview(hWnd);
- }
+ if (item) {
+ SetEditText(hWnd, item->GetFormat());
+ RefreshPreview(hWnd);
+ }
}
void SaveItem(HWND hWnd, PFolderItem item, int bEnableApply)
{
- if (item)
- {
- if (item->IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- item->SetFormatW(buffer);
- }
- else{
- WCHAR buffer[MAX_FOLDER_SIZE];
- char ansi[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- WideCharToMultiByte(CallService(MS_LANGPACK_GETCODEPAGE, 0, 0), 0, buffer, -1, ansi, MAX_FOLDER_SIZE, NULL, NULL);
- item->SetFormat(ansi);
- }
- if (bEnableApply)
- {
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
- }
- }
+ if (!item)
+ return;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, buffer, SIZEOF(buffer));
+ item->SetFormat(buffer);
+
+ if (bEnableApply)
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0);
}
int ChangesNotSaved(HWND hWnd, PFolderItem item)
{
int res = 0;
- if (item)
- {
- if (item->IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- res = (wcscmp(item->GetFormatW(), buffer) != 0);
- }
- else{
- WCHAR buffer[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, buffer, MAX_FOLDER_SIZE);
- char *ansi = mir_u2a(buffer);
-
- res = (strcmp(item->GetFormat(), ansi) != 0);
- mir_free(ansi);
- }
- }
+ if (item) {
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, buffer, MAX_FOLDER_SIZE);
+ res = _tcscmp(item->GetFormat(), buffer) != 0;
+ }
return res;
}
@@ -186,22 +128,16 @@ int ChangesNotSaved(HWND hWnd, PFolderItem item) void CheckForChanges(HWND hWnd, int bNeedConfirmation = 1)
{
if (ChangesNotSaved(hWnd, lastItem))
- {
- if ((!bNeedConfirmation) || MessageBoxW(hWnd, TranslateW(L"Some changes weren't saved. Apply the changes now ?"), TranslateW(L"Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
- {
- SaveItem(hWnd, lastItem);
- }
- }
+ if ((!bNeedConfirmation) || MessageBox(hWnd, TranslateT("Some changes weren't saved. Apply the changes now ?"), TranslateT("Changes not saved"), MB_YESNO | MB_ICONINFORMATION) == IDYES)
+ SaveItem(hWnd, lastItem);
}
void RefreshPreview(HWND hWnd)
{
- wchar_t tmp[MAX_FOLDER_SIZE];
- wchar_t res[MAX_FOLDER_SIZE];
- GetEditTextW(hWnd, tmp, MAX_FOLDER_SIZE);
- ExpandPathW(res, tmp, MAX_FOLDER_SIZE);
- SetWindowTextW(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
- //SendDlgItemMessage(hWnd, IDC_PREVIEW_EDIT, WM_SETTEXT, 0, (LPARAM) res);
+ TCHAR tmp[MAX_FOLDER_SIZE], res[MAX_FOLDER_SIZE];
+ GetEditText(hWnd, tmp, MAX_FOLDER_SIZE);
+ ExpandPath(res, tmp, MAX_FOLDER_SIZE);
+ SetWindowText(GetDlgItem(hWnd, IDC_PREVIEW_EDIT), res);
}
@@ -210,148 +146,97 @@ void RefreshPreview(HWND hWnd) INT_PTR CALLBACK DlgProcOpts(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- bInitializing = 1;
- lastItem = NULL;
- TranslateDialogDefault(hWnd);
- LoadRegisteredFolderSections(hWnd);
- bInitializing = 0;
+ switch (msg) {
+ case WM_INITDIALOG:
+ bInitializing = 1;
+ lastItem = NULL;
+ TranslateDialogDefault(hWnd);
+ LoadRegisteredFolderSections(hWnd);
+ bInitializing = 0;
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDC_FOLDER_EDIT:
+ switch (HIWORD(wParam)) {
+ case EN_CHANGE:
+ RefreshPreview(hWnd);
+ if (!bInitializing)
+ SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); //show the apply button.
+ }
+ break;
- break;
- }
+ case IDC_REFRESH_BUTTON:
+ RefreshPreview(hWnd);
+ break;
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDC_FOLDER_EDIT:
- {
- switch (HIWORD(wParam))
- {
- case EN_CHANGE:
- {
- RefreshPreview(hWnd);
- if (!bInitializing)
- {
- SendMessage(GetParent(hWnd), PSM_CHANGED, 0, 0); //show the apply button.
- }
-
- break;
- }
- }
-
- break;
- }
-
- case IDC_REFRESH_BUTTON:
- {
- RefreshPreview(hWnd);
-
- break;
- }
-
- case IDC_HELP_BUTTON:
- {
- HWND helpDlg = CreateDialogW(hInstance, MAKEINTRESOURCEW(IDD_VARIABLES_HELP), hWnd, DlgProcVariables);
- ShowWindow(helpDlg, SW_SHOW);
-
- break;
- }
-
- case IDC_FOLDERS_SECTIONS_LIST:
- {
- switch (HIWORD(wParam))
- {
- case LBN_SELCHANGE:
- {
- CheckForChanges(hWnd);
- LoadRegisteredFolderItems(hWnd);
- lastItem = NULL;
- SetEditTextW(hWnd, L"");
- RefreshPreview(hWnd);
-
- break;
- }
- }
-
- break;
- }
-
- case IDC_FOLDERS_ITEMS_LIST:
- {
- switch (HIWORD(wParam))
- {
- case LBN_SELCHANGE:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item != NULL)
- {
- CheckForChanges(hWnd);
- LoadItem(hWnd, item);
- }
- lastItem = item;
-
- break;
- }
- }
-
- break;
- }
- }
+ case IDC_HELP_BUTTON:
+ {
+ HWND helpDlg = CreateDialog(hInstance, MAKEINTRESOURCE(IDD_VARIABLES_HELP), hWnd, DlgProcVariables);
+ ShowWindow(helpDlg, SW_SHOW);
+ }
+ break;
+
+ case IDC_FOLDERS_SECTIONS_LIST:
+ switch (HIWORD(wParam)) {
+ case LBN_SELCHANGE:
+ CheckForChanges(hWnd);
+ LoadRegisteredFolderItems(hWnd);
+ lastItem = NULL;
+ SetEditText(hWnd, L"");
+ RefreshPreview(hWnd);
+ break;
+ }
- break;
- }
+ break;
- case WM_NOTIFY:
+ case IDC_FOLDERS_ITEMS_LIST:
+ switch (HIWORD(wParam)) {
+ case LBN_SELCHANGE:
{
-// Log("WM_NOTIFY %d %d", wParam, lParam);
- switch(((LPNMHDR)lParam)->idFrom)
+ PFolderItem item = GetSelectedItem(hWnd);
+ if (item != NULL)
{
- case 0:
- switch (((LPNMHDR)lParam)->code)
- {
- case PSN_APPLY:
- {
- PFolderItem item = GetSelectedItem(hWnd);
- if (item)
- {
- SaveItem(hWnd, item, FALSE);
- LoadItem(hWnd, item);
- }
-
- lstRegisteredFolders.Save();
- CallPathChangedEvents();
-
- break;
- }
- }
-
- break;
+ CheckForChanges(hWnd);
+ LoadItem(hWnd, item);
}
+ lastItem = item;
+
+ break;
}
+ }
- break;
+ break;
+ }
+
+ break;
- default:
+ case WM_NOTIFY:
+ switch(((LPNMHDR)lParam)->idFrom) {
+ case 0:
+ switch (((LPNMHDR)lParam)->code) {
+ case PSN_APPLY:
{
+ PFolderItem item = GetSelectedItem(hWnd);
+ if (item) {
+ SaveItem(hWnd, item, FALSE);
+ LoadItem(hWnd, item);
+ }
+
+ lstRegisteredFolders.Save();
+ CallPathChangedEvents();
break;
}
+ }
}
+ break;
+ }
return 0;
}
-INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
-{
- switch (msg)
- {
- case WM_INITDIALOG:
- {
- SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, _T("\
+static TCHAR tszMessage[] = _T("\
Don\'t forget to click on Apply to save the changes. If you don\'t then the changes won\'t\r\n\
be saved to the database, they will only be valid for this session.\r\n\r\n\
Variable string\t\tWhat it expands to:\r\n\
@@ -376,36 +261,28 @@ profile is \'default.dat\' and miranda\'s path is \'c:\\program files\\miranda i %profile_path%\\%current_profile%\twill expand to \'c:\\program files\\miranda im\\profiles\\default\\'\r\n\
%miranda_path%\\plugins\\config\twill expand to \'c:\\program files\\miranda im\\plugins\\config\\'\r\n\
\' %miranda_path%\\\\\\\\ \'\t\twill expand to \'c:\\program files\\miranda im\\'\r\n\
-notice that the spaces at the beginning and the end of the string are trimmed, as well as the last \\\
-"));
-
- TranslateDialogDefault(hWnd);
-
- break;
- }
-
- case WM_CLOSE:
- {
- DestroyWindow(hWnd);
+notice that the spaces at the beginning and the end of the string are trimmed, as well as the last");
- break;
- }
-
- case WM_COMMAND:
- {
- switch (LOWORD(wParam))
- {
- case IDCLOSE:
- {
- DestroyWindow(hWnd);
-
- break;
- }
- }
-
- break;
- }
+INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
+{
+ switch (msg) {
+ case WM_INITDIALOG:
+ SetDlgItemText(hWnd, IDC_HELP_RICHEDIT, tszMessage);
+ TranslateDialogDefault(hWnd);
+ break;
+
+ case WM_CLOSE:
+ DestroyWindow(hWnd);
+ break;
+
+ case WM_COMMAND:
+ switch (LOWORD(wParam)) {
+ case IDCLOSE:
+ DestroyWindow(hWnd);
+ break;
}
+ break;
+ }
return 0;
-}
\ No newline at end of file +}
diff --git a/plugins/Folders/src/dlg_handlers.h b/plugins/Folders/src/dlg_handlers.h index 4f3a4f15ca..18de486289 100644 --- a/plugins/Folders/src/dlg_handlers.h +++ b/plugins/Folders/src/dlg_handlers.h @@ -12,12 +12,10 @@ INT_PTR CALLBACK DlgProcVariables(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lPa int GetCurrentItemSelection(HWND hWnd);
int GetCurrentSectionSelection(HWND hWnd);
PFolderItem GetSelectedItem(HWND hWnd);
-int GetCurrentSectionText(HWND hWnd, WCHAR *buffer, int count);
-int GetCurrentItemText(HWND hWnd, WCHAR *buffer, int count);
-//void GetEditText(HWND hWnd, char *buffer, int size);
-void GetEditTextW(HWND hWnd, wchar_t *buffer, int size);
-//void SetEditText(HWND hWnd, const char *buffer);
-void SetEditTextW(HWND hWnd, const wchar_t *buffer);
+int GetCurrentSectionText(HWND hWnd, char *buffer, int count);
+int GetCurrentItemText(HWND hWnd, char *buffer, int count);
+void GetEditText(HWND hWnd, TCHAR *buffer, int size);
+void SetEditText(HWND hWnd, const TCHAR *buffer);
void LoadRegisteredFolderSections(HWND hWnd);
void LoadRegisteredFolderItems(HWND hWnd);
void LoadItem(HWND hWnd, PFolderItem item);
diff --git a/plugins/Folders/src/events.cpp b/plugins/Folders/src/events.cpp index 359ac81bf4..dae59e6d8f 100644 --- a/plugins/Folders/src/events.cpp +++ b/plugins/Folders/src/events.cpp @@ -20,7 +20,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "events.h"
-HANDLE hPathChanged;
+static HANDLE hPathChanged;
int InitEvents()
{
@@ -38,4 +38,4 @@ int DestroyEvents() int CallPathChangedEvents()
{
return NotifyEventHooks(hPathChanged, 0, 0);
-}
\ No newline at end of file +}
diff --git a/plugins/Folders/src/events.h b/plugins/Folders/src/events.h index 8f73ee7cfe..35dfa2fe8d 100644 --- a/plugins/Folders/src/events.h +++ b/plugins/Folders/src/events.h @@ -24,8 +24,6 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
#include "m_folders.h"
-extern HANDLE hPathChanged;
-
int InitEvents();
int DestroyEvents();
diff --git a/plugins/Folders/src/folderItem.cpp b/plugins/Folders/src/folderItem.cpp index cf58e5feac..fa40d855c9 100644 --- a/plugins/Folders/src/folderItem.cpp +++ b/plugins/Folders/src/folderItem.cpp @@ -22,78 +22,30 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "commonheaders.h"
#include "services.h"
-CFolderItem::CFolderItem(const char *sectionName, const char *name, const char *format, const DWORD flags)
+CFolderItem::CFolderItem(const char *sectionName, const char *name, const TCHAR *format, const DWORD flags)
{
- strncpy(szSection, sectionName, sizeof(szSection));
- szFormat = NULL;
- szOldFormat = NULL;
- szFormatW = NULL;
- szOldFormatW = NULL;
- strncpy(szName, name, sizeof(szName));
- this->flags = flags;
+ m_szSection = mir_strdup(sectionName);
+ m_szName = mir_strdup(name);
+ m_tszFormat = NULL;
+ m_tszOldFormat = NULL;
+ m_flags = flags;
GetDataFromDatabase(format);
FolderCreateDirectory();
}
-void MyFree(void *data)
-{
- if (data)
- {
- free(data);
- }
-}
-
CFolderItem::~CFolderItem()
{
-// WriteDataToDatabase();
- if (IsUnicode())
- {
- MyFree(szFormatW);
- MyFree(szOldFormatW);
- }
- else{
- MyFree(szFormat);
- MyFree(szOldFormat);
- }
-}
-
-const char *CFolderItem::GetSection() const
-{
- return szSection;
-}
-
-const char *CFolderItem::GetName() const
-{
- return szName;
-}
-
-const char *CFolderItem::GetFormat() const
-{
- return szFormat;
-}
-
-const wchar_t *CFolderItem::GetFormatW() const
-{
- return szFormatW;
+ mir_free(m_szSection);
+ mir_free(m_szName);
+ mir_free(m_tszFormat);
+ mir_free(m_tszOldFormat);
}
-void CFolderItem::SetFormat(const char *newFormat)
+void CFolderItem::SetFormat(const TCHAR *newFormat)
{
- MyFree(szOldFormat);
- szOldFormat = szFormat;
- szFormat = _strdup((strlen(newFormat) > 0) ? newFormat : MIRANDA_PATH);
-}
-
-void CFolderItem::SetFormatW(const wchar_t *newFormat)
-{
- MyFree(szOldFormatW);
- szOldFormatW = szFormatW;
- szFormatW = _wcsdup((wcslen(newFormat) > 0) ? newFormat : MIRANDA_PATHW);
-}
-
-int CFolderItem::IsUnicode() const
-{
- return (flags & FF_UNICODE);
+ mir_free(m_tszOldFormat);
+ m_tszOldFormat = m_tszFormat;
+ m_tszFormat = mir_tstrdup( *newFormat ? newFormat : MIRANDA_PATHT);
}
int CFolderItem::IsEqual(const CFolderItem *other)
@@ -103,12 +55,12 @@ int CFolderItem::IsEqual(const CFolderItem *other) int CFolderItem::IsEqual(const char *section, const char *name)
{
- return ((strcmp(szName, name) == 0) && (strcmp(szSection, section) == 0));
+ return ((strcmp(m_szName, name) == 0) && (strcmp(m_szSection, section) == 0));
}
int CFolderItem::IsEqualTranslated(const char *trSection, const char *trName)
{
- return ((strcmp(Translate(szName), trName) == 0) && (strcmp(Translate(szSection), trSection) == 0));
+ return ((strcmp(Translate(m_szName), trName) == 0) && (strcmp(Translate(m_szSection), trSection) == 0));
}
int CFolderItem::operator ==(const CFolderItem *other)
@@ -116,135 +68,66 @@ int CFolderItem::operator ==(const CFolderItem *other) return IsEqual(other);
}
-void CFolderItem::Expand(char *buffer, int size)
+void CFolderItem::Expand(TCHAR *buffer, int size)
{
- if (IsUnicode())
- {
- ExpandPathW((wchar_t *) buffer, szFormatW, size);
- }
- else{
- ExpandPath(buffer, szFormat, size);
- }
+ ExpandPath(buffer, m_tszFormat, size);
}
void CFolderItem::Save()
{
- int res = FolderDeleteOldDirectory(FALSE);
- //FolderCreateDirectory(!res);
+ FolderDeleteOldDirectory(FALSE);
FolderCreateDirectory(FALSE);
WriteDataToDatabase();
}
int CFolderItem::FolderCreateDirectory(int showFolder)
{
- int res = FOLDER_SUCCESS;
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- if (szFormatW)
- {
- ExpandPathW(buffer, szFormatW, MAX_FOLDER_SIZE);
- CreateDirectories(buffer);
- if (showFolder)
- {
- ShellExecuteW(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
- }
- res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
- }
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- if (szFormat)
- {
- ExpandPath(buffer, szFormat, MAX_FOLDER_SIZE);
- CreateDirectories(buffer);
- if (showFolder)
- {
- ShellExecuteA(NULL, "explore", buffer, NULL, NULL, SW_SHOW);
- }
- res = (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
- }
- }
- return res;
+ if (m_tszFormat == NULL)
+ return FOLDER_SUCCESS;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ ExpandPath(buffer, m_tszFormat, SIZEOF(buffer));
+ CreateDirectoryTreeT(buffer);
+ if (showFolder)
+ ShellExecute(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
+
+ return (DirectoryExists(buffer)) ? FOLDER_SUCCESS : FOLDER_FAILURE;
}
int CFolderItem::FolderDeleteOldDirectory(int showFolder)
{
- int res = FOLDER_SUCCESS;
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- if (szOldFormatW)
- {
- if (wcscmp(szFormatW, szOldFormatW) == 0) //format wasn't changed
- {
- return res;
- }
- ExpandPathW(buffer, szOldFormatW, MAX_FOLDER_SIZE);
- RemoveDirectories(buffer);
- res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
- if ((res == FOLDER_FAILURE) && (showFolder))
- {
- ShellExecuteW(NULL, L"explore", buffer, NULL, NULL, SW_SHOW);
- }
- }
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- if (szOldFormat)
- {
- if (strcmp(szFormat, szOldFormat) == 0) //format wasn't changed
- {
- return res;
- }
- ExpandPath(buffer, szOldFormat, MAX_FOLDER_SIZE);
- RemoveDirectories(buffer);
- res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
- if ((res == FOLDER_FAILURE) && (showFolder))
- {
- ShellExecuteA(NULL, "explore", buffer, NULL, NULL, SW_SHOW);
- }
- }
- }
+ if ( !m_tszOldFormat)
+ return FOLDER_SUCCESS;
+
+ if ( !_tcscmp(m_tszFormat, m_tszOldFormat)) //format wasn't changed
+ return FOLDER_SUCCESS;
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ ExpandPath(buffer, m_tszOldFormat, SIZEOF(buffer));
+ RemoveDirectories(buffer);
+ int res = (DirectoryExists(buffer)) ? FOLDER_FAILURE : FOLDER_SUCCESS;
+ if ((res == FOLDER_FAILURE) && (showFolder))
+ ShellExecute(NULL, _T("explore"), buffer, NULL, NULL, SW_SHOW);
return res;
}
-void CFolderItem::GetDataFromDatabase(const char *szNotFound)
+void CFolderItem::GetDataFromDatabase(const TCHAR *szNotFound)
{
char name[256];
- strcpy(name, szSection);
- strcat(name, szName);
-
- if (IsUnicode())
- {
- wchar_t buffer[MAX_FOLDER_SIZE];
- GetStringFromDatabase(name, (const wchar_t *) szNotFound, buffer, MAX_FOLDER_SIZE);
- SetFormatW(buffer);
- }
- else{
- char buffer[MAX_FOLDER_SIZE];
- GetStringFromDatabase(name, szNotFound, buffer, MAX_FOLDER_SIZE);
- SetFormat(buffer);
- }
+ strcpy_s(name, sizeof(name), m_szSection);
+ strcat_s(name, sizeof(name), m_szName);
+
+ TCHAR buffer[MAX_FOLDER_SIZE];
+ GetStringFromDatabase(name, szNotFound, buffer, SIZEOF(buffer));
+ SetFormat(buffer);
}
void CFolderItem::WriteDataToDatabase()
{
- char name[256];
- strcpy(name, szSection);
- strcat(name, szName);
-
- if (IsUnicode())
- {
- if (szFormatW)
- {
- WriteStringToDatabase(name, szFormatW);
- }
- }
- else{
- if (szFormat)
- {
- WriteStringToDatabase(name, szFormat);
- }
- }
-}
\ No newline at end of file + char szSettingName[256];
+ strcpy_s(szSettingName, sizeof(szSettingName), m_szSection);
+ strcat_s(szSettingName, sizeof(szSettingName), m_szName);
+
+ if (m_tszFormat)
+ db_set_ts(NULL, ModuleName, szSettingName, m_tszFormat);
+}
diff --git a/plugins/Folders/src/folderItem.h b/plugins/Folders/src/folderItem.h index ab2c1bbd38..89731b32be 100644 --- a/plugins/Folders/src/folderItem.h +++ b/plugins/Folders/src/folderItem.h @@ -35,44 +35,34 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define FOLDER_SUCCESS 1
#define FOLDER_FAILURE 0
-class CFolderItem{
- protected:
- char szSection[FOLDERS_NAME_MAX_SIZE];
- char szName[FOLDERS_NAME_MAX_SIZE]; //don't forget to modify in m_folders.h
- union{
- char *szFormat;
- wchar_t *szFormatW;
- };
- union{
- char *szOldFormat;
- wchar_t *szOldFormatW;
- };
- DWORD flags;
+class CFolderItem
+{
+ char *m_szSection;
+ char *m_szName;
+ TCHAR *m_tszFormat, *m_tszOldFormat;
+ DWORD m_flags;
- void GetDataFromDatabase(const char *szNotFound);
- void WriteDataToDatabase();
+ void GetDataFromDatabase(const TCHAR *szNotFound);
+ void WriteDataToDatabase();
- int FolderCreateDirectory(int showFolder = 0);
- int FolderDeleteOldDirectory(int showFolder = 0);
+ int FolderCreateDirectory(int showFolder = 0);
+ int FolderDeleteOldDirectory(int showFolder = 0);
+public:
+ CFolderItem(const char *sectionName, const char *name, const TCHAR *format, const DWORD flags);
+ virtual ~CFolderItem();
+
+ void Expand(TCHAR *buffer, int size);
+ void Save();
- public:
- CFolderItem(const char *sectionName, const char *name, const char *format, const DWORD flags);
- virtual ~CFolderItem();
- void Expand(char *buffer, int size);
- void Save();
-
- int IsUnicode() const;
- int IsEqual(const CFolderItem *other);
- int IsEqual(const char *section, const char *name);
- int IsEqualTranslated(const char *trSection, const char *trName);
- int operator ==(const CFolderItem *other);
+ int IsEqual(const CFolderItem *other);
+ int IsEqual(const char *section, const char *name);
+ int IsEqualTranslated(const char *trSection, const char *trName);
+ int operator ==(const CFolderItem *other);
- const char *GetSection() const;
- const char *GetName() const;
- const char *GetFormat() const;
- const wchar_t *GetFormatW() const;
- void SetFormat(const char *newFormat);
- void SetFormatW(const wchar_t *newFormat);
+ __inline const char* GetSection() const { return m_szSection; }
+ __inline const char* GetName() const { return m_szName; }
+ __inline const TCHAR* GetFormat() const { return m_tszFormat; }
+ void SetFormat(const TCHAR *newFormat);
};
typedef CFolderItem *PFolderItem;
diff --git a/plugins/Folders/src/folders.cpp b/plugins/Folders/src/folders.cpp index 721c43ee5f..3dfa8e4b89 100644 --- a/plugins/Folders/src/folders.cpp +++ b/plugins/Folders/src/folders.cpp @@ -33,8 +33,6 @@ int hLangpack; CFoldersList &lstRegisteredFolders = CFoldersList(10); //the list
-
-
PLUGININFOEX pluginInfo = {
sizeof(PLUGININFOEX),
__PLUGIN_DISPLAY_NAME,
@@ -45,117 +43,9 @@ PLUGININFOEX pluginInfo = { __COPYRIGHT,
__AUTHORWEB,
UNICODE_AWARE,
- {0x2f129563, 0x2c7d, 0x4a9a, {0xb9, 0x48, 0x97, 0xdf, 0xcc, 0x0a, 0xfd, 0xd7}} //{2f129563-2c7d-4a9a-b948-97dfcc0afdd7}
-}; //not used
-
-#ifdef _DEBUG
-
-typedef struct{
- int cbSize; //size of struct
- int nUniqueID; //unique id for this path. This ID should be unique for your plugin.
- char szName[FOLDERS_NAME_MAX_SIZE]; //name to show in options
-} FOLDERSDATA_OLD;
-
-INT_PTR TestPlugin(WPARAM wParam, LPARAM lParam)
-{
- char temp[MAX_PATH];
- const int MAX = 20;
- int i;
- HANDLE handles[MAX][2];
-/* FOLDERSDATA caca;
- caca.cbSize = sizeof(caca);
- caca.szFormat = FOLDER_LOGS;*/
- char *section;
- for (i = 0; i < MAX; i++)
- {
- switch (i % 4)
- {
- case 0:
- section = "Section 1";
- break;
- case 1:
- section = "Section 2";
- break;
- case 2:
- section = "Yet another section";
- break;
- case 3:
- section = "Section no 4";
- break;
- default:
- section = "Uhh ohh";
- break;
- }
- //strcpy(caca.szSection, section);
- _itoa(i, temp, 10);
- //strcpy(caca.szName, temp);
-
- handles[i][0] = FoldersRegisterCustomPathT(section, temp, FOLDER_LOGS); //CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM) &caca);
- }
- //caca.szFormatW = L"%profile_path%\\%current_profile%\\Ø";
- //caca.flags = FF_UNICODE;
- FoldersRegisterCustomPath("Unicode stuff", "non unicode", " %profile_path%\\%current_profile%\\Ø\\\\\\");
- for (i = 0; i < MAX; i++)
- {
- //strcpy(caca.szSection, "Unicode stuff");
- sprintf(temp, "Value %d", i);
- //strcpy(caca.szName, temp);
- handles[i][1] = FoldersRegisterCustomPathW("Unicode stuff", temp, L"%profile_path%\\%current_profile%\\\u1FA6"); //CallService(MS_FOLDERS_REGISTER_PATH, 0, (LPARAM) &caca);
- }
-/*
- FOLDERSAPPENDDATA data;
- data.hRegisteredPath = handles[0];
- data.szAppendData = "just an appended string";
- char *cacat;
- CallService(MS_FOLDERS_GET_PATH_ALLOC_APPEND, (WPARAM) &data, (LPARAM) &cacat);
- Log("Append function returned : %s", cacat); */
- /*FOLDERSGETDATA data = {0};
- data.cbSize = sizeof(data);
- data.nMaxPathSize = sizeof(temp);
- data.szPath = temp; */
- for (i = 0; i < MAX; i++)
- {
- //CallService(MS_FOLDERS_GET_PATH, handles[i][0], (LPARAM) &data);
- FoldersGetCustomPath((HANDLE) handles[i][0], temp, sizeof(temp), "<not found>");
- Log("Path function[%d] returned : %s", i, temp);
- }
- wchar_t buffer[MAX_PATH];
- //data.szPathW = buffer;
- for (i = 0; i < MAX; i++)
- {
- //CallService(MS_FOLDERS_GET_PATH, handles[i][0], (LPARAM) &data);
- FoldersGetCustomPathW((HANDLE) handles[i][1], buffer, MAX_PATH, L"<not found>");
- Log("Unicode path function[%d] returned: %S", i, buffer);
- }
-// GetPathService(CONFIGURATION_PATH, (LPARAM) temp);
-// GetPathAllocService(AVATARS_PATH, (LPARAM) &caca);
-
-
- for (i = 0; i < MAX; i++)
- {
- FoldersGetCustomPathEx((HANDLE) handles[i][0], temp, sizeof(temp), "<not found>", "test");
- Log("Path function Ex (test) [%d] returned : %s", i, temp);
- FoldersGetCustomPathEx((HANDLE) handles[i][0], temp, sizeof(temp), "<not found>", "");
- Log("Path function Ex () [%d] returned : %s", i, temp);
- FoldersGetCustomPathEx((HANDLE) handles[i][0], temp, sizeof(temp), "<not found>", NULL);
- Log("Path function Ex (NULL) [%d] returned : %s", i, temp);
- }
-
- for (i = 0; i < MAX; i++)
- {
- FoldersGetCustomPathExW((HANDLE) handles[i][1], buffer, MAX_PATH, L"<not found>", L"test");
- Log("Unicode path function Ex (test) [%d] returned : %S", i, buffer);
- FoldersGetCustomPathExW((HANDLE) handles[i][1], buffer, MAX_PATH, L"<not found>", L"");
- Log("Unicode path function Ex () [%d] returned : %S", i, buffer);
- FoldersGetCustomPathExW((HANDLE) handles[i][1], buffer, MAX_PATH, L"<not found>", NULL);
- Log("Unicode path function Ex (NULL) [%d] returned : %S", i, buffer);
- }
-
- return 0;
-}
-
-HANDLE hTestPlugin;
-#endif
+ {0x2f129563, 0x2c7d, 0x4a9a, {0xb9, 0x48, 0x97, 0xdf, 0xcc, 0x0a, 0xfd, 0xd7}}
+ //{2f129563-2c7d-4a9a-b948-97dfcc0afdd7}
+};
extern "C" __declspec(dllexport) PLUGININFOEX *MirandaPluginInfoEx(DWORD mirandaVersion)
{
@@ -166,57 +56,20 @@ extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = {MIID_FOLDERS extern "C" int __declspec(dllexport) Load(void)
{
-#if _MSC_VER >= 1300
- Log("%s", "Entering function " __FUNCTION__);
-#endif
-
mir_getLP(&pluginInfo);
- Log("%s", "Creating service functions ...");
InitServices();
InitEvents();
-
-#ifdef _DEBUG
- hTestPlugin = CreateServiceFunction(MS_FOLDERS_TEST_PLUGIN, TestPlugin);
- CLISTMENUITEM mi = {0};
-
- mi.cbSize=sizeof(mi);
- mi.position=300050000;
- mi.flags=0;
- mi.hIcon=0;
- mi.pszName=Translate("Test folders");
- mi.pszService=MS_FOLDERS_TEST_PLUGIN;
- Menu_AddMainMenuItem(&mi);
-#endif
-#if _MSC_VER >= 1300
- Log("%s", "Hooking events ...");
-#endif
HookEvents();
-#if _MSC_VER >= 1300
- Log("%s", "Leaving function " __FUNCTION__);
-#endif
return 0;
}
extern "C" int __declspec(dllexport) Unload()
{
-#if _MSC_VER >= 1300
- Log("%s", "Entering function " __FUNCTION__);
- Log("%s", "Unhooking events ...");
-
- Log("%s", "Destroying service functions ...");
-#endif
// DestroyServiceFunction(MS_HISTORY_SHOWCONTACTHISTORY);
DestroyServices();
DestroyEvents();
UnhookEvents();
-#ifdef _DEBUG
- DestroyServiceFunction(hTestPlugin);
-#endif
-
-#if _MSC_VER >= 1300
- Log("%s", "Leaving function " __FUNCTION__);
-#endif
return 0;
}
@@ -224,8 +77,7 @@ bool WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) {
hInstance = hinstDLL;
if (fdwReason == DLL_PROCESS_ATTACH)
- {
- DisableThreadLibraryCalls(hinstDLL);
- }
+ DisableThreadLibraryCalls(hinstDLL);
+
return TRUE;
-}
\ No newline at end of file +}
diff --git a/plugins/Folders/src/foldersList.cpp b/plugins/Folders/src/foldersList.cpp index b13620fe71..b887264541 100644 --- a/plugins/Folders/src/foldersList.cpp +++ b/plugins/Folders/src/foldersList.cpp @@ -36,11 +36,8 @@ CFoldersList::~CFoldersList() void CFoldersList::Clear()
{
- int i;
- for (i = 0; i < count; i++)
- {
- delete (list[i]);
- }
+ for (int i = 0; i < count; i++)
+ delete (list[i]);
count = 0;
}
@@ -57,145 +54,79 @@ int CFoldersList::Capacity() void CFoldersList::Save()
{
- int i;
- for (i = 0; i < count; i++)
- {
- list[i]->Save();
- }
+ for (int i = 0; i < count; i++)
+ list[i]->Save();
}
PFolderItem CFoldersList::Get(int index)
{
index--;
if ((index < 0) || (index >= count))
- {
- return NULL;
- }
+ return NULL;
+
return list[index];
}
PFolderItem CFoldersList::Get(const char *section, const char *name)
{
- int i;
- for (i = 0; i < count; i++)
- {
- if (list[i]->IsEqual(section, name))
- {
- return list[i];
- }
- }
- return NULL;
-}
+ for (int i = 0; i < count; i++)
+ if (list[i]->IsEqual(section, name))
+ return list[i];
-PFolderItem CFoldersList::Get(const WCHAR *section, const WCHAR *name)
-{
- const int MAX_SIZE = 2048;
- char aSection[MAX_SIZE];
- char aName[MAX_SIZE];
- UINT cp = static_cast<UINT>(CallService(MS_LANGPACK_GETCODEPAGE, 0, 0));
-
- WideCharToMultiByte(cp, 0, section, -1, aSection, MAX_SIZE, NULL, NULL);
- WideCharToMultiByte(cp, 0, name, -1, aName, MAX_SIZE, NULL, NULL);
-
- return Get(aSection, aName);
+ return NULL;
}
PFolderItem CFoldersList::GetTranslated(const char *trSection, const char *trName)
{
- int i;
- for (i = 0; i < count; i++)
- {
+ for (int i = 0; i < count; i++)
if (list[i]->IsEqualTranslated(trSection, trName))
- {
return list[i];
- }
- }
return NULL;
}
-PFolderItem CFoldersList::GetTranslated(WCHAR *trSection, const WCHAR *trName)
-{
- const int MAX_SIZE = 2048;
- char aSection[MAX_SIZE];
- char aName[MAX_SIZE];
- UINT cp = static_cast<UINT>(CallService(MS_LANGPACK_GETCODEPAGE, 0, 0));
-
- WideCharToMultiByte(cp, 0, trSection, -1, aSection, MAX_SIZE, NULL, NULL);
- WideCharToMultiByte(cp, 0, trName, -1, aName, MAX_SIZE, NULL, NULL);
-
- return GetTranslated(aSection, aName);
-}
-
-
-int CFoldersList::Expand(int index, char *szResult, int size)
+int CFoldersList::Expand(int index, TCHAR *szResult, int size)
{
PFolderItem tmp = Get(index);
- int res = 1;
- if (tmp)
- {
- tmp->Expand(szResult, size);
- res = 0;
- }
- else{
- memset(szResult, 0, size);
- }
- return res;
+ if (tmp) {
+ tmp->Expand(szResult, size);
+ return 0;
+ }
+
+ memset(szResult, 0, size);
+ return 1;
}
int CFoldersList::Add(CFolderItem *item)
{
EnsureCapacity();
int pos = Contains(item);
- if (!pos)
- {
- list[count++] = item;
- return count;
- }
- else{
- delete item;
- return pos;
- }
+ if (!pos) {
+ list[count++] = item;
+ return count;
+ }
+
+ delete item;
return 0;
}
-int CFoldersList::Add(FOLDERSDATA data)
+int CFoldersList::Add(FOLDERSDATA* data)
{
CFolderItem *item;
- if (data.flags & FF_UNICODE)
- {
- item = new CFolderItem(data.szSection, data.szName, (char *) data.szFormatW, data.flags);
- }
- else{
- item = new CFolderItem(data.szSection, data.szName, data.szFormat, data.flags);
- }
+ if (data->flags & FF_UNICODE)
+ item = new CFolderItem(data->szSection, data->szName, data->szFormatW, data->flags);
+ else
+ item = new CFolderItem(data->szSection, data->szName, _A2T(data->szFormat), data->flags);
+
return Add(item);
}
void CFoldersList::Remove(CFolderItem *item)
{
-// Remove(item->GetUniqueID());
}
void CFoldersList::Remove(int uniqueID)
{
-/* int i, j;
- CFolderItem *tmp;
- for (i = 0; i < count; i++)
- {
- if (list[i]->GetUniqueID() == uniqueID)
- {
- tmp = list[i];
- for (j = i; j < count - 1; j++)
- {
- list[j] = list[j + 1];
- }
- count--;
- delete tmp;
- return;
- }
- }
-*/
}
int CFoldersList::Contains(CFolderItem *item)
@@ -205,23 +136,17 @@ int CFoldersList::Contains(CFolderItem *item) int CFoldersList::Contains(const char *section, const char *name)
{
- int i;
- for (i = 0; i < count; i++)
- {
- if (list[i]->IsEqual(section, name))
- {
- return i + 1;
- }
- }
+ for (int i = 0; i < count; i++)
+ if (list[i]->IsEqual(section, name))
+ return i + 1;
+
return 0;
}
void CFoldersList::EnsureCapacity()
{
if (count >= capacity)
- {
- Enlarge(capacity / 2);
- }
+ Enlarge(capacity / 2);
}
void CFoldersList::Enlarge(int increaseAmount)
@@ -229,4 +154,4 @@ void CFoldersList::Enlarge(int increaseAmount) int newSize = capacity + increaseAmount;
list = (PFolderItem *) realloc(list, newSize * sizeof(PFolderItem));
capacity = newSize;
-}
\ No newline at end of file +}
diff --git a/plugins/Folders/src/foldersList.h b/plugins/Folders/src/foldersList.h index 854249b3a3..93ea38cc57 100644 --- a/plugins/Folders/src/foldersList.h +++ b/plugins/Folders/src/foldersList.h @@ -47,7 +47,7 @@ class CFoldersList{ void Clear();
int Add(CFolderItem *item);
- int Add(FOLDERSDATA data);
+ int Add(FOLDERSDATA* data);
void Remove(CFolderItem *item);
void Remove(int uniqueID);
int Contains(CFolderItem *item);
@@ -58,10 +58,8 @@ class CFoldersList{ PFolderItem Get(int index);
PFolderItem Get(const char *section, const char *name);
- PFolderItem Get(const WCHAR *section, const WCHAR *name);
PFolderItem GetTranslated(const char *trSection, const char *trName);
- PFolderItem GetTranslated(WCHAR *trSection, const WCHAR *trName);
- int Expand(int index, char *szResult, int size);
+ int Expand(int index, TCHAR *szResult, int size);
void Save();
};
diff --git a/plugins/Folders/src/services.cpp b/plugins/Folders/src/services.cpp index f811bf2246..d62272301b 100644 --- a/plugins/Folders/src/services.cpp +++ b/plugins/Folders/src/services.cpp @@ -22,229 +22,107 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define DEFAULT_SECTION "Unknown"
-char szCurrentProfilePath[MAX_FOLDERS_PATH] = {0};
-char szCurrentProfile[MAX_FOLDERS_PATH] = {0};
-char szMirandaPath[MAX_FOLDERS_PATH] = {0};
-char szUserDataPath[MAX_FOLDERS_PATH] = {0};
-
-wchar_t szCurrentProfilePathW[MAX_FOLDERS_PATH] = {0};
-wchar_t szCurrentProfileW[MAX_FOLDERS_PATH] = {0};
-wchar_t szMirandaPathW[MAX_FOLDERS_PATH] = {0};
-wchar_t szUserDataPathW[MAX_FOLDERS_PATH] = {0};
+TCHAR szCurrentProfilePath[MAX_FOLDERS_PATH];
+TCHAR szCurrentProfile[MAX_FOLDERS_PATH];
+TCHAR szMirandaPath[MAX_FOLDERS_PATH];
+TCHAR szUserDataPath[MAX_FOLDERS_PATH];
HANDLE hsFoldersGetPath;
HANDLE hsFoldersGetSize;
HANDLE hsFoldersGetPathAlloc;
HANDLE hsFoldersRegisterPath;
-int InitServices()
-{
- ServiceExists(MS_DB_GETPROFILEPATH_BASIC) ? CallService(MS_DB_GETPROFILEPATH_BASIC, sizeof(szCurrentProfilePath), (LPARAM) szCurrentProfilePath) : CallService(MS_DB_GETPROFILEPATH, sizeof(szCurrentProfilePath), (LPARAM) szCurrentProfilePath);
- CallService(MS_DB_GETPROFILENAME, sizeof(szCurrentProfile), (LPARAM) szCurrentProfile);
- char *pos = strrchr(szCurrentProfile, '.');
- szCurrentProfile[pos - szCurrentProfile] = '\0'; //remove the extension (.dat)
- GetModuleFileNameA(GetModuleHandleA(NULL), szMirandaPath, sizeof(szMirandaPath));
- pos = strrchr(szMirandaPath, '\\');
- szMirandaPath[pos - szMirandaPath] = '\0'; //remove '\miranda32.exe'
-
- char *szTemp = Utils_ReplaceVars("%miranda_userdata%");
- mir_snprintf(szUserDataPath, MAX_FOLDERS_PATH, szTemp);
- mir_free(szTemp);
-
- MultiByteToWideChar(CP_ACP, 0, szCurrentProfilePath, -1, szCurrentProfilePathW, MAX_FOLDERS_PATH);
- MultiByteToWideChar(CP_ACP, 0, szCurrentProfile, -1, szCurrentProfileW, MAX_FOLDERS_PATH);
- MultiByteToWideChar(CP_ACP, 0, szMirandaPath, -1, szMirandaPathW, MAX_FOLDERS_PATH);
- MultiByteToWideChar(CP_ACP, 0, szUserDataPath, -1, szUserDataPathW, MAX_FOLDERS_PATH);
-
- hsFoldersGetPath = CreateServiceFunction(MS_FOLDERS_GET_PATH, GetPathService);
-// CreateServiceFunction(MS_FOLDERS_GET_PATH_APPEND, GetPathAppendService);
- hsFoldersGetSize = CreateServiceFunction(MS_FOLDERS_GET_SIZE, GetPathSizeService);
- hsFoldersGetPathAlloc = CreateServiceFunction(MS_FOLDERS_GET_PATH_ALLOC, GetPathAllocService);
-// CreateServiceFunction(MS_FOLDERS_GET_PATH_ALLOC_APPEND, GetPathAllocAppendService);
- hsFoldersRegisterPath = CreateServiceFunction(MS_FOLDERS_REGISTER_PATH, RegisterPathService);
-
- return 0;
-}
-
-int DestroyServices()
-{
- DestroyServiceFunction(hsFoldersGetPath);
-// DestroyServiceFunction(MS_FOLDERS_GET_PATH_APPEND);
- DestroyServiceFunction(hsFoldersGetSize);
- DestroyServiceFunction(hsFoldersGetPathAlloc);
-// DestroyServiceFunction(MS_FOLDERS_GET_PATH_ALLOC_APPEND);
- DestroyServiceFunction(hsFoldersRegisterPath);
- return 0;
-}
-
-INT_PTR ExpandPath(char *szResult, char *format, int size)
+INT_PTR ExpandPath(TCHAR *szResult, TCHAR *format, int size)
{
szResult[0] = '\0';
- char *input = NULL;
-
- if (ServiceExists(MS_VARS_FORMATSTRING))
- {
- TCHAR* tmp_format = mir_a2t(format);
- TCHAR *vars_result_tmp = variables_parse(tmp_format, NULL, NULL);
- mir_free(tmp_format);
- char *vars_result = mir_t2a(vars_result_tmp);
-
- if (vars_result != NULL)
- {
- input = mir_strdup(vars_result);
- variables_free(vars_result_tmp);
- }
- mir_free(vars_result);
- }
+ TCHAR *input = NULL;
+ if ( ServiceExists(MS_VARS_FORMATSTRING))
+ input = variables_parse(format, NULL, NULL);
if (input == NULL)
- {
- input = mir_strdup(format);
- }
-
- char *core_result = Utils_ReplaceVars(input);
- strncpy(szResult, core_result, size);
-
- mir_free(core_result);
-
- StrReplace(szResult, PROFILE_PATH, szCurrentProfilePath);
- StrReplace(szResult, CURRENT_PROFILE, szCurrentProfile);
- StrReplace(szResult, MIRANDA_PATH, szMirandaPath);
- StrReplace(szResult, MIRANDA_USERDATA, szUserDataPath);
+ input = mir_tstrdup(format);
- StrTrim(szResult, "\t \\");
-
- mir_free(input);
-
- return strlen(szResult);
-}
-
-INT_PTR ExpandPathW(wchar_t *szResult, wchar_t *format, int size)
-{
- szResult[0] = '\0';
- wchar_t *input = NULL;
-
- if (ServiceExists(MS_VARS_FORMATSTRING))
- {
- TCHAR* tmp_format = mir_u2t(format);
- TCHAR *vars_result_tmp = variables_parse(tmp_format, NULL, NULL);
- mir_free(tmp_format);
- wchar_t *vars_result = mir_t2u(vars_result_tmp);
+ TCHAR *core_result = Utils_ReplaceVarsT(input);
+ _tcsncpy(szResult, core_result, size);
- if (vars_result != NULL)
- {
- input = mir_wstrdup(vars_result);
-
- variables_free(vars_result_tmp);
- }
- mir_free(vars_result);
- }
-
- if (input == NULL)
- {
- input = mir_wstrdup(format);
- }
-
- wchar_t *core_result = Utils_ReplaceVarsW(input);
- if (core_result)
- {
- wcsncpy(szResult, core_result, size);
- }
- else {
- wcsncpy(szResult, input, size);
- }
-
mir_free(core_result);
- StrReplace(szResult, PROFILE_PATHW, szCurrentProfilePathW);
- StrReplace(szResult, CURRENT_PROFILEW, szCurrentProfileW);
- StrReplace(szResult, MIRANDA_PATHW, szMirandaPathW);
- StrReplace(szResult, MIRANDA_USERDATAW, szUserDataPathW);
+ StrReplace(szResult, PROFILE_PATHT, szCurrentProfilePath);
+ StrReplace(szResult, CURRENT_PROFILET, szCurrentProfile);
+ StrReplace(szResult, MIRANDA_PATHT, szMirandaPath);
+ StrReplace(szResult, MIRANDA_USERDATAT, szUserDataPath);
- StrTrim(szResult, L"\t \\");
+ StrTrim(szResult, _T("\t \\"));
mir_free(input);
- return wcslen(szResult);
-}
-
-INT_PTR GetPath(int hRegisteredFolder, char *szResult, int size)
-{
- return lstRegisteredFolders.Expand(hRegisteredFolder, szResult, size);
- //return 0;
+ return _tcslen(szResult);
}
INT_PTR RegisterPathService(WPARAM wParam, LPARAM lParam)
{
- FOLDERSDATA tmp = *(FOLDERSDATA *) lParam;
- int res = 0;
- if (tmp.cbSize == sizeof(FOLDERSDATA))
- {
- res = lstRegisteredFolders.Add(tmp); //returns 1..n or 0 on error
- }
- return res;
+ FOLDERSDATA *tmp = (FOLDERSDATA *) lParam;
+ if (tmp == NULL || tmp->cbSize != sizeof(FOLDERSDATA))
+ return NULL;
+
+ return lstRegisteredFolders.Add(tmp); //returns 1..n or 0 on error
}
INT_PTR GetPathSizeService(WPARAM wParam, LPARAM lParam)
{
- char tmp[MAX_FOLDER_SIZE * 4]; //dumb
- int res = lstRegisteredFolders.Expand(wParam, tmp, sizeof(tmp));
- size_t len = 0;
- if ((lstRegisteredFolders.Get(wParam)) && (lstRegisteredFolders.Get(wParam)->IsUnicode()))
- {
- len = wcslen((wchar_t *)tmp);
- }
- else{
- len = strlen(tmp);
- }
+ TCHAR tmp[MAX_FOLDER_SIZE];
+ int res = lstRegisteredFolders.Expand(wParam, tmp, SIZEOF(tmp));
+ size_t len = _tcslen(tmp);
+
if (lParam != NULL)
- {
- *((size_t *) lParam) = len;
- }
+ *((size_t *) lParam) = len;
+
return len;
}
INT_PTR GetPathService(WPARAM wParam, LPARAM lParam)
{
- FOLDERSGETDATA data = *(FOLDERSGETDATA *) lParam;
- size_t res = 1;
- if (data.cbSize == sizeof(FOLDERSGETDATA))
- {
- res = GetPath(wParam, data.szPath, data.nMaxPathSize); //dumb ...
- }
- return res;
-}
+ FOLDERSGETDATA* data = (FOLDERSGETDATA *) lParam;
+ if (data->cbSize != sizeof(FOLDERSGETDATA))
+ return 1;
-INT_PTR GetPathAllocService(WPARAM wParam, LPARAM lParam)
-{
- int size;
- int res = 1;
- FOLDERSGETALLOCDATA data = *(FOLDERSGETALLOCDATA *) lParam;
- if (data.cbSize == sizeof(FOLDERSGETALLOCDATA))
- {
- size = GetPathSizeService(wParam, (LPARAM) &size);
- char **buffer = data.szPath;
- *buffer = (char *) mir_alloc(size + 1);
- res = GetPath(wParam, *buffer, size);
- }
- return res;
+ if (data->flags & FF_UNICODE)
+ return lstRegisteredFolders.Expand(wParam, data->szPathT, data->nMaxPathSize);
+
+ TCHAR buf[MAX_FOLDER_SIZE];
+ if ( lstRegisteredFolders.Expand(wParam, buf, MAX_FOLDER_SIZE))
+ return 1;
+
+ strncpy(data->szPath, _T2A(buf), data->nMaxPathSize);
+ return 0;
}
-/*
-int GetPathAppendService(WPARAM wParam, LPARAM lParam)
+
+/////////////////////////////////////////////////////////////////////////////////////////
+
+int InitServices()
{
- FOLDERSAPPENDDATA data = *(FOLDERSAPPENDDATA *) wParam;
- int res = GetPathService(data.hRegisteredPath, lParam);
- strcat((char *) lParam, data.szAppendData);
- return res;
+ CallService(MS_DB_GETPROFILEPATHT, SIZEOF(szCurrentProfilePath), (LPARAM)szCurrentProfilePath);
+ CallService(MS_DB_GETPROFILENAMET, SIZEOF(szCurrentProfile), (LPARAM)szCurrentProfile);
+ TCHAR *pos = _tcsrchr(szCurrentProfile, '.'); if (pos) *pos = 0;
+
+ GetModuleFileName( GetModuleHandle(NULL), szMirandaPath, SIZEOF(szMirandaPath));
+ pos = _tcsrchr(szMirandaPath, '\\'); if (pos) *pos = 0;
+
+ TCHAR *szTemp = Utils_ReplaceVarsT( _T("%miranda_userdata%"));
+ mir_sntprintf(szUserDataPath, MAX_FOLDERS_PATH, szTemp);
+ mir_free(szTemp);
+
+ hsFoldersGetPath = CreateServiceFunction(MS_FOLDERS_GET_PATH, GetPathService);
+ hsFoldersGetSize = CreateServiceFunction(MS_FOLDERS_GET_SIZE, GetPathSizeService);
+ hsFoldersRegisterPath = CreateServiceFunction(MS_FOLDERS_REGISTER_PATH, RegisterPathService);
+ return 0;
}
-*/
-/*
-int GetPathAllocAppendService(WPARAM wParam, LPARAM lParam)
+
+int DestroyServices()
{
- FOLDERSAPPENDDATA data = *(FOLDERSAPPENDDATA *) wParam;
- int res = GetPathAllocService(data.hRegisteredPath, lParam);
- strcat(*(char **) lParam, data.szAppendData);
- return res;
+ DestroyServiceFunction(hsFoldersGetPath);
+ DestroyServiceFunction(hsFoldersGetSize);
+ DestroyServiceFunction(hsFoldersRegisterPath);
+ return 0;
}
-*/
\ No newline at end of file diff --git a/plugins/Folders/src/services.h b/plugins/Folders/src/services.h index 3a2ee1aa9f..2a96493193 100644 --- a/plugins/Folders/src/services.h +++ b/plugins/Folders/src/services.h @@ -26,25 +26,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #define MAX_FOLDERS_PATH 512
-extern char szCurrentProfilePath[MAX_FOLDERS_PATH];
-extern char szCurrentProfile[MAX_FOLDERS_PATH];
-extern char szMirandaPath[MAX_FOLDERS_PATH];
-
-extern wchar_t szCurrentProfilePathW[MAX_FOLDERS_PATH];
-extern wchar_t szCurrentProfileW[MAX_FOLDERS_PATH];
-extern wchar_t szMirandaPathW[MAX_FOLDERS_PATH];
+extern TCHAR szCurrentProfilePath[MAX_FOLDERS_PATH];
+extern TCHAR szCurrentProfile[MAX_FOLDERS_PATH];
+extern TCHAR szMirandaPath[MAX_FOLDERS_PATH];
int InitServices();
int DestroyServices();
-INT_PTR ExpandPath(char *szResult, char *format, int size);
-INT_PTR ExpandPathW(wchar_t *szResult, wchar_t *format, int size);
-INT_PTR GetPath(int hRegisteredFolder, char *szResult, int size);
-
-INT_PTR RegisterPathService(WPARAM wParam, LPARAM lParam);
-INT_PTR GetPathSizeService(WPARAM wParam, LPARAM lParam);
-INT_PTR GetPathService(WPARAM wParam, LPARAM lParam);
-INT_PTR GetPathAllocService(WPARAM wParam, LPARAM lParam);
-//int GetPathAppendService(WPARAM wParam, LPARAM lParam);
-//int GetPathAllocAppendService(WPARAM wParam, LPARAM lParam);
+INT_PTR ExpandPath(TCHAR *szResult, TCHAR *format, int size);
+INT_PTR GetPath(int hRegisteredFolder, TCHAR *szResult, int size);
#endif //M_FOLDERS_PROVIDED_SERVICES_H
\ No newline at end of file diff --git a/plugins/Folders/src/utils.cpp b/plugins/Folders/src/utils.cpp index 64623b63f1..df4131ff84 100644 --- a/plugins/Folders/src/utils.cpp +++ b/plugins/Folders/src/utils.cpp @@ -20,50 +20,19 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include "utils.h"
-int Log(char *format, ...)
-{
-#ifdef _DEBUG
- char str[4096];
- va_list vararg;
- int tBytes;
- FILE *fout = fopen("folders.log", "at");
-
- va_start(vararg, format);
-
- tBytes = _vsnprintf(str, sizeof(str), format, vararg);
- if (tBytes > 0)
- {
- str[tBytes] = 0;
- }
-
- va_end(vararg);
- if (str[strlen(str) - 1] != '\n')
- {
- strcat(str, "\n");
- }
- fputs(str, fout);
- fclose(fout);
-#endif
- return 0;
-}
-
char *StrCopy(char *source, size_t index, const char *what, size_t count)
{
- size_t i;
- for (i = 0; i < count; i++)
- {
- source[index + i] = what[i];
- }
+ for (size_t i = 0; i < count; i++)
+ source[index + i] = what[i];
+
return source;
}
wchar_t *StrCopy(wchar_t *source, size_t index, const wchar_t *what, size_t count)
{
- size_t i;
- for (i = 0; i < count; i++)
- {
- source[index + i] = what[i];
- }
+ for (size_t i = 0; i < count; i++)
+ source[index + i] = what[i];
+
return source;
}
@@ -73,38 +42,32 @@ char *StrDelete(char *source, size_t index, size_t count) size_t i;
count = (count + index > len) ? len - index : count;
for (i = index; i + count <= len; i++)
- {
- source[i] = source[i + count];
- }
+ source[i] = source[i + count];
+
return source;
}
wchar_t *StrDelete(wchar_t *source, size_t index, size_t count)
{
size_t len = wcslen(source);
- size_t i;
count = (count + index > len) ? len - index : count;
- for (i = index; i + count <= len; i++)
- {
- source[i] = source[i + count];
- }
+ for (size_t i = index; i + count <= len; i++)
+ source[i] = source[i + count];
+
return source;
}
-
char *StrInsert(char *source, size_t index, const char *what)
{
size_t whatLen = strlen(what);
size_t sourceLen = strlen(source);
size_t i;
for (i = sourceLen; i >= index; i--)
- {
- source[i + whatLen] = source[i];
- }
+ source[i + whatLen] = source[i];
+
for (i = 0; i < whatLen; i++)
- {
- source[index + i] = what[i];
- }
+ source[index + i] = what[i];
+
return source;
}
@@ -114,68 +77,51 @@ wchar_t *StrInsert(wchar_t *source, size_t index, const wchar_t *what) size_t sourceLen = wcslen(source);
size_t i;
for (i = sourceLen; i >= index; i--)
- {
- source[i + whatLen] = source[i];
- }
+ source[i + whatLen] = source[i];
+
for (i = 0; i < whatLen; i++)
- {
- source[index + i] = what[i];
- }
+ source[index + i] = what[i];
+
return source;
}
-
char *StrReplace(char *source, const char *what, const char *withWhat)
{
- char *pos;
size_t whatLen = strlen(what);
size_t withWhatLen = strlen(withWhat);
- size_t minLen;
- size_t index;
- while ((pos = strstr(source, what)))
- {
- minLen = min(whatLen, withWhatLen);
- StrCopy(source, pos - source, withWhat, minLen);
- index = pos - source + minLen;
- if (whatLen > withWhatLen)
- {
- StrDelete(source, index, whatLen - withWhatLen);
- }
- else{
- if (whatLen < withWhatLen)
- {
- StrInsert(source, index, withWhat + minLen);
- }
- }
- }
+ char *pos;
+ while ((pos = strstr(source, what))) {
+ size_t minLen = min(whatLen, withWhatLen);
+ StrCopy(source, pos - source, withWhat, minLen);
+ size_t index = pos - source + minLen;
+ if (whatLen > withWhatLen)
+ StrDelete(source, index, whatLen - withWhatLen);
+ else {
+ if (whatLen < withWhatLen)
+ StrInsert(source, index, withWhat + minLen);
+ }
+ }
return source;
}
wchar_t *StrReplace(wchar_t *source, const wchar_t *what, const wchar_t *withWhat)
{
- wchar_t *pos;
size_t whatLen = wcslen(what);
size_t withWhatLen = wcslen(withWhat);
- size_t minLen;
- size_t index;
-
- while ((pos = wcsstr(source, what)))
- {
- minLen = min(whatLen, withWhatLen);
- StrCopy(source, pos - source, withWhat, minLen);
- index = pos - source + minLen;
- if (whatLen > withWhatLen)
- {
- StrDelete(source, index, whatLen - withWhatLen);
- }
- else{
- if (whatLen < withWhatLen)
- {
- StrInsert(source, index, withWhat + minLen);
- }
- }
- }
+
+ wchar_t *pos;
+ while ((pos = wcsstr(source, what))) {
+ size_t minLen = min(whatLen, withWhatLen);
+ StrCopy(source, pos - source, withWhat, minLen);
+ size_t index = pos - source + minLen;
+ if (whatLen > withWhatLen)
+ StrDelete(source, index, whatLen - withWhatLen);
+ else {
+ if (whatLen < withWhatLen)
+ StrInsert(source, index, withWhat + minLen);
+ }
+ }
return source;
}
@@ -183,18 +129,15 @@ char *StrTrim(char *szText, const char *szTrimChars) {
size_t i = strlen(szText) - 1;
while ((i >= 0) && (strchr(szTrimChars, szText[i])))
- {
- szText[i--] = '\0';
- }
+ szText[i--] = '\0';
+
i = 0;
while ((i < strlen(szText)) && (strchr(szTrimChars, szText[i])))
- {
- i++;
- }
+ i++;
+
if (i)
- {
- StrDelete(szText, 0, i);
- }
+ StrDelete(szText, 0, i);
+
return szText;
}
@@ -202,156 +145,56 @@ wchar_t *StrTrim(wchar_t *szText, const wchar_t *szTrimChars) {
size_t i = wcslen(szText) - 1;
while ((i >= 0) && (wcschr(szTrimChars, szText[i])))
- {
- szText[i--] = '\0';
- }
+ szText[i--] = '\0';
+
i = 0;
while ((i < wcslen(szText)) && (wcschr(szTrimChars, szText[i])))
- {
- i++;
- }
- if (i)
- {
- StrDelete(szText, 0, i);
- }
- return szText;
-}
-
-void CreateDirectories(char *path)
-{
- char *pos = path;
- char tmp;
- while (pos = strchr(pos, '\\'))
- {
- tmp = pos[0];
- pos[0] = '\0';
- CreateDirectoryA(path, NULL);
- pos[0] = tmp;
- pos++;
- }
- CreateDirectoryA(path, NULL);
- GetLastError();
-}
-
-void CreateDirectories(wchar_t *path)
-{
- wchar_t *pos = path;
- wchar_t tmp;
- while (pos = wcschr(pos, '\\'))
- {
- tmp = pos[0];
- pos[0] = '\0';
- CreateDirectoryW(path, NULL);
- pos[0] = tmp;
- pos++;
- }
- CreateDirectoryW(path, NULL);
- GetLastError();
-}
+ i++;
-void RemoveDirectories(char *path)
-{
- char *pos;
- char *buffer = _strdup(path);
- if (!(GetFileAttributesA(buffer) & FILE_ATTRIBUTE_REPARSE_POINT)) { RemoveDirectoryA(buffer); }
- while (pos = strrchr(buffer, '\\'))
- {
- pos[0] = '\0';
- if (!(GetFileAttributesA(buffer) & FILE_ATTRIBUTE_REPARSE_POINT)) { RemoveDirectoryA(buffer); }
- }
- free(buffer);
-}
-
-void RemoveDirectories(wchar_t *path)
-{
- wchar_t *pos;
- wchar_t *buffer = _wcsdup(path);
- if (!(GetFileAttributesW(buffer) & FILE_ATTRIBUTE_REPARSE_POINT)) { RemoveDirectoryW(buffer); }
- while (pos = wcsrchr(buffer, '\\'))
- {
- pos[0] = '\0';
- if (!(GetFileAttributesW(buffer) & FILE_ATTRIBUTE_REPARSE_POINT)) { RemoveDirectoryW(buffer); }
- }
- free(buffer);
-}
+ if (i)
+ StrDelete(szText, 0, i);
-int DirectoryExists(char *path)
-{
- char buffer[4096];
- GetCurrentDirectoryA(sizeof(buffer), buffer);
- int res = SetCurrentDirectoryA(path);
- SetCurrentDirectoryA(buffer);
- return res;
+ return szText;
}
-int DirectoryExists(wchar_t *path)
+void RemoveDirectories(TCHAR *path)
{
- wchar_t buffer[4096];
- GetCurrentDirectoryW(sizeof(buffer), buffer);
- int res = SetCurrentDirectoryW(path);
- SetCurrentDirectoryW(buffer);
- return res;
+ TCHAR *pos;
+ TCHAR *buffer = NEWWSTR_ALLOCA(path);
+ if (!(GetFileAttributes(buffer) & FILE_ATTRIBUTE_REPARSE_POINT))
+ RemoveDirectory(buffer);
+ while (pos = _tcsrchr(buffer, '\\')) {
+ pos[0] = '\0';
+ if (!(GetFileAttributes(buffer) & FILE_ATTRIBUTE_REPARSE_POINT))
+ RemoveDirectory(buffer);
+ }
}
-
-int GetStringFromDatabase(char *szSettingName, const char *szError, char *szResult, size_t size)
+int DirectoryExists(TCHAR *path)
{
- DBVARIANT dbv = {0};
- int res = 1;
- size_t len;
- dbv.type = DBVT_ASCIIZ;
- if (DBGetContactSetting(NULL, ModuleName, szSettingName, &dbv) == 0)
- {
- res = 0;
- size_t tmp = strlen(dbv.pszVal);
- len = (tmp < size - 1) ? tmp : size - 1;
- strncpy(szResult, dbv.pszVal, len);
- szResult[len] = '\0';
- mir_free(dbv.pszVal);
- }
- else{
- res = 1;
- size_t tmp = strlen(szError);
- len = (tmp < size - 1) ? tmp : size - 1;
- strncpy(szResult, szError, len);
- szResult[len] = '\0';
- }
+ TCHAR buffer[4096];
+ GetCurrentDirectory( SIZEOF(buffer), buffer);
+ int res = SetCurrentDirectory(path);
+ SetCurrentDirectory(buffer);
return res;
}
-int GetStringFromDatabase(char *szSettingName, const wchar_t *szError, wchar_t *szResult, size_t size)
+int GetStringFromDatabase(char *szSettingName, const wchar_t *szError, TCHAR *szResult, size_t size)
{
- DBVARIANT dbv = {0};
- int res = 1;
size_t len;
- dbv.type = DBVT_WCHAR;
- if (DBGetContactSettingWString(NULL, ModuleName, szSettingName, &dbv) == 0)
- //if (DBGetContactSetting(NULL, ModuleName, szSettingName, &dbv) == 0)
- {
- res = 0;
- size_t tmp = wcslen(dbv.pwszVal);
- len = (tmp < size - 1) ? tmp : size - 1;
- wcsncpy(szResult, dbv.pwszVal, len);
- szResult[len] = '\0';
- mir_free(dbv.pwszVal);
- }
- else{
- res = 1;
- size_t tmp = wcslen(szError);
- len = (tmp < size - 1) ? tmp : size - 1;
- wcsncpy(szResult, szError, len);
- szResult[len] = '\0';
- }
- return res;
-}
-
-
-int WriteStringToDatabase(char *szSettingName, const char *szValue)
-{
- return DBWriteContactSettingString(NULL, ModuleName, szSettingName, szValue);
+ DBVARIANT dbv;
+ if ( DBGetContactSettingWString(NULL, ModuleName, szSettingName, &dbv) == 0) {
+ size_t tmp = _tcslen(dbv.ptszVal);
+ len = (tmp < size - 1) ? tmp : size - 1;
+ _tcsncpy(szResult, dbv.ptszVal, len);
+ szResult[len] = '\0';
+ db_free(&dbv);
+ return 0;
+ }
+
+ size_t tmp = _tcslen(szError);
+ len = (tmp < size - 1) ? tmp : size - 1;
+ _tcsncpy(szResult, szError, len);
+ szResult[len] = '\0';
+ return 1;
}
-
-int WriteStringToDatabase(char *szSettingName, const wchar_t *szValue)
-{
- return DBWriteContactSettingWString(NULL, ModuleName, szSettingName, szValue);
-}
\ No newline at end of file diff --git a/plugins/Folders/src/utils.h b/plugins/Folders/src/utils.h index 066c822900..987b422e08 100644 --- a/plugins/Folders/src/utils.h +++ b/plugins/Folders/src/utils.h @@ -24,39 +24,15 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #include <stdarg.h>
#include "commonheaders.h"
-int Log(char *format, ...);
-
-char *StrReplace(char *source, const char *what, const char *withWhat);
-char *StrCopy(char *source, size_t index, const char *what, size_t count);
-char *StrDelete(char *source, size_t index, size_t count);
-char *StrInsert(char *source, size_t index, const char *what);
-char *StrTrim(char *szText, const char *szTrimChars);
-
-wchar_t *StrReplace(wchar_t *source, const wchar_t *what, const wchar_t *withWhat);
-wchar_t *StrCopy(wchar_t *source, size_t index, const wchar_t *what, size_t count);
-wchar_t *StrDelete(wchar_t *source, size_t index, size_t count);
-wchar_t *StrInsert(wchar_t *source, size_t index, const wchar_t *what);
-wchar_t *StrTrim(wchar_t *szText, const wchar_t *szTrimChars);
-
-void CreateDirectories(char *szPath);
-void RemoveDirectories(char *szPath);
-int DirectoryExists(char *szPath);
-
-void CreateDirectories(wchar_t *szPath);
-void RemoveDirectories(wchar_t *szPath);
-int DirectoryExists(wchar_t *szPath);
-
-int GetStringFromDatabase(char *szSettingName, const char *szError, char *szResult, size_t size);
-int WriteStringToDatabase(char *szSettingName, const char *szValue);
-
-int GetStringFromDatabase(char *szSettingName, const wchar_t *szError, wchar_t *szResult, size_t size);
-int WriteStringToDatabase(char *szSettingName, const wchar_t *szValue);
-
-__inline static wchar_t *Utils_ReplaceVarsW(wchar_t *szData) {
- REPLACEVARSDATA dat = {0};
- dat.cbSize = sizeof(dat);
- dat.dwFlags = RVF_UNICODE;
- return (wchar_t *) CallService(MS_UTILS_REPLACEVARS, (WPARAM) szData, (LPARAM) &dat);
-}
+TCHAR *StrReplace(TCHAR *source, const TCHAR *what, const TCHAR *withWhat);
+TCHAR *StrCopy(TCHAR *source, size_t index, const TCHAR *what, size_t count);
+TCHAR *StrDelete(TCHAR *source, size_t index, size_t count);
+TCHAR *StrInsert(TCHAR *source, size_t index, const TCHAR *what);
+TCHAR *StrTrim(TCHAR *szText, const TCHAR *szTrimChars);
+
+void RemoveDirectories(TCHAR *szPath);
+int DirectoryExists(TCHAR *szPath);
+
+int GetStringFromDatabase(char *szSettingName, const TCHAR *szError, TCHAR *szResult, size_t size);
#endif
\ No newline at end of file |