From 0cda0baab21d4d4bf40c9459f6f5a7e49aa92492 Mon Sep 17 00:00:00 2001 From: Vadim Dashevskiy Date: Tue, 24 Jul 2012 12:45:18 +0000 Subject: VersionInfo, W7UI, WhoUsesMyFiles, YAPP, ZeroNotification: changed folder structure git-svn-id: http://svn.miranda-ng.org/main/trunk@1161 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/WhoUsesMyFiles/src/list.c | 172 +++++++++ plugins/WhoUsesMyFiles/src/resizer.c | 131 +++++++ plugins/WhoUsesMyFiles/src/resource.h | 46 +++ plugins/WhoUsesMyFiles/src/wumf.c | 330 ++++++++++++++++++ plugins/WhoUsesMyFiles/src/wumf.h | 167 +++++++++ plugins/WhoUsesMyFiles/src/wumfplug.c | 634 ++++++++++++++++++++++++++++++++++ 6 files changed, 1480 insertions(+) create mode 100644 plugins/WhoUsesMyFiles/src/list.c create mode 100644 plugins/WhoUsesMyFiles/src/resizer.c create mode 100644 plugins/WhoUsesMyFiles/src/resource.h create mode 100644 plugins/WhoUsesMyFiles/src/wumf.c create mode 100644 plugins/WhoUsesMyFiles/src/wumf.h create mode 100644 plugins/WhoUsesMyFiles/src/wumfplug.c (limited to 'plugins/WhoUsesMyFiles/src') diff --git a/plugins/WhoUsesMyFiles/src/list.c b/plugins/WhoUsesMyFiles/src/list.c new file mode 100644 index 0000000000..1e52e12e4d --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/list.c @@ -0,0 +1,172 @@ +#include "wumf.h" + +PWumf new_wumf( DWORD dwID, + LPTSTR szUser, + LPTSTR szPath, + LPTSTR szComp, + LPTSTR szUNC, + DWORD dwSess, + DWORD dwPerm, + DWORD dwAttr) +{ + PWumf w; + CHAR szID[10]; + + w = (PWumf)malloc(sizeof(Wumf)); + if(!w)return NULL; + + #define SCPY(X) if(X){w->X = (LPSTR)malloc(1+strlen(X));if(!w->X)return NULL;strcpy(w->X, X);} else { w->X = NULL;} + #define SCPYW(X) if(X){w->X = (LPSTR)malloc(1+lstrlenW(X));if(!w->X)return NULL;wsprintfA(w->X, "%S", X);} else { w->X = NULL;} + + #define SCCPY(X, Y) w->X = (LPSTR)malloc(1+strlen(Y));if(!w->X)return NULL;strcpy(w->X, Y) + + SCPYW(szUser); + SCPYW(szPath); + SCPYW(szComp); + SCPYW(szUNC); + switch(dwPerm) + { + case PERM_FILE_READ: SCCPY(szPerm, "Read");break; + case PERM_FILE_WRITE: SCCPY(szPerm, "Write");break; + case PERM_FILE_CREATE: SCCPY(szPerm, "Create");break; + default: SCCPY(szPerm, "Execute");//w->szPerm = NULL; + }; + wsprintf(szID, "%i", dwID); + SCPY(szID); + + #undef SCPY + w->dwID = dwID; + w->dwSess = dwSess; + w->dwAttr = dwAttr; + w->dwPerm = dwPerm; + w->mark = FALSE; + w->next = NULL; + return w; +} + +BOOL del_wumf(PWumf w) +{ + if(!w) return FALSE; + free(w->szUser); + free(w->szPath); + free(w->szComp); + free(w->szUNC); + free(w->szID); + free(w->szPerm); + free(w); + return TRUE; +} + +BOOL add_cell(PWumf* l, PWumf w) +{ + PWumf p; + if(!w || !l)return FALSE; + if(!(*l)) + { + *l = w; + } + else + { + p = *l; + while(p->next) p = p->next; + p->next = w; + } + w->next = NULL; + return TRUE; +} + +BOOL del_cell(PWumf *l, PWumf w) +{ + PWumf p; + if(!l || !*l || !w)return FALSE; + p = *l; + if(w == *l) + *l = p->next; + else + { + while(p && p->next != w) p = p->next; + if(!p) return FALSE; + p->next = w->next; + } + return del_wumf(w); + +}; + +BOOL cpy_cell(PWumf *l, PWumf w) +{ + PWumf w1; + w1 = new_wumf(w->dwID, w->szUser, w->szPath, w->szComp,w->szUNC, w->dwSess, w->dwPerm, w->dwAttr); + if(!w1) return FALSE; + w1->mark = w->mark; + return add_cell(l, w1); +}; + +PWumf cpy_list(PWumf *l) +{ + PWumf w, p = NULL; + + if(!l || !*l) return NULL; + w = *l; + while(w) + { + if(!cpy_cell(&p, w))return NULL; + w = w->next; + } + return p; +} + +PWumf fnd_cell(PWumf *l, DWORD dwID) +{ + PWumf w; + if(!l || !*l)return NULL; + w = *l; + while(w && w->dwID != dwID) w = w->next; + return w; +} + +BOOL del_all(PWumf *l) +{ + PWumf w, p; + if(!l || !*l) return FALSE; + w = *l; + while(w) + { + p = w->next; + if(!del_cell(l, w)) + { + return FALSE; + } + w = p; + } + *l = NULL; + + return TRUE; +} + +BOOL del_marked(PWumf *l) +{ + PWumf w, p; + if(!l)return FALSE; + w = *l; + while(w) + { + p = w->next; + if(w->mark) + { + if(!del_cell(l, w)) return FALSE; + }; + w = p; + } + return TRUE; +} + +void mark_all(PWumf *l, BOOL mark) +{ + PWumf w; + w = *l; + while(w) + { + w->mark = mark; + w = w->next; + } +} diff --git a/plugins/WhoUsesMyFiles/src/resizer.c b/plugins/WhoUsesMyFiles/src/resizer.c new file mode 100644 index 0000000000..e45d10a453 --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/resizer.c @@ -0,0 +1,131 @@ +#include "wumf.h" +#pragma hdrstop + +typedef struct { + DWORD helpID; + DWORD exStyle; + DWORD style; + short x; + short y; + short cx; + short cy; + WORD id; +} START_OF_DLGITEMTEMPLATEEX; + +typedef struct { + WORD dlgVer; + WORD signature; + DWORD helpID; + DWORD exStyle; + DWORD style; + WORD cDlgItems; + short x; + short y; + short cx; + short cy; +} START_OF_DLGTEMPLATEEX; + +int ResizeDialog(WPARAM wParam,LPARAM lParam) +{ + UTILRESIZEDIALOG *urd=(UTILRESIZEDIALOG*)lParam; + HDWP hDwp; + int i; + DLGITEMTEMPLATE *pItem; + START_OF_DLGITEMTEMPLATEEX *pItemEx; + RECT rc; + PWORD pWord; + DLGTEMPLATE *pTemplate; + START_OF_DLGTEMPLATEEX *pTemplateEx; + UTILRESIZECONTROL urc; + int procResult; + int extendedDlg,itemCount; + + if(urd->cbSize!=sizeof(UTILRESIZEDIALOG)) return 1; + pTemplate=(DLGTEMPLATE*)LockResource(LoadResource(urd->hInstance,FindResource(urd->hInstance,urd->lpTemplate,RT_DIALOG))); + pTemplateEx=(START_OF_DLGTEMPLATEEX*)pTemplate; + extendedDlg=pTemplateEx->signature==0xFFFF; + if(extendedDlg && pTemplateEx->dlgVer!=1) + return 1; + + if(extendedDlg) pWord=(PWORD)(pTemplateEx+1); + else pWord=(PWORD)(pTemplate+1); + if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //menu + if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //class + while(*pWord++); //title + if(extendedDlg) { + if(pTemplateEx->style&DS_SETFONT) { + pWord+=3; //font size,weight,italic + while(*pWord++); //font name + } + } + else { + if(pTemplate->style&DS_SETFONT) { + pWord++; //font size + while(*pWord++); //font name + } + } + + urc.cbSize=sizeof(UTILRESIZECONTROL); + rc.left=0; rc.top=0; + if(extendedDlg) {rc.right=pTemplateEx->cx; rc.bottom=pTemplateEx->cy;} + else {rc.right=pTemplate->cx; rc.bottom=pTemplate->cy;} + MapDialogRect(urd->hwndDlg,&rc); + urc.dlgOriginalSize.cx=rc.right; urc.dlgOriginalSize.cy=rc.bottom; + GetClientRect(urd->hwndDlg,&rc); + urc.dlgNewSize.cx=rc.right; urc.dlgNewSize.cy=rc.bottom; + + if(extendedDlg) itemCount=pTemplateEx->cDlgItems; + else itemCount=pTemplate->cdit; + hDwp=BeginDeferWindowPos(itemCount); + for(i=0;iid; + urc.rcItem.left=pItemEx->x; urc.rcItem.top=pItemEx->y; + urc.rcItem.right=urc.rcItem.left+pItemEx->cx; urc.rcItem.bottom=urc.rcItem.top+pItemEx->cy; + } + else { + pItem=(DLGITEMTEMPLATE*)pWord; + pWord=(PWORD)(pItem+1); + + urc.wId=pItem->id; + urc.rcItem.left=pItem->x; urc.rcItem.top=pItem->y; + urc.rcItem.right=urc.rcItem.left+pItem->cx; urc.rcItem.bottom=urc.rcItem.top+pItem->cy; + } + if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //menu + if(*pWord==0xFFFF) pWord+=2; else while(*pWord++); //class + pWord+=1+(1+*pWord)/2; //creation data + + if(urc.wId==65535) continue; //using this breaks the dwp, so just ignore it + + MapDialogRect(urd->hwndDlg,&urc.rcItem); + procResult=(urd->pfnResizer)(urd->hwndDlg,urd->lParam,&urc); + if(procResult&RD_ANCHORX_RIGHT) { + urc.rcItem.left+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; + urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; + } + else if(procResult&RD_ANCHORX_WIDTH) + urc.rcItem.right+=urc.dlgNewSize.cx-urc.dlgOriginalSize.cx; + else if(procResult&RD_ANCHORX_CENTRE) { + urc.rcItem.left+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; + urc.rcItem.right+=(urc.dlgNewSize.cx-urc.dlgOriginalSize.cx)/2; + } + if(procResult&RD_ANCHORY_BOTTOM) { + urc.rcItem.top+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; + urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; + } + else if(procResult&RD_ANCHORY_HEIGHT) + urc.rcItem.bottom+=urc.dlgNewSize.cy-urc.dlgOriginalSize.cy; + else if(procResult&RD_ANCHORY_CENTRE) { + urc.rcItem.top+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; + urc.rcItem.bottom+=(urc.dlgNewSize.cy-urc.dlgOriginalSize.cy)/2; + } + hDwp=DeferWindowPos(hDwp,GetDlgItem(urd->hwndDlg,extendedDlg?pItemEx->id:pItem->id),0,urc.rcItem.left,urc.rcItem.top,urc.rcItem.right-urc.rcItem.left,urc.rcItem.bottom-urc.rcItem.top,SWP_NOZORDER); + } + EndDeferWindowPos(hDwp); + return 0; +} \ No newline at end of file diff --git a/plugins/WhoUsesMyFiles/src/resource.h b/plugins/WhoUsesMyFiles/src/resource.h new file mode 100644 index 0000000000..6e4cd69615 --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/resource.h @@ -0,0 +1,46 @@ +//{{NO_DEPENDENCIES}} +// Microsoft Developer Studio generated include file. +// Used by resource.rc +// +#define IDD_OPTIONS 101 +#define IDI_POPUP 102 +#define IDI_NOPOPUP 103 +#define IDI_DRIVE 106 +#define IDD_CONNLIST 107 +#define IDC_COLOR_SET 1000 +#define IDC_COLOR_WIN 1001 +#define IDC_COLOR_DEF 1002 +#define IDC_COLOR_BACK 1003 +#define IDC_COLOR_TEXT 1004 +#define IDC_FILE 1006 +#define IDC_SEL_FILE 1007 +#define IDC_DELAY_SEC 1026 +#define IDC_PREVIEW 1033 +#define IDC_DEBUG 1034 +#define IDC_DELAY_SET 1049 +#define IDC_DELAY_INF 1050 +#define IDC_DELAY_DEF 1051 +#define IDC_DELAY_NOTE 1052 +#define IDC_TX_DELAY_SEC 1053 +#define IDC_LOG_INTO_FILE 1054 +#define IDC_LOG_FOLDER 1055 +#define IDC_ALERT_FOLDER 1056 +#define IDC_LOG_UNC 1057 +#define IDC_ALERT_UNC 1058 +#define IDC_LOG_COMP 1059 +#define IDC_ALERT_COMP 1060 +#define IDC_CONNLIST 1061 +#define IDC_CONN 1062 + +// Next default values for new objects +// +#ifdef APSTUDIO_INVOKED +#ifndef APSTUDIO_READONLY_SYMBOLS +#define _APS_NO_MFC 1 +#define _APS_3D_CONTROLS 1 +#define _APS_NEXT_RESOURCE_VALUE 109 +#define _APS_NEXT_COMMAND_VALUE 40081 +#define _APS_NEXT_CONTROL_VALUE 1063 +#define _APS_NEXT_SYMED_VALUE 101 +#endif +#endif diff --git a/plugins/WhoUsesMyFiles/src/wumf.c b/plugins/WhoUsesMyFiles/src/wumf.c new file mode 100644 index 0000000000..03aa576d38 --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/wumf.c @@ -0,0 +1,330 @@ +#define MAX_CHARS 4096 +#define WS_WINDOW_STYLE WS_OVERLAPPED +#define NAME "WUMF" +#define WM_MYCMD 0x0401 + +#include "wumf.h" +static PWumf list = NULL; +static PWumf lst = NULL; + +extern WUMF_OPTIONS WumfOptions; +extern HANDLE hInst; +extern HWND hDlg; +extern char ModuleName[]; + +HANDLE hLog = INVALID_HANDLE_VALUE; +BOOL wumf(); + +static int DlgResizer(HWND hwndDlg,LPARAM lParam,UTILRESIZECONTROL *urc) { + switch(urc->wId) { + case IDC_CONNLIST: + return RD_ANCHORX_WIDTH|RD_ANCHORY_HEIGHT; + case IDOK: + return RD_ANCHORX_RIGHT|RD_ANCHORY_BOTTOM; + } + return RD_ANCHORX_LEFT|RD_ANCHORY_TOP; +} + + + +void AddToList(HWND hList, PWumf w) +{ + LVITEM lvi = { 0 }; + lvi.iItem=ListView_GetItemCount(hList)+1; + lvi.mask= LVIF_PARAM|LVIF_TEXT; + lvi.pszText = w->szID; + lvi.cchTextMax = (int)_tcslen(w->szID); + lvi.lParam = (LPARAM)w; + ListView_InsertItem(hList,&lvi); +} + +void ShowList(PWumf l, HWND hList) +{ + PWumf w; + w = l; + while(w) + { + AddToList(hList,w); + w = w->next; + } +} + +VOID OnGetDispInfo(NMLVDISPINFO *plvdi) +{ + PWumf w; + w = (PWumf)(plvdi->item.lParam); + switch (plvdi->item.iSubItem) + { + case 0: + plvdi->item.pszText = w->szID; + break; + case 1: + plvdi->item.pszText = w->szUser; + break; + case 2: + plvdi->item.pszText = w->szPath; + break; + case 3: + plvdi->item.pszText = w->szPerm; + break; + default: + break; + } +} + + +int CALLBACK ConnDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam) +{ + UTILRESIZEDIALOG urd={0}; + LV_COLUMN lvc = { 0 }; + char col0[] = "ID"; + char col1[] = "User"; + char col2[] = "File"; + char col3[] = "Access"; +// char buff[256]; + HWND hList; + switch( Msg ) + { + case WM_INITDIALOG: + hList = GetDlgItem(hWnd, IDC_CONNLIST); +// ListView_DeleteAllItems(hList); + ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT); + lvc.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH; + lvc.fmt = LVCFMT_LEFT; + lvc.cx = 40; + lvc.pszText = col0; + lvc.cchTextMax = sizeof(col0); + ListView_InsertColumn(hList, 0, &lvc); + lvc.cx = 50; + lvc.pszText = col1; + lvc.cchTextMax = sizeof(col1); + ListView_InsertColumn(hList, 1, &lvc); + lvc.cx = 250; + lvc.pszText = col2; + lvc.cchTextMax = sizeof(col2); + ListView_InsertColumn(hList, 2, &lvc); + lvc.cx = 50; + lvc.pszText = col3; + lvc.cchTextMax = sizeof(col3); + ListView_InsertColumn(hList, 3, &lvc); + KillTimer(NULL, 777); + lst = cpy_list(&list); + if (IsUserAnAdmin()) { + SetTimer(NULL, 777, TIME,(TIMERPROC) TimerProc); + } else { + MessageBox(NULL, "Plugin WhoUsesMyFiles requires admin privileges in order to work.", "Miranda IM", MB_OK); + } + ShowList(lst, hList); + Utils_RestoreWindowPosition(hWnd, NULL, ModuleName,"conn"); + break; + case WM_CLOSE: + PostMessage( hWnd, WM_COMMAND, IDCANCEL, 0l ); + break; + case WM_COMMAND: + switch( LOWORD(wParam) ) + { + case IDOK: + case IDCANCEL: + PostMessage( hWnd, WM_DESTROY, 0, 0l ); + break; + } + break; + case WM_SIZE: + urd.cbSize=sizeof(urd); + urd.hwndDlg=hWnd; + urd.hInstance=hInst; + urd.lpTemplate=MAKEINTRESOURCE(IDD_CONNLIST); + urd.lParam=(LPARAM)NULL; + urd.pfnResizer=DlgResizer; + ResizeDialog(0,(LPARAM)&urd); + Utils_SaveWindowPosition(hWnd, NULL, ModuleName,"conn"); + return TRUE; + case WM_MOVE: + Utils_SaveWindowPosition(hWnd, NULL, ModuleName,"conn"); + break; + case WM_NOTIFY: + switch (((LPNMHDR) lParam)->code) + { + case LVN_GETDISPINFO: + OnGetDispInfo((NMLVDISPINFO *) lParam); + break; + } + break; + case WM_DESTROY: + del_all(&lst); + PostQuitMessage(0); + break; + default: + return FALSE; + } + return TRUE; +} + +void LogWumf(PWumf w) +{ + char str[256]; + LPTSTR lpstr; + char lpDateStr[20]; + char lpTimeStr[20]; + SYSTEMTIME time; + DWORD bytes; + + if(!WumfOptions.LogFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return; + + if(hLog == INVALID_HANDLE_VALUE || hLog == NULL) + { + hLog = CreateFile(WumfOptions.LogFile, + GENERIC_WRITE, + FILE_SHARE_READ, + (LPSECURITY_ATTRIBUTES) NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + (HANDLE) NULL); + if(hLog == INVALID_HANDLE_VALUE) + { + FormatMessage( + FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + GetLastError(), + MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language + (LPTSTR) &lpstr, + 0, + NULL); + wsprintf(str, "Can't open log file %s\nError:%s", WumfOptions.LogFile, lpstr); + LocalFree(lpstr); + MessageBox( NULL, str, "Error opening file", MB_OK | MB_ICONSTOP); + WumfOptions.LogToFile = FALSE; + } + } + GetLocalTime(&time); + GetDateFormat(LOCALE_USER_DEFAULT,DATE_SHORTDATE, &time,NULL, lpDateStr, 20); + GetTimeFormat(LOCALE_USER_DEFAULT,TIME_FORCE24HOURFORMAT|TIME_NOTIMEMARKER, &time,NULL, lpTimeStr, 20); + wsprintf(str ,"%s %s %20s\t%s\r\n\0",lpDateStr, lpTimeStr, w->szUser, w->szPath); + SetFilePointer (hLog, 0, NULL, FILE_END); + WriteFile(hLog, str, (DWORD)_tcslen(str), &bytes, NULL); +} + +/* +BOOL wumf() +{ + FILE_INFO_3 *buf, *cur; + SESSION_INFO_0 *sinfo; + DWORD read, total, resumeh, rc, i, sess = 0L; + wchar_t server[20]; + char user[512], path[512], comp[512]; + char* UNC = NULL; + PWumf w = NULL; + + mbstowcs( server, "\\\\.", 8); + resumeh = 0; + + mark_all(&list, TRUE); + do + { + buf = NULL; + rc = NetFileEnum( (LPWSTR)server, + NULL, + NULL, 3, + (BYTE **) &buf, 2048, &read, &total, &resumeh ); + if ( rc != ERROR_MORE_DATA && rc != ERROR_SUCCESS ) + break; + for ( i = 0, cur = buf; i < read; ++ i, ++ cur) + { + w = fnd_cell(&list, cur->fi3_id); + if(!w) + { + wcstombs(user, (wchar_t *) cur->fi3_username, 512); + wcstombs(path, (wchar_t *) cur->fi3_pathname, 512); + + w = new_wumf(cur->fi3_id, user, path, comp, UNC, sess, cur->fi3_permissions,GetFileAttributes(path)); + w->mark = FALSE; + if(!add_cell(&list, w)){ + msg("Error memory allocation"); + return FALSE; + }; + + if(WumfOptions.PopupsEnabled) ShowWumfPopUp(w); + if(WumfOptions.LogToFile) LogWumf(w); + } + else + w->mark = FALSE; + } + if(buf != NULL) NetApiBufferFree( buf ); + } while(rc == ERROR_MORE_DATA); + return del_marked(&list); +};*/ + +BOOL wumf() +{ + LPSESSION_INFO_1 s_info = NULL; + DWORD ent_read = 0, ent_total = 0, res_handle = 0, i = 0; + NET_API_STATUS res = NERR_Success; + if( (res = NetSessionEnum(NULL, NULL, NULL, 1, (LPBYTE *)&s_info, MAX_PREFERRED_LENGTH, &ent_read, &ent_total, &res_handle)) == NERR_Success || + res == ERROR_MORE_DATA) + { + mark_all(&list, TRUE); + for(i = 0; i < ent_read; i++) + { + process_session(s_info[ i ]); + } + NetApiBufferFree(s_info); + } else { + printError(res); + } + return del_marked(&list); +}; + +void process_session(SESSION_INFO_1 s_info) +{ + LPFILE_INFO_3 f_info = NULL; + DWORD ent_read = 0, ent_total = 0, res_handle = 0, i = 0; + NET_API_STATUS res = NERR_Success; + if( (res = NetFileEnum(NULL, NULL, s_info.sesi1_username, 3, (LPBYTE *)&f_info, MAX_PREFERRED_LENGTH, &ent_read, &ent_total, &res_handle)) == NERR_Success || + res == ERROR_MORE_DATA) + { + for(i = 0; i < ent_read; i++) + { + process_file(s_info, f_info[ i ]); + } + NetApiBufferFree(f_info); + } else { + printError(res); + } +} + +void process_file(SESSION_INFO_1 s_info, FILE_INFO_3 f_info) +{ + PWumf w = fnd_cell(&list, f_info.fi3_id); + if(!w) + { + w = new_wumf(f_info.fi3_id, f_info.fi3_username, f_info.fi3_pathname, s_info.sesi1_cname, NULL, 0, f_info.fi3_permissions, GetFileAttributes(f_info.fi3_pathname)); + w->mark = FALSE; + if(!add_cell(&list, w)){ + msg("Error memory allocation"); + }; + if(WumfOptions.PopupsEnabled) ShowWumfPopUp(w); + if(WumfOptions.LogToFile) LogWumf(w); + } else { + w->mark = FALSE; + } +} + +void printError(DWORD res) +{ + LPVOID lpMsgBuf; + FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER|FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, NULL, res, 0, (LPTSTR) &lpMsgBuf, 0, NULL ); + OutputDebugString(lpMsgBuf); + msg(lpMsgBuf); + LocalFree( lpMsgBuf ); +} + +VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) +{ + if(!wumf()) + KillTimer(NULL, 777); +}; + +void FreeAll() +{ + del_all(&list); +}; diff --git a/plugins/WhoUsesMyFiles/src/wumf.h b/plugins/WhoUsesMyFiles/src/wumf.h new file mode 100644 index 0000000000..5535ae0c5f --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/wumf.h @@ -0,0 +1,167 @@ +#define _CRT_SECURE_NO_WARNINGS + +#include +#include +#include +#include +#include + +#include "newpluginapi.h" +#include "m_system.h" +#include "m_options.h" +#include "m_langpack.h" +#include "m_clui.h" +#include "m_clist.h" +#include "m_database.h" +#include "m_utils.h" +#include "m_skin.h" +#include "m_popup.h" + +#include "m_toptoolbar.h" + +#include "resource.h" + +#define LIFETIME_MAX 60 +#define LIFETIME_MIN 1 +#define MAX_PATHNAME 512 +#define MAX_USERNAME 512 +#define TIME 500 + +#define POPUPS_ENABLED "1033" +#define DELAY_SEC "1026" +#define DELAY_SET "1049" +#define DELAY_INF "1050" +#define DELAY_DEF "1051" +#define COLOR_SET "1000" +#define COLOR_WIN "1001" +#define COLOR_DEF "1002" +#define COLOR_BACK "1003" +#define COLOR_TEXT "1004" +#define OPT_FILE "1006" +#define LOG_INTO_FILE "1054" +#define LOG_FOLDER "1055" +#define ALERT_FOLDER "1056" +#define LOG_UNC "1057" +#define ALERT_UNC "1058" +#define LOG_COMP "1059" +#define ALERT_COMP "1060" + +#define IDM_SETUP 0x0402 +#define IDM_ABOUT 0x0403 +#define IDM_SHOW 0x0405 +#define IDM_EXIT 0x0404 + +typedef struct +{ + BOOL PopupsEnabled; + + BOOL UseWinColor; + BOOL UseDefColor; + BOOL SelectColor; + COLORREF ColorText; + COLORREF ColorBack; + BOOL DelayInf; + BOOL DelayDef; + BOOL DelaySet; + int DelaySec; + + BOOL LogToFile; + BOOL LogFolders; + BOOL AlertFolders; + BOOL LogUNC; + BOOL AlertUNC; + BOOL LogComp; + BOOL AlertComp; + + char LogFile[255]; +} WUMF_OPTIONS; + +typedef struct _WUMF{ + DWORD dwID; + LPSTR szID; + LPSTR szUser; + LPSTR szPath; + LPSTR szComp; + LPSTR szUNC; + LPSTR szPerm; + DWORD dwSess; + DWORD dwLocks; + DWORD dwAttr; + DWORD dwPerm; + BOOL mark; + struct _WUMF* next; +} Wumf, *PWumf; + +PWumf new_wumf( + DWORD dwID, + LPSTR szUser, + LPSTR szPath, + LPSTR szComp, + LPSTR szUNC, + DWORD szSess, + DWORD dwPerm, + DWORD dwAttr); + +BOOL add_cell (PWumf* l, PWumf w); +BOOL del_cell (PWumf* l, PWumf w); +BOOL cpy_cell (PWumf* l, PWumf w); +PWumf fnd_cell (PWumf* l, DWORD dwID); +PWumf cpy_list (PWumf* l); +BOOL del_all (PWumf* l); +void mark_all (PWumf* l, BOOL mark); +BOOL del_marked(PWumf* l); + + + +void FreeAll(); +VOID CALLBACK TimerProc(HWND, UINT, UINT_PTR, DWORD); +int CALLBACK ConnDlgProc(HWND, UINT, WPARAM, LPARAM); +int ResizeDialog(WPARAM wParam,LPARAM lParam); + +void ShowThePopUp(PWumf w, LPSTR, LPSTR); +void ShowWumfPopUp(PWumf w); + +void process_session(SESSION_INFO_1 s_info); +void process_file(SESSION_INFO_1 s_info, FILE_INFO_3 f_info); +void printError(DWORD res); + +#define msg(X) MessageBox(NULL, X, "WUMF", MB_OK|MB_ICONSTOP) +#define MS_WUMF_SWITCHPOPUP "WUMF/SwitchPopup" +#define MS_WUMF_CONNECTIONSSHOW "WUMF/ShowConnections" + +#define malloc(size) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size) +#define free(something) HeapFree(GetProcessHeap(), 0, something) + +#ifndef RD_ANCHORX_CUSTOM +#define RD_ANCHORX_CUSTOM 0 //function did everything required to the x axis, do no more processing +#define RD_ANCHORX_LEFT 0 //move the control to keep it constant distance from the left edge of the dialog +#define RD_ANCHORX_RIGHT 1 //move the control to keep it constant distance from the right edge of the dialog +#define RD_ANCHORX_WIDTH 2 //size the control to keep it constant distance from both edges of the dialog +#define RD_ANCHORX_CENTRE 4 //move the control to keep it constant distance from the centre of the dialog +#define RD_ANCHORY_CUSTOM 0 +#define RD_ANCHORY_TOP 0 +#define RD_ANCHORY_BOTTOM 8 +#define RD_ANCHORY_HEIGHT 16 +#define RD_ANCHORY_CENTRE 32 + +typedef struct { + int cbSize; + UINT wId; //control ID + RECT rcItem; //original control rectangle, relative to dialog + //modify in-place to specify the new position + SIZE dlgOriginalSize; //size of dialog client area in template + SIZE dlgNewSize; //current size of dialog client area +} UTILRESIZECONTROL; + +typedef int (*DIALOGRESIZERPROC)(HWND hwndDlg,LPARAM lParam,UTILRESIZECONTROL *urc); + +typedef struct { + int cbSize; + HWND hwndDlg; + HINSTANCE hInstance; //module containing the dialog template + LPCTSTR lpTemplate; //dialog template + LPARAM lParam; //caller-defined + DIALOGRESIZERPROC pfnResizer; +} UTILRESIZEDIALOG; + +#endif diff --git a/plugins/WhoUsesMyFiles/src/wumfplug.c b/plugins/WhoUsesMyFiles/src/wumfplug.c new file mode 100644 index 0000000000..2493de584b --- /dev/null +++ b/plugins/WhoUsesMyFiles/src/wumfplug.c @@ -0,0 +1,634 @@ +#include "wumf.h" + +HINSTANCE hInst; +WUMF_OPTIONS WumfOptions = { 0 }; +const char ModuleName[] = "WUMF Plugin"; +HANDLE hMenuItem = 0; +extern HANDLE hLog; +static HWND hDlg; +static HANDLE hWumfBut; +extern PWumf list; +int hLangpack; + +static PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + "WUMF: Who Use My Files?", + PLUGIN_MAKE_VERSION(0,1,0,1), + "Scans for network users of your shared files and notify you with popups. Uses PopUps Interoperability by Luca Santarelli. PopUps plugin must be activated!", + "Nikolay Redko", + "nike000@users.sf.net", + "© 2003 Nike. Freeware. Please mail me all bugs & your suggestions.", + "http://nightly.miranda.im/", + UNICODE_AWARE, + // {80DCA515-973A-4A7E-8B85-5D8EC88FC5A7} + { 0x80dca515, 0x973a, 0x4a7e, { 0x8b, 0x85, 0x5d, 0x8e, 0xc8, 0x8f, 0xc5, 0xa7 } } +}; + +void LoadOptions() +{ + DBVARIANT dbv = { 0 }; + dbv.type = DBVT_ASCIIZ; + ZeroMemory(&WumfOptions, sizeof(WumfOptions)); + if (DBGetContactSetting(NULL, ModuleName, OPT_FILE, &dbv) == 0) + { + strncpy(WumfOptions.LogFile, dbv.pszVal, 255); + } + else + { + WumfOptions.LogFile[0] = '\0'; + }; + WumfOptions.PopupsEnabled = DBGetContactSettingByte(NULL,ModuleName, POPUPS_ENABLED, TRUE); + + WumfOptions.UseDefColor = DBGetContactSettingByte(NULL,ModuleName, COLOR_DEF, TRUE); + WumfOptions.UseWinColor = DBGetContactSettingByte(NULL,ModuleName, COLOR_WIN, FALSE); + WumfOptions.SelectColor = DBGetContactSettingByte(NULL,ModuleName, COLOR_SET, FALSE); + + WumfOptions.ColorText = DBGetContactSettingDword(NULL,ModuleName, COLOR_TEXT, RGB(0,0,0)); + WumfOptions.ColorBack = DBGetContactSettingDword(NULL,ModuleName, COLOR_BACK, RGB(255,255,255)); + + WumfOptions.DelayDef = DBGetContactSettingByte(NULL,ModuleName, DELAY_DEF, TRUE); + WumfOptions.DelayInf = DBGetContactSettingByte(NULL,ModuleName, DELAY_INF, FALSE); + WumfOptions.DelaySet = DBGetContactSettingByte(NULL,ModuleName, DELAY_SET, FALSE); + WumfOptions.DelaySec = DBGetContactSettingByte(NULL,ModuleName, DELAY_SEC, 0); + if(!ServiceExists(MS_POPUP_ADDPOPUPEX)) + { + WumfOptions.DelayDef = TRUE; + WumfOptions.DelaySet = FALSE; + WumfOptions.DelayInf = FALSE; + } + WumfOptions.LogToFile = DBGetContactSettingByte(NULL,ModuleName, LOG_INTO_FILE, FALSE); + WumfOptions.LogFolders = DBGetContactSettingByte(NULL,ModuleName, LOG_FOLDER, TRUE); + WumfOptions.AlertFolders = DBGetContactSettingByte(NULL,ModuleName, ALERT_FOLDER, TRUE); + WumfOptions.LogUNC = DBGetContactSettingByte(NULL,ModuleName, LOG_UNC, FALSE); + WumfOptions.AlertUNC = DBGetContactSettingByte(NULL,ModuleName, ALERT_UNC, FALSE); + WumfOptions.LogComp = DBGetContactSettingByte(NULL,ModuleName, LOG_COMP, FALSE); + WumfOptions.AlertComp = DBGetContactSettingByte(NULL,ModuleName, ALERT_COMP, FALSE); + return; +} + + +void ExecuteMenu(HWND hWnd) +{ + HMENU hMenu; + POINT point; + + hMenu=CreatePopupMenu(); + if(!hMenu) + { + MessageBox(NULL, "Error crerating menu", "WUMF",MB_OK); + return; + }; + AppendMenu(hMenu,MF_STRING,IDM_ABOUT, "About\0"); + AppendMenu(hMenu,MF_SEPARATOR,0,NULL);//------------------ + AppendMenu(hMenu,MF_STRING,IDM_SHOW, "Show connections\0"); + AppendMenu(hMenu,MF_SEPARATOR,0,NULL);//------------------ + AppendMenu(hMenu,MF_STRING,IDM_EXIT, "Dismiss popup\0"); + + GetCursorPos (&point); + SetForegroundWindow (hWnd); + + TrackPopupMenu (hMenu, TPM_LEFTBUTTON | TPM_RIGHTBUTTON | TPM_RIGHTALIGN | TPM_TOPALIGN, + point.x, point.y, 0, hWnd, NULL); + + PostMessage (hWnd, WM_USER, 0, 0); + DestroyMenu(hMenu); +} + +static int CALLBACK PopupDlgProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam) +{ +// PWumf w = NULL; + switch(message) { + case WM_COMMAND: + switch (LOWORD(wParam)) + { + case IDM_ABOUT: + break; + case IDM_EXIT: + PUDeletePopUp(hWnd); + break; + case IDM_SHOW: + CallService(MS_WUMF_CONNECTIONSSHOW, (WPARAM)0, (LPARAM)0); + return TRUE; + } + switch (HIWORD(wParam)) + { + case STN_CLICKED: + PUDeletePopUp(hWnd); + return TRUE; + } + break; + case WM_CONTEXTMENU: +// ExecuteMenu(hWnd); + CallService(MS_WUMF_CONNECTIONSSHOW, (WPARAM)0, (LPARAM)0); + break; + case UM_FREEPLUGINDATA: { +/* w = (PWumf)CallService(MS_POPUP_GETPLUGINDATA, (WPARAM)hWnd,(LPARAM)w); + if(w) free(w);*/ + return TRUE; //TRUE or FALSE is the same, it gets ignored. + } + default: + break; + } + return DefWindowProc(hWnd, message, wParam, lParam); +}; + +void ShowWumfPopUp(PWumf w) +{ + char text[512], title[512]; + + if(!WumfOptions.AlertFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return; + mir_snprintf(title, sizeof(title)/sizeof(title[0]), "%s (%s)", w->szComp, w->szUser); + mir_snprintf(text, sizeof(text)/sizeof(text[0]), "%s (%s)", w->szPath, w->szPerm); + ShowThePopUp(w, title, text); +} +void ShowThePopUp(PWumf w, LPSTR title, LPSTR text) +{ + POPUPDATAEX ppd = { 0 }; + COLORREF colorBack; + COLORREF colorText; + + colorBack = GetSysColor(COLOR_BTNFACE); + colorText = RGB(0,0,0); + + ppd.lchContact = NULL; + ppd.lchIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_DRIVE)); + ppd.iSeconds = -1; + + if(WumfOptions.DelayInf) + { + ppd.iSeconds = -1; + } + else if(WumfOptions.DelayDef) + { + ppd.iSeconds = 0; + } + else if(WumfOptions.DelaySet) + { + ppd.iSeconds = WumfOptions.DelaySec; + } + + lstrcpyn(ppd.lpzContactName, title, 128); + lstrcpyn(ppd.lpzText, text, 128); + if(WumfOptions.UseWinColor) + { + ppd.colorBack = GetSysColor(COLOR_WINDOW); + ppd.colorText = GetSysColor(COLOR_WINDOWTEXT); + } + else if(WumfOptions.UseDefColor) + { + ppd.colorBack = 0L; + ppd.colorText = 0L; + } + else if(WumfOptions.SelectColor) + { + ppd.colorBack = WumfOptions.ColorBack; + ppd.colorText = WumfOptions.ColorText; + } + + ppd.PluginWindowProc = (WNDPROC)PopupDlgProc; + ppd.PluginData = w; + if(CALLSERVICE_NOTFOUND == CallService(MS_POPUP_ADDPOPUPEX, (WPARAM)&ppd, 0)) + CallService(MS_POPUP_ADDPOPUP, (WPARAM)&ppd, 0); +} + +void ShowThePreview() +{ + if(!ServiceExists(MS_POPUP_ADDPOPUP)) + { + MessageBox(NULL,"PopUp plugin not found!", "WUMF plugin", MB_OK|MB_ICONSTOP); + return; + }; + if(WumfOptions.AlertFolders) + { + ShowThePopUp(NULL, "Guest", "C:\\My Share"); + Sleep(300); + ShowThePopUp(NULL, "Guest", "C:\\My Share\\Photos"); + Sleep(300); + } + ShowThePopUp(NULL, "Guest", "C:\\Share\\My Photos\\photo.jpg"); + Sleep(300); + if(WumfOptions.AlertFolders) + { + ShowThePopUp(NULL, "User", "C:\\My Share"); + Sleep(300); + ShowThePopUp(NULL, "User", "C:\\My Share\\Movies"); + Sleep(300); + } + ShowThePopUp(NULL, "User", "C:\\My Share\\Movies\\The Two Towers.avi"); + Sleep(300); + if(WumfOptions.AlertFolders) + { + ShowThePopUp(NULL, "Administrator", "C:\\Distributives"); + Sleep(300); + ShowThePopUp(NULL, "Administrator", "C:\\Distributives\\Win2k"); + Sleep(300); + } + ShowThePopUp(NULL, "Administrator", "C:\\Distributives\\Win2k\\setup.exe"); +}; + + + +BOOL WINAPI DllMain(HINSTANCE hinstDLL,DWORD fdwReason,LPVOID lpvReserved) +{ + hInst=hinstDLL; + return TRUE; +} + +DWORD WINAPI ThreadProc(LPVOID lpParameter) +{ + MSG msg; //Message pump. + if(hDlg) + { + ShowWindow(hDlg, SW_SHOWNORMAL); + SetForegroundWindow(hDlg); + return (int)(1); + } + hDlg = CreateDialog(hInst, MAKEINTRESOURCE(IDD_CONNLIST), NULL, (DLGPROC)ConnDlgProc); + SendMessage(hDlg, WM_SETICON, ICON_SMALL, (LPARAM)LoadIcon(hInst,MAKEINTRESOURCE(IDI_DRIVE))); + ShowWindow(hDlg, SW_SHOW); + while(GetMessage(&msg, NULL, 0, 0) == TRUE) + { + TranslateMessage(&msg); + DispatchMessage(&msg); + } + hDlg = NULL; + ExitThread(0); + + return (int)(1); +} + + +static INT_PTR WumfShowConnections(WPARAM wParam,LPARAM lParam) +{ + DWORD threadID = 0; + CloseHandle(CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)ThreadProc, (LPVOID)NULL,0,&threadID)); + Sleep(100); + CallService(MS_TTB_SETBUTTONSTATE, (WPARAM)hWumfBut, TTBST_RELEASED); + return 0; +} + +static INT_PTR WumfMenuCommand(WPARAM wParam,LPARAM lParam) +{ + BOOL MajorTo0121 = FALSE; + int iResult = 0; + CLISTMENUITEM mi = { 0 }; + + mi.cbSize = sizeof(mi); + if (WumfOptions.PopupsEnabled == TRUE) + { + WumfOptions.PopupsEnabled = FALSE; + mi.pszName = Translate("Enable WUMF popups"); + mi.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_NOPOPUP)); + } + else + { + WumfOptions.PopupsEnabled = TRUE; + mi.pszName = Translate("Disable WUMF popups"); + mi.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_POPUP)); + } + DBWriteContactSettingByte(NULL, ModuleName, POPUPS_ENABLED, (BYTE)WumfOptions.PopupsEnabled); + mi.flags = CMIM_NAME | CMIM_ICON; + iResult = CallService(MS_CLIST_MODIFYMENUITEM,(WPARAM)hMenuItem,(LPARAM)&mi); + return iResult; +} + +__declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +void DisableDelayOptions(HWND hwndDlg) +{ + CheckDlgButton(hwndDlg, IDC_DELAY_INF,BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DELAY_SET,BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DELAY_DEF,BST_CHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_INF), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_SET), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_DEF), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_SEC), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_TX_DELAY_SEC), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_NOTE), TRUE); +} +void ChooseFile(HWND hDlg) +{ + OPENFILENAME ofn; // common dialog box structure + char szFile[260]; // buffer for filename + HANDLE hf; // file handle + // Initialize OPENFILENAME + ZeroMemory(&ofn, sizeof(OPENFILENAME)); + ofn.lStructSize = sizeof(OPENFILENAME); + ofn.hwndOwner =hDlg; + szFile[0]=0; + ofn.lpstrFile = szFile; + ofn.nMaxFile = 260; + ofn.lpstrFilter = "All files (*.*)\0*.*\0Text files (*.txt)\0*.txt\0Log files (*.log)\0*.log\0\0"; + ofn.nFilterIndex = 2; + ofn.lpstrFileTitle = NULL; + ofn.nMaxFileTitle = 0; + ofn.lpstrInitialDir = NULL; + ofn.Flags = OFN_CREATEPROMPT; + // Display the Open dialog box. + if (GetSaveFileName(&ofn)==TRUE) + { + hf = CreateFile(ofn.lpstrFile, + GENERIC_WRITE, + 0, + (LPSECURITY_ATTRIBUTES) NULL, + OPEN_ALWAYS, + FILE_ATTRIBUTE_NORMAL, + (HANDLE) NULL); + if(hf!=INVALID_HANDLE_VALUE) + { + SetDlgItemText(hDlg,IDC_FILE,ofn.lpstrFile); + lstrcpyn(WumfOptions.LogFile, ofn.lpstrFile, 255); + CloseHandle(hf); + } + } + else if(CommDlgExtendedError()!=0L) + { + char str[256]; + wsprintf(str,"Common Dialog Error 0x%lx",CommDlgExtendedError()); + MessageBox(hDlg,str,"Wumf plugin",MB_OK|MB_ICONSTOP); + }; + +}; + +INT_PTR CALLBACK OptionsDlgProc(HWND hwndDlg,UINT msg,WPARAM wparam,LPARAM lparam) +{ + WORD wControlId = LOWORD(wparam); + WORD wNotifyCode = HIWORD(wparam); + int seconds; + + switch(msg) + { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + CheckDlgButton(hwndDlg, IDC_COLOR_WIN, WumfOptions.UseWinColor?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_COLOR_DEF, WumfOptions.UseDefColor?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_COLOR_SET, WumfOptions.SelectColor?BST_CHECKED:BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_COLOR_BACK), WumfOptions.SelectColor); + EnableWindow(GetDlgItem(hwndDlg, IDC_COLOR_TEXT), WumfOptions.SelectColor); + if(WumfOptions.SelectColor) + { + SendDlgItemMessage(hwndDlg,IDC_COLOR_BACK,CPM_SETCOLOUR,0,WumfOptions.ColorBack); + SendDlgItemMessage(hwndDlg,IDC_COLOR_TEXT,CPM_SETCOLOUR,0,WumfOptions.ColorText); + } + if(!ServiceExists(MS_POPUP_ADDPOPUPEX)) + { + DisableDelayOptions(hwndDlg); + break; + } + CheckDlgButton(hwndDlg, IDC_DELAY_INF, WumfOptions.DelayInf?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DELAY_DEF, WumfOptions.DelayDef?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_DELAY_SET, WumfOptions.DelaySet?BST_CHECKED:BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_SEC), WumfOptions.DelaySet); + SetDlgItemInt(hwndDlg, IDC_DELAY_SEC, WumfOptions.DelaySec, FALSE); + //Logging & alerts + CheckDlgButton(hwndDlg, IDC_LOG_FOLDER, WumfOptions.LogFolders?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_ALERT_FOLDER, WumfOptions.AlertFolders?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_LOG_UNC, WumfOptions.LogUNC?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_ALERT_UNC, WumfOptions.AlertUNC?BST_CHECKED:BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_LOG_COMP, WumfOptions.LogComp?BST_CHECKED:BST_UNCHECKED); + + if(WumfOptions.LogToFile) + { + CheckDlgButton(hwndDlg,IDC_LOG_INTO_FILE,BST_CHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_FILE), TRUE); + EnableWindow(GetDlgItem(hwndDlg, IDC_SEL_FILE), TRUE); + SetDlgItemText(hwndDlg,IDC_FILE,WumfOptions.LogFile); + } + else + { + CheckDlgButton(hwndDlg,IDC_LOG_INTO_FILE,BST_UNCHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_FILE), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_SEL_FILE), FALSE); + SetDlgItemText(hwndDlg,IDC_FILE,""); + }; + + break; + case WM_COMMAND: + switch(wNotifyCode) + { + case BN_CLICKED : + switch(wControlId) + { + case IDC_DELAY_SET: + case IDC_DELAY_DEF: + case IDC_DELAY_INF: + WumfOptions.DelaySet = (IsDlgButtonChecked(hwndDlg, IDC_DELAY_SET) == BST_CHECKED); + WumfOptions.DelayDef = (IsDlgButtonChecked(hwndDlg, IDC_DELAY_DEF) == BST_CHECKED); + WumfOptions.DelayInf = (IsDlgButtonChecked(hwndDlg, IDC_DELAY_INF) == BST_CHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_DELAY_SEC), WumfOptions.DelaySet); + SetDlgItemInt(hwndDlg, IDC_DELAY_SEC, WumfOptions.DelaySec, TRUE); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case IDC_COLOR_SET: + case IDC_COLOR_DEF: + case IDC_COLOR_WIN: + WumfOptions.SelectColor = (IsDlgButtonChecked(hwndDlg, IDC_COLOR_SET) == BST_CHECKED); + WumfOptions.UseDefColor = (IsDlgButtonChecked(hwndDlg, IDC_COLOR_DEF) == BST_CHECKED); + WumfOptions.UseWinColor = (IsDlgButtonChecked(hwndDlg, IDC_COLOR_WIN) == BST_CHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_COLOR_BACK),WumfOptions.SelectColor); + EnableWindow(GetDlgItem(hwndDlg, IDC_COLOR_TEXT), WumfOptions.SelectColor); + SendDlgItemMessage(hwndDlg,IDC_COLOR_BACK,CPM_SETCOLOUR,0,WumfOptions.ColorBack); + SendDlgItemMessage(hwndDlg,IDC_COLOR_TEXT,CPM_SETCOLOUR,0,WumfOptions.ColorText); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + /* not implemented */ + case IDC_LOG_COMP: + case IDC_ALERT_COMP: + case IDC_LOG_UNC: + case IDC_ALERT_UNC: + MessageBox(NULL, "Not implemented yet...", "WUMF", MB_OK|MB_ICONINFORMATION); + break; + /* end */ + case IDC_LOG_INTO_FILE: + WumfOptions.LogToFile = (IsDlgButtonChecked(hwndDlg, IDC_LOG_INTO_FILE) == BST_CHECKED); + EnableWindow(GetDlgItem(hwndDlg, IDC_FILE), WumfOptions.LogToFile); + EnableWindow(GetDlgItem(hwndDlg, IDC_SEL_FILE), WumfOptions.LogToFile); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case IDC_SEL_FILE: + ChooseFile(hwndDlg); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case IDC_LOG_FOLDER: + WumfOptions.LogFolders = (IsDlgButtonChecked(hwndDlg, IDC_LOG_FOLDER) == BST_CHECKED); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case IDC_ALERT_FOLDER: + WumfOptions.AlertFolders = (IsDlgButtonChecked(hwndDlg, IDC_ALERT_FOLDER) == BST_CHECKED); + break; +/* case IDC_LOG_COMP: + WumfOptions.LogComp = (IsDlgButtonChecked(hwndDlg, IDC_LOG_COMP) == BST_CHECKED); + break; + case IDC_ALERT_COMP: + WumfOptions.AlertComp = (IsDlgButtonChecked(hwndDlg, IDC_ALERT_COMP) == BST_CHECKED); + break; + case IDC_LOG_UNC: + WumfOptions.LogUNC = (IsDlgButtonChecked(hwndDlg, IDC_LOG_UNC) == BST_CHECKED); + break; + case IDC_ALERT_UNC: + WumfOptions.AlertUNC = (IsDlgButtonChecked(hwndDlg, IDC_ALERT_UNC) == BST_CHECKED); + break; +*/ case IDC_PREVIEW: + ShowThePreview(); + break; + case IDC_CONN: + CallService(MS_WUMF_CONNECTIONSSHOW, (WPARAM)0, (LPARAM)0); + break; + } + break; + case CPN_COLOURCHANGED: + WumfOptions.ColorText = SendDlgItemMessage(hwndDlg,IDC_COLOR_TEXT,CPM_GETCOLOUR,0,0); + WumfOptions.ColorBack = SendDlgItemMessage(hwndDlg,IDC_COLOR_BACK,CPM_GETCOLOUR,0,0); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case EN_CHANGE: + switch(wControlId) + { + case IDC_DELAY_SEC: + seconds = GetDlgItemInt(hwndDlg, IDC_DELAY_SEC, NULL, FALSE); + if (seconds > LIFETIME_MAX) + WumfOptions.DelaySec = LIFETIME_MAX; + else if (seconds < LIFETIME_MIN) + WumfOptions.DelaySec = LIFETIME_MIN; + else if (seconds <= LIFETIME_MAX || seconds >= LIFETIME_MIN) + WumfOptions.DelaySec = seconds; + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + case IDC_FILE: + GetDlgItemText(hwndDlg,IDC_FILE,WumfOptions.LogFile, sizeof(WumfOptions.LogFile)); + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + } + break; + case EN_KILLFOCUS: + switch(wControlId) + { + case IDC_DELAY_SEC: + SetDlgItemInt(hwndDlg, IDC_DELAY_SEC, WumfOptions.DelaySec, FALSE); + break; + }; + break; + } + break; + case WM_NOTIFY: + switch(((LPNMHDR)lparam)->idFrom) { + case 0: + switch (((LPNMHDR)lparam)->code) { + case PSN_RESET: + LoadOptions(); + return TRUE; + case PSN_APPLY: + DBWriteContactSettingByte(NULL,ModuleName, COLOR_DEF, (BYTE)WumfOptions.UseDefColor); + DBWriteContactSettingByte(NULL,ModuleName, COLOR_WIN, (BYTE)WumfOptions.UseWinColor); + DBWriteContactSettingByte(NULL,ModuleName, COLOR_SET, (BYTE)WumfOptions.SelectColor ); + DBWriteContactSettingDword(NULL,ModuleName, COLOR_TEXT, (DWORD)WumfOptions.ColorText); + DBWriteContactSettingDword(NULL,ModuleName, COLOR_BACK, (DWORD)WumfOptions.ColorBack); + DBWriteContactSettingByte(NULL,ModuleName, DELAY_DEF, (BYTE)WumfOptions.DelayDef); + DBWriteContactSettingByte(NULL,ModuleName, DELAY_INF, (BYTE)WumfOptions.DelayInf); + DBWriteContactSettingByte(NULL,ModuleName, DELAY_SET, (BYTE)WumfOptions.DelaySet); + DBWriteContactSettingByte(NULL,ModuleName, DELAY_SEC, (BYTE)WumfOptions.DelaySec); + DBWriteContactSettingByte(NULL,ModuleName, LOG_INTO_FILE, (BYTE)WumfOptions.LogToFile); + DBWriteContactSettingByte(NULL,ModuleName, LOG_FOLDER, (BYTE)WumfOptions.LogFolders); + DBWriteContactSettingByte(NULL,ModuleName, ALERT_FOLDER, (BYTE)WumfOptions.AlertFolders); + DBWriteContactSettingByte(NULL,ModuleName, LOG_UNC, (BYTE)WumfOptions.LogUNC); + DBWriteContactSettingByte(NULL,ModuleName, ALERT_UNC, (BYTE)WumfOptions.AlertUNC); + DBWriteContactSettingByte(NULL,ModuleName, LOG_COMP, (BYTE)WumfOptions.LogComp); + DBWriteContactSettingByte(NULL,ModuleName, ALERT_COMP, (BYTE)WumfOptions.AlertComp); + GetDlgItemText(hwndDlg,IDC_FILE,WumfOptions.LogFile, 255); + DBWriteContactSettingString(NULL,ModuleName, OPT_FILE, WumfOptions.LogFile); + break; + } + break; + } + break; + } + return 0; +} + +int InitTopToolbar(WPARAM wparam,LPARAM lparam) +{ + TTBButton ttb = { 0 }; + ttb.cbSize = sizeof(ttb); + ttb.hIconUp = LoadIcon(hInst, MAKEINTRESOURCE(IDI_DRIVE)); + ttb.pszService = MS_WUMF_CONNECTIONSSHOW; + ttb.dwFlags = TTBBF_VISIBLE|TTBBF_SHOWTOOLTIP; + ttb.name = ttb.pszTooltipUp = LPGEN("Show connections list"); + hWumfBut = TopToolbar_AddButton(&ttb); + return 0; +} + +int OptionsInit(WPARAM wparam,LPARAM lparam) +{ + OPTIONSDIALOGPAGE odp = { 0 }; + + + odp.cbSize=sizeof(odp); + odp.position=945000000; + odp.hInstance=hInst; + odp.pszTemplate=MAKEINTRESOURCE(IDD_OPTIONS); + odp.pszTitle="Wumf"; + odp.pfnDlgProc=OptionsDlgProc; + odp.pszGroup=Translate("Plugins"); + odp.flags=ODPF_BOLDGROUPS; + Options_AddPage(wparam, &odp); + return 0; +} + +__declspec(dllexport) int Load(void) +{ + CLISTMENUITEM mi = { 0 }; + + mir_getLP(&pluginInfo); + + ZeroMemory(&mi, sizeof(mi)); + mi.cbSize = sizeof(mi); + LoadOptions(); + + CreateServiceFunction(MS_WUMF_SWITCHPOPUP, WumfMenuCommand); + CreateServiceFunction(MS_WUMF_CONNECTIONSSHOW, WumfShowConnections); + if (WumfOptions.PopupsEnabled == FALSE) + { + mi.pszName = Translate("Enable WUMF popups"); + mi.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_NOPOPUP)); + } + else + { + mi.pszName = Translate("Disable WUMF popups"); + mi.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_POPUP)); + } + mi.pszService = MS_WUMF_SWITCHPOPUP; + mi.popupPosition = 1999990000; + mi.pszPopupName = Translate("PopUps"); + hMenuItem = (HANDLE)Menu_AddMainMenuItem(&mi); + + mi.pszName = Translate("WUMF: Show connections"); + mi.hIcon = LoadIcon(hInst,MAKEINTRESOURCE(IDI_DRIVE)); + mi.pszService = MS_WUMF_CONNECTIONSSHOW; + mi.popupPosition = 1999990000; + mi.pszPopupName = NULL; + Menu_AddMainMenuItem(&mi); + + HookEvent(ME_OPT_INITIALISE,OptionsInit); + HookEvent(ME_TTB_MODULELOADED, InitTopToolbar); + setlocale( LC_ALL, ".ACP"); +// _setmbcp(_MB_CP_ANSI); + + if (IsUserAnAdmin()) { + SetTimer(NULL, 777, TIME,(TIMERPROC) TimerProc); + } else { + MessageBox(NULL, "Plugin WhoUsesMyFiles requires admin privileges in order to work.", "Miranda IM", MB_OK); + } + + return 0; +} + +__declspec(dllexport) int Unload(void) +{ + KillTimer(NULL, 777); + CloseHandle(hLog); + FreeAll(); + return 0; +} \ No newline at end of file -- cgit v1.2.3