diff options
Diffstat (limited to 'plugins/WhoUsesMyFiles/src/wumf.cpp')
-rw-r--r-- | plugins/WhoUsesMyFiles/src/wumf.cpp | 310 |
1 files changed, 123 insertions, 187 deletions
diff --git a/plugins/WhoUsesMyFiles/src/wumf.cpp b/plugins/WhoUsesMyFiles/src/wumf.cpp index fbca6874df..9b88a75155 100644 --- a/plugins/WhoUsesMyFiles/src/wumf.cpp +++ b/plugins/WhoUsesMyFiles/src/wumf.cpp @@ -11,23 +11,22 @@ static PWumf lst = NULL; HANDLE hLog = INVALID_HANDLE_VALUE;
BOOL wumf();
-static int DlgResizer(HWND hwndDlg,LPARAM lParam,UTILRESIZECONTROL *urc) {
+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;
+ 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.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;
@@ -36,10 +35,8 @@ void AddToList(HWND hList, PWumf w) void ShowList(PWumf l, HWND hList)
{
- PWumf w;
- w = l;
- while(w)
- {
+ PWumf w = l;
+ while(w) {
AddToList(hList,w);
w = w->next;
}
@@ -47,107 +44,101 @@ void ShowList(PWumf l, HWND hList) 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;
+ PWumf 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;
}
}
-
INT_PTR CALLBACK ConnDlgProc(HWND hWnd, UINT Msg, WPARAM wParam, LPARAM lParam)
{
- switch( Msg )
- {
- case WM_INITDIALOG:
- {
- HWND hList = GetDlgItem(hWnd, IDC_CONNLIST);
-// ListView_DeleteAllItems(hList);
- ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);
- LV_COLUMN lvc = { 0 };
- lvc.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
- lvc.fmt = LVCFMT_LEFT;
- lvc.cx = 40;
- lvc.pszText = TranslateT("ID");
- ListView_InsertColumn(hList, 0, &lvc);
- lvc.cx = 50;
- lvc.pszText = TranslateT("User");
- ListView_InsertColumn(hList, 1, &lvc);
- lvc.cx = 250;
- lvc.pszText = TranslateT("File");
- ListView_InsertColumn(hList, 2, &lvc);
- lvc.cx = 50;
- lvc.pszText = TranslateT("Access");
- ListView_InsertColumn(hList, 3, &lvc);
- KillTimer(NULL, 777);
- lst = cpy_list(&list);
- if (IsUserAnAdmin()) {
- SetTimer(NULL, 777, TIME, TimerProc);
- } else {
- MessageBox(NULL, TranslateT("Plugin WhoUsesMyFiles requires admin privileges in order to work."), _T("Miranda NG"), 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:
- {
- UTILRESIZEDIALOG urd={0};
- urd.cbSize=sizeof(urd);
- urd.hwndDlg=hWnd;
- urd.hInstance=hInst;
- urd.lpTemplate = MAKEINTRESOURCEA(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);
+ switch( Msg ) {
+ case WM_INITDIALOG:
+ {
+ HWND hList = GetDlgItem(hWnd, IDC_CONNLIST);
+
+ ListView_SetExtendedListViewStyle(hList, LVS_EX_FULLROWSELECT);
+ LV_COLUMN lvc = { 0 };
+ lvc.mask = LVCF_TEXT|LVCF_FMT|LVCF_WIDTH;
+ lvc.fmt = LVCFMT_LEFT;
+ lvc.cx = 40;
+ lvc.pszText = TranslateT("ID");
+ ListView_InsertColumn(hList, 0, &lvc);
+ lvc.cx = 50;
+ lvc.pszText = TranslateT("User");
+ ListView_InsertColumn(hList, 1, &lvc);
+ lvc.cx = 250;
+ lvc.pszText = TranslateT("File");
+ ListView_InsertColumn(hList, 2, &lvc);
+ lvc.cx = 50;
+ lvc.pszText = TranslateT("Access");
+ ListView_InsertColumn(hList, 3, &lvc);
+ KillTimer(NULL, 777);
+ lst = cpy_list(&list);
+ if (IsUserAnAdmin())
+ SetTimer(NULL, 777, TIME, TimerProc);
+ else
+ MessageBox(NULL, TranslateT("Plugin WhoUsesMyFiles requires admin privileges in order to work."), _T("Miranda NG"), MB_OK);
+ ShowList(lst, hList);
+ }
+ Utils_RestoreWindowPosition(hWnd, NULL, MODULENAME,"conn");
+ return TRUE;
+
+ 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, 0);
break;
- default:
- return FALSE;
- }
- return TRUE;
+ }
+ break;
+
+ case WM_SIZE:
+ {
+ UTILRESIZEDIALOG urd = { sizeof(urd) };
+ urd.hwndDlg = hWnd;
+ urd.hInstance = hInst;
+ urd.lpTemplate = MAKEINTRESOURCEA(IDD_CONNLIST);
+ urd.lParam = (LPARAM)NULL;
+ urd.pfnResizer = DlgResizer;
+ CallService(MS_UTILS_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;
+ }
+ return FALSE;
}
void LogWumf(PWumf w)
@@ -159,12 +150,12 @@ void LogWumf(PWumf w) SYSTEMTIME time;
DWORD bytes;
- if(!WumfOptions.LogFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return;
+ if (!WumfOptions.LogFolders && (w->dwAttr & FILE_ATTRIBUTE_DIRECTORY)) return;
- if(hLog == INVALID_HANDLE_VALUE || hLog == NULL)
+ if (hLog == INVALID_HANDLE_VALUE || hLog == NULL)
{
hLog = CreateFile(WumfOptions.LogFile, GENERIC_WRITE, FILE_SHARE_READ, NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
- if(hLog == INVALID_HANDLE_VALUE)
+ if (hLog == INVALID_HANDLE_VALUE)
{
FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -186,109 +177,54 @@ void LogWumf(PWumf w) 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;
+ DWORD ent_read = 0, ent_total = 0, res_handle = 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 ||
+ 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++)
- {
+ for(unsigned i = 0; i < ent_read; i++)
process_session(s_info[ i ]);
- }
+
NetApiBufferFree(s_info);
- } else {
- printError(res);
}
+ 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;
+ DWORD ent_read = 0, ent_total = 0, res_handle = 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, (PDWORD_PTR)&res_handle)) == NERR_Success ||
- res == ERROR_MORE_DATA)
+ if ((res = NetFileEnum(NULL, NULL, s_info.sesi1_username, 3, (LPBYTE *)&f_info, MAX_PREFERRED_LENGTH, &ent_read, &ent_total, (PDWORD_PTR)&res_handle)) == NERR_Success ||
+ res == ERROR_MORE_DATA)
{
- for(i = 0; i < ent_read; i++)
- {
+ for(unsigned i=0; i < ent_read; i++)
process_file(s_info, f_info[ i ]);
- }
+
NetApiBufferFree(f_info);
- } else {
- printError(res);
}
+ 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)
- {
+ 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)){
+ if (!add_cell(&list, w))
msg(TranslateT("Error memory allocation"));
- };
- if(WumfOptions.PopupsEnabled) ShowWumfPopUp(w);
- if(WumfOptions.LogToFile) LogWumf(w);
- } else {
- w->mark = FALSE;
+
+ if (WumfOptions.PopupsEnabled) ShowWumfPopUp(w);
+ if (WumfOptions.LogToFile) LogWumf(w);
}
+ else w->mark = FALSE;
}
void printError(DWORD res)
@@ -302,11 +238,11 @@ void printError(DWORD res) VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime)
{
- if(!wumf())
+ if (!wumf())
KillTimer(NULL, 777);
};
void FreeAll()
{
del_all(&list);
-};
+}
|