From ea4dddac9eb336c841acd69f3040943f8ef1f774 Mon Sep 17 00:00:00 2001 From: Kirill Volinsky Date: Thu, 25 Dec 2014 18:43:37 +0000 Subject: files structure changed git-svn-id: http://svn.miranda-ng.org/main/trunk@11632 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- src/core/stdfile/commonheaders.cpp | 2 - src/core/stdfile/commonheaders.h | 87 ---- src/core/stdfile/file.cpp | 444 ---------------- src/core/stdfile/file.h | 120 ----- src/core/stdfile/fileexistsdlg.cpp | 340 ------------ src/core/stdfile/fileopts.cpp | 244 --------- src/core/stdfile/filerecvdlg.cpp | 426 ---------------- src/core/stdfile/filesenddlg.cpp | 370 -------------- src/core/stdfile/filexferdlg.cpp | 766 ---------------------------- src/core/stdfile/ftmanager.cpp | 534 ------------------- src/core/stdfile/main.cpp | 79 --- src/core/stdfile/res/resource.rc | 287 +++++++++++ src/core/stdfile/res/version.rc | 38 ++ src/core/stdfile/resource.rc | 287 ----------- src/core/stdfile/src/commonheaders.cpp | 2 + src/core/stdfile/src/commonheaders.h | 87 ++++ src/core/stdfile/src/file.cpp | 444 ++++++++++++++++ src/core/stdfile/src/file.h | 120 +++++ src/core/stdfile/src/fileexistsdlg.cpp | 340 ++++++++++++ src/core/stdfile/src/fileopts.cpp | 244 +++++++++ src/core/stdfile/src/filerecvdlg.cpp | 426 ++++++++++++++++ src/core/stdfile/src/filesenddlg.cpp | 370 ++++++++++++++ src/core/stdfile/src/filexferdlg.cpp | 766 ++++++++++++++++++++++++++++ src/core/stdfile/src/ftmanager.cpp | 534 +++++++++++++++++++ src/core/stdfile/src/main.cpp | 79 +++ src/core/stdfile/src/version.h | 12 + src/core/stdfile/stdfile_10.vcxproj | 32 +- src/core/stdfile/stdfile_10.vcxproj.filters | 29 +- src/core/stdfile/stdfile_12.vcxproj | 32 +- src/core/stdfile/stdfile_12.vcxproj.filters | 29 +- src/core/stdfile/version.h | 14 - src/core/stdfile/version.rc | 42 -- 32 files changed, 3811 insertions(+), 3815 deletions(-) delete mode 100644 src/core/stdfile/commonheaders.cpp delete mode 100644 src/core/stdfile/commonheaders.h delete mode 100644 src/core/stdfile/file.cpp delete mode 100644 src/core/stdfile/file.h delete mode 100644 src/core/stdfile/fileexistsdlg.cpp delete mode 100644 src/core/stdfile/fileopts.cpp delete mode 100644 src/core/stdfile/filerecvdlg.cpp delete mode 100644 src/core/stdfile/filesenddlg.cpp delete mode 100644 src/core/stdfile/filexferdlg.cpp delete mode 100644 src/core/stdfile/ftmanager.cpp delete mode 100644 src/core/stdfile/main.cpp create mode 100644 src/core/stdfile/res/resource.rc create mode 100644 src/core/stdfile/res/version.rc delete mode 100644 src/core/stdfile/resource.rc create mode 100644 src/core/stdfile/src/commonheaders.cpp create mode 100644 src/core/stdfile/src/commonheaders.h create mode 100644 src/core/stdfile/src/file.cpp create mode 100644 src/core/stdfile/src/file.h create mode 100644 src/core/stdfile/src/fileexistsdlg.cpp create mode 100644 src/core/stdfile/src/fileopts.cpp create mode 100644 src/core/stdfile/src/filerecvdlg.cpp create mode 100644 src/core/stdfile/src/filesenddlg.cpp create mode 100644 src/core/stdfile/src/filexferdlg.cpp create mode 100644 src/core/stdfile/src/ftmanager.cpp create mode 100644 src/core/stdfile/src/main.cpp create mode 100644 src/core/stdfile/src/version.h delete mode 100644 src/core/stdfile/version.h delete mode 100644 src/core/stdfile/version.rc (limited to 'src') diff --git a/src/core/stdfile/commonheaders.cpp b/src/core/stdfile/commonheaders.cpp deleted file mode 100644 index 95b2201163..0000000000 --- a/src/core/stdfile/commonheaders.cpp +++ /dev/null @@ -1,2 +0,0 @@ -#include "commonheaders.h" - diff --git a/src/core/stdfile/commonheaders.h b/src/core/stdfile/commonheaders.h deleted file mode 100644 index 058ddb124d..0000000000 --- a/src/core/stdfile/commonheaders.h +++ /dev/null @@ -1,87 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#define WINVER 0x0700 -#define _WIN32_WINNT 0x0700 -#define _WIN32_IE 0x0601 - -#include -#include -#include -#include -#include -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "version.h" - -#include "../../resource.h" -#include "../stdplug.h" - -extern HINSTANCE hInst; - -extern ITaskbarList3 * pTaskbarInterface; diff --git a/src/core/stdfile/file.cpp b/src/core/stdfile/file.cpp deleted file mode 100644 index 10a6269869..0000000000 --- a/src/core/stdfile/file.cpp +++ /dev/null @@ -1,444 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "commonheaders.h" -#include "file.h" - -HANDLE hDlgSucceeded, hDlgCanceled; - -TCHAR* PFTS_StringToTchar(int flags, const PROTOCHAR* s); -int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS* ft, const PROTOCHAR* s, TCHAR *r); - -static HGENMENU hSRFileMenuItem; - -TCHAR* GetContactID(MCONTACT hContact) -{ - char *szProto = GetContactProto(hContact); - if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1) { - if (TCHAR *theValue = db_get_tsa(hContact, szProto, "ChatRoomID")) - return theValue; - } - else { - CONTACTINFO ci = { sizeof(ci) }; - ci.hContact = hContact; - ci.szProto = szProto; - ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - return (TCHAR*)ci.pszVal; - case CNFT_DWORD: - return _itot(ci.dVal, (TCHAR*)mir_alloc(sizeof(TCHAR)*32), 10); - } - } - } - return NULL; -} - -static INT_PTR SendFileCommand(WPARAM hContact, LPARAM) -{ - struct FileSendData fsd; - fsd.hContact = hContact; - fsd.ppFiles = NULL; - return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); -} - -static INT_PTR SendSpecificFiles(WPARAM hContact, LPARAM lParam) -{ - FileSendData fsd; - fsd.hContact = hContact; - - char** ppFiles = (char**)lParam; - int count = 0; - while (ppFiles[count] != NULL) - count++; - - fsd.ppFiles = (const TCHAR**)alloca((count + 1) * sizeof(void*)); - for (int i = 0; i < count; i++) - fsd.ppFiles[i] = mir_a2t(ppFiles[i]); - fsd.ppFiles[count] = NULL; - - HWND hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); - for (int j = 0; j < count; j++) - mir_free((void*)fsd.ppFiles[j]); - return (INT_PTR)hWnd; -} - -static INT_PTR SendSpecificFilesT(WPARAM hContact, LPARAM lParam) -{ - FileSendData fsd; - fsd.hContact = hContact; - fsd.ppFiles = (const TCHAR**)lParam; - return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); -} - -static INT_PTR GetReceivedFilesFolder(WPARAM wParam, LPARAM lParam) -{ - TCHAR buf[MAX_PATH]; - GetContactReceivedFilesDir(wParam, buf, MAX_PATH, TRUE); - char* dir = mir_t2a(buf); - mir_strncpy((char*)lParam, dir, MAX_PATH); - mir_free(dir); - return 0; -} - -static INT_PTR RecvFileCommand(WPARAM, LPARAM lParam) -{ - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILERECV), NULL, DlgProcRecvFile, lParam); - return 0; -} - -void PushFileEvent(MCONTACT hContact, HANDLE hdbe, LPARAM lParam) -{ - CLISTEVENT cle = { 0 }; - cle.cbSize = sizeof(cle); - cle.hContact = hContact; - cle.hDbEvent = hdbe; - cle.lParam = lParam; - if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && !db_get_b(hContact, "CList", "NotOnList", 0)) { - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILERECV), NULL, DlgProcRecvFile, (LPARAM)&cle); - } - else { - SkinPlaySound("RecvFile"); - - TCHAR szTooltip[256]; - mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("File from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); - cle.ptszTooltip = szTooltip; - - cle.flags |= CLEF_TCHAR; - cle.hIcon = LoadSkinIcon(SKINICON_EVENT_FILE); - cle.pszService = "SRFile/RecvFile"; - CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); - } -} - -static int FileEventAdded(WPARAM wParam, LPARAM lParam) -{ - DWORD dwSignature; - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.cbBlob = sizeof(DWORD); - dbei.pBlob = (PBYTE)&dwSignature; - db_event_get((HANDLE)lParam, &dbei); - if (dbei.flags & (DBEF_SENT | DBEF_READ) || dbei.eventType != EVENTTYPE_FILE || dwSignature == 0) - return 0; - - PushFileEvent(wParam, (HANDLE)lParam, 0); - return 0; -} - -int SRFile_GetRegValue(HKEY hKeyBase, const TCHAR *szSubKey, const TCHAR *szValue, TCHAR *szOutput, int cbOutput) -{ - HKEY hKey; - DWORD cbOut = cbOutput; - - if (RegOpenKeyEx(hKeyBase, szSubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) - return 0; - - if (RegQueryValueEx(hKey, szValue, NULL, NULL, (PBYTE)szOutput, &cbOut) != ERROR_SUCCESS) { - RegCloseKey(hKey); - return 0; - } - - RegCloseKey(hKey); - return 1; -} - -void GetSensiblyFormattedSize(__int64 size, TCHAR *szOut, int cchOut, int unitsOverride, int appendUnits, int *unitsUsed) -{ - if (!unitsOverride) { - if (size < 1000) unitsOverride = UNITS_BYTES; - else if (size < 100 * 1024) unitsOverride = UNITS_KBPOINT1; - else if (size < 1024 * 1024) unitsOverride = UNITS_KBPOINT0; - else if (size < 1024 * 1024 * 1024) unitsOverride = UNITS_MBPOINT2; - else unitsOverride = UNITS_GBPOINT3; - } - - if (unitsUsed) - *unitsUsed = unitsOverride; - - switch (unitsOverride) { - case UNITS_BYTES: mir_sntprintf(szOut, cchOut, _T("%u%s%s"), (int)size, appendUnits ? _T(" ") : _T(""), appendUnits ? TranslateT("bytes") : _T("")); break; - case UNITS_KBPOINT1: mir_sntprintf(szOut, cchOut, _T("%.1lf%s"), size / 1024.0, appendUnits ? _T(" KB") : _T("")); break; - case UNITS_KBPOINT0: mir_sntprintf(szOut, cchOut, _T("%u%s"), (int)(size / 1024), appendUnits ? _T(" KB") : _T("")); break; - case UNITS_GBPOINT3: mir_sntprintf(szOut, cchOut, _T("%.3f%s"), (size >> 20) / 1024.0, appendUnits ? _T(" GB") : _T("")); break; - default: mir_sntprintf(szOut, cchOut, _T("%.2lf%s"), size / 1048576.0, appendUnits ? _T(" MB") : _T("")); break; - } -} - -// Tripple redirection sucks but is needed to nullify the array pointer -void FreeFilesMatrix(TCHAR ***files) -{ - if (*files == NULL) - return; - - // Free each filename in the pointer array - TCHAR **pFile = *files; - while (*pFile != NULL) { - mir_free(*pFile); - *pFile = NULL; - pFile++; - } - - // Free the array itself - mir_free(*files); - *files = NULL; -} - -void FreeProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *fts) -{ - mir_free(fts->tszCurrentFile); - if (fts->ptszFiles) { - for (int i = 0; i < fts->totalFiles; i++) mir_free(fts->ptszFiles[i]); - mir_free(fts->ptszFiles); - } - mir_free(fts->tszWorkingDir); -} - -void CopyProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src) -{ - *dest = *src; - if (src->tszCurrentFile) dest->tszCurrentFile = PFTS_StringToTchar(src->flags, src->tszCurrentFile); - if (src->ptszFiles) { - dest->ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*)*src->totalFiles); - for (int i = 0; i < src->totalFiles; i++) - dest->ptszFiles[i] = PFTS_StringToTchar(src->flags, src->ptszFiles[i]); - } - if (src->tszWorkingDir) dest->tszWorkingDir = PFTS_StringToTchar(src->flags, src->tszWorkingDir); - dest->flags &= ~PFTS_UTF; - dest->flags |= PFTS_TCHAR; -} - -void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src) -{ - dest->hContact = src->hContact; - dest->flags = src->flags; - if (dest->totalFiles != src->totalFiles) { - for (int i = 0; i < dest->totalFiles; i++) mir_free(dest->ptszFiles[i]); - mir_free(dest->ptszFiles); - dest->ptszFiles = NULL; - dest->totalFiles = src->totalFiles; - } - if (src->ptszFiles) { - if (!dest->ptszFiles) - dest->ptszFiles = (TCHAR**)mir_calloc(sizeof(TCHAR*)*src->totalFiles); - for (int i = 0; i < src->totalFiles; i++) - if (!dest->ptszFiles[i] || !src->ptszFiles[i] || PFTS_CompareWithTchar(src, src->ptszFiles[i], dest->ptszFiles[i])) { - mir_free(dest->ptszFiles[i]); - if (src->ptszFiles[i]) - dest->ptszFiles[i] = PFTS_StringToTchar(src->flags, src->ptszFiles[i]); - else - dest->ptszFiles[i] = NULL; - } - } - else if (dest->ptszFiles) { - for (int i = 0; i < dest->totalFiles; i++) - mir_free(dest->ptszFiles[i]); - mir_free(dest->ptszFiles); - dest->ptszFiles = NULL; - } - - dest->currentFileNumber = src->currentFileNumber; - dest->totalBytes = src->totalBytes; - dest->totalProgress = src->totalProgress; - if (src->tszWorkingDir && (!dest->tszWorkingDir || PFTS_CompareWithTchar(src, src->tszWorkingDir, dest->tszWorkingDir))) { - mir_free(dest->tszWorkingDir); - if (src->tszWorkingDir) - dest->tszWorkingDir = PFTS_StringToTchar(src->flags, src->tszWorkingDir); - else - dest->tszWorkingDir = NULL; - } - - if (!dest->tszCurrentFile || !src->tszCurrentFile || PFTS_CompareWithTchar(src, src->tszCurrentFile, dest->tszCurrentFile)) { - mir_free(dest->tszCurrentFile); - if (src->tszCurrentFile) - dest->tszCurrentFile = PFTS_StringToTchar(src->flags, src->tszCurrentFile); - else - dest->tszCurrentFile = NULL; - } - dest->currentFileSize = src->currentFileSize; - dest->currentFileProgress = src->currentFileProgress; - dest->currentFileTime = src->currentFileTime; - dest->flags &= ~PFTS_UTF; - dest->flags |= PFTS_TCHAR; -} - -static void RemoveUnreadFileEvents(void) -{ - for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { - HANDLE hDbEvent = db_event_firstUnread(hContact); - while (hDbEvent) { - DBEVENTINFO dbei = { sizeof(dbei) }; - db_event_get(hDbEvent, &dbei); - if (!(dbei.flags&(DBEF_SENT | DBEF_READ)) && dbei.eventType == EVENTTYPE_FILE) - db_event_markRead(hContact, hDbEvent); - hDbEvent = db_event_next(hContact, hDbEvent); - } - } -} - -static int SRFilePreBuildMenu(WPARAM wParam, LPARAM) -{ - bool bEnabled = false; - char *szProto = GetContactProto(wParam); - if (szProto != NULL) { - bool isChat = db_get_b(wParam, szProto, "ChatRoom", false) != 0; - if (CallProtoService(szProto, PS_GETCAPS, isChat ? PFLAGNUM_4 : PFLAGNUM_1, 0) & (isChat ? PF4_GROUPCHATFILES : PF1_FILESEND)) { - if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_OFFLINEFILES) - bEnabled = true; - else if (db_get_w(wParam, szProto, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) - bEnabled = true; - } - } - - Menu_ShowItem(hSRFileMenuItem, bEnabled); - return 0; -} - -static int SRFileModulesLoaded(WPARAM, LPARAM) -{ - CLISTMENUITEM mi = { sizeof(mi) }; - mi.position = -2000020000; - mi.icolibItem = GetSkinIconHandle(SKINICON_EVENT_FILE); - mi.pszName = LPGEN("&File"); - mi.pszService = MS_FILE_SENDFILE; - hSRFileMenuItem = Menu_AddContactMenuItem(&mi); - - RemoveUnreadFileEvents(); - return 0; -} - -INT_PTR FtMgrShowCommand(WPARAM, LPARAM) -{ - FtMgr_Show(true, true); - return 0; -} - -INT_PTR openContRecDir(WPARAM hContact, LPARAM) -{ - TCHAR szContRecDir[MAX_PATH]; - GetContactReceivedFilesDir(hContact, szContRecDir, SIZEOF(szContRecDir), TRUE); - ShellExecute(0, _T("open"), szContRecDir, 0, 0, SW_SHOW); - return 0; -} - -INT_PTR openRecDir(WPARAM, LPARAM) -{ - TCHAR szContRecDir[MAX_PATH]; - GetReceivedFilesDir(szContRecDir, SIZEOF(szContRecDir)); - ShellExecute(0, _T("open"), szContRecDir, 0, 0, SW_SHOW); - return 0; -} - -///////////////////////////////////////////////////////////////////////////////////////// - -static void sttRecvCreateBlob(DBEVENTINFO &dbei, int fileCount, char **pszFiles, char *szDescr) -{ - dbei.cbBlob = sizeof(DWORD); - - for (int i = 0; i < fileCount; i++) - dbei.cbBlob += (int)mir_strlen(pszFiles[i]) + 1; - - dbei.cbBlob += (int)mir_strlen(szDescr) + 1; - - if ((dbei.pBlob = (BYTE*)mir_alloc(dbei.cbBlob)) == 0) - return; - - *(DWORD*)dbei.pBlob = 0; - BYTE* p = dbei.pBlob + sizeof(DWORD); - for (int i = 0; i < fileCount; i++) { - strcpy((char*)p, pszFiles[i]); - p += mir_strlen(pszFiles[i]) + 1; - } - strcpy((char*)p, (szDescr == NULL) ? "" : szDescr); -} - -static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam) -{ - CCSDATA *ccs = (CCSDATA*)lParam; - PROTORECVFILET* pre = (PROTORECVFILET*)ccs->lParam; - if (pre->fileCount == 0) - return 0; - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.szModule = GetContactProto(ccs->hContact); - dbei.timestamp = pre->timestamp; - dbei.flags = (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0; - dbei.eventType = EVENTTYPE_FILE; - - char **pszFiles = (char**)alloca(pre->fileCount * sizeof(char*)); - for (int i = 0; i < pre->fileCount; i++) - pszFiles[i] = Utf8EncodeT(pre->ptszFiles[i]); - - char *szDescr = Utf8EncodeT(pre->tszDescription); - dbei.flags |= DBEF_UTF; - sttRecvCreateBlob(dbei, pre->fileCount, pszFiles, szDescr); - - for (int i = 0; i < pre->fileCount; i++) - mir_free(pszFiles[i]); - mir_free(szDescr); - - HANDLE hdbe = db_event_add(ccs->hContact, &dbei); - - PushFileEvent(ccs->hContact, hdbe, pre->lParam); - mir_free(dbei.pBlob); - return 0; -} - -int LoadSendRecvFileModule(void) -{ - CreateServiceFunction("FtMgr/Show", FtMgrShowCommand); - - CLISTMENUITEM mi = { sizeof(mi) }; - mi.icolibItem = GetSkinIconHandle(SKINICON_EVENT_FILE); - mi.position = 1900000000; - mi.pszName = LPGEN("File &transfers..."); - mi.pszService = "FtMgr/Show"; //MS_PROTO_SHOWFTMGR; - Menu_AddMainMenuItem(&mi); - - HookEvent(ME_SYSTEM_MODULESLOADED, SRFileModulesLoaded); - HookEvent(ME_DB_EVENT_ADDED, FileEventAdded); - HookEvent(ME_OPT_INITIALISE, FileOptInitialise); - HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SRFilePreBuildMenu); - - hDlgSucceeded = CreateHookableEvent(ME_FILEDLG_SUCCEEDED); - hDlgCanceled = CreateHookableEvent(ME_FILEDLG_CANCELED); - - CreateServiceFunction(MS_PROTO_RECVFILET, Proto_RecvFileT); - - CreateServiceFunction(MS_FILE_SENDFILE, SendFileCommand); - CreateServiceFunction(MS_FILE_SENDSPECIFICFILES, SendSpecificFiles); - CreateServiceFunction(MS_FILE_SENDSPECIFICFILEST, SendSpecificFilesT); - CreateServiceFunction(MS_FILE_GETRECEIVEDFILESFOLDER, GetReceivedFilesFolder); - CreateServiceFunction("SRFile/RecvFile", RecvFileCommand); - - CreateServiceFunction("SRFile/OpenContRecDir", openContRecDir); - CreateServiceFunction("SRFile/OpenRecDir", openRecDir); - - SkinAddNewSoundEx("RecvFile", LPGEN("File"), LPGEN("Incoming")); - SkinAddNewSoundEx("FileDone", LPGEN("File"), LPGEN("Complete")); - SkinAddNewSoundEx("FileFailed", LPGEN("File"), LPGEN("Error")); - SkinAddNewSoundEx("FileDenied", LPGEN("File"), LPGEN("Denied")); - return 0; -} diff --git a/src/core/stdfile/file.h b/src/core/stdfile/file.h deleted file mode 100644 index f86bc57fe6..0000000000 --- a/src/core/stdfile/file.h +++ /dev/null @@ -1,120 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#define VIRUSSCAN_DISABLE 0 -#define VIRUSSCAN_AFTERDL 1 -#define VIRUSSCAN_DURINGDL 2 - -#define FILERESUME_ASK 0 -//1, 2, 3, 4: resume, overwrite, rename, skip: from proto library -#define FILERESUMEF_ALL 0x80 -#define FILERESUME_RESUMEALL (FILERESUME_RESUME|FILERESUMEF_ALL) -#define FILERESUME_OVERWRITEALL (FILERESUME_OVERWRITE|FILERESUMEF_ALL) -#define FILERESUME_RENAMEALL (FILERESUME_RENAME|FILERESUMEF_ALL) -#define FILERESUME_CANCEL 0xFFFFFFFF - -#define M_FILEEXISTSDLGREPLY (WM_USER+200) -#define M_PRESHUTDOWN (WM_USER+201) - -struct FileSendData -{ - MCONTACT hContact; - const TCHAR **ppFiles; -}; - -#define BYTESRECVEDHISTORYCOUNT 10 //the number of bytes recved is sampled once a second and the last 10 are used to get the transfer speed -struct FileDlgData -{ - HWND hwndTransfer; - HANDLE fs; - MCONTACT hContact; - HANDLE hDbEvent; - HANDLE hNotifyEvent; - TCHAR **files; - int send; - int closeIfFileChooseCancelled; - int resumeBehaviour; - int bytesRecvedHistory[BYTESRECVEDHISTORYCOUNT]; - int bytesRecvedHistorySize; - int waitingForAcceptance; - PROTOFILETRANSFERSTATUS transferStatus; - int *fileVirusScanned; - HANDLE hPreshutdownEvent; - DWORD dwTicks; - - TCHAR szSavePath[MAX_PATH]; - TCHAR szMsg[450], szFilenames[1024]; - HICON hIcon, hIconFolder; -}; - -//file.c -#define UNITS_BYTES 1 // 0 <= size<1000: "%d bytes" -#define UNITS_KBPOINT1 2 // 1000 <= size<100*1024: "%.1f KB" -#define UNITS_KBPOINT0 3 // 100*1024 <= size<1024*1024: "%d KB" -#define UNITS_MBPOINT2 4 // 1024*1024 <= size: "%.2f MB" -#define UNITS_GBPOINT3 5 // 1024*1024*1024 <= size: "%.3f GB" - -void GetSensiblyFormattedSize(__int64 size, TCHAR *szOut, int cchOut, int unitsOverride, int appendUnits, int *unitsUsed); -void FreeFilesMatrix(TCHAR ***files); //loving that triple indirection -void FreeProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *fts); -void CopyProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src); -void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src); -int SRFile_GetRegValue(HKEY hKeyBase, const TCHAR *szSubKey, const TCHAR *szValue, TCHAR *szOutput, int cbOutput); -//filesenddlg.c -INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -//filerecv.c -INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -void RemoveInvalidFilenameChars(TCHAR *tszString); -void RemoveInvalidPathChars(TCHAR *tszString); -void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL substVars); -void GetReceivedFilesDir(TCHAR *szDir, int cchDir); -int BrowseForFolder(HWND hwnd, TCHAR *szPath); -//fileexistsdlg.c -struct TDlgProcFileExistsParam -{ - HWND hwndParent; - PROTOFILETRANSFERSTATUS *fts; -}; -INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -//filexferdlg.c -INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); -//fileopts.c -int FileOptInitialise(WPARAM wParam, LPARAM lParam); -//ftmanager.c -#define WM_FT_ADD (WM_USER+701) -#define WM_FT_RESIZE (WM_USER+702) -#define WM_FT_REMOVE (WM_USER+703) -#define WM_FT_SELECTPAGE (WM_USER+704) -#define WM_FT_CLEANUP (WM_USER+705) -#define WM_FT_COMPLETED (WM_USER+706) - -HWND FtMgr_Show(bool bForceActivate, bool bFromMenu); -void FtMgr_Destroy(); -HWND FtMgr_AddTransfer(FileDlgData *dat); - -void FreeFileDlgData(FileDlgData* dat); - -TCHAR *GetContactID(MCONTACT hContact); - -extern HANDLE hDlgSucceeded, hDlgCanceled; diff --git a/src/core/stdfile/fileexistsdlg.cpp b/src/core/stdfile/fileexistsdlg.cpp deleted file mode 100644 index 1c3e7dedef..0000000000 --- a/src/core/stdfile/fileexistsdlg.cpp +++ /dev/null @@ -1,340 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "commonheaders.h" -#include "file.h" - -static void SetControlToUnixTime(HWND hwndDlg, UINT idCtrl, time_t unixTime) -{ - LARGE_INTEGER liFiletime; - FILETIME filetime; - SYSTEMTIME st; - char szTime[64], szDate[64], szOutput[128]; - - liFiletime.QuadPart = (BIGI(11644473600)+(__int64)unixTime)*10000000; - filetime.dwHighDateTime = liFiletime.HighPart; - filetime.dwLowDateTime = liFiletime.LowPart; - FileTimeToSystemTime(&filetime, &st); - GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &st, NULL, szTime, SIZEOF(szTime)); - GetDateFormatA(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szDate, SIZEOF(szDate)); - mir_snprintf(szOutput, SIZEOF(szOutput), "%s %s", szDate, szTime); - SetDlgItemTextA(hwndDlg, idCtrl, szOutput); -} - -#define C_CONTEXTMENU 0 -#define C_PROPERTIES 1 -// not defined in VC++ 6.0 SE -#ifndef CMF_EXTENDEDVERBS -#define CMF_EXTENDEDVERBS 0x00000100 -#endif -static void DoAnnoyingShellCommand(HWND hwnd, const TCHAR *szFilename, int cmd, POINT *ptCursor) -{ - IShellFolder *pDesktopFolder; - if (SHGetDesktopFolder(&pDesktopFolder) == NOERROR) { - ITEMIDLIST *pCurrentIdl; - WCHAR* wszFilename = (LPWSTR)szFilename; - - if (pDesktopFolder->ParseDisplayName(NULL, NULL, wszFilename, NULL, &pCurrentIdl, NULL) == NOERROR) { - if (pCurrentIdl->mkid.cb) { - ITEMIDLIST *pidl, *pidlNext, *pidlFilename; - IShellFolder *pFileFolder; - - for (pidl = pCurrentIdl;;) { - pidlNext = (ITEMIDLIST*)((PBYTE)pidl + pidl->mkid.cb); - if (pidlNext->mkid.cb == 0) { - pidlFilename = (ITEMIDLIST*)CoTaskMemAlloc(pidl->mkid.cb + sizeof(pidl->mkid.cb)); - memcpy(pidlFilename, pidl, pidl->mkid.cb + sizeof(pidl->mkid.cb)); - pidl->mkid.cb = 0; - break; - } - pidl = pidlNext; - } - if (pDesktopFolder->BindToObject(pCurrentIdl, NULL, IID_IShellFolder, (void**)&pFileFolder) == NOERROR) { - IContextMenu *pContextMenu; - if (pFileFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlFilename, IID_IContextMenu, NULL, (void**)&pContextMenu) == NOERROR) { - switch (cmd) { - case C_PROPERTIES: - { - CMINVOKECOMMANDINFO ici = { 0 }; - ici.cbSize = sizeof(ici); - ici.hwnd = hwnd; - ici.lpVerb = "properties"; - ici.nShow = SW_SHOW; - pContextMenu->InvokeCommand(&ici); - } - break; - - case C_CONTEXTMENU: - HMENU hMenu = CreatePopupMenu(); - if (SUCCEEDED(pContextMenu->QueryContextMenu(hMenu, 0, 1000, 65535, (GetKeyState(VK_SHIFT) & 0x8000 ? CMF_EXTENDEDVERBS : 0) | CMF_NORMAL))) { - int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, ptCursor->x, ptCursor->y, 0, hwnd, NULL); - if (cmd) { - CMINVOKECOMMANDINFO ici = { 0 }; - ici.cbSize = sizeof(ici); - ici.hwnd = hwnd; - ici.lpVerb = MAKEINTRESOURCEA(cmd - 1000); - ici.nShow = SW_SHOW; - pContextMenu->InvokeCommand(&ici); - } - } - DestroyMenu(hMenu); - break; - } - pContextMenu->Release(); - } - pFileFolder->Release(); - } - CoTaskMemFree(pidlFilename); - } - CoTaskMemFree(pCurrentIdl); - } - pDesktopFolder->Release(); - } -} - -static LRESULT CALLBACK IconCtrlSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - PROTOFILETRANSFERSTATUS* pft = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); - - switch (msg) { - case WM_LBUTTONDBLCLK: - ShellExecute(hwnd, NULL, pft->tszCurrentFile, NULL, NULL, SW_SHOW); - break; - case WM_RBUTTONUP: - POINT pt; - pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); - ClientToScreen(hwnd, &pt); - DoAnnoyingShellCommand(hwnd, pft->tszCurrentFile, C_CONTEXTMENU, &pt); - return 0; - } - return mir_callNextSubclass(hwnd, IconCtrlSubclassProc, msg, wParam, lParam); -} - -struct loadiconsstartinfo { - HWND hwndDlg; - TCHAR *szFilename; -}; - -void __cdecl LoadIconsAndTypesThread(void* param) -{ - loadiconsstartinfo *info = (loadiconsstartinfo*)param; - SHFILEINFO fileInfo; - - if (SHGetFileInfo(info->szFilename, 0, &fileInfo, sizeof(fileInfo), SHGFI_TYPENAME | SHGFI_ICON | SHGFI_LARGEICON)) { - TCHAR szExtension[64], szIconFile[MAX_PATH]; - - TCHAR *pszFilename = _tcsrchr(info->szFilename, '\\'); - if (pszFilename == NULL) - pszFilename = info->szFilename; - - TCHAR *pszExtension = _tcsrchr(pszFilename, '.'); - if (pszExtension) - mir_tstrncpy(szExtension, pszExtension + 1, SIZEOF(szExtension)); - else { - pszExtension = _T("."); - szExtension[0] = '\0'; - } - CharUpper(szExtension); - if (fileInfo.szTypeName[0] == '\0') - mir_sntprintf(fileInfo.szTypeName, SIZEOF(fileInfo.szTypeName), TranslateT("%s file"), szExtension); - SetDlgItemText(info->hwndDlg, IDC_EXISTINGTYPE, fileInfo.szTypeName); - SetDlgItemText(info->hwndDlg, IDC_NEWTYPE, fileInfo.szTypeName); - SendDlgItemMessage(info->hwndDlg, IDC_EXISTINGICON, STM_SETICON, (WPARAM)fileInfo.hIcon, 0); - szIconFile[0] = '\0'; - if (!mir_tstrcmp(szExtension, _T("EXE"))) - SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("2"), szIconFile, SIZEOF(szIconFile)); - else { - TCHAR szTypeName[MAX_PATH]; - if (SRFile_GetRegValue(HKEY_CLASSES_ROOT, pszExtension, NULL, szTypeName, SIZEOF(szTypeName))) { - mir_tstrcat(szTypeName, _T("\\DefaultIcon")); - if (SRFile_GetRegValue(HKEY_CLASSES_ROOT, szTypeName, NULL, szIconFile, SIZEOF(szIconFile))) { - if (_tcsstr(szIconFile, _T("%1"))) - SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("0"), szIconFile, SIZEOF(szIconFile)); - else szIconFile[0] = '\0'; - } - } - } - - if (szIconFile[0]) { - TCHAR *pszComma = _tcsrchr(szIconFile, ','); - int iconIndex = (pszComma == NULL) ? 0 : _ttoi(pszComma + 1); *pszComma = '\0'; - HICON hIcon = ExtractIcon(hInst, szIconFile, iconIndex); - if (hIcon) - fileInfo.hIcon = hIcon; - } - SendDlgItemMessage(info->hwndDlg, IDC_NEWICON, STM_SETICON, (WPARAM)fileInfo.hIcon, 0); - } - mir_free(info->szFilename); - mir_free(info); -} - -INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - TCHAR szSize[64]; - struct _stati64 statbuf; - struct TDlgProcFileExistsParam *dat = (struct TDlgProcFileExistsParam *)lParam; - - SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN)); - SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent); - - fts = (PROTOFILETRANSFERSTATUS*)mir_alloc(sizeof(PROTOFILETRANSFERSTATUS)); - CopyProtoFileTransferStatus(fts, dat->fts); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)fts); - SetDlgItemText(hwndDlg, IDC_FILENAME, fts->tszCurrentFile); - SetControlToUnixTime(hwndDlg, IDC_NEWDATE, fts->currentFileTime); - GetSensiblyFormattedSize(fts->currentFileSize, szSize, SIZEOF(szSize), 0, 1, NULL); - SetDlgItemText(hwndDlg, IDC_NEWSIZE, szSize); - - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_EXISTINGICON), IconCtrlSubclassProc); - - HWND hwndFocus = GetDlgItem(hwndDlg, IDC_RESUME); - if (_tstati64(fts->tszCurrentFile, &statbuf) == 0) { - SetControlToUnixTime(hwndDlg, IDC_EXISTINGDATE, statbuf.st_mtime); - GetSensiblyFormattedSize(statbuf.st_size, szSize, SIZEOF(szSize), 0, 1, NULL); - SetDlgItemText(hwndDlg, IDC_EXISTINGSIZE, szSize); - if (statbuf.st_size > (int)fts->currentFileSize) { - EnableWindow(GetDlgItem(hwndDlg, IDC_RESUME), FALSE); - hwndFocus = GetDlgItem(hwndDlg, IDC_OVERWRITE); - } - } - - loadiconsstartinfo *lisi = (loadiconsstartinfo*)mir_alloc(sizeof(loadiconsstartinfo)); - lisi->hwndDlg = hwndDlg; - lisi->szFilename = mir_tstrdup(fts->tszCurrentFile); - //can be a little slow, so why not? - forkthread(LoadIconsAndTypesThread, 0, lisi); - SetFocus(hwndFocus); - SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE) | BS_DEFPUSHBUTTON); - } - return FALSE; - - case WM_COMMAND: - { - PROTOFILERESUME pfr = { 0 }; - switch (LOWORD(wParam)) { - case IDC_OPENFILE: - ShellExecute(hwndDlg, NULL, fts->tszCurrentFile, NULL, NULL, SW_SHOW); - return FALSE; - - case IDC_OPENFOLDER: - { - TCHAR szFile[MAX_PATH]; - mir_tstrncpy(szFile, fts->tszCurrentFile, SIZEOF(szFile)); - TCHAR *pszLastBackslash = _tcsrchr(szFile, '\\'); - if (pszLastBackslash) - *pszLastBackslash = '\0'; - ShellExecute(hwndDlg, NULL, szFile, NULL, NULL, SW_SHOW); - } - return FALSE; - case IDC_PROPERTIES: - DoAnnoyingShellCommand(hwndDlg, fts->tszCurrentFile, C_PROPERTIES, NULL); - return FALSE; - case IDC_RESUME: - pfr.action = FILERESUME_RESUME; - break; - case IDC_RESUMEALL: - pfr.action = FILERESUME_RESUMEALL; - break; - case IDC_OVERWRITE: - pfr.action = FILERESUME_OVERWRITE; - break; - case IDC_OVERWRITEALL: - pfr.action = FILERESUME_OVERWRITEALL; - break; - - case IDC_AUTORENAME: - pfr.action = FILERESUME_RENAMEALL; - break; - - case IDC_SAVEAS: - { - OPENFILENAME ofn = { 0 }; - TCHAR filter[512], *pfilter; - TCHAR str[MAX_PATH]; - - mir_tstrncpy(str, fts->tszCurrentFile, SIZEOF(str)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hwndDlg; - ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; - _tcscpy(filter, TranslateT("All files")); - _tcscat(filter, _T(" (*)")); - pfilter = filter + _tcslen(filter) + 1; - _tcscpy(pfilter, _T("*")); - pfilter = pfilter + _tcslen(pfilter) + 1; - *pfilter = '\0'; - ofn.lpstrFilter = filter; - ofn.lpstrFile = str; - ofn.nMaxFile = SIZEOF(str); - ofn.nMaxFileTitle = MAX_PATH; - if (!GetSaveFileName(&ofn)) - return FALSE; - - pfr.szFilename = mir_tstrdup(str); - pfr.action = FILERESUME_RENAME; - } - break; - - case IDC_SKIP: - pfr.action = FILERESUME_SKIP; - break; - - case IDCANCEL: - pfr.action = FILERESUME_CANCEL; - break; - - default: - return FALSE; - } - - PROTOFILERESUME *pfrCopy = (PROTOFILERESUME*)mir_alloc(sizeof(pfr)); - memcpy(pfrCopy, &pfr, sizeof(pfr)); - PostMessage((HWND)GetPropA(hwndDlg, "Miranda.ParentWnd"), M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfrCopy); - DestroyWindow(hwndDlg); - } - break; - - case WM_CLOSE: - PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDCANCEL)); - break; - - case M_PRESHUTDOWN: - PostMessage(hwndDlg, WM_CLOSE, 0, 0); - break; - - case WM_DESTROY: - UnhookEvent(GetPropA(hwndDlg, "Miranda.Preshutdown")); // GetProp() will return NULL if it couldnt find anything - RemovePropA(hwndDlg, "Miranda.Preshutdown"); - RemovePropA(hwndDlg, "Miranda.ParentWnd"); - DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_EXISTINGICON, STM_GETICON, 0, 0)); - DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_NEWICON, STM_GETICON, 0, 0)); - FreeProtoFileTransferStatus(fts); - mir_free(fts); - break; - } - return FALSE; -} diff --git a/src/core/stdfile/fileopts.cpp b/src/core/stdfile/fileopts.cpp deleted file mode 100644 index b76a25caa6..0000000000 --- a/src/core/stdfile/fileopts.cpp +++ /dev/null @@ -1,244 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ -#include "commonheaders.h" -#include "file.h" - -#define VSCAN_MCAFEE 1 -#define VSCAN_DRSOLOMON 2 -#define VSCAN_NORTON 3 -#define VSCAN_CA 4 - -struct virusscannerinfo { - const TCHAR *szProductName; - const TCHAR *szExeRegPath; - const TCHAR *szExeRegValue; - const TCHAR *szCommandLine; -}; - -static const struct virusscannerinfo virusScanners[] = { - {_T("Network Associates/McAfee VirusScan"), _T("SOFTWARE\\McAfee\\VirusScan"), _T("Scan32EXE"), _T("\"%s\" %%f /nosplash /comp /autoscan /autoexit /noboot")}, - {_T("Dr Solomon's VirusScan (Network Associates)"), _T("SOFTWARE\\Network Associates\\TVD\\VirusScan\\AVConsol\\General"), _T("szScannerExe"), _T("\"%s\" %%f /uinone /noboot /comp /prompt /autoexit")}, - {_T("Norton AntiVirus"), _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Navw32.exe"), NULL, _T("\"%s\" %%f /b- /m- /s+ /noresults")}, - {_T("Computer Associates/Inoculate IT"), _T("Software\\Antivirus"), _T("ImageFilename"), _T("\"%s\" %%f /display = progress /exit")}, - {_T("Computer Associates eTrust"), _T("SOFTWARE\\ComputerAssociates\\Anti-Virus\\Resident"), _T("VetPath"), _T("\"%s\" %%f /display = progress /exit")}, - {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\Components\\101"), _T("EXEName"), _T("\"%s\" /S /Q %%f")}, - {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\SetupFolders"), _T("KAV8"), _T("\"%savp.exe\" SCAN %%f")}, - {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\SetupFolders"), _T("KAV9"), _T("\"%savp.exe\" SCAN %%f")}, - {_T("AntiVir PersonalEdition Classic"), _T("SOFTWARE\\Avira\\AntiVir PersonalEdition Classic"), _T("Path"), _T("\"%savscan.exe\" /GUIMODE = 2 /PATH = \"%%f\"")}, - {_T("ESET NOD32 Antivirus"), _T("SOFTWARE\\ESET\\ESET Security\\CurrentVersion\\Info"), _T("InstallDir"), _T("\"%secls.exe\" /log-all /aind /no-boots /adware /sfx /unsafe /unwanted /heur /adv-heur /action = clean \"%%f\"")}, -}; - -#define M_UPDATEENABLING (WM_USER+100) -#define M_SCANCMDLINESELCHANGE (WM_USER+101) - -#ifndef SHACF_FILESYS_DIRS - #define SHACF_FILESYS_DIRS 0x00000020 -#endif - -static INT_PTR CALLBACK DlgProcFileOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - SHAutoComplete(GetDlgItem(hwndDlg, IDC_FILEDIR), SHACF_FILESYS_DIRS); - - TCHAR str[MAX_PATH]; - GetContactReceivedFilesDir(NULL, str, SIZEOF(str), FALSE); - SetDlgItemText(hwndDlg, IDC_FILEDIR, str); - - CheckDlgButton(hwndDlg, IDC_AUTOACCEPT, db_get_b(NULL, "SRFile", "AutoAccept", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOMIN, db_get_b(NULL, "SRFile", "AutoMin", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOCLOSE, db_get_b(NULL, "SRFile", "AutoClose", 0) ? BST_CHECKED : BST_UNCHECKED); - CheckDlgButton(hwndDlg, IDC_AUTOCLEAR, db_get_b(NULL, "SRFile", "AutoClear", 1) ? BST_CHECKED : BST_UNCHECKED); - switch (db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE)) { - case VIRUSSCAN_AFTERDL: CheckDlgButton(hwndDlg, IDC_SCANAFTERDL, BST_CHECKED); break; - case VIRUSSCAN_DURINGDL: CheckDlgButton(hwndDlg, IDC_SCANDURINGDL, BST_CHECKED); break; - default: CheckDlgButton(hwndDlg, IDC_NOSCANNER, BST_CHECKED); break; - } - CheckDlgButton(hwndDlg, IDC_WARNBEFOREOPENING, db_get_b(NULL, "SRFile", "WarnBeforeOpening", 1) ? BST_CHECKED : BST_UNCHECKED); - - for (int i = 0; i < SIZEOF(virusScanners); i++) { - TCHAR szScanExe[MAX_PATH]; - if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[i].szExeRegPath, virusScanners[i].szExeRegValue, szScanExe, SIZEOF(szScanExe))) { - int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)virusScanners[i].szProductName); - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, i); - } - } - if (SendDlgItemMessageA(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0) == 0) { - int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)_T("")); - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, (LPARAM)-1); - } - - DBVARIANT dbv; - if (db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv) == 0) { - SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, dbv.ptszVal); - db_free(&dbv); - } - else if (SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0)) { - SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETCURSEL, 0, 0); - PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); - } - - switch (db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK)) { - case FILERESUME_RESUMEALL: CheckDlgButton(hwndDlg, IDC_RESUME, BST_CHECKED); break; - case FILERESUME_OVERWRITEALL: CheckDlgButton(hwndDlg, IDC_OVERWRITE, BST_CHECKED); break; - case FILERESUME_RENAMEALL: CheckDlgButton(hwndDlg, IDC_RENAME, BST_CHECKED); break; - default: CheckDlgButton(hwndDlg, IDC_ASK, BST_CHECKED); break; - } - SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); - } - return TRUE; - - case M_UPDATEENABLING: - { - int on = BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_NOSCANNER); - EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINE), on); - EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINE), on); - EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINEBROWSE), on); - EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINEHELP), on); - EnableWindow(GetDlgItem(hwndDlg, IDC_AUTOMIN), IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); - } - break; - case M_SCANCMDLINESELCHANGE: - { - TCHAR str[512]; - TCHAR szScanExe[MAX_PATH]; - int iScanner = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCURSEL, 0, 0), 0); - if (iScanner >= SIZEOF(virusScanners) || iScanner < 0) break; - str[0] = '\0'; - if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[iScanner].szExeRegPath, virusScanners[iScanner].szExeRegValue, szScanExe, SIZEOF(szScanExe))) - mir_sntprintf(str, SIZEOF(str), virusScanners[iScanner].szCommandLine, szScanExe); - SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); - } - break; - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDC_FILEDIR: - if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; - break; - - case IDC_FILEDIRBROWSE: - { - TCHAR str[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); - if (BrowseForFolder(hwndDlg, str)) - SetDlgItemText(hwndDlg, IDC_FILEDIR, str); - } - break; - - case IDC_AUTOACCEPT: - case IDC_NOSCANNER: - case IDC_SCANAFTERDL: - case IDC_SCANDURINGDL: - SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); - break; - - case IDC_SCANCMDLINE: - if (HIWORD(wParam) == CBN_SELCHANGE) PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); - else if (HIWORD(wParam) != CBN_EDITCHANGE) return 0; - break; - - case IDC_SCANCMDLINEBROWSE: - TCHAR str[MAX_PATH + 2]; - OPENFILENAME ofn = { 0 }; - TCHAR filter[512], *pfilter; - - GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hwndDlg; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; - _tcscpy(filter, TranslateT("Executable files")); - _tcscat(filter, _T(" (*.exe)")); - pfilter = filter + _tcslen(filter) + 1; - _tcscpy(pfilter, _T("*.exe")); - pfilter = pfilter + _tcslen(pfilter) + 1; - _tcscpy(pfilter, TranslateT("All files")); - _tcscat(pfilter, _T(" (*)")); - pfilter = pfilter + _tcslen(pfilter) + 1; - _tcscpy(pfilter, _T("*")); - pfilter = pfilter + _tcslen(pfilter) + 1; - *pfilter = 0; - ofn.lpstrFilter = filter; - ofn.lpstrFile = str; - ofn.nMaxFile = SIZEOF(str) - 2; - if (str[0] == '"') { - TCHAR *pszQuote = _tcschr(str + 1, '"'); - if (pszQuote) *pszQuote = 0; - memmove(str, str + 1, (_tcslen(str) * sizeof(TCHAR))); - } - else { - TCHAR *pszSpace = _tcschr(str, ' '); - if (pszSpace) *pszSpace = 0; - } - ofn.nMaxFileTitle = MAX_PATH; - if (!GetOpenFileName(&ofn)) break; - if (_tcschr(str, ' ') != NULL) { - memmove(str + 1, str, ((SIZEOF(str) - 2) * sizeof(TCHAR))); - str[0] = '"'; - _tcscat(str, _T("\"")); - } - SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); - break; - } - SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->code) { - case PSN_APPLY: - TCHAR str[512]; - GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); - RemoveInvalidPathChars(str); - db_set_ts(NULL, "SRFile", "RecvFilesDirAdv", str); - db_set_b(NULL, "SRFile", "AutoAccept", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); - db_set_b(NULL, "SRFile", "AutoMin", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOMIN)); - db_set_b(NULL, "SRFile", "AutoClose", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLOSE)); - db_set_b(NULL, "SRFile", "AutoClear", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLEAR)); - db_set_b(NULL, "SRFile", "UseScanner", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_SCANAFTERDL) ? VIRUSSCAN_AFTERDL : (IsDlgButtonChecked(hwndDlg, IDC_SCANDURINGDL) ? VIRUSSCAN_DURINGDL : VIRUSSCAN_DISABLE))); - GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); - db_set_ts(NULL, "SRFile", "ScanCmdLine", str); - db_set_b(NULL, "SRFile", "WarnBeforeOpening", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_WARNBEFOREOPENING)); - db_set_b(NULL, "SRFile", "IfExists", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ASK) ? FILERESUME_ASK : (IsDlgButtonChecked(hwndDlg, IDC_RESUME) ? FILERESUME_RESUMEALL : (IsDlgButtonChecked(hwndDlg, IDC_OVERWRITE) ? FILERESUME_OVERWRITEALL : FILERESUME_RENAMEALL)))); - return TRUE; - } - break; - } - return FALSE; -} - -int FileOptInitialise(WPARAM wParam, LPARAM) -{ - OPTIONSDIALOGPAGE odp = { sizeof(odp) }; - odp.position = 900000000; - odp.hInstance = hInst; - odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FILETRANSFER); - odp.pszTitle = LPGEN("File transfers"); - odp.pszGroup = LPGEN("Events"); - odp.pfnDlgProc = DlgProcFileOpts; - odp.flags = ODPF_BOLDGROUPS; - Options_AddPage(wParam, &odp); - return 0; -} diff --git a/src/core/stdfile/filerecvdlg.cpp b/src/core/stdfile/filerecvdlg.cpp deleted file mode 100644 index 8a1ff1b5b7..0000000000 --- a/src/core/stdfile/filerecvdlg.cpp +++ /dev/null @@ -1,426 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "commonheaders.h" -#include "file.h" - -#define MAX_MRU_DIRS 5 - -static BOOL CALLBACK ClipSiblingsChildEnumProc(HWND hwnd, LPARAM) -{ - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE)|WS_CLIPSIBLINGS); - return TRUE; -} - -static void GetLowestExistingDirName(const TCHAR *szTestDir, TCHAR *szExistingDir, int cchExistingDir) -{ - DWORD dwAttributes; - TCHAR *pszLastBackslash; - - mir_tstrncpy(szExistingDir, szTestDir, cchExistingDir); - while ((dwAttributes = GetFileAttributes(szExistingDir)) != INVALID_FILE_ATTRIBUTES && !(dwAttributes&FILE_ATTRIBUTE_DIRECTORY)) { - pszLastBackslash = _tcsrchr(szExistingDir, '\\'); - if (pszLastBackslash == NULL) { *szExistingDir = '\0'; break; } - *pszLastBackslash = '\0'; - } - if (szExistingDir[0] == '\0') - GetCurrentDirectory(cchExistingDir, szExistingDir); -} - -static const TCHAR InvalidFilenameChars[] = _T("\\/:*?\"<>|"); -void RemoveInvalidFilenameChars(TCHAR *tszString) -{ - size_t i; - if (tszString) { - for (i = _tcscspn(tszString, InvalidFilenameChars); tszString[i]; i+=_tcscspn(tszString+i+1, InvalidFilenameChars)+1) - if (tszString[i] >= 0) - tszString[i] = _T('_'); - } -} - -static const TCHAR InvalidPathChars[] = _T("*?\"<>|"); // "\/:" are excluded as they are allowed in file path -void RemoveInvalidPathChars(TCHAR *tszString) -{ - if (tszString) - for (size_t i = _tcscspn(tszString, InvalidPathChars); tszString[i]; i += _tcscspn(tszString + i + 1, InvalidPathChars) + 1) - if (tszString[i] >= 0) - tszString[i] = _T('_'); -} - -static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) -{ - TCHAR szDir[MAX_PATH]; - switch (uMsg) { - case BFFM_INITIALIZED: - SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); - break; - case BFFM_SELCHANGED: - if (SHGetPathFromIDList((LPITEMIDLIST)lp, szDir)) - SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir); - break; - } - return 0; -} - -int BrowseForFolder(HWND hwnd, TCHAR *szPath) -{ - BROWSEINFO bi = { 0 }; - bi.hwndOwner = hwnd; - bi.pszDisplayName = szPath; - bi.lpszTitle = TranslateT("Select folder"); - bi.ulFlags = BIF_NEWDIALOGSTYLE|BIF_EDITBOX|BIF_RETURNONLYFSDIRS; // Use this combo instead of BIF_USENEWUI - bi.lpfn = BrowseCallbackProc; - bi.lParam = (LPARAM)szPath; - - LPITEMIDLIST pidlResult = SHBrowseForFolder(&bi); - if (pidlResult) { - SHGetPathFromIDList(pidlResult, szPath); - mir_tstrcat(szPath, _T("\\")); - CoTaskMemFree(pidlResult); - } - return pidlResult != NULL; -} - -static REPLACEVARSARRAY sttVarsToReplace[] = -{ - { (TCHAR*)"///", (TCHAR*)"//" }, - { (TCHAR*)"//", (TCHAR*)"/" }, - { (TCHAR*)"()", (TCHAR*)"" }, - { NULL, NULL } -}; - -static void patchDir(TCHAR *str, size_t strSize) -{ - REPLACEVARSDATA dat = { 0 }; - dat.cbSize = sizeof(dat); - dat.dwFlags = RVF_TCHAR; - dat.variables = sttVarsToReplace; - - TCHAR *result = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)str, (LPARAM)&dat); - if (result) { - _tcsncpy(str, result, strSize); - mir_free(result); - } - - size_t len = mir_tstrlen(str); - if (len + 1 < strSize && str[len - 1] != '\\') - mir_tstrcpy(str + len, _T("\\")); -} - -void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL patchVars) -{ - TCHAR tszTemp[MAX_PATH]; - - ptrT tszRecvPath(db_get_tsa(NULL, "SRFile", "RecvFilesDirAdv")); - if (tszRecvPath) - _tcsncpy_s(tszTemp, tszRecvPath, _TRUNCATE); - else - mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files")); - - if (hContact) { - hContact = db_mc_tryMeta(hContact); - - REPLACEVARSDATA dat = { 0 }; - REPLACEVARSARRAY rvaVarsToReplace[4]; - rvaVarsToReplace[0].lptzKey = _T("nick"); - rvaVarsToReplace[0].lptzValue = mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); - rvaVarsToReplace[1].lptzKey = _T("userid"); - rvaVarsToReplace[1].lptzValue = GetContactID(hContact); - rvaVarsToReplace[2].lptzKey = _T("proto"); - rvaVarsToReplace[2].lptzValue = mir_a2t(GetContactProto(hContact)); - rvaVarsToReplace[3].lptzKey = NULL; - rvaVarsToReplace[3].lptzValue = NULL; - for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) - RemoveInvalidFilenameChars(rvaVarsToReplace[i].lptzValue); - - dat.cbSize = sizeof(dat); - dat.dwFlags = RVF_TCHAR; - dat.variables = rvaVarsToReplace; - dat.hContact = hContact; - TCHAR *result = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)tszTemp, (LPARAM)&dat); - if (result) { - _tcsncpy(tszTemp, result, SIZEOF(tszTemp)); - mir_free(result); - for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) - mir_free(rvaVarsToReplace[i].lptzValue); - } - } - - if (patchVars) - patchDir(tszTemp, SIZEOF(tszTemp)); - RemoveInvalidPathChars(tszTemp); - mir_tstrncpy(szDir, tszTemp, cchDir); -} - -void GetReceivedFilesDir(TCHAR *szDir, int cchDir) -{ - TCHAR tszTemp[MAX_PATH]; - - ptrT tszRecvPath(db_get_tsa(NULL, "SRFile", "RecvFilesDirAdv")); - if (tszRecvPath) - _tcsncpy_s(tszTemp, tszRecvPath, _TRUNCATE); - else - mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files")); - - patchDir(tszTemp, SIZEOF(tszTemp)); - RemoveInvalidPathChars(tszTemp); - mir_tstrncpy(szDir, tszTemp, cchDir); -} - -INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - TCHAR szPath[450]; - CLISTEVENT* cle = (CLISTEVENT*)lParam; - - dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData)); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - dat->hContact = cle->hContact; - dat->hDbEvent = cle->hDbEvent; - dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN); - dat->dwTicks = GetTickCount(); - - EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0); - - Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE); - Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); - Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); - Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); - Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); - - TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0); - SetDlgItemText(hwndDlg, IDC_FROM, contactName); - GetContactReceivedFilesDir(dat->hContact, szPath, SIZEOF(szPath), TRUE); - SetDlgItemText(hwndDlg, IDC_FILEDIR, szPath); - SHAutoComplete(GetWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), GW_CHILD), 1); - - for (int i = 0; i < MAX_MRU_DIRS; i++) { - char idstr[32]; - mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i); - - DBVARIANT dbv; - if (db_get_ts(NULL, "SRFile", idstr, &dbv)) - break; - SendDlgItemMessage(hwndDlg, IDC_FILEDIR, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal); - db_free(&dbv); - } - - db_event_markRead(dat->hContact, dat->hDbEvent); - - DBEVENTINFO dbei = { sizeof(dbei) }; - dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); - if (dbei.cbBlob > 4 && dbei.cbBlob <= 8196) { - dbei.pBlob = (PBYTE)alloca(dbei.cbBlob + 1); - db_event_get(dat->hDbEvent, &dbei); - dbei.pBlob[dbei.cbBlob] = 0; - dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; - - char *str = (char*)dbei.pBlob + 4; - ptrT ptszFileName(DbGetEventStringT(&dbei, str)); - SetDlgItemText(hwndDlg, IDC_FILENAMES, ptszFileName); - - unsigned len = (unsigned)strlen(str) + 1; - if (len + 4 < dbei.cbBlob) { - str += len; - ptrT ptszDescription(DbGetEventStringT(&dbei, str)); - SetDlgItemText(hwndDlg, IDC_MSG, ptszDescription); - } - } - else DestroyWindow(hwndDlg); - - TCHAR datetimestr[64]; - tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0); - SetDlgItemText(hwndDlg, IDC_DATE, datetimestr); - - char* szProto = GetContactProto(dat->hContact); - if (szProto) { - int hasName = 0; - char buf[128]; - - CONTACTINFO ci = { 0 }; - ci.cbSize = sizeof(ci); - ci.hContact = dat->hContact; - ci.szProto = szProto; - ci.dwFlag = CNF_UNIQUEID; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - hasName = 1; - strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE); - mir_free(ci.pszVal); - break; - case CNFT_DWORD: - hasName = 1; - mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal); - break; - } - } - if (hasName) - SetDlgItemTextA(hwndDlg, IDC_NAME, buf); - else - SetDlgItemText(hwndDlg, IDC_NAME, contactName); - } - - if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) { - RECT rcBtn1, rcBtn2, rcDateCtrl; - GetWindowRect(GetDlgItem(hwndDlg, IDC_ADD), &rcBtn1); - GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rcBtn2); - GetWindowRect(GetDlgItem(hwndDlg, IDC_DATE), &rcDateCtrl); - SetWindowPos(GetDlgItem(hwndDlg, IDC_DATE), 0, 0, 0, rcDateCtrl.right - rcDateCtrl.left - (rcBtn2.left - rcBtn1.left), rcDateCtrl.bottom - rcDateCtrl.top, SWP_NOZORDER | SWP_NOMOVE); - } - else if (db_get_b(NULL, "SRFile", "AutoAccept", 0)) { - //don't check auto-min here to fix BUG#647620 - PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDOK)); - } - if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) - ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); - } - return TRUE; - - case WM_MEASUREITEM: - return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); - - case WM_DRAWITEM: - { - LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; - if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { - char *szProto = GetContactProto(dat->hContact); - if (szProto) { - HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0); - if (hIcon) { - DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); - DestroyIcon(hIcon); - } } } } - return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); - - case WM_COMMAND: - if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) - break; - - switch (LOWORD(wParam)) { - case IDC_FILEDIRBROWSE: - { - TCHAR szDirName[MAX_PATH], szExistingDirName[MAX_PATH]; - - GetDlgItemText(hwndDlg, IDC_FILEDIR, szDirName, SIZEOF(szDirName)); - GetLowestExistingDirName(szDirName, szExistingDirName, SIZEOF(szExistingDirName)); - if (BrowseForFolder(hwndDlg, szExistingDirName)) - SetDlgItemText(hwndDlg, IDC_FILEDIR, szExistingDirName); - } - break; - - case IDOK: - { //most recently used directories - TCHAR szRecvDir[MAX_PATH], szDefaultRecvDir[MAX_PATH]; - GetDlgItemText(hwndDlg, IDC_FILEDIR, szRecvDir, SIZEOF(szRecvDir)); - RemoveInvalidPathChars(szRecvDir); - GetContactReceivedFilesDir(NULL, szDefaultRecvDir, SIZEOF(szDefaultRecvDir), TRUE); - if (_tcsnicmp(szRecvDir, szDefaultRecvDir, mir_tstrlen(szDefaultRecvDir))) { - char idstr[32]; - int i; - DBVARIANT dbv; - for (i = MAX_MRU_DIRS-2;i>=0;i--) { - mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i); - if (db_get_ts(NULL, "SRFile", idstr, &dbv)) continue; - mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i+1); - db_set_ts(NULL, "SRFile", idstr, dbv.ptszVal); - db_free(&dbv); - } - db_set_ts(NULL, "SRFile", idstr, szRecvDir); - } - } - EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAMES), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIRBROWSE), FALSE); - - GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, SIZEOF(dat->szSavePath)); - GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, SIZEOF(dat->szFilenames)); - GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, SIZEOF(dat->szMsg)); - dat->hwndTransfer = FtMgr_AddTransfer(dat); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - //check for auto-minimize here to fix BUG#647620 - if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && db_get_b(NULL, "SRFile", "AutoMin", 0)) { - ShowWindow(hwndDlg, SW_HIDE); - ShowWindow(hwndDlg, SW_SHOWMINNOACTIVE); - } - DestroyWindow(hwndDlg); - break; - - case IDCANCEL: - if (dat->fs) CallContactService(dat->hContact, PSS_FILEDENYT, (WPARAM)dat->fs, (LPARAM)TranslateT("Canceled")); - dat->fs = NULL; /* the protocol will free the handle */ - DestroyWindow(hwndDlg); - break; - - case IDC_ADD: - { - ADDCONTACTSTRUCT acs = { 0 }; - acs.hContact = dat->hContact; - acs.handleType = HANDLE_CONTACT; - acs.szProto = ""; - CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs); - if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) - ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); - } - break; - - case IDC_USERMENU: - { - RECT rc; - HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); - GetWindowRect((HWND)lParam, &rc); - TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); - DestroyMenu(hMenu); - } - break; - - case IDC_DETAILS: - CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); - break; - - case IDC_HISTORY: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); - break; - } - break; - - case WM_DESTROY: - Window_FreeIcon_IcoLib(hwndDlg); - Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); - Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); - Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); - Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); - - FreeFileDlgData(dat); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; - } - return FALSE; -} diff --git a/src/core/stdfile/filesenddlg.cpp b/src/core/stdfile/filesenddlg.cpp deleted file mode 100644 index 5abc5221ff..0000000000 --- a/src/core/stdfile/filesenddlg.cpp +++ /dev/null @@ -1,370 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "commonheaders.h" -#include -#include -#include "file.h" - -static void SetFileListAndSizeControls(HWND hwndDlg, FileDlgData *dat) -{ - int fileCount = 0, dirCount = 0, i; - __int64 totalSize = 0; - struct _stat statbuf; - TCHAR str[64]; - - for (i = 0; dat->files[i]; i++) { - if (_tstat(dat->files[i], &statbuf) == 0) { - if (statbuf.st_mode & _S_IFDIR) - dirCount++; - else - fileCount++; - totalSize += statbuf.st_size; - } - } - - GetSensiblyFormattedSize(totalSize, str, SIZEOF(str), 0, 1, NULL); - SetDlgItemText(hwndDlg, IDC_TOTALSIZE, str); - if (i > 1) { - TCHAR szFormat[32]; - if (fileCount && dirCount) { - mir_sntprintf(szFormat, SIZEOF(szFormat), _T("%s, %s"), TranslateTS(fileCount == 1 ? _T("%d file") : _T("%d files")), TranslateTS(dirCount == 1 ? _T("%d directory") : _T("%d directories"))); - mir_sntprintf(str, SIZEOF(str), szFormat, fileCount, dirCount); - } - else if (fileCount) { - mir_tstrcpy(szFormat, TranslateT("%d files")); - mir_sntprintf(str, SIZEOF(str), szFormat, fileCount); - } - else { - mir_tstrcpy(szFormat, TranslateT("%d directories")); - mir_sntprintf(str, SIZEOF(str), szFormat, dirCount); - } - SetDlgItemText(hwndDlg, IDC_FILE, str); - } - else SetDlgItemText(hwndDlg, IDC_FILE, dat->files[0]); - - EnableWindow(GetDlgItem(hwndDlg, IDOK), fileCount || dirCount); -} - -static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const TCHAR *buf) -{ - // Make sure that the file matrix is empty (the user may select files several times) - FreeFilesMatrix(&dat->files); - - // Get the file attributes of selection - DWORD dwFileAttributes = GetFileAttributes(buf); - if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) - return; - - // Check if the selection is a directory or a file - if (GetFileAttributes(buf) & FILE_ATTRIBUTE_DIRECTORY) { - const TCHAR *pBuf; - int nNumberOfFiles = 0; - int nTemp; - - // :NOTE: The first string in the buffer is the directory, followed by a - // NULL separated list of all files - - // fileOffset is the offset to the first file. - size_t fileOffset = mir_tstrlen(buf) + 1; - - // Count number of files - pBuf = buf + fileOffset; - while (*pBuf) { - pBuf += mir_tstrlen(pBuf) + 1; - nNumberOfFiles++; - } - - // Allocate memory for a pointer array - if ((dat->files = (TCHAR**)mir_alloc((nNumberOfFiles + 1) * sizeof(TCHAR*))) == NULL) - return; - - // Fill the array - pBuf = buf + fileOffset; - nTemp = 0; - while (*pBuf) { - // Allocate space for path+filename - size_t cbFileNameLen = mir_tstrlen(pBuf); - dat->files[nTemp] = (TCHAR*)mir_alloc(sizeof(TCHAR)*(fileOffset + cbFileNameLen + 1)); - - // Add path to filename and copy into array - memcpy(dat->files[nTemp], buf, (fileOffset - 1)*sizeof(TCHAR)); - dat->files[nTemp][fileOffset - 1] = '\\'; - _tcscpy(dat->files[nTemp] + fileOffset - (buf[fileOffset - 2] == '\\' ? 1 : 0), pBuf); - - // Move pointers to next file... - pBuf += cbFileNameLen + 1; - nTemp++; - } - // Terminate array - dat->files[nNumberOfFiles] = NULL; - } - // ...the selection is a single file - else { - if ((dat->files = (TCHAR **)mir_alloc(2 * sizeof(TCHAR*))) == NULL) // Leaks when aborted - return; - - dat->files[0] = mir_tstrdup(buf); - dat->files[1] = NULL; - } - - // Update dialog text with new file selection - SetFileListAndSizeControls(hwndDlg, dat); -} - -#define M_FILECHOOSEDONE (WM_USER+100) -void __cdecl ChooseFilesThread(void* param) -{ - HWND hwndDlg = (HWND)param; - FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - TCHAR *buf = (TCHAR*)mir_alloc(sizeof(TCHAR) * 32767); - if (buf == NULL) { - PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, (LPARAM)(TCHAR*)NULL); - return; - } - - TCHAR filter[128]; - mir_tstrcpy(filter, TranslateT("All files")); - mir_tstrcat(filter, _T(" (*)")); - TCHAR *pfilter = filter + mir_tstrlen(filter) + 1; - mir_tstrcpy(pfilter, _T("*")); - pfilter = filter + mir_tstrlen(filter) + 1; - pfilter[0] = '\0'; - - OPENFILENAME ofn = { 0 }; - ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; - ofn.hwndOwner = hwndDlg; - ofn.lpstrFilter = filter; - ofn.lpstrFile = buf; *buf = 0; - ofn.nMaxFile = 32767; - ofn.Flags = OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; - - char *szProto = GetContactProto(dat->hContact); - if (!(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_SINGLEFILEONLY)) - ofn.Flags |= OFN_ALLOWMULTISELECT; - - if (GetOpenFileName(&ofn)) - PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, (LPARAM)buf); - else { - mir_free(buf); - PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, NULL); - } -} - -static BOOL CALLBACK ClipSiblingsChildEnumProc(HWND hwnd, LPARAM) -{ - SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | WS_CLIPSIBLINGS); - return TRUE; -} - -static LRESULT CALLBACK SendEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) { - case WM_CHAR: - if (wParam == '\n' && GetKeyState(VK_CONTROL) & 0x8000) { - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - return 0; - } - break; - case WM_SYSCHAR: - if ((wParam == 's' || wParam == 'S') && GetKeyState(VK_MENU) & 0x8000) { - PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); - return 0; - } - break; - } - return mir_callNextSubclass(hwnd, SendEditSubclassProc, msg, wParam, lParam); -} - -INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - { - struct FileSendData *fsd = (struct FileSendData*)lParam; - - dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData)); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - dat->hContact = fsd->hContact; - dat->send = 1; - dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN); - dat->fs = NULL; - dat->dwTicks = GetTickCount(); - - EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0); - mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MSG), SendEditSubclassProc); - - Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE); - Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); - Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); - Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); - - EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); - - if (fsd->ppFiles != NULL && fsd->ppFiles[0] != NULL) { - int totalCount, i; - for (totalCount = 0; fsd->ppFiles[totalCount]; totalCount++); - dat->files = (TCHAR**)mir_alloc(sizeof(TCHAR*)*(totalCount + 1)); // Leaks - for (i = 0; i < totalCount; i++) - dat->files[i] = mir_tstrdup(fsd->ppFiles[i]); - dat->files[totalCount] = NULL; - SetFileListAndSizeControls(hwndDlg, dat); - } - - TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0); - SetDlgItemText(hwndDlg, IDC_TO, contactName); - - char *szProto = GetContactProto(dat->hContact); - if (szProto) { - int hasName = 0; - char buf[128]; - - CONTACTINFO ci = { sizeof(ci) }; - ci.hContact = dat->hContact; - ci.szProto = szProto; - ci.dwFlag = CNF_UNIQUEID; - if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { - switch (ci.type) { - case CNFT_ASCIIZ: - hasName = 1; - strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE); - mir_free(ci.pszVal); - break; - case CNFT_DWORD: - hasName = 1; - mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal); - break; - } - } - - if (hasName) - SetDlgItemTextA(hwndDlg, IDC_NAME, buf); - else - SetDlgItemText(hwndDlg, IDC_NAME, contactName); - } - - if (fsd->ppFiles == NULL) { - EnableWindow(hwndDlg, FALSE); - dat->closeIfFileChooseCancelled = 1; - PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CHOOSE, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDC_CHOOSE)); - } - } - return TRUE; - - case WM_MEASUREITEM: - return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); - - case WM_DRAWITEM: - { - LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; - if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { - char *szProto = GetContactProto(dat->hContact); - if (szProto) { - HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); - if (hIcon) { - DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); - DestroyIcon(hIcon); - } - } - } - } - return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); - - case M_FILECHOOSEDONE: - if (lParam != 0) { - FilenameToFileList(hwndDlg, dat, (TCHAR*)lParam); - mir_free((TCHAR*)lParam); - dat->closeIfFileChooseCancelled = 0; - } - else if (dat->closeIfFileChooseCancelled) - PostMessage(hwndDlg, WM_COMMAND, IDCANCEL, 0); - - EnableWindow(hwndDlg, TRUE); - break; - - case WM_COMMAND: - if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) - break; - - switch (LOWORD(wParam)) { - case IDC_CHOOSE: - EnableWindow(hwndDlg, FALSE); - forkthread(ChooseFilesThread, 0, hwndDlg); - break; - - case IDOK: - NotifyEventHooks(hDlgSucceeded, dat->hContact, (LPARAM)hwndDlg); - - EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE); - EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSE), FALSE); - - GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, SIZEOF(dat->szSavePath)); - GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, SIZEOF(dat->szFilenames)); - GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, SIZEOF(dat->szMsg)); - dat->hwndTransfer = FtMgr_AddTransfer(dat); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - DestroyWindow(hwndDlg); - return TRUE; - - case IDCANCEL: - NotifyEventHooks(hDlgCanceled, dat->hContact, (LPARAM)hwndDlg); - DestroyWindow(hwndDlg); - return TRUE; - - case IDC_USERMENU: - { - HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); - RECT rc; - GetWindowRect((HWND)lParam, &rc); - TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); - DestroyMenu(hMenu); - } - break; - - case IDC_DETAILS: - CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); - return TRUE; - - case IDC_HISTORY: - CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); - return TRUE; - } - break; - - case WM_DESTROY: - Window_FreeIcon_IcoLib(hwndDlg); - Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); - Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); - Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); - - FreeFileDlgData(dat); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - return TRUE; - } - return FALSE; -} diff --git a/src/core/stdfile/filexferdlg.cpp b/src/core/stdfile/filexferdlg.cpp deleted file mode 100644 index b9d5980746..0000000000 --- a/src/core/stdfile/filexferdlg.cpp +++ /dev/null @@ -1,766 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "commonheaders.h" -#include -#include "file.h" - -#define HM_RECVEVENT (WM_USER+10) - -static int CheckVirusScanned(HWND hwnd, FileDlgData *dat, int i) -{ - if (dat->send) return 1; - if (dat->fileVirusScanned == NULL) return 0; - if (dat->fileVirusScanned[i]) return 1; - if (db_get_b(NULL, "SRFile", "WarnBeforeOpening", 1) == 0) return 1; - return IDYES == MessageBox(hwnd, TranslateT("This file has not yet been scanned for viruses. Are you certain you want to open it?"), TranslateT("File received"), MB_YESNO|MB_DEFBUTTON2); -} - -#define M_VIRUSSCANDONE (WM_USER+100) -struct virusscanthreadstartinfo { - TCHAR *szFile; - int returnCode; - HWND hwndReply; -}; - -TCHAR* PFTS_StringToTchar(int flags, const PROTOCHAR* s) -{ - if (flags & PFTS_UTF) - return Utf8DecodeW((char*)s); - if (flags & PFTS_UNICODE) - return mir_tstrdup(s); - return mir_a2t((char*)s); -} - -int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const PROTOCHAR *s, TCHAR *r) -{ - if (ft->flags & PFTS_UTF) { - TCHAR *ts = Utf8DecodeW((char*)s); - int res = _tcscmp(ts, r); - mir_free(ts); - return res; - } - if (ft->flags & PFTS_UNICODE) - return _tcscmp(s, r); - - TCHAR *ts = mir_a2t((char*)s); - int res = _tcscmp(ts, r); - mir_free(ts); - return res; -} - -static void SetOpenFileButtonStyle(HWND hwndButton, int enabled) -{ - EnableWindow(hwndButton, enabled); -} - -void FillSendData(FileDlgData *dat, DBEVENTINFO& dbei) -{ - dbei.cbSize = sizeof(dbei); - dbei.szModule = GetContactProto(dat->hContact); - dbei.eventType = EVENTTYPE_FILE; - dbei.flags = DBEF_SENT; - dbei.timestamp = time(NULL); - char *szFileNames = Utf8EncodeT(dat->szFilenames), *szMsg = Utf8EncodeT(dat->szMsg); - dbei.flags |= DBEF_UTF; - - dbei.cbBlob = int(sizeof(DWORD) + mir_strlen(szFileNames) + mir_strlen(szMsg) + 2); - dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); - *(PDWORD)dbei.pBlob = 0; - mir_strcpy((char*)dbei.pBlob + sizeof(DWORD), szFileNames); - mir_strcpy((char*)dbei.pBlob + sizeof(DWORD) + mir_strlen(szFileNames) + 1, szMsg); - - mir_free(szFileNames), mir_free(szMsg); -} - -static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) -{ - DBVARIANT dbv; - if (!db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv)) { - if (dbv.ptszVal[0]) { - STARTUPINFO si = { 0 }; - si.cb = sizeof(si); - TCHAR *pszReplace = _tcsstr(dbv.ptszVal, _T("%f")); - TCHAR szCmdLine[768]; - if (pszReplace) { - if (info->szFile[_tcslen(info->szFile) - 1] == '\\') - info->szFile[_tcslen(info->szFile) - 1] = '\0'; - *pszReplace = 0; - mir_sntprintf(szCmdLine, SIZEOF(szCmdLine), _T("%s\"%s\"%s"), dbv.ptszVal, info->szFile, pszReplace + 2); - } else - _tcsncpy_s(szCmdLine, dbv.ptszVal, _TRUNCATE); - - PROCESS_INFORMATION pi; - if (CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { - if (WaitForSingleObject(pi.hProcess, 3600 * 1000) == WAIT_OBJECT_0) - PostMessage(info->hwndReply, M_VIRUSSCANDONE, info->returnCode, 0); - CloseHandle(pi.hProcess); - CloseHandle(pi.hThread); - } - } - db_free(&dbv); - } - mir_free(info->szFile); - mir_free(info); -} - -static void SetFilenameControls(HWND hwndDlg, FileDlgData *dat, PROTOFILETRANSFERSTATUS *fts) -{ - TCHAR msg[MAX_PATH]; - TCHAR *fnbuf = NULL, *fn = NULL; - SHFILEINFO shfi = { 0 }; - - if (fts->tszCurrentFile) { - fnbuf = mir_tstrdup(fts->tszCurrentFile); - if ((fn = _tcsrchr(fnbuf, '\\')) == NULL) - fn = fnbuf; - else fn++; - } - - if (dat->hIcon) DestroyIcon(dat->hIcon); dat->hIcon = NULL; - - if (fn && (fts->totalFiles > 1)) { - mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s (%d %s %d)"), - pcli->pfnGetContactDisplayName(fts->hContact, 0), - fn, fts->currentFileNumber + 1, TranslateT("of"), fts->totalFiles); - - SHGetFileInfo(fn, FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); - dat->hIcon = shfi.hIcon; - } - else if (fn) { - mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s"), pcli->pfnGetContactDisplayName(fts->hContact, 0), fn); - - SHGetFileInfo(fn, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); - dat->hIcon = shfi.hIcon; - } - else { - mir_tstrncpy(msg, pcli->pfnGetContactDisplayName(fts->hContact, 0), SIZEOF(msg)); - HICON hIcon = LoadSkinIcon(SKINICON_OTHER_DOWNARROW); - dat->hIcon = CopyIcon(hIcon); - IcoLib_ReleaseIcon(hIcon, NULL); - } - - mir_free(fnbuf); - - SendDlgItemMessage(hwndDlg, IDC_FILEICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIcon); - SetDlgItemText(hwndDlg, IDC_CONTACTNAME, msg); -} - -enum { FTS_TEXT, FTS_PROGRESS, FTS_OPEN }; -static void SetFtStatus(HWND hwndDlg, TCHAR *text, int mode) -{ - SetDlgItemText(hwndDlg, IDC_STATUS, TranslateTS(text)); - SetDlgItemText(hwndDlg, IDC_TRANSFERCOMPLETED, TranslateTS(text)); - - ShowWindow(GetDlgItem(hwndDlg, IDC_STATUS), (mode == FTS_TEXT) ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), (mode == FTS_PROGRESS) ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_TRANSFERCOMPLETED), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_FILEICON), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); -} - -static void HideProgressControls(HWND hwndDlg) -{ - RECT rc; - char buf[64]; - - GetWindowRect(GetDlgItem(hwndDlg, IDC_ALLPRECENTS), &rc); - MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rc, 2); - SetWindowPos(hwndDlg, NULL, 0, 0, 100, rc.bottom + 3, SWP_NOMOVE | SWP_NOZORDER); - ShowWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), SW_HIDE); - - _strtime(buf); - SetDlgItemTextA(hwndDlg, IDC_ALLPRECENTS, buf); - - PostMessage(GetParent(hwndDlg), WM_FT_RESIZE, 0, (LPARAM)hwndDlg); -} - -static int FileTransferDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) -{ - switch (urc->wId) { - case IDC_CONTACTNAME: - case IDC_STATUS: - case IDC_ALLFILESPROGRESS: - case IDC_TRANSFERCOMPLETED: - return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; - case IDC_FRAME: - return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; - case IDC_ALLPRECENTS: - case IDCANCEL: - case IDC_OPENFILE: - case IDC_OPENFOLDER: - return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP; - - case IDC_ALLTRANSFERRED: - urc->rcItem.right = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx) / 3; - return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; - - case IDC_ALLSPEED: - urc->rcItem.right = urc->rcItem.right - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx; - urc->rcItem.left = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left) / 3; - return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; - } - return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; -} - -INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) -{ - FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - TranslateDialogDefault(hwndDlg); - dat = (FileDlgData*)lParam; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); - dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_RECVEVENT); - dat->transferStatus.currentFileNumber = -1; - if (dat->send) { - if (db_mc_isMeta(dat->hContact)) - dat->hContact = db_mc_getMostOnline(dat->hContact); - dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILET, (WPARAM)dat->szMsg, (LPARAM)dat->files); - SetFtStatus(hwndDlg, LPGENT("Request sent, waiting for acceptance..."), FTS_TEXT); - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - dat->waitingForAcceptance = 1; - // hide "open" button since it may cause potential access violations... - ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFILE), SW_HIDE); - ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFOLDER), SW_HIDE); - } - else { //recv - CreateDirectoryTreeT(dat->szSavePath); - dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILEALLOWT, (WPARAM)dat->fs, (LPARAM)dat->szSavePath); - dat->transferStatus.tszWorkingDir = mir_tstrdup(dat->szSavePath); - if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) dat->resumeBehaviour = FILERESUME_ASK; - else dat->resumeBehaviour = db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK); - SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); - } - - /* check we actually got an fs handle back from the protocol */ - if (!dat->fs) { - SetFtStatus(hwndDlg, LPGENT("Unable to initiate transfer."), FTS_TEXT); - dat->waitingForAcceptance = 0; - } - { - LOGFONT lf; - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); - GetObject(hFont, sizeof(lf), &lf); - lf.lfWeight = FW_BOLD; - hFont = CreateFontIndirect(&lf); - SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_SETFONT, (WPARAM)hFont, 0); - - SHFILEINFO shfi = { 0 }; - SHGetFileInfo(_T(""), FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); - dat->hIconFolder = shfi.hIcon; - } - dat->hIcon = NULL; - { - char *szProto = GetContactProto(dat->hContact); - WORD status = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_ONLINE); - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedProtoIcon(szProto, status)); - } - - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Contact menu"), 0); - SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONSETASFLATBTN, TRUE, 0); - - Button_SetIcon_IcoLib(hwndDlg, IDC_OPENFILE, SKINICON_OTHER_DOWNARROW, LPGEN("Open...")); - SendDlgItemMessage(hwndDlg, IDC_OPENFILE, BUTTONSETASPUSHBTN, TRUE, 0); - - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIconFolder); - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Open folder"), 0); - SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONSETASFLATBTN, TRUE, 0); - - Button_SetIcon_IcoLib(hwndDlg, IDCANCEL, SKINICON_OTHER_DELETE, LPGEN("Cancel")); - - SetDlgItemText(hwndDlg, IDC_CONTACTNAME, pcli->pfnGetContactDisplayName(dat->hContact, 0)); - - if (!dat->waitingForAcceptance) SetTimer(hwndDlg, 1, 1000, NULL); - return TRUE; - - case WM_TIMER: - memmove(dat->bytesRecvedHistory + 1, dat->bytesRecvedHistory, sizeof(dat->bytesRecvedHistory) - sizeof(dat->bytesRecvedHistory[0])); - dat->bytesRecvedHistory[0] = dat->transferStatus.totalProgress; - if (dat->bytesRecvedHistorySize < SIZEOF(dat->bytesRecvedHistory)) - dat->bytesRecvedHistorySize++; - - { - TCHAR szSpeed[32], szTime[32], szDisplay[96]; - SYSTEMTIME st; - ULARGE_INTEGER li; - FILETIME ft; - - GetSensiblyFormattedSize((dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) / dat->bytesRecvedHistorySize, szSpeed, SIZEOF(szSpeed), 0, 1, NULL); - if (dat->bytesRecvedHistory[0] == dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) - mir_tstrcpy(szTime, _T("??:??:??")); - else { - li.QuadPart = BIGI(10000000)*(dat->transferStatus.currentFileSize - dat->transferStatus.currentFileProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); - ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; - FileTimeToSystemTime(&ft, &st); - GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); - } - if (dat->bytesRecvedHistory[0] != dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) { - li.QuadPart = BIGI(10000000)*(dat->transferStatus.totalBytes - dat->transferStatus.totalProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); - ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; - FileTimeToSystemTime(&ft, &st); - GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); - } - - mir_sntprintf(szDisplay, SIZEOF(szDisplay), _T("%s/%s (%s %s)"), szSpeed, TranslateT("sec"), szTime, TranslateT("remaining")); - SetDlgItemText(hwndDlg, IDC_ALLSPEED, szDisplay); - } - break; - - case WM_MEASUREITEM: - return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); - - case WM_DRAWITEM: - return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); - - case WM_FT_CLEANUP: - if (!dat->fs) { - PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); - DestroyWindow(hwndDlg); - } - break; - - case WM_COMMAND: - if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) - break; - - switch (LOWORD(wParam)) { - case IDOK: - case IDCANCEL: - PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); - DestroyWindow(hwndDlg); - break; - - case IDC_CONTACT: - { - RECT rc; - HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); - GetWindowRect((HWND)lParam, &rc); - TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); - DestroyMenu(hMenu); - } - break; - - case IDC_TRANSFERCOMPLETED: - if (dat->transferStatus.currentFileNumber <= 1 && CheckVirusScanned(hwndDlg, dat, 0)) { - ShellExecute(NULL, NULL, dat->files[0], NULL, NULL, SW_SHOW); - break; - } - - case IDC_OPENFOLDER: - if (dat) { - TCHAR *path = dat->transferStatus.tszWorkingDir; - if (!path || !path[0]) { - path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); - TCHAR *p = _tcsrchr(path, '\\'); if (p) *p = 0; - } - - if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); - } - break; - - case IDC_OPENFILE: - TCHAR **files; - if (dat->send) { - if (dat->files == NULL) - files = dat->transferStatus.ptszFiles; - else - files = dat->files; - } - else files = dat->files; - - HMENU hMenu = CreatePopupMenu(); - AppendMenu(hMenu, MF_STRING, 1, TranslateT("Open folder")); - AppendMenu(hMenu, MF_SEPARATOR, 0, 0); - - if (files && *files) { - int limit; - TCHAR *pszFilename, *pszNewFileName; - - if (dat->send) - limit = dat->transferStatus.totalFiles; - else - limit = dat->transferStatus.currentFileNumber; - - // Loop over all transfered files and add them to the menu - for (int i = 0; i < limit; i++) { - pszFilename = _tcsrchr(files[i], '\\'); - if (pszFilename == NULL) - pszFilename = files[i]; - else - pszFilename++; - - if (pszFilename) { - size_t cbFileNameLen = _tcslen(pszFilename); - - pszNewFileName = (TCHAR*)mir_alloc(cbFileNameLen * 2 * sizeof(TCHAR)); - TCHAR *p = pszNewFileName; - for (size_t pszlen = 0; pszlen < cbFileNameLen; pszlen++) { - *p++ = pszFilename[pszlen]; - if (pszFilename[pszlen] == '&') - *p++ = '&'; - } - *p = '\0'; - AppendMenu(hMenu, MF_STRING, i + 10, pszNewFileName); - mir_free(pszNewFileName); - } - } - } - - RECT rc; - GetWindowRect((HWND)lParam, &rc); - CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_CHECKED); - int ret = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_RIGHTALIGN, rc.right, rc.bottom, 0, hwndDlg, NULL); - CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_UNCHECKED); - DestroyMenu(hMenu); - - if (ret == 1) { - TCHAR *path = dat->transferStatus.tszWorkingDir; - if (!path || !path[0]) { - path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); - TCHAR *p = _tcsrchr(path, '\\'); - if (p) - *p = 0; - } - - if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); - } - else if (ret && CheckVirusScanned(hwndDlg, dat, ret)) - ShellExecute(NULL, NULL, files[ret - 10], NULL, NULL, SW_SHOW); - } - break; - - case M_FILEEXISTSDLGREPLY: - EnableWindow(hwndDlg, TRUE); - { - PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam; - TCHAR *szOriginalFilename = (TCHAR*)wParam; - char *szProto = GetContactProto(dat->hContact); - - switch (pfr->action) { - case FILERESUME_CANCEL: - if (dat->fs) CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); - dat->fs = NULL; - mir_free(szOriginalFilename); - if (pfr->szFilename) mir_free((char*)pfr->szFilename); - mir_free(pfr); - return 0; - case FILERESUME_RESUMEALL: - case FILERESUME_OVERWRITEALL: - dat->resumeBehaviour = pfr->action; - pfr->action &= ~FILERESUMEF_ALL; - break; - case FILERESUME_RENAMEALL: - pfr->action = FILERESUME_RENAME; - { - TCHAR *pszExtension, *pszFilename; - if ((pszFilename = _tcsrchr(szOriginalFilename, '\\')) == NULL) pszFilename = szOriginalFilename; - if ((pszExtension = _tcsrchr(pszFilename + 1, '.')) == NULL) pszExtension = pszFilename + mir_tstrlen(pszFilename); - if (pfr->szFilename) mir_free((TCHAR*)pfr->szFilename); - size_t size = (pszExtension - szOriginalFilename) + 21 + mir_tstrlen(pszExtension); - pfr->szFilename = (TCHAR*)mir_alloc(sizeof(TCHAR)*size); - for (int i = 1;; i++) { - mir_sntprintf((TCHAR*)pfr->szFilename, size, _T("%.*s (%u)%s"), pszExtension - szOriginalFilename, szOriginalFilename, i, pszExtension); - if (_taccess(pfr->szFilename, 0) != 0) - break; - } - } - break; - } - mir_free(szOriginalFilename); - CallProtoService(szProto, PS_FILERESUMET, (WPARAM)dat->fs, (LPARAM)pfr); - if (pfr->szFilename) mir_free((char*)pfr->szFilename); - mir_free(pfr); - } - break; - - case HM_RECVEVENT: - { - ACKDATA *ack = (ACKDATA*)lParam; - if (ack->hProcess != dat->fs) break; - if (ack->type != ACKTYPE_FILE) break; - if (ack->hContact != dat->hContact) break; - - if (dat->waitingForAcceptance) { - SetTimer(hwndDlg, 1, 1000, NULL); - dat->waitingForAcceptance = 0; - } - - switch (ack->result) { - case ACKRESULT_SENTREQUEST: SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; - case ACKRESULT_CONNECTING: SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; - case ACKRESULT_CONNECTPROXY: SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; - case ACKRESULT_CONNECTED: SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; - case ACKRESULT_LISTENING: SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; - case ACKRESULT_INITIALISING: SetFtStatus(hwndDlg, LPGENT("Initializing..."), FTS_TEXT); break; - case ACKRESULT_NEXTFILE: - SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); - SetDlgItemTextA(hwndDlg, IDC_FILENAME, ""); - if (dat->transferStatus.currentFileNumber == 1 && dat->transferStatus.totalFiles > 1 && !dat->send) - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - if (dat->transferStatus.currentFileNumber != -1 && dat->files && !dat->send && db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE) == VIRUSSCAN_DURINGDL) { - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) - PostMessage(hwndDlg, M_VIRUSSCANDONE, dat->transferStatus.currentFileNumber, 0); - else { - virusscanthreadstartinfo *vstsi; - vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); - vstsi->hwndReply = hwndDlg; - vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); - vstsi->returnCode = dat->transferStatus.currentFileNumber; - forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); - } - } - break; - - case ACKRESULT_FILERESUME: - UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS*)ack->lParam); - { - PROTOFILETRANSFERSTATUS *fts = &dat->transferStatus; - SetFilenameControls(hwndDlg, dat, fts); - if (_taccess(fts->tszCurrentFile, 0)) - break; - - SetFtStatus(hwndDlg, LPGENT("File already exists"), FTS_TEXT); - if (dat->resumeBehaviour == FILERESUME_ASK) { - TDlgProcFileExistsParam param = { hwndDlg, fts }; - ShowWindow(hwndDlg, SW_SHOWNORMAL); - CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILEEXISTS), hwndDlg, DlgProcFileExists, (LPARAM)¶m); - EnableWindow(hwndDlg, FALSE); - } - else { - PROTOFILERESUME *pfr = (PROTOFILERESUME*)mir_alloc(sizeof(PROTOFILERESUME)); - pfr->action = dat->resumeBehaviour; - pfr->szFilename = NULL; - PostMessage(hwndDlg, M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfr); - } - } - SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1); - return TRUE; - - case ACKRESULT_DATA: - { - PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)ack->lParam; - TCHAR str[64], str2[64], szSizeDone[32], szSizeTotal[32];//, *contactName; - - if (dat->fileVirusScanned == NULL) - dat->fileVirusScanned = (int*)mir_calloc(sizeof(int) * fts->totalFiles); - - // This needs to be here - otherwise we get holes in the files array - if (!dat->send) { - if (dat->files == NULL) - dat->files = (TCHAR**)mir_calloc((fts->totalFiles + 1) * sizeof(TCHAR*)); - if (fts->currentFileNumber < fts->totalFiles && dat->files[fts->currentFileNumber] == NULL) - dat->files[fts->currentFileNumber] = PFTS_StringToTchar(fts->flags, fts->tszCurrentFile); - } - - /* HACK: for 0.3.3, limit updates to around 1.1 ack per second */ - if (fts->totalProgress != fts->totalBytes && GetTickCount() < (dat->dwTicks + 650)) - break; // the last update was less than a second ago! - dat->dwTicks = GetTickCount(); - - // Update local transfer status with data from protocol - UpdateProtoFileTransferStatus(&dat->transferStatus, fts); - fts = &dat->transferStatus; - - bool firstTime = false; - if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), GWL_STYLE) & WS_VISIBLE) == 0) { - SetFtStatus(hwndDlg, (fts->flags & PFTS_SENDING) ? LPGENT("Sending...") : LPGENT("Receiving..."), FTS_PROGRESS); - SetFilenameControls(hwndDlg, dat, fts); - firstTime = true; - } - - const unsigned long lastPos = SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_GETPOS, 0, 0); - const unsigned long nextPos = fts->totalBytes ? (BIGI(100) * fts->totalProgress / fts->totalBytes) : 0; - if (lastPos != nextPos || firstTime) { - SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_SETPOS, nextPos, 0); - mir_sntprintf(str, SIZEOF(str), _T("%u%%"), nextPos); - SetDlgItemText(hwndDlg, IDC_ALLPRECENTS, str); - } - - int units; - GetSensiblyFormattedSize(fts->totalBytes, szSizeTotal, SIZEOF(szSizeTotal), 0, 1, &units); - GetSensiblyFormattedSize(fts->totalProgress, szSizeDone, SIZEOF(szSizeDone), units, 0, NULL); - mir_sntprintf(str, SIZEOF(str), _T("%s/%s"), szSizeDone, szSizeTotal); - str2[0] = 0; - GetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str2, SIZEOF(str2)); - if (_tcscmp(str, str2)) - SetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str); - } - break; - - case ACKRESULT_SUCCESS: - case ACKRESULT_FAILED: - case ACKRESULT_DENIED: - HideProgressControls(hwndDlg); - KillTimer(hwndDlg, 1); - if (!dat->send) - SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); - SetDlgItemText(hwndDlg, IDCANCEL, TranslateT("Close")); - if (dat->hNotifyEvent) - UnhookEvent(dat->hNotifyEvent); - dat->hNotifyEvent = NULL; - - if (ack->result == ACKRESULT_DENIED) { - dat->fs = NULL; /* protocol will free structure */ - SkinPlaySound("FileDenied"); - SetFtStatus(hwndDlg, LPGENT("File transfer denied"), FTS_TEXT); - } - else if (ack->result == ACKRESULT_FAILED) { - dat->fs = NULL; /* protocol will free structure */ - SkinPlaySound("FileFailed"); - SetFtStatus(hwndDlg, LPGENT("File transfer failed"), FTS_TEXT); - } - else { - SkinPlaySound("FileDone"); - if (dat->send) { - dat->fs = NULL; /* protocol will free structure */ - SetFtStatus(hwndDlg, LPGENT("Transfer completed."), FTS_TEXT); - - DBEVENTINFO dbei = { 0 }; - FillSendData(dat, dbei); - db_event_add(dat->hContact, &dbei); - if (dbei.pBlob) - mir_free(dbei.pBlob); - dat->files = NULL; //protocol library frees this - } - else { - SetFtStatus(hwndDlg, - (dat->transferStatus.totalFiles == 1) ? - LPGENT("Transfer completed, open file.") : - LPGENT("Transfer completed, open folder."), - FTS_OPEN); - - int useScanner = db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE); - if (useScanner != VIRUSSCAN_DISABLE) { - struct virusscanthreadstartinfo *vstsi; - vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); - vstsi->hwndReply = hwndDlg; - if (useScanner == VIRUSSCAN_DURINGDL) { - vstsi->returnCode = dat->transferStatus.currentFileNumber; - if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) { - PostMessage(hwndDlg, M_VIRUSSCANDONE, vstsi->returnCode, 0); - mir_free(vstsi); - vstsi = NULL; - } - else vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); - } - else { - vstsi->szFile = mir_tstrdup(dat->transferStatus.tszWorkingDir); - vstsi->returnCode = -1; - } - SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT); - if (vstsi) - forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); - } - else dat->fs = NULL; /* protocol will free structure */ - - dat->transferStatus.currentFileNumber = dat->transferStatus.totalFiles; - } // else dat->send - - } // else ack->result - - PostMessage(GetParent(hwndDlg), WM_FT_COMPLETED, ack->result, (LPARAM)hwndDlg); - break; - } // switch ack->result - } // case HM_RECVEVENT - break; - - case M_VIRUSSCANDONE: - { - int done = 1; - if ((int)wParam == -1) { - for (int i = 0; i < dat->transferStatus.totalFiles; i++) - dat->fileVirusScanned[i] = 1; - } - else { - dat->fileVirusScanned[wParam] = 1; - for (int i = 0; i < dat->transferStatus.totalFiles; i++) - if (!dat->fileVirusScanned[i]) { - done = 0; - break; - } - } - if (done) { - dat->fs = NULL; /* protocol will free structure */ - SetFtStatus(hwndDlg, LPGENT("Transfer and virus scan complete"), FTS_TEXT); - } - } - break; - - case WM_SIZE: - { - UTILRESIZEDIALOG urd = { 0 }; - urd.cbSize = sizeof(urd); - urd.hwndDlg = hwndDlg; - urd.hInstance = hInst; - urd.lpTemplate = MAKEINTRESOURCEA(IDD_FILETRANSFERINFO); - urd.pfnResizer = FileTransferDlgResizer; - CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); - } - RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_CONTACTNAME), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); - RedrawWindow(GetDlgItem(hwndDlg, IDC_STATUS), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); - break; - - case WM_DESTROY: - KillTimer(hwndDlg, 1); - - HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); - DeleteObject(hFont); - - Button_FreeIcon_IcoLib(hwndDlg, IDC_CONTACT); - Button_FreeIcon_IcoLib(hwndDlg, IDC_OPENFILE); - Button_FreeIcon_IcoLib(hwndDlg, IDCANCEL); - - FreeFileDlgData(dat); - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - break; - } - return FALSE; -} - -void FreeFileDlgData(FileDlgData* dat) -{ - if (dat == NULL) - return; - - if (dat->fs) - CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); - if (dat->hPreshutdownEvent) - UnhookEvent(dat->hPreshutdownEvent); - if (dat->hNotifyEvent) - UnhookEvent(dat->hNotifyEvent); - - FreeProtoFileTransferStatus(&dat->transferStatus); - FreeFilesMatrix(&dat->files); - - mir_free(dat->fileVirusScanned); - if (dat->hIcon) - DestroyIcon(dat->hIcon); - if (dat->hIconFolder) - DestroyIcon(dat->hIconFolder); - mir_free(dat); -} diff --git a/src/core/stdfile/ftmanager.cpp b/src/core/stdfile/ftmanager.cpp deleted file mode 100644 index 9788776091..0000000000 --- a/src/core/stdfile/ftmanager.cpp +++ /dev/null @@ -1,534 +0,0 @@ -/* - -Miranda NG: the free IM client for Microsoft* Windows* - -Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), -Copyright (c) 2000-12 Miranda IM project, -all portions of this codebase are copyrighted to the people -listed in contributors.txt. - -This program is free software; you can redistribute it and/or -modify it under the terms of the GNU General Public License -as published by the Free Software Foundation; either version 2 -of the License, or (at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License -along with this program; if not, write to the Free Software -Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -*/ - -#include "commonheaders.h" -#include "file.h" - -static HWND hwndFtMgr = NULL; - -struct TFtMgrData -{ - HWND hwndIncoming; - HWND hwndOutgoing; - - HANDLE hhkPreshutdown; - TBPFLAG errorState; -}; - -#define M_CALCPROGRESS (WM_USER + 200) - -struct TFtProgressData -{ - unsigned int init, run, scan; - unsigned __int64 totalBytes, totalProgress; -}; - -struct TLayoutWindowInfo -{ - HWND hwnd; - RECT rc; -}; - -struct TLayoutWindowList -{ - struct TLayoutWindowInfo **items; - int realCount, limit, increment; - FSortFunc sortFunc; -}; - -struct TFtPageData -{ - struct TLayoutWindowList *wnds; - int runningCount; - int height, dataHeight, scrollPos; -}; - -static void LayoutTransfers(HWND hwnd, struct TFtPageData *dat) -{ - int top = 0; - RECT rc; - GetClientRect(hwnd, &rc); - - dat->scrollPos = GetScrollPos(hwnd, SB_VERT); - dat->height = rc.bottom - rc.top; - - if (dat->wnds->realCount) { - HDWP hdwp = BeginDeferWindowPos(dat->wnds->realCount); - top -= dat->scrollPos; - for (int i = 0; i < dat->wnds->realCount; ++i) { - int height = dat->wnds->items[i]->rc.bottom - dat->wnds->items[i]->rc.top; - hdwp = DeferWindowPos(hdwp, dat->wnds->items[i]->hwnd, NULL, 0, top, rc.right, height, SWP_NOZORDER); - top += height; - } - top += dat->scrollPos; - EndDeferWindowPos(hdwp); - } - - dat->dataHeight = top; - - SCROLLINFO si = { 0 }; - si.cbSize = sizeof(si); - si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_RANGE; - si.nPage = dat->height; - si.nMin = 0; - si.nMax = dat->dataHeight; - SetScrollInfo(hwnd, SB_VERT, &si, TRUE); -} - -static INT_PTR CALLBACK FtMgrPageDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - struct TFtPageData *dat = (struct TFtPageData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - int i; - - switch (msg) { - case WM_INITDIALOG: - { - // Force scrollbar visibility - SCROLLINFO si = {0}; - si.cbSize = sizeof(si); - si.fMask = SIF_DISABLENOSCROLL; - SetScrollInfo(hwnd, SB_VERT, &si, TRUE); - - dat = (struct TFtPageData *)mir_alloc(sizeof(struct TFtPageData)); - dat->wnds = (struct TLayoutWindowList *)List_Create(0, 1); - dat->scrollPos = 0; - dat->runningCount = 0; - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); - } - break; - - case WM_FT_ADD: - { - TLayoutWindowInfo *wnd = (struct TLayoutWindowInfo *)mir_alloc(sizeof(struct TLayoutWindowInfo)); - wnd->hwnd = (HWND)lParam; - GetWindowRect(wnd->hwnd, &wnd->rc); - List_Insert((SortedList *)dat->wnds, wnd, dat->wnds->realCount); - LayoutTransfers(hwnd, dat); - dat->runningCount++; - PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); - } - break; - - case WM_FT_RESIZE: - for (i=0; i < dat->wnds->realCount; ++i) - if (dat->wnds->items[i]->hwnd == (HWND)lParam) { - GetWindowRect(dat->wnds->items[i]->hwnd, &dat->wnds->items[i]->rc); - break; - } - LayoutTransfers(hwnd, dat); - break; - - case WM_FT_REMOVE: - for (i=0; i < dat->wnds->realCount; ++i) - if (dat->wnds->items[i]->hwnd == (HWND)lParam) { - mir_free(dat->wnds->items[i]); - List_Remove((SortedList *)dat->wnds, i); - break; - } - LayoutTransfers(hwnd, dat); - break; - - case WM_FT_COMPLETED: - //wParam: { ACKRESULT_SUCCESS | ACKRESULT_FAILED | ACKRESULT_DENIED } - dat->runningCount--; - for (i=0; i < dat->wnds->realCount; i++) { - // no error when canceling (WM_FT_REMOVE is send first, check if hwnd is still registered) - if (dat->wnds->items[i]->hwnd == (HWND)lParam) { - SendMessage(GetParent(hwnd), WM_TIMER, 1, (LPARAM)wParam); - break; - } - } - if (i == dat->wnds->realCount) - PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); - - if(dat->runningCount == 0 && wParam == ACKRESULT_SUCCESS && db_get_b(NULL, "SRFile", "AutoClose", 0)) - ShowWindow(hwndFtMgr, SW_HIDE); - break; - - case WM_FT_CLEANUP: - for (i=0; i < dat->wnds->realCount; ++i) - SendMessage(dat->wnds->items[i]->hwnd, WM_FT_CLEANUP, wParam, lParam); - break; - - case WM_SIZE: - LayoutTransfers(hwnd, dat); - break; - - case WM_MOUSEWHEEL: - { - int zDelta = GET_WHEEL_DELTA_WPARAM(wParam); - if (zDelta) { - int nScrollLines = 0; - SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, (void*)&nScrollLines, 0); - for (i=0; i < (nScrollLines + 1) / 2; i++) - SendMessage(hwnd, WM_VSCROLL, (zDelta < 0) ? SB_LINEDOWN : SB_LINEUP, 0); - } - - SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0); - return TRUE; - } - - case WM_VSCROLL: - { - int pos = dat->scrollPos; - switch (LOWORD(wParam)) { - case SB_LINEDOWN: - pos += 15; - break; - case SB_LINEUP: - pos -= 15; - break; - case SB_PAGEDOWN: - pos += dat->height - 10; - break; - case SB_PAGEUP: - pos -= dat->height - 10; - break; - case SB_THUMBTRACK: - pos = HIWORD(wParam); - break; - } - - if (pos > dat->dataHeight - dat->height) pos = dat->dataHeight - dat->height; - if (pos < 0) pos = 0; - - if (dat->scrollPos != pos) { - ScrollWindow(hwnd, 0, dat->scrollPos - pos, NULL, NULL); - SetScrollPos(hwnd, SB_VERT, pos, TRUE); - dat->scrollPos = pos; - } - break; - } - - case M_PRESHUTDOWN: - for (i=0; i < dat->wnds->realCount; ++i) - PostMessage(dat->wnds->items[i]->hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), 0); - break; - - case M_CALCPROGRESS: - { - TFtProgressData *prg = (TFtProgressData *)wParam; - for (i=0; i < dat->wnds->realCount; ++i) { - FileDlgData *trdat = (FileDlgData *)GetWindowLongPtr(dat->wnds->items[i]->hwnd, GWLP_USERDATA); - if (trdat->transferStatus.totalBytes && trdat->fs && !trdat->send && (trdat->transferStatus.totalBytes == trdat->transferStatus.totalProgress)) - prg->scan++; - else if (trdat->transferStatus.totalBytes && trdat->fs) { // in progress - prg->run++; - prg->totalBytes += trdat->transferStatus.totalBytes; - prg->totalProgress += trdat->transferStatus.totalProgress; - } - else if (trdat->fs) // starting - prg->init++; - } - } - break; - - case WM_DESTROY: - for (i=0; i < dat->wnds->realCount; ++i) - mir_free(dat->wnds->items[i]); - List_Destroy((SortedList *)dat->wnds); - mir_free(dat->wnds); - mir_free(dat); - break; - } - - return FALSE; -} - -static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - struct TFtMgrData *dat = (struct TFtMgrData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); - - switch (msg) { - case WM_INITDIALOG: - { - TCITEM tci = {0}; - HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); - - TranslateDialogDefault(hwnd); - Window_SetIcon_IcoLib(hwnd, SKINICON_EVENT_FILE); - - dat = (struct TFtMgrData *)mir_calloc(sizeof(struct TFtMgrData)); - - SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); - - dat->hhkPreshutdown = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwnd, M_PRESHUTDOWN); - - dat->hwndIncoming = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc); - dat->hwndOutgoing = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc); - ShowWindow(dat->hwndIncoming, SW_SHOW); - - tci.mask = TCIF_PARAM|TCIF_TEXT; - tci.pszText = TranslateT("Incoming"); - tci.lParam = (LPARAM)dat->hwndIncoming; - TabCtrl_InsertItem(hwndTab, 0, &tci); - tci.pszText = TranslateT("Outgoing"); - tci.lParam = (LPARAM)dat->hwndOutgoing; - TabCtrl_InsertItem(hwndTab, 1, &tci); - - // Utils_RestoreWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_"); - SAVEWINDOWPOS swp; - swp.hwnd = hwnd; swp.hContact = NULL; swp.szModule = "SRFile"; swp.szNamePrefix = "FtMgrDlg_"; - CallService(MS_UTILS_RESTOREWINDOWPOSITION, RWPF_NOACTIVATE, (LPARAM)&swp); - - // Fall through to setup initial placement - } - case WM_SIZE: - { - RECT rc, rcButton; - HDWP hdwp; - HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); - - GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rcButton); - OffsetRect(&rcButton, -rcButton.left, -rcButton.top); - - GetClientRect(hwnd, &rc); - InflateRect(&rc, -6, -6); - - hdwp = BeginDeferWindowPos(3); - - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_CLEAR), NULL, rc.left, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE); - hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDCANCEL), NULL, rc.right-rcButton.right, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE); - - rc.bottom -= rcButton.bottom + 5; - - hdwp = DeferWindowPos(hdwp, hwndTab, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); - - EndDeferWindowPos(hdwp); - - GetWindowRect(hwndTab, &rc); - MapWindowPoints(NULL, hwnd, (LPPOINT)&rc, 2); - TabCtrl_AdjustRect(hwndTab, FALSE, &rc); - InflateRect(&rc, -5, -5); - - hdwp = BeginDeferWindowPos(2); - - hdwp = DeferWindowPos(hdwp, dat->hwndIncoming, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0); - hdwp = DeferWindowPos(hdwp, dat->hwndOutgoing, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0); - - EndDeferWindowPos(hdwp); - - break; - } - - case WM_MOUSEWHEEL: - if (IsWindowVisible(dat->hwndIncoming)) SendMessage(dat->hwndIncoming, msg, wParam, lParam); - if (IsWindowVisible(dat->hwndOutgoing)) SendMessage(dat->hwndOutgoing, msg, wParam, lParam); - break; - - case WM_FT_SELECTPAGE: - { - TCITEM tci = {0}; - HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); - - if (TabCtrl_GetCurSel(hwndTab) == (int)wParam) break; - - tci.mask = TCIF_PARAM; - - TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); - ShowWindow((HWND)tci.lParam, SW_HIDE); - - TabCtrl_SetCurSel(hwndTab, wParam); - - TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); - ShowWindow((HWND)tci.lParam, SW_SHOW); - } - break; - - case WM_GETMINMAXINFO: - { - LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam; - lpmmi->ptMinTrackSize.x = 300; - lpmmi->ptMinTrackSize.y = 400; - return 0; - } - - case WM_COMMAND: - switch (LOWORD(wParam)) { - case IDCANCEL: - PostMessage(hwnd, WM_CLOSE , 0, 0); - break; - - case IDC_CLEAR: - PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0); - PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0); - break; - } - break; - - case WM_NOTIFY: - switch (((LPNMHDR)lParam)->idFrom) { - case IDC_TABS: - { - HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); - switch (((LPNMHDR)lParam)->code) { - case TCN_SELCHANGING: - { - TCITEM tci = {0}; - tci.mask = TCIF_PARAM; - TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); - ShowWindow((HWND)tci.lParam, SW_HIDE); - break; - } - - case TCN_SELCHANGE: - { - TCITEM tci = {0}; - tci.mask = TCIF_PARAM; - TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); - ShowWindow((HWND)tci.lParam, SW_SHOW); - break; - } - } - break; - } - } - break; - - case M_PRESHUTDOWN: - SendMessage(dat->hwndIncoming, M_PRESHUTDOWN, 0, 0); - SendMessage(dat->hwndOutgoing, M_PRESHUTDOWN, 0, 0); - DestroyWindow(hwnd); - break; - - case WM_CLOSE: - ShowWindow(hwnd, SW_HIDE); - if (db_get_b(NULL, "SRFile", "AutoClear", 1)) { - PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0); - PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0); - } - return TRUE; /* Disable default IDCANCEL notification */ - - case WM_DESTROY: - UnhookEvent(dat->hhkPreshutdown); - Window_FreeIcon_IcoLib(hwnd); - DestroyWindow(dat->hwndIncoming); - DestroyWindow(dat->hwndOutgoing); - mir_free(dat); - SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); - Utils_SaveWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_"); - break; - - case WM_ACTIVATE: - dat->errorState = TBPF_NOPROGRESS; - wParam = 1; - break; - - case WM_SHOWWINDOW: - if ( !wParam) { // hiding - KillTimer(hwnd, 1); - break; - } - lParam = 0; - - case WM_TIMER: - if (pTaskbarInterface) { - SetTimer(hwnd, 1, 400, NULL); - if ((lParam == ACKRESULT_FAILED) || (lParam == ACKRESULT_DENIED)) - dat->errorState = TBPF_ERROR; - - TFtProgressData prg = {0}; - SendMessage(dat->hwndIncoming, M_CALCPROGRESS, (WPARAM)&prg, 0); - SendMessage(dat->hwndOutgoing, M_CALCPROGRESS, (WPARAM)&prg, 0); - if (dat->errorState) { - pTaskbarInterface->SetProgressState(hwnd, dat->errorState); - if ( !prg.run) - pTaskbarInterface->SetProgressValue(hwnd, 1, 1); - } - else if (prg.run) - pTaskbarInterface->SetProgressState(hwnd, TBPF_NORMAL); - else if (prg.init || prg.scan) - pTaskbarInterface->SetProgressState(hwnd, TBPF_INDETERMINATE); - else { - pTaskbarInterface->SetProgressState(hwnd, TBPF_NOPROGRESS); - KillTimer(hwnd, 1); - } - - if (prg.run) - pTaskbarInterface->SetProgressValue(hwnd, prg.totalProgress, prg.totalBytes); - } - break; - } - - return FALSE; -} - -HWND FtMgr_Show(bool bForceActivate, bool bFromMenu) -{ - bool bAutoMin = db_get_b(NULL, "SRFile", "AutoMin", 0) != 0; /* lqbe */ - - bool bJustCreated = (hwndFtMgr == NULL); - if (bJustCreated) - hwndFtMgr = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTMGR), NULL, FtMgrDlgProc); - - if (bFromMenu) { /* lqbe */ - ShowWindow(hwndFtMgr, SW_RESTORE); - ShowWindow(hwndFtMgr, SW_SHOW); - SetForegroundWindow(hwndFtMgr); - return hwndFtMgr; - } - if (bAutoMin && bJustCreated) { /* lqbe */ - ShowWindow(hwndFtMgr, SW_HIDE); - ShowWindow(hwndFtMgr, SW_MINIMIZE); - return hwndFtMgr; - } - if (bForceActivate) { /* lqbe */ - ShowWindow(hwndFtMgr, SW_RESTORE); - ShowWindow(hwndFtMgr, SW_SHOWNOACTIVATE); - SetForegroundWindow(hwndFtMgr); - return hwndFtMgr; - } - if ( !bJustCreated && IsWindowVisible(hwndFtMgr)) - return hwndFtMgr; - - ShowWindow(hwndFtMgr, bAutoMin ? SW_SHOWMINNOACTIVE : SW_SHOWNOACTIVATE); - return hwndFtMgr; -} - -void FtMgr_Destroy() -{ - if (hwndFtMgr) - DestroyWindow(hwndFtMgr); -} - -void FtMgr_ShowPage(int page) -{ - if (hwndFtMgr) - SendMessage(hwndFtMgr, WM_FT_SELECTPAGE, page, 0); -} - -HWND FtMgr_AddTransfer(FileDlgData *fdd) -{ - bool bForceActivate = fdd->send || !db_get_b(NULL, "SRFile", "AutoAccept", 0); - TFtMgrData *dat = (TFtMgrData*)GetWindowLongPtr(FtMgr_Show(bForceActivate, false), GWLP_USERDATA); - if (dat == NULL) - return NULL; - - HWND hwndBox = fdd->send ? dat->hwndOutgoing : dat->hwndIncoming; - HWND hwndFt = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILETRANSFERINFO), hwndBox, DlgProcFileTransfer, (LPARAM)fdd); - ShowWindow(hwndFt, SW_SHOWNA); - SendMessage(hwndBox, WM_FT_ADD, 0, (LPARAM)hwndFt); - FtMgr_ShowPage(fdd->send ? 1 : 0); - return hwndFt; -} diff --git a/src/core/stdfile/main.cpp b/src/core/stdfile/main.cpp deleted file mode 100644 index abf3e56402..0000000000 --- a/src/core/stdfile/main.cpp +++ /dev/null @@ -1,79 +0,0 @@ -/* - -Standard file transfers' plugin for Miranda NG - -Copyright (C) 2012-14 George Hazan - -This program is free software; you can redistribute it and/or modify -it under the terms of the GNU General Public License as published by -the Free Software Foundation; either version 2 of the License, or -(at your option) any later version. - -This program is distributed in the hope that it will be useful, -but WITHOUT ANY WARRANTY; without even the implied warranty of -MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -GNU General Public License for more details. - -You should have received a copy of the GNU General Public License along -with this program; if not, write to the Free Software Foundation, Inc., -51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. -*/ - -#include "commonheaders.h" - -int LoadSendRecvFileModule(void); - -CLIST_INTERFACE* pcli; -TIME_API tmi; -HINSTANCE hInst; -int hLangpack; - -ITaskbarList3 * pTaskbarInterface; - -PLUGININFOEX pluginInfo = { - sizeof(PLUGININFOEX), - __PLUGIN_NAME, - MIRANDA_VERSION_DWORD, - __DESCRIPTION, - __AUTHOR, - __AUTHOREMAIL, - __COPYRIGHT, - __AUTHORWEB, - UNICODE_AWARE, - // 39698dce-7ed4-4334-ac4c-ba8b37a86f13 - { 0x39698dce, 0x7ed4, 0x4334, {0xac, 0x4c, 0xba, 0x8b, 0x37, 0xa8, 0x6f, 0x13}} -}; - -BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) -{ - hInst = hinstDLL; - return TRUE; -} - -extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) -{ - return &pluginInfo; -} - -extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRFILE, MIID_LAST }; - -extern "C" int __declspec(dllexport) Load(void) -{ - mir_getLP(&pluginInfo); - mir_getTMI(&tmi); - mir_getCLI(); - - if ( IsWinVer7Plus()) - CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface); - - LoadSendRecvFileModule(); - return 0; -} - -extern "C" int __declspec(dllexport) Unload(void) -{ - if (pTaskbarInterface) - pTaskbarInterface->Release(); - - return 0; -} diff --git a/src/core/stdfile/res/resource.rc b/src/core/stdfile/res/resource.rc new file mode 100644 index 0000000000..ed986fbaf2 --- /dev/null +++ b/src/core/stdfile/res/resource.rc @@ -0,0 +1,287 @@ +// Microsoft Visual C++ generated resource script. +// +#include "..\..\resource.h" + +#define APSTUDIO_READONLY_SYMBOLS +///////////////////////////////////////////////////////////////////////////// +// +// Generated from the TEXTINCLUDE 2 resource. +// +#include +#include + +///////////////////////////////////////////////////////////////////////////// +#undef APSTUDIO_READONLY_SYMBOLS + +///////////////////////////////////////////////////////////////////////////// +// English (United States) resources + +#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) +LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US +#pragma code_page(1252) + +///////////////////////////////////////////////////////////////////////////// +// +// Dialog +// + +IDD_FILESEND DIALOGEX 0, 0, 256, 177 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Send file(s)" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + EDITTEXT IDC_MSG,6,102,245,46,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL + DEFPUSHBUTTON "&Send",IDOK,67,157,50,15 + PUSHBUTTON "Cancel",IDCANCEL,140,157,50,15 + LTEXT "To:",IDC_STATIC,6,23,24,9,SS_CENTERIMAGE + CONTROL "",IDC_TO,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,43,24,159,9 + LTEXT "File(s):",IDC_STATIC,7,39,30,8 + EDITTEXT IDC_FILE,38,38,213,31,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY + PUSHBUTTON "&Choose again...",IDC_CHOOSE,39,74,77,14 + RTEXT "Total size:",IDC_STATIC,119,76,68,8 + CONTROL "",IDC_TOTALSIZE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,191,76,58,8 + LTEXT "Description:",IDC_STATIC,6,93,96,8 + CONTROL "&User menu",IDC_USERMENU,"MButtonClass",WS_TABSTOP,195,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "User &details",IDC_DETAILS,"MButtonClass",WS_TABSTOP,213,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "&History",IDC_HISTORY,"MButtonClass",WS_TABSTOP,231,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "",IDC_PROTOCOL,"Button",BS_OWNERDRAW | WS_TABSTOP,5,7,12,12 + LTEXT "",IDC_NAME,19,7,151,9,SS_NOPREFIX | SS_CENTERIMAGE +END + +IDD_FILERECV DIALOGEX 0, 0, 256, 174 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "Incoming file transfer" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + DEFPUSHBUTTON "A&ccept",IDOK,68,155,50,14 + PUSHBUTTON "&Decline",IDCANCEL,138,155,50,14 + LTEXT "From:",IDC_STATIC,6,20,24,9,SS_CENTERIMAGE + CONTROL "",IDC_FROM,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,39,21,159,9 + LTEXT "Date:",IDC_STATIC,6,35,28,9,SS_CENTERIMAGE + CONTROL "",IDC_DATE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,39,34,159,9 + LTEXT "Files:",IDC_STATIC,6,50,28,8 + EDITTEXT IDC_FILENAMES,39,50,210,16,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER + LTEXT "Description:",IDC_STATIC,6,69,64,8 + EDITTEXT IDC_MSG,6,79,243,45,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY + LTEXT "Save to:",IDC_STATIC,6,131,34,8 + PUSHBUTTON "...",IDC_FILEDIRBROWSE,235,130,14,10 + COMBOBOX IDC_FILEDIR,45,129,187,108,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP + CONTROL "&Add",IDC_ADD,"MButtonClass",WS_TABSTOP,177,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "&User menu",IDC_USERMENU,"MButtonClass",WS_TABSTOP,195,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "User &details",IDC_DETAILS,"MButtonClass",WS_TABSTOP,213,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "&History",IDC_HISTORY,"MButtonClass",WS_TABSTOP,231,5,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "",IDC_PROTOCOL,"Button",BS_OWNERDRAW | WS_TABSTOP,5,7,12,12 + LTEXT "",IDC_NAME,19,7,151,9,SS_NOPREFIX | SS_CENTERIMAGE +END + +IDD_FILETRANSFERINFO DIALOGEX 0, 0, 256, 44 +STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + CONTROL "&User menu",IDC_CONTACT,"MButtonClass",WS_TABSTOP,5,1,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "",IDC_CONTACTNAME,"Static",SS_LEFTNOWORDWRAP | SS_CENTERIMAGE | SS_WORDELLIPSIS | WS_GROUP,25,1,174,14 + CONTROL "&Open...",IDC_OPENFILE,"MButtonClass",WS_DISABLED | WS_TABSTOP,203,1,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "Open &folder",IDC_OPENFOLDER,"MButtonClass",WS_TABSTOP,219,1,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "&Cancel",IDCANCEL,"MButtonClass",WS_TABSTOP,235,1,16,14,WS_EX_NOACTIVATE | 0x10000000L + CONTROL "",IDC_ALLFILESPROGRESS,"msctls_progress32",PBS_SMOOTH | NOT WS_VISIBLE | WS_DISABLED,25,16,190,12 + CONTROL "",IDC_STATUS,"Static",SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_GROUP,25,17,190,10 + ICON "",IDC_FILEICON,25,15,16,14,SS_CENTERIMAGE | SS_REALSIZEIMAGE + CONTROL "Transfer completed, open file(s).",IDC_TRANSFERCOMPLETED, + "Hyperlink",NOT WS_VISIBLE | WS_TABSTOP,42,17,173,10 + LTEXT "No data transferred",IDC_ALLTRANSFERRED,25,29,226,14,SS_NOPREFIX | SS_CENTERIMAGE + RTEXT "",IDC_ALLSPEED,25,29,226,14,SS_NOPREFIX | SS_CENTERIMAGE + LTEXT "",IDC_ALLPRECENTS,218,14,33,14,SS_CENTERIMAGE + CONTROL "",IDC_FRAME,"Static",SS_ETCHEDHORZ,1,43,254,1 +END + +IDD_FILEEXISTS DIALOGEX 0, 0, 288, 181 +STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT +CAPTION "File already exists" +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + PUSHBUTTON "Resume",IDC_RESUME,5,144,65,14 + PUSHBUTTON "Resume all",IDC_RESUMEALL,5,162,65,14 + PUSHBUTTON "Overwrite",IDC_OVERWRITE,76,144,65,14 + PUSHBUTTON "Overwrite all",IDC_OVERWRITEALL,76,162,65,14 + PUSHBUTTON "Save as...",IDC_SAVEAS,147,144,65,14 + PUSHBUTTON "Auto rename",IDC_AUTORENAME,147,162,65,14 + PUSHBUTTON "Skip",IDC_SKIP,218,144,65,14 + PUSHBUTTON "Cancel transfer",IDCANCEL,218,162,65,14 + LTEXT "You are about to receive the file",IDC_STATIC,5,5,278,8 + EDITTEXT IDC_FILENAME,15,16,268,8,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER + GROUPBOX "Existing file",IDC_STATIC,5,29,278,61 + ICON "",IDC_EXISTINGICON,14,45,20,20,SS_NOTIFY + LTEXT "Size:",IDC_STATIC,40,42,27,8 + LTEXT "",IDC_EXISTINGSIZE,67,42,35,8 + RTEXT "Last modified:",IDC_STATIC,103,42,58,8 + LTEXT "",IDC_EXISTINGDATE,166,42,115,8 + LTEXT "Type:",IDC_STATIC,40,55,27,8 + LTEXT "",IDC_EXISTINGTYPE,67,55,214,8 + PUSHBUTTON "Open file",IDC_OPENFILE,12,70,62,13 + PUSHBUTTON "Open folder",IDC_OPENFOLDER,82,70,62,13 + PUSHBUTTON "File properties",IDC_PROPERTIES,201,70,74,13 + GROUPBOX "File being received",IDC_STATIC,5,95,278,42 + ICON "",IDC_NEWICON,14,110,20,20,SS_NOTIFY + LTEXT "Size:",IDC_STATIC,40,108,27,8 + LTEXT "",IDC_NEWSIZE,67,108,35,8 + RTEXT "Last modified:",IDC_STATIC,103,108,58,8 + LTEXT "",IDC_NEWDATE,166,108,115,8 + LTEXT "Type:",IDC_STATIC,40,121,27,8 + LTEXT "",IDC_NEWTYPE,67,121,214,8 +END + +IDD_FTMGR DIALOGEX 0, 0, 276, 255 +STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME +CAPTION "File transfers" +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN + CONTROL "",IDC_TABS,"SysTabControl32", WS_TABSTOP,7,7,262,224 + PUSHBUTTON "Clear completed",IDC_CLEAR,7,234,100,14 + PUSHBUTTON "Close",IDCANCEL,219,234,50,14 +END + +IDD_FTPAGE DIALOGEX 0, 0, 320, 183 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VSCROLL | WS_SYSMENU +EXSTYLE WS_EX_CONTROLPARENT | WS_EX_STATICEDGE +FONT 8, "MS Shell Dlg", 400, 0, 0x1 +BEGIN +END + +IDD_OPT_FILETRANSFER DIALOGEX 0, 0, 313, 232 +STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE +EXSTYLE WS_EX_CONTROLPARENT +FONT 8, "MS Shell Dlg", 0, 0, 0x1 +BEGIN + GROUPBOX "Receiving files",IDC_STATIC,0,0,313,90 + LTEXT "Received files folder:",IDC_STATIC,8,15,82,8 + EDITTEXT IDC_FILEDIR,92,13,190,12,ES_AUTOHSCROLL + PUSHBUTTON "...",IDC_FILEDIRBROWSE,287,14,15,11 + LTEXT "Variables allowed: %userid%, %nick%, %proto%, %miranda_path%, %userprofile%",IDC_STATIC,8,27,294,11,WS_DISABLED + CONTROL "Auto-accept incoming files from people on my contact list",IDC_AUTOACCEPT, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,39,294,10 + CONTROL "Minimize the file transfer window",IDC_AUTOMIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,52,285,10 + CONTROL "Close window when transfer completes",IDC_AUTOCLOSE, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,65,294,10 + CONTROL "Clear completed transfers on window closing",IDC_AUTOCLEAR, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,76,294,10 + GROUPBOX "Virus scanner",IDC_VIRUSSCANNERGROUP,0,90,313,93 + LTEXT "Scan files:",IDC_STATIC,8,102,43,9,SS_CENTERIMAGE + CONTROL "Never, do not use virus scanning",IDC_NOSCANNER,"Button",BS_AUTORADIOBUTTON,52,102,250,10 + CONTROL "When all files have been downloaded",IDC_SCANAFTERDL, + "Button",BS_AUTORADIOBUTTON,52,114,250,10 + CONTROL "As each file finishes downloading",IDC_SCANDURINGDL, + "Button",BS_AUTORADIOBUTTON,52,126,250,10 + LTEXT "Command line:",IDC_ST_CMDLINE,7,142,62,8 + COMBOBOX IDC_SCANCMDLINE,70,141,213,71,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP + PUSHBUTTON "...",IDC_SCANCMDLINEBROWSE,287,142,15,11 + LTEXT "%f will be replaced by the file or folder name to be scanned",IDC_ST_CMDLINEHELP,70,155,232,8 + CONTROL "Warn me before opening a file that has not been scanned",IDC_WARNBEFOREOPENING, + "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,168,294,10 + GROUPBOX "If incoming files already exist",IDC_STATIC,0,187,313,41 + CONTROL "Ask me",IDC_ASK,"Button",BS_AUTORADIOBUTTON,8,200,73,10 + CONTROL "Resume",IDC_RESUME,"Button",BS_AUTORADIOBUTTON,82,200,125,10 + CONTROL "Overwrite",IDC_OVERWRITE,"Button",BS_AUTORADIOBUTTON,8,212,73,10 + CONTROL "Rename (append "" (1)"", etc.)",IDC_RENAME,"Button",BS_AUTORADIOBUTTON,82,212,125,10 + LTEXT "You will always be asked about files from people not on your contact list",IDC_STATIC,212,198,90,24 +END + +#endif // APSTUDIO_INVOKED + +///////////////////////////////////////////////////////////////////////////// +// +// DESIGNINFO +// + +#ifdef APSTUDIO_INVOKED +GUIDELINES DESIGNINFO +BEGIN + IDD_FILESEND, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 251 + VERTGUIDE, 7 + VERTGUIDE, 249 + TOPMARGIN, 5 + BOTTOMMARGIN, 172 + END + + IDD_FILERECV, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 249 + VERTGUIDE, 7 + VERTGUIDE, 249 + TOPMARGIN, 5 + BOTTOMMARGIN, 169 + END + + IDD_FILETRANSFERINFO, DIALOG + BEGIN + VERTGUIDE, 5 + VERTGUIDE, 25 + VERTGUIDE, 36 + VERTGUIDE, 120 + VERTGUIDE, 180 + VERTGUIDE, 215 + VERTGUIDE, 218 + VERTGUIDE, 235 + VERTGUIDE, 251 + BOTTOMMARGIN, 43 + HORZGUIDE, 14 + HORZGUIDE, 28 + HORZGUIDE, 42 + END + + IDD_FILEEXISTS, DIALOG + BEGIN + LEFTMARGIN, 5 + RIGHTMARGIN, 283 + TOPMARGIN, 5 + BOTTOMMARGIN, 176 + END + + IDD_FTPAGE, DIALOG + BEGIN + LEFTMARGIN, 7 + RIGHTMARGIN, 303 + TOPMARGIN, 7 + BOTTOMMARGIN, 176 + END + + IDD_OPT_FILETRANSFER, DIALOG + BEGIN + VERTGUIDE, 8 + VERTGUIDE, 302 + END +END +#endif // APSTUDIO_INVOKED + +#ifdef APSTUDIO_INVOKED +///////////////////////////////////////////////////////////////////////////// +// +// TEXTINCLUDE +// + +1 TEXTINCLUDE +BEGIN + "..\..\resource.h\0" +END + +2 TEXTINCLUDE +BEGIN + "#include \r\n" + "#include \r\n" + "\0" +END + +3 TEXTINCLUDE +BEGIN + "\r\n" + "\0" +END + +#endif // APSTUDIO_INVOKED diff --git a/src/core/stdfile/res/version.rc b/src/core/stdfile/res/version.rc new file mode 100644 index 0000000000..5bfbab4754 --- /dev/null +++ b/src/core/stdfile/res/version.rc @@ -0,0 +1,38 @@ +// Microsoft Visual C++ generated resource script. +// +#ifdef APSTUDIO_INVOKED +#error this file is not editable by Microsoft Visual C++ +#endif //APSTUDIO_INVOKED + +#include "afxres.h" +#include "..\src\version.h" + +VS_VERSION_INFO VERSIONINFO + FILEVERSION __FILEVERSION_STRING + PRODUCTVERSION __FILEVERSION_STRING + FILEFLAGSMASK 0x17L +#ifdef _DEBUG + FILEFLAGS 0x1L +#else + FILEFLAGS 0x0L +#endif + FILEOS 0x4L + FILETYPE 0x0L + FILESUBTYPE 0x0L +BEGIN + BLOCK "StringFileInfo" + BEGIN + BLOCK "000004b0" + BEGIN + VALUE "FileDescription", __DESCRIPTION + VALUE "InternalName", __PLUGIN_NAME + VALUE "LegalCopyright", __COPYRIGHT + VALUE "OriginalFilename", __FILENAME + VALUE "ProductName", __PLUGIN_NAME + END + END + BLOCK "VarFileInfo" + BEGIN + VALUE "Translation", 0x0, 1200 + END +END diff --git a/src/core/stdfile/resource.rc b/src/core/stdfile/resource.rc deleted file mode 100644 index ed986fbaf2..0000000000 --- a/src/core/stdfile/resource.rc +++ /dev/null @@ -1,287 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#include "..\..\resource.h" - -#define APSTUDIO_READONLY_SYMBOLS -///////////////////////////////////////////////////////////////////////////// -// -// Generated from the TEXTINCLUDE 2 resource. -// -#include -#include - -///////////////////////////////////////////////////////////////////////////// -#undef APSTUDIO_READONLY_SYMBOLS - -///////////////////////////////////////////////////////////////////////////// -// English (United States) resources - -#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) -LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US -#pragma code_page(1252) - -///////////////////////////////////////////////////////////////////////////// -// -// Dialog -// - -IDD_FILESEND DIALOGEX 0, 0, 256, 177 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_3DLOOK | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Send file(s)" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - EDITTEXT IDC_MSG,6,102,245,46,ES_MULTILINE | ES_AUTOVSCROLL | ES_WANTRETURN | WS_VSCROLL - DEFPUSHBUTTON "&Send",IDOK,67,157,50,15 - PUSHBUTTON "Cancel",IDCANCEL,140,157,50,15 - LTEXT "To:",IDC_STATIC,6,23,24,9,SS_CENTERIMAGE - CONTROL "",IDC_TO,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,43,24,159,9 - LTEXT "File(s):",IDC_STATIC,7,39,30,8 - EDITTEXT IDC_FILE,38,38,213,31,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY - PUSHBUTTON "&Choose again...",IDC_CHOOSE,39,74,77,14 - RTEXT "Total size:",IDC_STATIC,119,76,68,8 - CONTROL "",IDC_TOTALSIZE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,191,76,58,8 - LTEXT "Description:",IDC_STATIC,6,93,96,8 - CONTROL "&User menu",IDC_USERMENU,"MButtonClass",WS_TABSTOP,195,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "User &details",IDC_DETAILS,"MButtonClass",WS_TABSTOP,213,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "&History",IDC_HISTORY,"MButtonClass",WS_TABSTOP,231,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "",IDC_PROTOCOL,"Button",BS_OWNERDRAW | WS_TABSTOP,5,7,12,12 - LTEXT "",IDC_NAME,19,7,151,9,SS_NOPREFIX | SS_CENTERIMAGE -END - -IDD_FILERECV DIALOGEX 0, 0, 256, 174 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_VISIBLE | WS_CLIPCHILDREN | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "Incoming file transfer" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - DEFPUSHBUTTON "A&ccept",IDOK,68,155,50,14 - PUSHBUTTON "&Decline",IDCANCEL,138,155,50,14 - LTEXT "From:",IDC_STATIC,6,20,24,9,SS_CENTERIMAGE - CONTROL "",IDC_FROM,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,39,21,159,9 - LTEXT "Date:",IDC_STATIC,6,35,28,9,SS_CENTERIMAGE - CONTROL "",IDC_DATE,"Static",SS_SIMPLE | SS_NOPREFIX | WS_GROUP,39,34,159,9 - LTEXT "Files:",IDC_STATIC,6,50,28,8 - EDITTEXT IDC_FILENAMES,39,50,210,16,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY | NOT WS_BORDER - LTEXT "Description:",IDC_STATIC,6,69,64,8 - EDITTEXT IDC_MSG,6,79,243,45,ES_MULTILINE | ES_AUTOVSCROLL | ES_READONLY - LTEXT "Save to:",IDC_STATIC,6,131,34,8 - PUSHBUTTON "...",IDC_FILEDIRBROWSE,235,130,14,10 - COMBOBOX IDC_FILEDIR,45,129,187,108,CBS_DROPDOWN | CBS_AUTOHSCROLL | WS_VSCROLL | WS_TABSTOP - CONTROL "&Add",IDC_ADD,"MButtonClass",WS_TABSTOP,177,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "&User menu",IDC_USERMENU,"MButtonClass",WS_TABSTOP,195,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "User &details",IDC_DETAILS,"MButtonClass",WS_TABSTOP,213,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "&History",IDC_HISTORY,"MButtonClass",WS_TABSTOP,231,5,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "",IDC_PROTOCOL,"Button",BS_OWNERDRAW | WS_TABSTOP,5,7,12,12 - LTEXT "",IDC_NAME,19,7,151,9,SS_NOPREFIX | SS_CENTERIMAGE -END - -IDD_FILETRANSFERINFO DIALOGEX 0, 0, 256, 44 -STYLE DS_SETFONT | DS_3DLOOK | DS_FIXEDSYS | WS_CHILD -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - CONTROL "&User menu",IDC_CONTACT,"MButtonClass",WS_TABSTOP,5,1,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "",IDC_CONTACTNAME,"Static",SS_LEFTNOWORDWRAP | SS_CENTERIMAGE | SS_WORDELLIPSIS | WS_GROUP,25,1,174,14 - CONTROL "&Open...",IDC_OPENFILE,"MButtonClass",WS_DISABLED | WS_TABSTOP,203,1,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "Open &folder",IDC_OPENFOLDER,"MButtonClass",WS_TABSTOP,219,1,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "&Cancel",IDCANCEL,"MButtonClass",WS_TABSTOP,235,1,16,14,WS_EX_NOACTIVATE | 0x10000000L - CONTROL "",IDC_ALLFILESPROGRESS,"msctls_progress32",PBS_SMOOTH | NOT WS_VISIBLE | WS_DISABLED,25,16,190,12 - CONTROL "",IDC_STATUS,"Static",SS_LEFTNOWORDWRAP | SS_NOPREFIX | WS_GROUP,25,17,190,10 - ICON "",IDC_FILEICON,25,15,16,14,SS_CENTERIMAGE | SS_REALSIZEIMAGE - CONTROL "Transfer completed, open file(s).",IDC_TRANSFERCOMPLETED, - "Hyperlink",NOT WS_VISIBLE | WS_TABSTOP,42,17,173,10 - LTEXT "No data transferred",IDC_ALLTRANSFERRED,25,29,226,14,SS_NOPREFIX | SS_CENTERIMAGE - RTEXT "",IDC_ALLSPEED,25,29,226,14,SS_NOPREFIX | SS_CENTERIMAGE - LTEXT "",IDC_ALLPRECENTS,218,14,33,14,SS_CENTERIMAGE - CONTROL "",IDC_FRAME,"Static",SS_ETCHEDHORZ,1,43,254,1 -END - -IDD_FILEEXISTS DIALOGEX 0, 0, 288, 181 -STYLE DS_SETFONT | DS_MODALFRAME | DS_SETFOREGROUND | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT -CAPTION "File already exists" -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - PUSHBUTTON "Resume",IDC_RESUME,5,144,65,14 - PUSHBUTTON "Resume all",IDC_RESUMEALL,5,162,65,14 - PUSHBUTTON "Overwrite",IDC_OVERWRITE,76,144,65,14 - PUSHBUTTON "Overwrite all",IDC_OVERWRITEALL,76,162,65,14 - PUSHBUTTON "Save as...",IDC_SAVEAS,147,144,65,14 - PUSHBUTTON "Auto rename",IDC_AUTORENAME,147,162,65,14 - PUSHBUTTON "Skip",IDC_SKIP,218,144,65,14 - PUSHBUTTON "Cancel transfer",IDCANCEL,218,162,65,14 - LTEXT "You are about to receive the file",IDC_STATIC,5,5,278,8 - EDITTEXT IDC_FILENAME,15,16,268,8,ES_AUTOHSCROLL | ES_READONLY | NOT WS_BORDER - GROUPBOX "Existing file",IDC_STATIC,5,29,278,61 - ICON "",IDC_EXISTINGICON,14,45,20,20,SS_NOTIFY - LTEXT "Size:",IDC_STATIC,40,42,27,8 - LTEXT "",IDC_EXISTINGSIZE,67,42,35,8 - RTEXT "Last modified:",IDC_STATIC,103,42,58,8 - LTEXT "",IDC_EXISTINGDATE,166,42,115,8 - LTEXT "Type:",IDC_STATIC,40,55,27,8 - LTEXT "",IDC_EXISTINGTYPE,67,55,214,8 - PUSHBUTTON "Open file",IDC_OPENFILE,12,70,62,13 - PUSHBUTTON "Open folder",IDC_OPENFOLDER,82,70,62,13 - PUSHBUTTON "File properties",IDC_PROPERTIES,201,70,74,13 - GROUPBOX "File being received",IDC_STATIC,5,95,278,42 - ICON "",IDC_NEWICON,14,110,20,20,SS_NOTIFY - LTEXT "Size:",IDC_STATIC,40,108,27,8 - LTEXT "",IDC_NEWSIZE,67,108,35,8 - RTEXT "Last modified:",IDC_STATIC,103,108,58,8 - LTEXT "",IDC_NEWDATE,166,108,115,8 - LTEXT "Type:",IDC_STATIC,40,121,27,8 - LTEXT "",IDC_NEWTYPE,67,121,214,8 -END - -IDD_FTMGR DIALOGEX 0, 0, 276, 255 -STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_MINIMIZEBOX | WS_POPUP | WS_CAPTION | WS_SYSMENU | WS_THICKFRAME -CAPTION "File transfers" -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN - CONTROL "",IDC_TABS,"SysTabControl32", WS_TABSTOP,7,7,262,224 - PUSHBUTTON "Clear completed",IDC_CLEAR,7,234,100,14 - PUSHBUTTON "Close",IDCANCEL,219,234,50,14 -END - -IDD_FTPAGE DIALOGEX 0, 0, 320, 183 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VSCROLL | WS_SYSMENU -EXSTYLE WS_EX_CONTROLPARENT | WS_EX_STATICEDGE -FONT 8, "MS Shell Dlg", 400, 0, 0x1 -BEGIN -END - -IDD_OPT_FILETRANSFER DIALOGEX 0, 0, 313, 232 -STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE -EXSTYLE WS_EX_CONTROLPARENT -FONT 8, "MS Shell Dlg", 0, 0, 0x1 -BEGIN - GROUPBOX "Receiving files",IDC_STATIC,0,0,313,90 - LTEXT "Received files folder:",IDC_STATIC,8,15,82,8 - EDITTEXT IDC_FILEDIR,92,13,190,12,ES_AUTOHSCROLL - PUSHBUTTON "...",IDC_FILEDIRBROWSE,287,14,15,11 - LTEXT "Variables allowed: %userid%, %nick%, %proto%, %miranda_path%, %userprofile%",IDC_STATIC,8,27,294,11,WS_DISABLED - CONTROL "Auto-accept incoming files from people on my contact list",IDC_AUTOACCEPT, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,39,294,10 - CONTROL "Minimize the file transfer window",IDC_AUTOMIN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,17,52,285,10 - CONTROL "Close window when transfer completes",IDC_AUTOCLOSE, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,65,294,10 - CONTROL "Clear completed transfers on window closing",IDC_AUTOCLEAR, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,76,294,10 - GROUPBOX "Virus scanner",IDC_VIRUSSCANNERGROUP,0,90,313,93 - LTEXT "Scan files:",IDC_STATIC,8,102,43,9,SS_CENTERIMAGE - CONTROL "Never, do not use virus scanning",IDC_NOSCANNER,"Button",BS_AUTORADIOBUTTON,52,102,250,10 - CONTROL "When all files have been downloaded",IDC_SCANAFTERDL, - "Button",BS_AUTORADIOBUTTON,52,114,250,10 - CONTROL "As each file finishes downloading",IDC_SCANDURINGDL, - "Button",BS_AUTORADIOBUTTON,52,126,250,10 - LTEXT "Command line:",IDC_ST_CMDLINE,7,142,62,8 - COMBOBOX IDC_SCANCMDLINE,70,141,213,71,CBS_DROPDOWN | CBS_AUTOHSCROLL | CBS_SORT | WS_VSCROLL | WS_TABSTOP - PUSHBUTTON "...",IDC_SCANCMDLINEBROWSE,287,142,15,11 - LTEXT "%f will be replaced by the file or folder name to be scanned",IDC_ST_CMDLINEHELP,70,155,232,8 - CONTROL "Warn me before opening a file that has not been scanned",IDC_WARNBEFOREOPENING, - "Button",BS_AUTOCHECKBOX | WS_TABSTOP,8,168,294,10 - GROUPBOX "If incoming files already exist",IDC_STATIC,0,187,313,41 - CONTROL "Ask me",IDC_ASK,"Button",BS_AUTORADIOBUTTON,8,200,73,10 - CONTROL "Resume",IDC_RESUME,"Button",BS_AUTORADIOBUTTON,82,200,125,10 - CONTROL "Overwrite",IDC_OVERWRITE,"Button",BS_AUTORADIOBUTTON,8,212,73,10 - CONTROL "Rename (append "" (1)"", etc.)",IDC_RENAME,"Button",BS_AUTORADIOBUTTON,82,212,125,10 - LTEXT "You will always be asked about files from people not on your contact list",IDC_STATIC,212,198,90,24 -END - -#endif // APSTUDIO_INVOKED - -///////////////////////////////////////////////////////////////////////////// -// -// DESIGNINFO -// - -#ifdef APSTUDIO_INVOKED -GUIDELINES DESIGNINFO -BEGIN - IDD_FILESEND, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 251 - VERTGUIDE, 7 - VERTGUIDE, 249 - TOPMARGIN, 5 - BOTTOMMARGIN, 172 - END - - IDD_FILERECV, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 249 - VERTGUIDE, 7 - VERTGUIDE, 249 - TOPMARGIN, 5 - BOTTOMMARGIN, 169 - END - - IDD_FILETRANSFERINFO, DIALOG - BEGIN - VERTGUIDE, 5 - VERTGUIDE, 25 - VERTGUIDE, 36 - VERTGUIDE, 120 - VERTGUIDE, 180 - VERTGUIDE, 215 - VERTGUIDE, 218 - VERTGUIDE, 235 - VERTGUIDE, 251 - BOTTOMMARGIN, 43 - HORZGUIDE, 14 - HORZGUIDE, 28 - HORZGUIDE, 42 - END - - IDD_FILEEXISTS, DIALOG - BEGIN - LEFTMARGIN, 5 - RIGHTMARGIN, 283 - TOPMARGIN, 5 - BOTTOMMARGIN, 176 - END - - IDD_FTPAGE, DIALOG - BEGIN - LEFTMARGIN, 7 - RIGHTMARGIN, 303 - TOPMARGIN, 7 - BOTTOMMARGIN, 176 - END - - IDD_OPT_FILETRANSFER, DIALOG - BEGIN - VERTGUIDE, 8 - VERTGUIDE, 302 - END -END -#endif // APSTUDIO_INVOKED - -#ifdef APSTUDIO_INVOKED -///////////////////////////////////////////////////////////////////////////// -// -// TEXTINCLUDE -// - -1 TEXTINCLUDE -BEGIN - "..\..\resource.h\0" -END - -2 TEXTINCLUDE -BEGIN - "#include \r\n" - "#include \r\n" - "\0" -END - -3 TEXTINCLUDE -BEGIN - "\r\n" - "\0" -END - -#endif // APSTUDIO_INVOKED diff --git a/src/core/stdfile/src/commonheaders.cpp b/src/core/stdfile/src/commonheaders.cpp new file mode 100644 index 0000000000..95b2201163 --- /dev/null +++ b/src/core/stdfile/src/commonheaders.cpp @@ -0,0 +1,2 @@ +#include "commonheaders.h" + diff --git a/src/core/stdfile/src/commonheaders.h b/src/core/stdfile/src/commonheaders.h new file mode 100644 index 0000000000..058ddb124d --- /dev/null +++ b/src/core/stdfile/src/commonheaders.h @@ -0,0 +1,87 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#define WINVER 0x0700 +#define _WIN32_WINNT 0x0700 +#define _WIN32_IE 0x0601 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "version.h" + +#include "../../resource.h" +#include "../stdplug.h" + +extern HINSTANCE hInst; + +extern ITaskbarList3 * pTaskbarInterface; diff --git a/src/core/stdfile/src/file.cpp b/src/core/stdfile/src/file.cpp new file mode 100644 index 0000000000..10a6269869 --- /dev/null +++ b/src/core/stdfile/src/file.cpp @@ -0,0 +1,444 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include "file.h" + +HANDLE hDlgSucceeded, hDlgCanceled; + +TCHAR* PFTS_StringToTchar(int flags, const PROTOCHAR* s); +int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS* ft, const PROTOCHAR* s, TCHAR *r); + +static HGENMENU hSRFileMenuItem; + +TCHAR* GetContactID(MCONTACT hContact) +{ + char *szProto = GetContactProto(hContact); + if (db_get_b(hContact, szProto, "ChatRoom", 0) == 1) { + if (TCHAR *theValue = db_get_tsa(hContact, szProto, "ChatRoomID")) + return theValue; + } + else { + CONTACTINFO ci = { sizeof(ci) }; + ci.hContact = hContact; + ci.szProto = szProto; + ci.dwFlag = CNF_UNIQUEID | CNF_TCHAR; + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)& ci)) { + switch (ci.type) { + case CNFT_ASCIIZ: + return (TCHAR*)ci.pszVal; + case CNFT_DWORD: + return _itot(ci.dVal, (TCHAR*)mir_alloc(sizeof(TCHAR)*32), 10); + } + } + } + return NULL; +} + +static INT_PTR SendFileCommand(WPARAM hContact, LPARAM) +{ + struct FileSendData fsd; + fsd.hContact = hContact; + fsd.ppFiles = NULL; + return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); +} + +static INT_PTR SendSpecificFiles(WPARAM hContact, LPARAM lParam) +{ + FileSendData fsd; + fsd.hContact = hContact; + + char** ppFiles = (char**)lParam; + int count = 0; + while (ppFiles[count] != NULL) + count++; + + fsd.ppFiles = (const TCHAR**)alloca((count + 1) * sizeof(void*)); + for (int i = 0; i < count; i++) + fsd.ppFiles[i] = mir_a2t(ppFiles[i]); + fsd.ppFiles[count] = NULL; + + HWND hWnd = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); + for (int j = 0; j < count; j++) + mir_free((void*)fsd.ppFiles[j]); + return (INT_PTR)hWnd; +} + +static INT_PTR SendSpecificFilesT(WPARAM hContact, LPARAM lParam) +{ + FileSendData fsd; + fsd.hContact = hContact; + fsd.ppFiles = (const TCHAR**)lParam; + return (INT_PTR)CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILESEND), NULL, DlgProcSendFile, (LPARAM)&fsd); +} + +static INT_PTR GetReceivedFilesFolder(WPARAM wParam, LPARAM lParam) +{ + TCHAR buf[MAX_PATH]; + GetContactReceivedFilesDir(wParam, buf, MAX_PATH, TRUE); + char* dir = mir_t2a(buf); + mir_strncpy((char*)lParam, dir, MAX_PATH); + mir_free(dir); + return 0; +} + +static INT_PTR RecvFileCommand(WPARAM, LPARAM lParam) +{ + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILERECV), NULL, DlgProcRecvFile, lParam); + return 0; +} + +void PushFileEvent(MCONTACT hContact, HANDLE hdbe, LPARAM lParam) +{ + CLISTEVENT cle = { 0 }; + cle.cbSize = sizeof(cle); + cle.hContact = hContact; + cle.hDbEvent = hdbe; + cle.lParam = lParam; + if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && !db_get_b(hContact, "CList", "NotOnList", 0)) { + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILERECV), NULL, DlgProcRecvFile, (LPARAM)&cle); + } + else { + SkinPlaySound("RecvFile"); + + TCHAR szTooltip[256]; + mir_sntprintf(szTooltip, SIZEOF(szTooltip), TranslateT("File from %s"), pcli->pfnGetContactDisplayName(hContact, 0)); + cle.ptszTooltip = szTooltip; + + cle.flags |= CLEF_TCHAR; + cle.hIcon = LoadSkinIcon(SKINICON_EVENT_FILE); + cle.pszService = "SRFile/RecvFile"; + CallService(MS_CLIST_ADDEVENT, 0, (LPARAM)&cle); + } +} + +static int FileEventAdded(WPARAM wParam, LPARAM lParam) +{ + DWORD dwSignature; + + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.cbBlob = sizeof(DWORD); + dbei.pBlob = (PBYTE)&dwSignature; + db_event_get((HANDLE)lParam, &dbei); + if (dbei.flags & (DBEF_SENT | DBEF_READ) || dbei.eventType != EVENTTYPE_FILE || dwSignature == 0) + return 0; + + PushFileEvent(wParam, (HANDLE)lParam, 0); + return 0; +} + +int SRFile_GetRegValue(HKEY hKeyBase, const TCHAR *szSubKey, const TCHAR *szValue, TCHAR *szOutput, int cbOutput) +{ + HKEY hKey; + DWORD cbOut = cbOutput; + + if (RegOpenKeyEx(hKeyBase, szSubKey, 0, KEY_QUERY_VALUE, &hKey) != ERROR_SUCCESS) + return 0; + + if (RegQueryValueEx(hKey, szValue, NULL, NULL, (PBYTE)szOutput, &cbOut) != ERROR_SUCCESS) { + RegCloseKey(hKey); + return 0; + } + + RegCloseKey(hKey); + return 1; +} + +void GetSensiblyFormattedSize(__int64 size, TCHAR *szOut, int cchOut, int unitsOverride, int appendUnits, int *unitsUsed) +{ + if (!unitsOverride) { + if (size < 1000) unitsOverride = UNITS_BYTES; + else if (size < 100 * 1024) unitsOverride = UNITS_KBPOINT1; + else if (size < 1024 * 1024) unitsOverride = UNITS_KBPOINT0; + else if (size < 1024 * 1024 * 1024) unitsOverride = UNITS_MBPOINT2; + else unitsOverride = UNITS_GBPOINT3; + } + + if (unitsUsed) + *unitsUsed = unitsOverride; + + switch (unitsOverride) { + case UNITS_BYTES: mir_sntprintf(szOut, cchOut, _T("%u%s%s"), (int)size, appendUnits ? _T(" ") : _T(""), appendUnits ? TranslateT("bytes") : _T("")); break; + case UNITS_KBPOINT1: mir_sntprintf(szOut, cchOut, _T("%.1lf%s"), size / 1024.0, appendUnits ? _T(" KB") : _T("")); break; + case UNITS_KBPOINT0: mir_sntprintf(szOut, cchOut, _T("%u%s"), (int)(size / 1024), appendUnits ? _T(" KB") : _T("")); break; + case UNITS_GBPOINT3: mir_sntprintf(szOut, cchOut, _T("%.3f%s"), (size >> 20) / 1024.0, appendUnits ? _T(" GB") : _T("")); break; + default: mir_sntprintf(szOut, cchOut, _T("%.2lf%s"), size / 1048576.0, appendUnits ? _T(" MB") : _T("")); break; + } +} + +// Tripple redirection sucks but is needed to nullify the array pointer +void FreeFilesMatrix(TCHAR ***files) +{ + if (*files == NULL) + return; + + // Free each filename in the pointer array + TCHAR **pFile = *files; + while (*pFile != NULL) { + mir_free(*pFile); + *pFile = NULL; + pFile++; + } + + // Free the array itself + mir_free(*files); + *files = NULL; +} + +void FreeProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *fts) +{ + mir_free(fts->tszCurrentFile); + if (fts->ptszFiles) { + for (int i = 0; i < fts->totalFiles; i++) mir_free(fts->ptszFiles[i]); + mir_free(fts->ptszFiles); + } + mir_free(fts->tszWorkingDir); +} + +void CopyProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src) +{ + *dest = *src; + if (src->tszCurrentFile) dest->tszCurrentFile = PFTS_StringToTchar(src->flags, src->tszCurrentFile); + if (src->ptszFiles) { + dest->ptszFiles = (TCHAR**)mir_alloc(sizeof(TCHAR*)*src->totalFiles); + for (int i = 0; i < src->totalFiles; i++) + dest->ptszFiles[i] = PFTS_StringToTchar(src->flags, src->ptszFiles[i]); + } + if (src->tszWorkingDir) dest->tszWorkingDir = PFTS_StringToTchar(src->flags, src->tszWorkingDir); + dest->flags &= ~PFTS_UTF; + dest->flags |= PFTS_TCHAR; +} + +void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src) +{ + dest->hContact = src->hContact; + dest->flags = src->flags; + if (dest->totalFiles != src->totalFiles) { + for (int i = 0; i < dest->totalFiles; i++) mir_free(dest->ptszFiles[i]); + mir_free(dest->ptszFiles); + dest->ptszFiles = NULL; + dest->totalFiles = src->totalFiles; + } + if (src->ptszFiles) { + if (!dest->ptszFiles) + dest->ptszFiles = (TCHAR**)mir_calloc(sizeof(TCHAR*)*src->totalFiles); + for (int i = 0; i < src->totalFiles; i++) + if (!dest->ptszFiles[i] || !src->ptszFiles[i] || PFTS_CompareWithTchar(src, src->ptszFiles[i], dest->ptszFiles[i])) { + mir_free(dest->ptszFiles[i]); + if (src->ptszFiles[i]) + dest->ptszFiles[i] = PFTS_StringToTchar(src->flags, src->ptszFiles[i]); + else + dest->ptszFiles[i] = NULL; + } + } + else if (dest->ptszFiles) { + for (int i = 0; i < dest->totalFiles; i++) + mir_free(dest->ptszFiles[i]); + mir_free(dest->ptszFiles); + dest->ptszFiles = NULL; + } + + dest->currentFileNumber = src->currentFileNumber; + dest->totalBytes = src->totalBytes; + dest->totalProgress = src->totalProgress; + if (src->tszWorkingDir && (!dest->tszWorkingDir || PFTS_CompareWithTchar(src, src->tszWorkingDir, dest->tszWorkingDir))) { + mir_free(dest->tszWorkingDir); + if (src->tszWorkingDir) + dest->tszWorkingDir = PFTS_StringToTchar(src->flags, src->tszWorkingDir); + else + dest->tszWorkingDir = NULL; + } + + if (!dest->tszCurrentFile || !src->tszCurrentFile || PFTS_CompareWithTchar(src, src->tszCurrentFile, dest->tszCurrentFile)) { + mir_free(dest->tszCurrentFile); + if (src->tszCurrentFile) + dest->tszCurrentFile = PFTS_StringToTchar(src->flags, src->tszCurrentFile); + else + dest->tszCurrentFile = NULL; + } + dest->currentFileSize = src->currentFileSize; + dest->currentFileProgress = src->currentFileProgress; + dest->currentFileTime = src->currentFileTime; + dest->flags &= ~PFTS_UTF; + dest->flags |= PFTS_TCHAR; +} + +static void RemoveUnreadFileEvents(void) +{ + for (MCONTACT hContact = db_find_first(); hContact; hContact = db_find_next(hContact)) { + HANDLE hDbEvent = db_event_firstUnread(hContact); + while (hDbEvent) { + DBEVENTINFO dbei = { sizeof(dbei) }; + db_event_get(hDbEvent, &dbei); + if (!(dbei.flags&(DBEF_SENT | DBEF_READ)) && dbei.eventType == EVENTTYPE_FILE) + db_event_markRead(hContact, hDbEvent); + hDbEvent = db_event_next(hContact, hDbEvent); + } + } +} + +static int SRFilePreBuildMenu(WPARAM wParam, LPARAM) +{ + bool bEnabled = false; + char *szProto = GetContactProto(wParam); + if (szProto != NULL) { + bool isChat = db_get_b(wParam, szProto, "ChatRoom", false) != 0; + if (CallProtoService(szProto, PS_GETCAPS, isChat ? PFLAGNUM_4 : PFLAGNUM_1, 0) & (isChat ? PF4_GROUPCHATFILES : PF1_FILESEND)) { + if (CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_OFFLINEFILES) + bEnabled = true; + else if (db_get_w(wParam, szProto, "Status", ID_STATUS_OFFLINE) != ID_STATUS_OFFLINE) + bEnabled = true; + } + } + + Menu_ShowItem(hSRFileMenuItem, bEnabled); + return 0; +} + +static int SRFileModulesLoaded(WPARAM, LPARAM) +{ + CLISTMENUITEM mi = { sizeof(mi) }; + mi.position = -2000020000; + mi.icolibItem = GetSkinIconHandle(SKINICON_EVENT_FILE); + mi.pszName = LPGEN("&File"); + mi.pszService = MS_FILE_SENDFILE; + hSRFileMenuItem = Menu_AddContactMenuItem(&mi); + + RemoveUnreadFileEvents(); + return 0; +} + +INT_PTR FtMgrShowCommand(WPARAM, LPARAM) +{ + FtMgr_Show(true, true); + return 0; +} + +INT_PTR openContRecDir(WPARAM hContact, LPARAM) +{ + TCHAR szContRecDir[MAX_PATH]; + GetContactReceivedFilesDir(hContact, szContRecDir, SIZEOF(szContRecDir), TRUE); + ShellExecute(0, _T("open"), szContRecDir, 0, 0, SW_SHOW); + return 0; +} + +INT_PTR openRecDir(WPARAM, LPARAM) +{ + TCHAR szContRecDir[MAX_PATH]; + GetReceivedFilesDir(szContRecDir, SIZEOF(szContRecDir)); + ShellExecute(0, _T("open"), szContRecDir, 0, 0, SW_SHOW); + return 0; +} + +///////////////////////////////////////////////////////////////////////////////////////// + +static void sttRecvCreateBlob(DBEVENTINFO &dbei, int fileCount, char **pszFiles, char *szDescr) +{ + dbei.cbBlob = sizeof(DWORD); + + for (int i = 0; i < fileCount; i++) + dbei.cbBlob += (int)mir_strlen(pszFiles[i]) + 1; + + dbei.cbBlob += (int)mir_strlen(szDescr) + 1; + + if ((dbei.pBlob = (BYTE*)mir_alloc(dbei.cbBlob)) == 0) + return; + + *(DWORD*)dbei.pBlob = 0; + BYTE* p = dbei.pBlob + sizeof(DWORD); + for (int i = 0; i < fileCount; i++) { + strcpy((char*)p, pszFiles[i]); + p += mir_strlen(pszFiles[i]) + 1; + } + strcpy((char*)p, (szDescr == NULL) ? "" : szDescr); +} + +static INT_PTR Proto_RecvFileT(WPARAM, LPARAM lParam) +{ + CCSDATA *ccs = (CCSDATA*)lParam; + PROTORECVFILET* pre = (PROTORECVFILET*)ccs->lParam; + if (pre->fileCount == 0) + return 0; + + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.szModule = GetContactProto(ccs->hContact); + dbei.timestamp = pre->timestamp; + dbei.flags = (pre->flags & PREF_CREATEREAD) ? DBEF_READ : 0; + dbei.eventType = EVENTTYPE_FILE; + + char **pszFiles = (char**)alloca(pre->fileCount * sizeof(char*)); + for (int i = 0; i < pre->fileCount; i++) + pszFiles[i] = Utf8EncodeT(pre->ptszFiles[i]); + + char *szDescr = Utf8EncodeT(pre->tszDescription); + dbei.flags |= DBEF_UTF; + sttRecvCreateBlob(dbei, pre->fileCount, pszFiles, szDescr); + + for (int i = 0; i < pre->fileCount; i++) + mir_free(pszFiles[i]); + mir_free(szDescr); + + HANDLE hdbe = db_event_add(ccs->hContact, &dbei); + + PushFileEvent(ccs->hContact, hdbe, pre->lParam); + mir_free(dbei.pBlob); + return 0; +} + +int LoadSendRecvFileModule(void) +{ + CreateServiceFunction("FtMgr/Show", FtMgrShowCommand); + + CLISTMENUITEM mi = { sizeof(mi) }; + mi.icolibItem = GetSkinIconHandle(SKINICON_EVENT_FILE); + mi.position = 1900000000; + mi.pszName = LPGEN("File &transfers..."); + mi.pszService = "FtMgr/Show"; //MS_PROTO_SHOWFTMGR; + Menu_AddMainMenuItem(&mi); + + HookEvent(ME_SYSTEM_MODULESLOADED, SRFileModulesLoaded); + HookEvent(ME_DB_EVENT_ADDED, FileEventAdded); + HookEvent(ME_OPT_INITIALISE, FileOptInitialise); + HookEvent(ME_CLIST_PREBUILDCONTACTMENU, SRFilePreBuildMenu); + + hDlgSucceeded = CreateHookableEvent(ME_FILEDLG_SUCCEEDED); + hDlgCanceled = CreateHookableEvent(ME_FILEDLG_CANCELED); + + CreateServiceFunction(MS_PROTO_RECVFILET, Proto_RecvFileT); + + CreateServiceFunction(MS_FILE_SENDFILE, SendFileCommand); + CreateServiceFunction(MS_FILE_SENDSPECIFICFILES, SendSpecificFiles); + CreateServiceFunction(MS_FILE_SENDSPECIFICFILEST, SendSpecificFilesT); + CreateServiceFunction(MS_FILE_GETRECEIVEDFILESFOLDER, GetReceivedFilesFolder); + CreateServiceFunction("SRFile/RecvFile", RecvFileCommand); + + CreateServiceFunction("SRFile/OpenContRecDir", openContRecDir); + CreateServiceFunction("SRFile/OpenRecDir", openRecDir); + + SkinAddNewSoundEx("RecvFile", LPGEN("File"), LPGEN("Incoming")); + SkinAddNewSoundEx("FileDone", LPGEN("File"), LPGEN("Complete")); + SkinAddNewSoundEx("FileFailed", LPGEN("File"), LPGEN("Error")); + SkinAddNewSoundEx("FileDenied", LPGEN("File"), LPGEN("Denied")); + return 0; +} diff --git a/src/core/stdfile/src/file.h b/src/core/stdfile/src/file.h new file mode 100644 index 0000000000..f86bc57fe6 --- /dev/null +++ b/src/core/stdfile/src/file.h @@ -0,0 +1,120 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#define VIRUSSCAN_DISABLE 0 +#define VIRUSSCAN_AFTERDL 1 +#define VIRUSSCAN_DURINGDL 2 + +#define FILERESUME_ASK 0 +//1, 2, 3, 4: resume, overwrite, rename, skip: from proto library +#define FILERESUMEF_ALL 0x80 +#define FILERESUME_RESUMEALL (FILERESUME_RESUME|FILERESUMEF_ALL) +#define FILERESUME_OVERWRITEALL (FILERESUME_OVERWRITE|FILERESUMEF_ALL) +#define FILERESUME_RENAMEALL (FILERESUME_RENAME|FILERESUMEF_ALL) +#define FILERESUME_CANCEL 0xFFFFFFFF + +#define M_FILEEXISTSDLGREPLY (WM_USER+200) +#define M_PRESHUTDOWN (WM_USER+201) + +struct FileSendData +{ + MCONTACT hContact; + const TCHAR **ppFiles; +}; + +#define BYTESRECVEDHISTORYCOUNT 10 //the number of bytes recved is sampled once a second and the last 10 are used to get the transfer speed +struct FileDlgData +{ + HWND hwndTransfer; + HANDLE fs; + MCONTACT hContact; + HANDLE hDbEvent; + HANDLE hNotifyEvent; + TCHAR **files; + int send; + int closeIfFileChooseCancelled; + int resumeBehaviour; + int bytesRecvedHistory[BYTESRECVEDHISTORYCOUNT]; + int bytesRecvedHistorySize; + int waitingForAcceptance; + PROTOFILETRANSFERSTATUS transferStatus; + int *fileVirusScanned; + HANDLE hPreshutdownEvent; + DWORD dwTicks; + + TCHAR szSavePath[MAX_PATH]; + TCHAR szMsg[450], szFilenames[1024]; + HICON hIcon, hIconFolder; +}; + +//file.c +#define UNITS_BYTES 1 // 0 <= size<1000: "%d bytes" +#define UNITS_KBPOINT1 2 // 1000 <= size<100*1024: "%.1f KB" +#define UNITS_KBPOINT0 3 // 100*1024 <= size<1024*1024: "%d KB" +#define UNITS_MBPOINT2 4 // 1024*1024 <= size: "%.2f MB" +#define UNITS_GBPOINT3 5 // 1024*1024*1024 <= size: "%.3f GB" + +void GetSensiblyFormattedSize(__int64 size, TCHAR *szOut, int cchOut, int unitsOverride, int appendUnits, int *unitsUsed); +void FreeFilesMatrix(TCHAR ***files); //loving that triple indirection +void FreeProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *fts); +void CopyProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src); +void UpdateProtoFileTransferStatus(PROTOFILETRANSFERSTATUS *dest, PROTOFILETRANSFERSTATUS *src); +int SRFile_GetRegValue(HKEY hKeyBase, const TCHAR *szSubKey, const TCHAR *szValue, TCHAR *szOutput, int cbOutput); +//filesenddlg.c +INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +//filerecv.c +INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +void RemoveInvalidFilenameChars(TCHAR *tszString); +void RemoveInvalidPathChars(TCHAR *tszString); +void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL substVars); +void GetReceivedFilesDir(TCHAR *szDir, int cchDir); +int BrowseForFolder(HWND hwnd, TCHAR *szPath); +//fileexistsdlg.c +struct TDlgProcFileExistsParam +{ + HWND hwndParent; + PROTOFILETRANSFERSTATUS *fts; +}; +INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +//filexferdlg.c +INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam); +//fileopts.c +int FileOptInitialise(WPARAM wParam, LPARAM lParam); +//ftmanager.c +#define WM_FT_ADD (WM_USER+701) +#define WM_FT_RESIZE (WM_USER+702) +#define WM_FT_REMOVE (WM_USER+703) +#define WM_FT_SELECTPAGE (WM_USER+704) +#define WM_FT_CLEANUP (WM_USER+705) +#define WM_FT_COMPLETED (WM_USER+706) + +HWND FtMgr_Show(bool bForceActivate, bool bFromMenu); +void FtMgr_Destroy(); +HWND FtMgr_AddTransfer(FileDlgData *dat); + +void FreeFileDlgData(FileDlgData* dat); + +TCHAR *GetContactID(MCONTACT hContact); + +extern HANDLE hDlgSucceeded, hDlgCanceled; diff --git a/src/core/stdfile/src/fileexistsdlg.cpp b/src/core/stdfile/src/fileexistsdlg.cpp new file mode 100644 index 0000000000..1c3e7dedef --- /dev/null +++ b/src/core/stdfile/src/fileexistsdlg.cpp @@ -0,0 +1,340 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "commonheaders.h" +#include "file.h" + +static void SetControlToUnixTime(HWND hwndDlg, UINT idCtrl, time_t unixTime) +{ + LARGE_INTEGER liFiletime; + FILETIME filetime; + SYSTEMTIME st; + char szTime[64], szDate[64], szOutput[128]; + + liFiletime.QuadPart = (BIGI(11644473600)+(__int64)unixTime)*10000000; + filetime.dwHighDateTime = liFiletime.HighPart; + filetime.dwLowDateTime = liFiletime.LowPart; + FileTimeToSystemTime(&filetime, &st); + GetTimeFormatA(LOCALE_USER_DEFAULT, 0, &st, NULL, szTime, SIZEOF(szTime)); + GetDateFormatA(LOCALE_USER_DEFAULT, DATE_SHORTDATE, &st, NULL, szDate, SIZEOF(szDate)); + mir_snprintf(szOutput, SIZEOF(szOutput), "%s %s", szDate, szTime); + SetDlgItemTextA(hwndDlg, idCtrl, szOutput); +} + +#define C_CONTEXTMENU 0 +#define C_PROPERTIES 1 +// not defined in VC++ 6.0 SE +#ifndef CMF_EXTENDEDVERBS +#define CMF_EXTENDEDVERBS 0x00000100 +#endif +static void DoAnnoyingShellCommand(HWND hwnd, const TCHAR *szFilename, int cmd, POINT *ptCursor) +{ + IShellFolder *pDesktopFolder; + if (SHGetDesktopFolder(&pDesktopFolder) == NOERROR) { + ITEMIDLIST *pCurrentIdl; + WCHAR* wszFilename = (LPWSTR)szFilename; + + if (pDesktopFolder->ParseDisplayName(NULL, NULL, wszFilename, NULL, &pCurrentIdl, NULL) == NOERROR) { + if (pCurrentIdl->mkid.cb) { + ITEMIDLIST *pidl, *pidlNext, *pidlFilename; + IShellFolder *pFileFolder; + + for (pidl = pCurrentIdl;;) { + pidlNext = (ITEMIDLIST*)((PBYTE)pidl + pidl->mkid.cb); + if (pidlNext->mkid.cb == 0) { + pidlFilename = (ITEMIDLIST*)CoTaskMemAlloc(pidl->mkid.cb + sizeof(pidl->mkid.cb)); + memcpy(pidlFilename, pidl, pidl->mkid.cb + sizeof(pidl->mkid.cb)); + pidl->mkid.cb = 0; + break; + } + pidl = pidlNext; + } + if (pDesktopFolder->BindToObject(pCurrentIdl, NULL, IID_IShellFolder, (void**)&pFileFolder) == NOERROR) { + IContextMenu *pContextMenu; + if (pFileFolder->GetUIObjectOf(NULL, 1, (LPCITEMIDLIST*)&pidlFilename, IID_IContextMenu, NULL, (void**)&pContextMenu) == NOERROR) { + switch (cmd) { + case C_PROPERTIES: + { + CMINVOKECOMMANDINFO ici = { 0 }; + ici.cbSize = sizeof(ici); + ici.hwnd = hwnd; + ici.lpVerb = "properties"; + ici.nShow = SW_SHOW; + pContextMenu->InvokeCommand(&ici); + } + break; + + case C_CONTEXTMENU: + HMENU hMenu = CreatePopupMenu(); + if (SUCCEEDED(pContextMenu->QueryContextMenu(hMenu, 0, 1000, 65535, (GetKeyState(VK_SHIFT) & 0x8000 ? CMF_EXTENDEDVERBS : 0) | CMF_NORMAL))) { + int cmd = TrackPopupMenu(hMenu, TPM_RETURNCMD, ptCursor->x, ptCursor->y, 0, hwnd, NULL); + if (cmd) { + CMINVOKECOMMANDINFO ici = { 0 }; + ici.cbSize = sizeof(ici); + ici.hwnd = hwnd; + ici.lpVerb = MAKEINTRESOURCEA(cmd - 1000); + ici.nShow = SW_SHOW; + pContextMenu->InvokeCommand(&ici); + } + } + DestroyMenu(hMenu); + break; + } + pContextMenu->Release(); + } + pFileFolder->Release(); + } + CoTaskMemFree(pidlFilename); + } + CoTaskMemFree(pCurrentIdl); + } + pDesktopFolder->Release(); + } +} + +static LRESULT CALLBACK IconCtrlSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PROTOFILETRANSFERSTATUS* pft = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(GetParent(hwnd), GWLP_USERDATA); + + switch (msg) { + case WM_LBUTTONDBLCLK: + ShellExecute(hwnd, NULL, pft->tszCurrentFile, NULL, NULL, SW_SHOW); + break; + case WM_RBUTTONUP: + POINT pt; + pt.x = (short)LOWORD(lParam); pt.y = (short)HIWORD(lParam); + ClientToScreen(hwnd, &pt); + DoAnnoyingShellCommand(hwnd, pft->tszCurrentFile, C_CONTEXTMENU, &pt); + return 0; + } + return mir_callNextSubclass(hwnd, IconCtrlSubclassProc, msg, wParam, lParam); +} + +struct loadiconsstartinfo { + HWND hwndDlg; + TCHAR *szFilename; +}; + +void __cdecl LoadIconsAndTypesThread(void* param) +{ + loadiconsstartinfo *info = (loadiconsstartinfo*)param; + SHFILEINFO fileInfo; + + if (SHGetFileInfo(info->szFilename, 0, &fileInfo, sizeof(fileInfo), SHGFI_TYPENAME | SHGFI_ICON | SHGFI_LARGEICON)) { + TCHAR szExtension[64], szIconFile[MAX_PATH]; + + TCHAR *pszFilename = _tcsrchr(info->szFilename, '\\'); + if (pszFilename == NULL) + pszFilename = info->szFilename; + + TCHAR *pszExtension = _tcsrchr(pszFilename, '.'); + if (pszExtension) + mir_tstrncpy(szExtension, pszExtension + 1, SIZEOF(szExtension)); + else { + pszExtension = _T("."); + szExtension[0] = '\0'; + } + CharUpper(szExtension); + if (fileInfo.szTypeName[0] == '\0') + mir_sntprintf(fileInfo.szTypeName, SIZEOF(fileInfo.szTypeName), TranslateT("%s file"), szExtension); + SetDlgItemText(info->hwndDlg, IDC_EXISTINGTYPE, fileInfo.szTypeName); + SetDlgItemText(info->hwndDlg, IDC_NEWTYPE, fileInfo.szTypeName); + SendDlgItemMessage(info->hwndDlg, IDC_EXISTINGICON, STM_SETICON, (WPARAM)fileInfo.hIcon, 0); + szIconFile[0] = '\0'; + if (!mir_tstrcmp(szExtension, _T("EXE"))) + SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("2"), szIconFile, SIZEOF(szIconFile)); + else { + TCHAR szTypeName[MAX_PATH]; + if (SRFile_GetRegValue(HKEY_CLASSES_ROOT, pszExtension, NULL, szTypeName, SIZEOF(szTypeName))) { + mir_tstrcat(szTypeName, _T("\\DefaultIcon")); + if (SRFile_GetRegValue(HKEY_CLASSES_ROOT, szTypeName, NULL, szIconFile, SIZEOF(szIconFile))) { + if (_tcsstr(szIconFile, _T("%1"))) + SRFile_GetRegValue(HKEY_LOCAL_MACHINE, _T("Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Icons"), _T("0"), szIconFile, SIZEOF(szIconFile)); + else szIconFile[0] = '\0'; + } + } + } + + if (szIconFile[0]) { + TCHAR *pszComma = _tcsrchr(szIconFile, ','); + int iconIndex = (pszComma == NULL) ? 0 : _ttoi(pszComma + 1); *pszComma = '\0'; + HICON hIcon = ExtractIcon(hInst, szIconFile, iconIndex); + if (hIcon) + fileInfo.hIcon = hIcon; + } + SendDlgItemMessage(info->hwndDlg, IDC_NEWICON, STM_SETICON, (WPARAM)fileInfo.hIcon, 0); + } + mir_free(info->szFilename); + mir_free(info); +} + +INT_PTR CALLBACK DlgProcFileExists(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + TCHAR szSize[64]; + struct _stati64 statbuf; + struct TDlgProcFileExistsParam *dat = (struct TDlgProcFileExistsParam *)lParam; + + SetPropA(hwndDlg, "Miranda.Preshutdown", HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN)); + SetPropA(hwndDlg, "Miranda.ParentWnd", dat->hwndParent); + + fts = (PROTOFILETRANSFERSTATUS*)mir_alloc(sizeof(PROTOFILETRANSFERSTATUS)); + CopyProtoFileTransferStatus(fts, dat->fts); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)fts); + SetDlgItemText(hwndDlg, IDC_FILENAME, fts->tszCurrentFile); + SetControlToUnixTime(hwndDlg, IDC_NEWDATE, fts->currentFileTime); + GetSensiblyFormattedSize(fts->currentFileSize, szSize, SIZEOF(szSize), 0, 1, NULL); + SetDlgItemText(hwndDlg, IDC_NEWSIZE, szSize); + + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_EXISTINGICON), IconCtrlSubclassProc); + + HWND hwndFocus = GetDlgItem(hwndDlg, IDC_RESUME); + if (_tstati64(fts->tszCurrentFile, &statbuf) == 0) { + SetControlToUnixTime(hwndDlg, IDC_EXISTINGDATE, statbuf.st_mtime); + GetSensiblyFormattedSize(statbuf.st_size, szSize, SIZEOF(szSize), 0, 1, NULL); + SetDlgItemText(hwndDlg, IDC_EXISTINGSIZE, szSize); + if (statbuf.st_size > (int)fts->currentFileSize) { + EnableWindow(GetDlgItem(hwndDlg, IDC_RESUME), FALSE); + hwndFocus = GetDlgItem(hwndDlg, IDC_OVERWRITE); + } + } + + loadiconsstartinfo *lisi = (loadiconsstartinfo*)mir_alloc(sizeof(loadiconsstartinfo)); + lisi->hwndDlg = hwndDlg; + lisi->szFilename = mir_tstrdup(fts->tszCurrentFile); + //can be a little slow, so why not? + forkthread(LoadIconsAndTypesThread, 0, lisi); + SetFocus(hwndFocus); + SetWindowLongPtr(hwndFocus, GWL_STYLE, GetWindowLongPtr(hwndFocus, GWL_STYLE) | BS_DEFPUSHBUTTON); + } + return FALSE; + + case WM_COMMAND: + { + PROTOFILERESUME pfr = { 0 }; + switch (LOWORD(wParam)) { + case IDC_OPENFILE: + ShellExecute(hwndDlg, NULL, fts->tszCurrentFile, NULL, NULL, SW_SHOW); + return FALSE; + + case IDC_OPENFOLDER: + { + TCHAR szFile[MAX_PATH]; + mir_tstrncpy(szFile, fts->tszCurrentFile, SIZEOF(szFile)); + TCHAR *pszLastBackslash = _tcsrchr(szFile, '\\'); + if (pszLastBackslash) + *pszLastBackslash = '\0'; + ShellExecute(hwndDlg, NULL, szFile, NULL, NULL, SW_SHOW); + } + return FALSE; + case IDC_PROPERTIES: + DoAnnoyingShellCommand(hwndDlg, fts->tszCurrentFile, C_PROPERTIES, NULL); + return FALSE; + case IDC_RESUME: + pfr.action = FILERESUME_RESUME; + break; + case IDC_RESUMEALL: + pfr.action = FILERESUME_RESUMEALL; + break; + case IDC_OVERWRITE: + pfr.action = FILERESUME_OVERWRITE; + break; + case IDC_OVERWRITEALL: + pfr.action = FILERESUME_OVERWRITEALL; + break; + + case IDC_AUTORENAME: + pfr.action = FILERESUME_RENAMEALL; + break; + + case IDC_SAVEAS: + { + OPENFILENAME ofn = { 0 }; + TCHAR filter[512], *pfilter; + TCHAR str[MAX_PATH]; + + mir_tstrncpy(str, fts->tszCurrentFile, SIZEOF(str)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hwndDlg; + ofn.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY; + _tcscpy(filter, TranslateT("All files")); + _tcscat(filter, _T(" (*)")); + pfilter = filter + _tcslen(filter) + 1; + _tcscpy(pfilter, _T("*")); + pfilter = pfilter + _tcslen(pfilter) + 1; + *pfilter = '\0'; + ofn.lpstrFilter = filter; + ofn.lpstrFile = str; + ofn.nMaxFile = SIZEOF(str); + ofn.nMaxFileTitle = MAX_PATH; + if (!GetSaveFileName(&ofn)) + return FALSE; + + pfr.szFilename = mir_tstrdup(str); + pfr.action = FILERESUME_RENAME; + } + break; + + case IDC_SKIP: + pfr.action = FILERESUME_SKIP; + break; + + case IDCANCEL: + pfr.action = FILERESUME_CANCEL; + break; + + default: + return FALSE; + } + + PROTOFILERESUME *pfrCopy = (PROTOFILERESUME*)mir_alloc(sizeof(pfr)); + memcpy(pfrCopy, &pfr, sizeof(pfr)); + PostMessage((HWND)GetPropA(hwndDlg, "Miranda.ParentWnd"), M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfrCopy); + DestroyWindow(hwndDlg); + } + break; + + case WM_CLOSE: + PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDCANCEL)); + break; + + case M_PRESHUTDOWN: + PostMessage(hwndDlg, WM_CLOSE, 0, 0); + break; + + case WM_DESTROY: + UnhookEvent(GetPropA(hwndDlg, "Miranda.Preshutdown")); // GetProp() will return NULL if it couldnt find anything + RemovePropA(hwndDlg, "Miranda.Preshutdown"); + RemovePropA(hwndDlg, "Miranda.ParentWnd"); + DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_EXISTINGICON, STM_GETICON, 0, 0)); + DestroyIcon((HICON)SendDlgItemMessage(hwndDlg, IDC_NEWICON, STM_GETICON, 0, 0)); + FreeProtoFileTransferStatus(fts); + mir_free(fts); + break; + } + return FALSE; +} diff --git a/src/core/stdfile/src/fileopts.cpp b/src/core/stdfile/src/fileopts.cpp new file mode 100644 index 0000000000..b76a25caa6 --- /dev/null +++ b/src/core/stdfile/src/fileopts.cpp @@ -0,0 +1,244 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ +#include "commonheaders.h" +#include "file.h" + +#define VSCAN_MCAFEE 1 +#define VSCAN_DRSOLOMON 2 +#define VSCAN_NORTON 3 +#define VSCAN_CA 4 + +struct virusscannerinfo { + const TCHAR *szProductName; + const TCHAR *szExeRegPath; + const TCHAR *szExeRegValue; + const TCHAR *szCommandLine; +}; + +static const struct virusscannerinfo virusScanners[] = { + {_T("Network Associates/McAfee VirusScan"), _T("SOFTWARE\\McAfee\\VirusScan"), _T("Scan32EXE"), _T("\"%s\" %%f /nosplash /comp /autoscan /autoexit /noboot")}, + {_T("Dr Solomon's VirusScan (Network Associates)"), _T("SOFTWARE\\Network Associates\\TVD\\VirusScan\\AVConsol\\General"), _T("szScannerExe"), _T("\"%s\" %%f /uinone /noboot /comp /prompt /autoexit")}, + {_T("Norton AntiVirus"), _T("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths\\Navw32.exe"), NULL, _T("\"%s\" %%f /b- /m- /s+ /noresults")}, + {_T("Computer Associates/Inoculate IT"), _T("Software\\Antivirus"), _T("ImageFilename"), _T("\"%s\" %%f /display = progress /exit")}, + {_T("Computer Associates eTrust"), _T("SOFTWARE\\ComputerAssociates\\Anti-Virus\\Resident"), _T("VetPath"), _T("\"%s\" %%f /display = progress /exit")}, + {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\Components\\101"), _T("EXEName"), _T("\"%s\" /S /Q %%f")}, + {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\SetupFolders"), _T("KAV8"), _T("\"%savp.exe\" SCAN %%f")}, + {_T("Kaspersky Anti-Virus"), _T("SOFTWARE\\KasperskyLab\\SetupFolders"), _T("KAV9"), _T("\"%savp.exe\" SCAN %%f")}, + {_T("AntiVir PersonalEdition Classic"), _T("SOFTWARE\\Avira\\AntiVir PersonalEdition Classic"), _T("Path"), _T("\"%savscan.exe\" /GUIMODE = 2 /PATH = \"%%f\"")}, + {_T("ESET NOD32 Antivirus"), _T("SOFTWARE\\ESET\\ESET Security\\CurrentVersion\\Info"), _T("InstallDir"), _T("\"%secls.exe\" /log-all /aind /no-boots /adware /sfx /unsafe /unwanted /heur /adv-heur /action = clean \"%%f\"")}, +}; + +#define M_UPDATEENABLING (WM_USER+100) +#define M_SCANCMDLINESELCHANGE (WM_USER+101) + +#ifndef SHACF_FILESYS_DIRS + #define SHACF_FILESYS_DIRS 0x00000020 +#endif + +static INT_PTR CALLBACK DlgProcFileOpts(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + SHAutoComplete(GetDlgItem(hwndDlg, IDC_FILEDIR), SHACF_FILESYS_DIRS); + + TCHAR str[MAX_PATH]; + GetContactReceivedFilesDir(NULL, str, SIZEOF(str), FALSE); + SetDlgItemText(hwndDlg, IDC_FILEDIR, str); + + CheckDlgButton(hwndDlg, IDC_AUTOACCEPT, db_get_b(NULL, "SRFile", "AutoAccept", 0) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_AUTOMIN, db_get_b(NULL, "SRFile", "AutoMin", 0) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_AUTOCLOSE, db_get_b(NULL, "SRFile", "AutoClose", 0) ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(hwndDlg, IDC_AUTOCLEAR, db_get_b(NULL, "SRFile", "AutoClear", 1) ? BST_CHECKED : BST_UNCHECKED); + switch (db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE)) { + case VIRUSSCAN_AFTERDL: CheckDlgButton(hwndDlg, IDC_SCANAFTERDL, BST_CHECKED); break; + case VIRUSSCAN_DURINGDL: CheckDlgButton(hwndDlg, IDC_SCANDURINGDL, BST_CHECKED); break; + default: CheckDlgButton(hwndDlg, IDC_NOSCANNER, BST_CHECKED); break; + } + CheckDlgButton(hwndDlg, IDC_WARNBEFOREOPENING, db_get_b(NULL, "SRFile", "WarnBeforeOpening", 1) ? BST_CHECKED : BST_UNCHECKED); + + for (int i = 0; i < SIZEOF(virusScanners); i++) { + TCHAR szScanExe[MAX_PATH]; + if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[i].szExeRegPath, virusScanners[i].szExeRegValue, szScanExe, SIZEOF(szScanExe))) { + int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)virusScanners[i].szProductName); + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, i); + } + } + if (SendDlgItemMessageA(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0) == 0) { + int iItem = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_ADDSTRING, 0, (LPARAM)_T("")); + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETITEMDATA, iItem, (LPARAM)-1); + } + + DBVARIANT dbv; + if (db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv) == 0) { + SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, dbv.ptszVal); + db_free(&dbv); + } + else if (SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCOUNT, 0, 0)) { + SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_SETCURSEL, 0, 0); + PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); + } + + switch (db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK)) { + case FILERESUME_RESUMEALL: CheckDlgButton(hwndDlg, IDC_RESUME, BST_CHECKED); break; + case FILERESUME_OVERWRITEALL: CheckDlgButton(hwndDlg, IDC_OVERWRITE, BST_CHECKED); break; + case FILERESUME_RENAMEALL: CheckDlgButton(hwndDlg, IDC_RENAME, BST_CHECKED); break; + default: CheckDlgButton(hwndDlg, IDC_ASK, BST_CHECKED); break; + } + SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); + } + return TRUE; + + case M_UPDATEENABLING: + { + int on = BST_UNCHECKED == IsDlgButtonChecked(hwndDlg, IDC_NOSCANNER); + EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINE), on); + EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINE), on); + EnableWindow(GetDlgItem(hwndDlg, IDC_SCANCMDLINEBROWSE), on); + EnableWindow(GetDlgItem(hwndDlg, IDC_ST_CMDLINEHELP), on); + EnableWindow(GetDlgItem(hwndDlg, IDC_AUTOMIN), IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); + } + break; + case M_SCANCMDLINESELCHANGE: + { + TCHAR str[512]; + TCHAR szScanExe[MAX_PATH]; + int iScanner = SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETITEMDATA, SendDlgItemMessage(hwndDlg, IDC_SCANCMDLINE, CB_GETCURSEL, 0, 0), 0); + if (iScanner >= SIZEOF(virusScanners) || iScanner < 0) break; + str[0] = '\0'; + if (SRFile_GetRegValue(HKEY_LOCAL_MACHINE, virusScanners[iScanner].szExeRegPath, virusScanners[iScanner].szExeRegValue, szScanExe, SIZEOF(szScanExe))) + mir_sntprintf(str, SIZEOF(str), virusScanners[iScanner].szCommandLine, szScanExe); + SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); + } + break; + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDC_FILEDIR: + if ((HIWORD(wParam) != EN_CHANGE || (HWND)lParam != GetFocus())) return 0; + break; + + case IDC_FILEDIRBROWSE: + { + TCHAR str[MAX_PATH]; + GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); + if (BrowseForFolder(hwndDlg, str)) + SetDlgItemText(hwndDlg, IDC_FILEDIR, str); + } + break; + + case IDC_AUTOACCEPT: + case IDC_NOSCANNER: + case IDC_SCANAFTERDL: + case IDC_SCANDURINGDL: + SendMessage(hwndDlg, M_UPDATEENABLING, 0, 0); + break; + + case IDC_SCANCMDLINE: + if (HIWORD(wParam) == CBN_SELCHANGE) PostMessage(hwndDlg, M_SCANCMDLINESELCHANGE, 0, 0); + else if (HIWORD(wParam) != CBN_EDITCHANGE) return 0; + break; + + case IDC_SCANCMDLINEBROWSE: + TCHAR str[MAX_PATH + 2]; + OPENFILENAME ofn = { 0 }; + TCHAR filter[512], *pfilter; + + GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hwndDlg; + ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; + _tcscpy(filter, TranslateT("Executable files")); + _tcscat(filter, _T(" (*.exe)")); + pfilter = filter + _tcslen(filter) + 1; + _tcscpy(pfilter, _T("*.exe")); + pfilter = pfilter + _tcslen(pfilter) + 1; + _tcscpy(pfilter, TranslateT("All files")); + _tcscat(pfilter, _T(" (*)")); + pfilter = pfilter + _tcslen(pfilter) + 1; + _tcscpy(pfilter, _T("*")); + pfilter = pfilter + _tcslen(pfilter) + 1; + *pfilter = 0; + ofn.lpstrFilter = filter; + ofn.lpstrFile = str; + ofn.nMaxFile = SIZEOF(str) - 2; + if (str[0] == '"') { + TCHAR *pszQuote = _tcschr(str + 1, '"'); + if (pszQuote) *pszQuote = 0; + memmove(str, str + 1, (_tcslen(str) * sizeof(TCHAR))); + } + else { + TCHAR *pszSpace = _tcschr(str, ' '); + if (pszSpace) *pszSpace = 0; + } + ofn.nMaxFileTitle = MAX_PATH; + if (!GetOpenFileName(&ofn)) break; + if (_tcschr(str, ' ') != NULL) { + memmove(str + 1, str, ((SIZEOF(str) - 2) * sizeof(TCHAR))); + str[0] = '"'; + _tcscat(str, _T("\"")); + } + SetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str); + break; + } + SendMessage(GetParent(hwndDlg), PSM_CHANGED, 0, 0); + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->code) { + case PSN_APPLY: + TCHAR str[512]; + GetDlgItemText(hwndDlg, IDC_FILEDIR, str, SIZEOF(str)); + RemoveInvalidPathChars(str); + db_set_ts(NULL, "SRFile", "RecvFilesDirAdv", str); + db_set_b(NULL, "SRFile", "AutoAccept", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOACCEPT)); + db_set_b(NULL, "SRFile", "AutoMin", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOMIN)); + db_set_b(NULL, "SRFile", "AutoClose", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLOSE)); + db_set_b(NULL, "SRFile", "AutoClear", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_AUTOCLEAR)); + db_set_b(NULL, "SRFile", "UseScanner", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_SCANAFTERDL) ? VIRUSSCAN_AFTERDL : (IsDlgButtonChecked(hwndDlg, IDC_SCANDURINGDL) ? VIRUSSCAN_DURINGDL : VIRUSSCAN_DISABLE))); + GetDlgItemText(hwndDlg, IDC_SCANCMDLINE, str, SIZEOF(str)); + db_set_ts(NULL, "SRFile", "ScanCmdLine", str); + db_set_b(NULL, "SRFile", "WarnBeforeOpening", (BYTE)IsDlgButtonChecked(hwndDlg, IDC_WARNBEFOREOPENING)); + db_set_b(NULL, "SRFile", "IfExists", (BYTE)(IsDlgButtonChecked(hwndDlg, IDC_ASK) ? FILERESUME_ASK : (IsDlgButtonChecked(hwndDlg, IDC_RESUME) ? FILERESUME_RESUMEALL : (IsDlgButtonChecked(hwndDlg, IDC_OVERWRITE) ? FILERESUME_OVERWRITEALL : FILERESUME_RENAMEALL)))); + return TRUE; + } + break; + } + return FALSE; +} + +int FileOptInitialise(WPARAM wParam, LPARAM) +{ + OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.position = 900000000; + odp.hInstance = hInst; + odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPT_FILETRANSFER); + odp.pszTitle = LPGEN("File transfers"); + odp.pszGroup = LPGEN("Events"); + odp.pfnDlgProc = DlgProcFileOpts; + odp.flags = ODPF_BOLDGROUPS; + Options_AddPage(wParam, &odp); + return 0; +} diff --git a/src/core/stdfile/src/filerecvdlg.cpp b/src/core/stdfile/src/filerecvdlg.cpp new file mode 100644 index 0000000000..8a1ff1b5b7 --- /dev/null +++ b/src/core/stdfile/src/filerecvdlg.cpp @@ -0,0 +1,426 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include "file.h" + +#define MAX_MRU_DIRS 5 + +static BOOL CALLBACK ClipSiblingsChildEnumProc(HWND hwnd, LPARAM) +{ + SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE)|WS_CLIPSIBLINGS); + return TRUE; +} + +static void GetLowestExistingDirName(const TCHAR *szTestDir, TCHAR *szExistingDir, int cchExistingDir) +{ + DWORD dwAttributes; + TCHAR *pszLastBackslash; + + mir_tstrncpy(szExistingDir, szTestDir, cchExistingDir); + while ((dwAttributes = GetFileAttributes(szExistingDir)) != INVALID_FILE_ATTRIBUTES && !(dwAttributes&FILE_ATTRIBUTE_DIRECTORY)) { + pszLastBackslash = _tcsrchr(szExistingDir, '\\'); + if (pszLastBackslash == NULL) { *szExistingDir = '\0'; break; } + *pszLastBackslash = '\0'; + } + if (szExistingDir[0] == '\0') + GetCurrentDirectory(cchExistingDir, szExistingDir); +} + +static const TCHAR InvalidFilenameChars[] = _T("\\/:*?\"<>|"); +void RemoveInvalidFilenameChars(TCHAR *tszString) +{ + size_t i; + if (tszString) { + for (i = _tcscspn(tszString, InvalidFilenameChars); tszString[i]; i+=_tcscspn(tszString+i+1, InvalidFilenameChars)+1) + if (tszString[i] >= 0) + tszString[i] = _T('_'); + } +} + +static const TCHAR InvalidPathChars[] = _T("*?\"<>|"); // "\/:" are excluded as they are allowed in file path +void RemoveInvalidPathChars(TCHAR *tszString) +{ + if (tszString) + for (size_t i = _tcscspn(tszString, InvalidPathChars); tszString[i]; i += _tcscspn(tszString + i + 1, InvalidPathChars) + 1) + if (tszString[i] >= 0) + tszString[i] = _T('_'); +} + +static INT CALLBACK BrowseCallbackProc(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM pData) +{ + TCHAR szDir[MAX_PATH]; + switch (uMsg) { + case BFFM_INITIALIZED: + SendMessage(hwnd, BFFM_SETSELECTION, TRUE, pData); + break; + case BFFM_SELCHANGED: + if (SHGetPathFromIDList((LPITEMIDLIST)lp, szDir)) + SendMessage(hwnd, BFFM_SETSTATUSTEXT, 0, (LPARAM)szDir); + break; + } + return 0; +} + +int BrowseForFolder(HWND hwnd, TCHAR *szPath) +{ + BROWSEINFO bi = { 0 }; + bi.hwndOwner = hwnd; + bi.pszDisplayName = szPath; + bi.lpszTitle = TranslateT("Select folder"); + bi.ulFlags = BIF_NEWDIALOGSTYLE|BIF_EDITBOX|BIF_RETURNONLYFSDIRS; // Use this combo instead of BIF_USENEWUI + bi.lpfn = BrowseCallbackProc; + bi.lParam = (LPARAM)szPath; + + LPITEMIDLIST pidlResult = SHBrowseForFolder(&bi); + if (pidlResult) { + SHGetPathFromIDList(pidlResult, szPath); + mir_tstrcat(szPath, _T("\\")); + CoTaskMemFree(pidlResult); + } + return pidlResult != NULL; +} + +static REPLACEVARSARRAY sttVarsToReplace[] = +{ + { (TCHAR*)"///", (TCHAR*)"//" }, + { (TCHAR*)"//", (TCHAR*)"/" }, + { (TCHAR*)"()", (TCHAR*)"" }, + { NULL, NULL } +}; + +static void patchDir(TCHAR *str, size_t strSize) +{ + REPLACEVARSDATA dat = { 0 }; + dat.cbSize = sizeof(dat); + dat.dwFlags = RVF_TCHAR; + dat.variables = sttVarsToReplace; + + TCHAR *result = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)str, (LPARAM)&dat); + if (result) { + _tcsncpy(str, result, strSize); + mir_free(result); + } + + size_t len = mir_tstrlen(str); + if (len + 1 < strSize && str[len - 1] != '\\') + mir_tstrcpy(str + len, _T("\\")); +} + +void GetContactReceivedFilesDir(MCONTACT hContact, TCHAR *szDir, int cchDir, BOOL patchVars) +{ + TCHAR tszTemp[MAX_PATH]; + + ptrT tszRecvPath(db_get_tsa(NULL, "SRFile", "RecvFilesDirAdv")); + if (tszRecvPath) + _tcsncpy_s(tszTemp, tszRecvPath, _TRUNCATE); + else + mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files")); + + if (hContact) { + hContact = db_mc_tryMeta(hContact); + + REPLACEVARSDATA dat = { 0 }; + REPLACEVARSARRAY rvaVarsToReplace[4]; + rvaVarsToReplace[0].lptzKey = _T("nick"); + rvaVarsToReplace[0].lptzValue = mir_tstrdup((TCHAR *)CallService(MS_CLIST_GETCONTACTDISPLAYNAME, hContact, GCDNF_TCHAR)); + rvaVarsToReplace[1].lptzKey = _T("userid"); + rvaVarsToReplace[1].lptzValue = GetContactID(hContact); + rvaVarsToReplace[2].lptzKey = _T("proto"); + rvaVarsToReplace[2].lptzValue = mir_a2t(GetContactProto(hContact)); + rvaVarsToReplace[3].lptzKey = NULL; + rvaVarsToReplace[3].lptzValue = NULL; + for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) + RemoveInvalidFilenameChars(rvaVarsToReplace[i].lptzValue); + + dat.cbSize = sizeof(dat); + dat.dwFlags = RVF_TCHAR; + dat.variables = rvaVarsToReplace; + dat.hContact = hContact; + TCHAR *result = (TCHAR*)CallService(MS_UTILS_REPLACEVARS, (WPARAM)tszTemp, (LPARAM)&dat); + if (result) { + _tcsncpy(tszTemp, result, SIZEOF(tszTemp)); + mir_free(result); + for (int i = 0; i < (SIZEOF(rvaVarsToReplace) - 1); i++) + mir_free(rvaVarsToReplace[i].lptzValue); + } + } + + if (patchVars) + patchDir(tszTemp, SIZEOF(tszTemp)); + RemoveInvalidPathChars(tszTemp); + mir_tstrncpy(szDir, tszTemp, cchDir); +} + +void GetReceivedFilesDir(TCHAR *szDir, int cchDir) +{ + TCHAR tszTemp[MAX_PATH]; + + ptrT tszRecvPath(db_get_tsa(NULL, "SRFile", "RecvFilesDirAdv")); + if (tszRecvPath) + _tcsncpy_s(tszTemp, tszRecvPath, _TRUNCATE); + else + mir_sntprintf(tszTemp, SIZEOF(tszTemp), _T("%%mydocuments%%\\%s\\%%userid%%"), TranslateT("My received files")); + + patchDir(tszTemp, SIZEOF(tszTemp)); + RemoveInvalidPathChars(tszTemp); + mir_tstrncpy(szDir, tszTemp, cchDir); +} + +INT_PTR CALLBACK DlgProcRecvFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + TCHAR szPath[450]; + CLISTEVENT* cle = (CLISTEVENT*)lParam; + + dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->hContact = cle->hContact; + dat->hDbEvent = cle->hDbEvent; + dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN); + dat->dwTicks = GetTickCount(); + + EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0); + + Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE); + Button_SetIcon_IcoLib(hwndDlg, IDC_ADD, SKINICON_OTHER_ADDCONTACT, LPGEN("Add contact permanently to list")); + Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); + Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); + Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); + + TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0); + SetDlgItemText(hwndDlg, IDC_FROM, contactName); + GetContactReceivedFilesDir(dat->hContact, szPath, SIZEOF(szPath), TRUE); + SetDlgItemText(hwndDlg, IDC_FILEDIR, szPath); + SHAutoComplete(GetWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), GW_CHILD), 1); + + for (int i = 0; i < MAX_MRU_DIRS; i++) { + char idstr[32]; + mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i); + + DBVARIANT dbv; + if (db_get_ts(NULL, "SRFile", idstr, &dbv)) + break; + SendDlgItemMessage(hwndDlg, IDC_FILEDIR, CB_ADDSTRING, 0, (LPARAM)dbv.ptszVal); + db_free(&dbv); + } + + db_event_markRead(dat->hContact, dat->hDbEvent); + + DBEVENTINFO dbei = { sizeof(dbei) }; + dbei.cbBlob = db_event_getBlobSize(dat->hDbEvent); + if (dbei.cbBlob > 4 && dbei.cbBlob <= 8196) { + dbei.pBlob = (PBYTE)alloca(dbei.cbBlob + 1); + db_event_get(dat->hDbEvent, &dbei); + dbei.pBlob[dbei.cbBlob] = 0; + dat->fs = cle->lParam ? (HANDLE)cle->lParam : (HANDLE)*(PDWORD)dbei.pBlob; + + char *str = (char*)dbei.pBlob + 4; + ptrT ptszFileName(DbGetEventStringT(&dbei, str)); + SetDlgItemText(hwndDlg, IDC_FILENAMES, ptszFileName); + + unsigned len = (unsigned)strlen(str) + 1; + if (len + 4 < dbei.cbBlob) { + str += len; + ptrT ptszDescription(DbGetEventStringT(&dbei, str)); + SetDlgItemText(hwndDlg, IDC_MSG, ptszDescription); + } + } + else DestroyWindow(hwndDlg); + + TCHAR datetimestr[64]; + tmi.printTimeStamp(NULL, dbei.timestamp, _T("t d"), datetimestr, SIZEOF(datetimestr), 0); + SetDlgItemText(hwndDlg, IDC_DATE, datetimestr); + + char* szProto = GetContactProto(dat->hContact); + if (szProto) { + int hasName = 0; + char buf[128]; + + CONTACTINFO ci = { 0 }; + ci.cbSize = sizeof(ci); + ci.hContact = dat->hContact; + ci.szProto = szProto; + ci.dwFlag = CNF_UNIQUEID; + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { + switch (ci.type) { + case CNFT_ASCIIZ: + hasName = 1; + strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE); + mir_free(ci.pszVal); + break; + case CNFT_DWORD: + hasName = 1; + mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal); + break; + } + } + if (hasName) + SetDlgItemTextA(hwndDlg, IDC_NAME, buf); + else + SetDlgItemText(hwndDlg, IDC_NAME, contactName); + } + + if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) { + RECT rcBtn1, rcBtn2, rcDateCtrl; + GetWindowRect(GetDlgItem(hwndDlg, IDC_ADD), &rcBtn1); + GetWindowRect(GetDlgItem(hwndDlg, IDC_USERMENU), &rcBtn2); + GetWindowRect(GetDlgItem(hwndDlg, IDC_DATE), &rcDateCtrl); + SetWindowPos(GetDlgItem(hwndDlg, IDC_DATE), 0, 0, 0, rcDateCtrl.right - rcDateCtrl.left - (rcBtn2.left - rcBtn1.left), rcDateCtrl.bottom - rcDateCtrl.top, SWP_NOZORDER | SWP_NOMOVE); + } + else if (db_get_b(NULL, "SRFile", "AutoAccept", 0)) { + //don't check auto-min here to fix BUG#647620 + PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDOK, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDOK)); + } + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) + ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); + } + return TRUE; + + case WM_MEASUREITEM: + return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); + + case WM_DRAWITEM: + { + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; + if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { + char *szProto = GetContactProto(dat->hContact); + if (szProto) { + HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL|PLIF_SMALL, 0); + if (hIcon) { + DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); + DestroyIcon(hIcon); + } } } } + return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); + + case WM_COMMAND: + if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) + break; + + switch (LOWORD(wParam)) { + case IDC_FILEDIRBROWSE: + { + TCHAR szDirName[MAX_PATH], szExistingDirName[MAX_PATH]; + + GetDlgItemText(hwndDlg, IDC_FILEDIR, szDirName, SIZEOF(szDirName)); + GetLowestExistingDirName(szDirName, szExistingDirName, SIZEOF(szExistingDirName)); + if (BrowseForFolder(hwndDlg, szExistingDirName)) + SetDlgItemText(hwndDlg, IDC_FILEDIR, szExistingDirName); + } + break; + + case IDOK: + { //most recently used directories + TCHAR szRecvDir[MAX_PATH], szDefaultRecvDir[MAX_PATH]; + GetDlgItemText(hwndDlg, IDC_FILEDIR, szRecvDir, SIZEOF(szRecvDir)); + RemoveInvalidPathChars(szRecvDir); + GetContactReceivedFilesDir(NULL, szDefaultRecvDir, SIZEOF(szDefaultRecvDir), TRUE); + if (_tcsnicmp(szRecvDir, szDefaultRecvDir, mir_tstrlen(szDefaultRecvDir))) { + char idstr[32]; + int i; + DBVARIANT dbv; + for (i = MAX_MRU_DIRS-2;i>=0;i--) { + mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i); + if (db_get_ts(NULL, "SRFile", idstr, &dbv)) continue; + mir_snprintf(idstr, SIZEOF(idstr), "MruDir%d", i+1); + db_set_ts(NULL, "SRFile", idstr, dbv.ptszVal); + db_free(&dbv); + } + db_set_ts(NULL, "SRFile", idstr, szRecvDir); + } + } + EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAMES), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIR), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_FILEDIRBROWSE), FALSE); + + GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, SIZEOF(dat->szSavePath)); + GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, SIZEOF(dat->szFilenames)); + GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, SIZEOF(dat->szMsg)); + dat->hwndTransfer = FtMgr_AddTransfer(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + //check for auto-minimize here to fix BUG#647620 + if (db_get_b(NULL, "SRFile", "AutoAccept", 0) && db_get_b(NULL, "SRFile", "AutoMin", 0)) { + ShowWindow(hwndDlg, SW_HIDE); + ShowWindow(hwndDlg, SW_SHOWMINNOACTIVE); + } + DestroyWindow(hwndDlg); + break; + + case IDCANCEL: + if (dat->fs) CallContactService(dat->hContact, PSS_FILEDENYT, (WPARAM)dat->fs, (LPARAM)TranslateT("Canceled")); + dat->fs = NULL; /* the protocol will free the handle */ + DestroyWindow(hwndDlg); + break; + + case IDC_ADD: + { + ADDCONTACTSTRUCT acs = { 0 }; + acs.hContact = dat->hContact; + acs.handleType = HANDLE_CONTACT; + acs.szProto = ""; + CallService(MS_ADDCONTACT_SHOW, (WPARAM)hwndDlg, (LPARAM)&acs); + if (!db_get_b(dat->hContact, "CList", "NotOnList", 0)) + ShowWindow(GetDlgItem(hwndDlg, IDC_ADD), SW_HIDE); + } + break; + + case IDC_USERMENU: + { + RECT rc; + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); + GetWindowRect((HWND)lParam, &rc); + TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); + DestroyMenu(hMenu); + } + break; + + case IDC_DETAILS: + CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); + break; + + case IDC_HISTORY: + CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); + break; + } + break; + + case WM_DESTROY: + Window_FreeIcon_IcoLib(hwndDlg); + Button_FreeIcon_IcoLib(hwndDlg, IDC_ADD); + Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); + Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); + Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); + + FreeFileDlgData(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + break; + } + return FALSE; +} diff --git a/src/core/stdfile/src/filesenddlg.cpp b/src/core/stdfile/src/filesenddlg.cpp new file mode 100644 index 0000000000..5abc5221ff --- /dev/null +++ b/src/core/stdfile/src/filesenddlg.cpp @@ -0,0 +1,370 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include +#include +#include "file.h" + +static void SetFileListAndSizeControls(HWND hwndDlg, FileDlgData *dat) +{ + int fileCount = 0, dirCount = 0, i; + __int64 totalSize = 0; + struct _stat statbuf; + TCHAR str[64]; + + for (i = 0; dat->files[i]; i++) { + if (_tstat(dat->files[i], &statbuf) == 0) { + if (statbuf.st_mode & _S_IFDIR) + dirCount++; + else + fileCount++; + totalSize += statbuf.st_size; + } + } + + GetSensiblyFormattedSize(totalSize, str, SIZEOF(str), 0, 1, NULL); + SetDlgItemText(hwndDlg, IDC_TOTALSIZE, str); + if (i > 1) { + TCHAR szFormat[32]; + if (fileCount && dirCount) { + mir_sntprintf(szFormat, SIZEOF(szFormat), _T("%s, %s"), TranslateTS(fileCount == 1 ? _T("%d file") : _T("%d files")), TranslateTS(dirCount == 1 ? _T("%d directory") : _T("%d directories"))); + mir_sntprintf(str, SIZEOF(str), szFormat, fileCount, dirCount); + } + else if (fileCount) { + mir_tstrcpy(szFormat, TranslateT("%d files")); + mir_sntprintf(str, SIZEOF(str), szFormat, fileCount); + } + else { + mir_tstrcpy(szFormat, TranslateT("%d directories")); + mir_sntprintf(str, SIZEOF(str), szFormat, dirCount); + } + SetDlgItemText(hwndDlg, IDC_FILE, str); + } + else SetDlgItemText(hwndDlg, IDC_FILE, dat->files[0]); + + EnableWindow(GetDlgItem(hwndDlg, IDOK), fileCount || dirCount); +} + +static void FilenameToFileList(HWND hwndDlg, FileDlgData* dat, const TCHAR *buf) +{ + // Make sure that the file matrix is empty (the user may select files several times) + FreeFilesMatrix(&dat->files); + + // Get the file attributes of selection + DWORD dwFileAttributes = GetFileAttributes(buf); + if (dwFileAttributes == INVALID_FILE_ATTRIBUTES) + return; + + // Check if the selection is a directory or a file + if (GetFileAttributes(buf) & FILE_ATTRIBUTE_DIRECTORY) { + const TCHAR *pBuf; + int nNumberOfFiles = 0; + int nTemp; + + // :NOTE: The first string in the buffer is the directory, followed by a + // NULL separated list of all files + + // fileOffset is the offset to the first file. + size_t fileOffset = mir_tstrlen(buf) + 1; + + // Count number of files + pBuf = buf + fileOffset; + while (*pBuf) { + pBuf += mir_tstrlen(pBuf) + 1; + nNumberOfFiles++; + } + + // Allocate memory for a pointer array + if ((dat->files = (TCHAR**)mir_alloc((nNumberOfFiles + 1) * sizeof(TCHAR*))) == NULL) + return; + + // Fill the array + pBuf = buf + fileOffset; + nTemp = 0; + while (*pBuf) { + // Allocate space for path+filename + size_t cbFileNameLen = mir_tstrlen(pBuf); + dat->files[nTemp] = (TCHAR*)mir_alloc(sizeof(TCHAR)*(fileOffset + cbFileNameLen + 1)); + + // Add path to filename and copy into array + memcpy(dat->files[nTemp], buf, (fileOffset - 1)*sizeof(TCHAR)); + dat->files[nTemp][fileOffset - 1] = '\\'; + _tcscpy(dat->files[nTemp] + fileOffset - (buf[fileOffset - 2] == '\\' ? 1 : 0), pBuf); + + // Move pointers to next file... + pBuf += cbFileNameLen + 1; + nTemp++; + } + // Terminate array + dat->files[nNumberOfFiles] = NULL; + } + // ...the selection is a single file + else { + if ((dat->files = (TCHAR **)mir_alloc(2 * sizeof(TCHAR*))) == NULL) // Leaks when aborted + return; + + dat->files[0] = mir_tstrdup(buf); + dat->files[1] = NULL; + } + + // Update dialog text with new file selection + SetFileListAndSizeControls(hwndDlg, dat); +} + +#define M_FILECHOOSEDONE (WM_USER+100) +void __cdecl ChooseFilesThread(void* param) +{ + HWND hwndDlg = (HWND)param; + FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + TCHAR *buf = (TCHAR*)mir_alloc(sizeof(TCHAR) * 32767); + if (buf == NULL) { + PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, (LPARAM)(TCHAR*)NULL); + return; + } + + TCHAR filter[128]; + mir_tstrcpy(filter, TranslateT("All files")); + mir_tstrcat(filter, _T(" (*)")); + TCHAR *pfilter = filter + mir_tstrlen(filter) + 1; + mir_tstrcpy(pfilter, _T("*")); + pfilter = filter + mir_tstrlen(filter) + 1; + pfilter[0] = '\0'; + + OPENFILENAME ofn = { 0 }; + ofn.lStructSize = OPENFILENAME_SIZE_VERSION_400; + ofn.hwndOwner = hwndDlg; + ofn.lpstrFilter = filter; + ofn.lpstrFile = buf; *buf = 0; + ofn.nMaxFile = 32767; + ofn.Flags = OFN_NOCHANGEDIR | OFN_FILEMUSTEXIST | OFN_EXPLORER | OFN_HIDEREADONLY | OFN_DONTADDTORECENT; + + char *szProto = GetContactProto(dat->hContact); + if (!(CallProtoService(szProto, PS_GETCAPS, PFLAGNUM_4, 0) & PF4_SINGLEFILEONLY)) + ofn.Flags |= OFN_ALLOWMULTISELECT; + + if (GetOpenFileName(&ofn)) + PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, (LPARAM)buf); + else { + mir_free(buf); + PostMessage(hwndDlg, M_FILECHOOSEDONE, 0, NULL); + } +} + +static BOOL CALLBACK ClipSiblingsChildEnumProc(HWND hwnd, LPARAM) +{ + SetWindowLongPtr(hwnd, GWL_STYLE, GetWindowLongPtr(hwnd, GWL_STYLE) | WS_CLIPSIBLINGS); + return TRUE; +} + +static LRESULT CALLBACK SendEditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_CHAR: + if (wParam == '\n' && GetKeyState(VK_CONTROL) & 0x8000) { + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + return 0; + } + break; + case WM_SYSCHAR: + if ((wParam == 's' || wParam == 'S') && GetKeyState(VK_MENU) & 0x8000) { + PostMessage(GetParent(hwnd), WM_COMMAND, IDOK, 0); + return 0; + } + break; + } + return mir_callNextSubclass(hwnd, SendEditSubclassProc, msg, wParam, lParam); +} + +INT_PTR CALLBACK DlgProcSendFile(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + { + struct FileSendData *fsd = (struct FileSendData*)lParam; + + dat = (FileDlgData*)mir_calloc(sizeof(FileDlgData)); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->hContact = fsd->hContact; + dat->send = 1; + dat->hPreshutdownEvent = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwndDlg, M_PRESHUTDOWN); + dat->fs = NULL; + dat->dwTicks = GetTickCount(); + + EnumChildWindows(hwndDlg, ClipSiblingsChildEnumProc, 0); + mir_subclassWindow(GetDlgItem(hwndDlg, IDC_MSG), SendEditSubclassProc); + + Window_SetIcon_IcoLib(hwndDlg, SKINICON_EVENT_FILE); + Button_SetIcon_IcoLib(hwndDlg, IDC_DETAILS, SKINICON_OTHER_USERDETAILS, LPGEN("View user's details")); + Button_SetIcon_IcoLib(hwndDlg, IDC_HISTORY, SKINICON_OTHER_HISTORY, LPGEN("View user's history")); + Button_SetIcon_IcoLib(hwndDlg, IDC_USERMENU, SKINICON_OTHER_DOWNARROW, LPGEN("User menu")); + + EnableWindow(GetDlgItem(hwndDlg, IDOK), FALSE); + + if (fsd->ppFiles != NULL && fsd->ppFiles[0] != NULL) { + int totalCount, i; + for (totalCount = 0; fsd->ppFiles[totalCount]; totalCount++); + dat->files = (TCHAR**)mir_alloc(sizeof(TCHAR*)*(totalCount + 1)); // Leaks + for (i = 0; i < totalCount; i++) + dat->files[i] = mir_tstrdup(fsd->ppFiles[i]); + dat->files[totalCount] = NULL; + SetFileListAndSizeControls(hwndDlg, dat); + } + + TCHAR *contactName = pcli->pfnGetContactDisplayName(dat->hContact, 0); + SetDlgItemText(hwndDlg, IDC_TO, contactName); + + char *szProto = GetContactProto(dat->hContact); + if (szProto) { + int hasName = 0; + char buf[128]; + + CONTACTINFO ci = { sizeof(ci) }; + ci.hContact = dat->hContact; + ci.szProto = szProto; + ci.dwFlag = CNF_UNIQUEID; + if (!CallService(MS_CONTACT_GETCONTACTINFO, 0, (LPARAM)&ci)) { + switch (ci.type) { + case CNFT_ASCIIZ: + hasName = 1; + strncpy_s(buf, (char*)ci.pszVal, _TRUNCATE); + mir_free(ci.pszVal); + break; + case CNFT_DWORD: + hasName = 1; + mir_snprintf(buf, SIZEOF(buf), "%u", ci.dVal); + break; + } + } + + if (hasName) + SetDlgItemTextA(hwndDlg, IDC_NAME, buf); + else + SetDlgItemText(hwndDlg, IDC_NAME, contactName); + } + + if (fsd->ppFiles == NULL) { + EnableWindow(hwndDlg, FALSE); + dat->closeIfFileChooseCancelled = 1; + PostMessage(hwndDlg, WM_COMMAND, MAKEWPARAM(IDC_CHOOSE, BN_CLICKED), (LPARAM)GetDlgItem(hwndDlg, IDC_CHOOSE)); + } + } + return TRUE; + + case WM_MEASUREITEM: + return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); + + case WM_DRAWITEM: + { + LPDRAWITEMSTRUCT dis = (LPDRAWITEMSTRUCT)lParam; + if (dis->hwndItem == GetDlgItem(hwndDlg, IDC_PROTOCOL)) { + char *szProto = GetContactProto(dat->hContact); + if (szProto) { + HICON hIcon = (HICON)CallProtoService(szProto, PS_LOADICON, PLI_PROTOCOL | PLIF_SMALL, 0); + if (hIcon) { + DrawIconEx(dis->hDC, dis->rcItem.left, dis->rcItem.top, hIcon, GetSystemMetrics(SM_CXSMICON), GetSystemMetrics(SM_CYSMICON), 0, NULL, DI_NORMAL); + DestroyIcon(hIcon); + } + } + } + } + return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); + + case M_FILECHOOSEDONE: + if (lParam != 0) { + FilenameToFileList(hwndDlg, dat, (TCHAR*)lParam); + mir_free((TCHAR*)lParam); + dat->closeIfFileChooseCancelled = 0; + } + else if (dat->closeIfFileChooseCancelled) + PostMessage(hwndDlg, WM_COMMAND, IDCANCEL, 0); + + EnableWindow(hwndDlg, TRUE); + break; + + case WM_COMMAND: + if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) + break; + + switch (LOWORD(wParam)) { + case IDC_CHOOSE: + EnableWindow(hwndDlg, FALSE); + forkthread(ChooseFilesThread, 0, hwndDlg); + break; + + case IDOK: + NotifyEventHooks(hDlgSucceeded, dat->hContact, (LPARAM)hwndDlg); + + EnableWindow(GetDlgItem(hwndDlg, IDC_FILENAME), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_MSG), FALSE); + EnableWindow(GetDlgItem(hwndDlg, IDC_CHOOSE), FALSE); + + GetDlgItemText(hwndDlg, IDC_FILEDIR, dat->szSavePath, SIZEOF(dat->szSavePath)); + GetDlgItemText(hwndDlg, IDC_FILE, dat->szFilenames, SIZEOF(dat->szFilenames)); + GetDlgItemText(hwndDlg, IDC_MSG, dat->szMsg, SIZEOF(dat->szMsg)); + dat->hwndTransfer = FtMgr_AddTransfer(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + DestroyWindow(hwndDlg); + return TRUE; + + case IDCANCEL: + NotifyEventHooks(hDlgCanceled, dat->hContact, (LPARAM)hwndDlg); + DestroyWindow(hwndDlg); + return TRUE; + + case IDC_USERMENU: + { + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); + RECT rc; + GetWindowRect((HWND)lParam, &rc); + TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); + DestroyMenu(hMenu); + } + break; + + case IDC_DETAILS: + CallService(MS_USERINFO_SHOWDIALOG, (WPARAM)dat->hContact, 0); + return TRUE; + + case IDC_HISTORY: + CallService(MS_HISTORY_SHOWCONTACTHISTORY, (WPARAM)dat->hContact, 0); + return TRUE; + } + break; + + case WM_DESTROY: + Window_FreeIcon_IcoLib(hwndDlg); + Button_FreeIcon_IcoLib(hwndDlg, IDC_DETAILS); + Button_FreeIcon_IcoLib(hwndDlg, IDC_HISTORY); + Button_FreeIcon_IcoLib(hwndDlg, IDC_USERMENU); + + FreeFileDlgData(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + return TRUE; + } + return FALSE; +} diff --git a/src/core/stdfile/src/filexferdlg.cpp b/src/core/stdfile/src/filexferdlg.cpp new file mode 100644 index 0000000000..b9d5980746 --- /dev/null +++ b/src/core/stdfile/src/filexferdlg.cpp @@ -0,0 +1,766 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include +#include "file.h" + +#define HM_RECVEVENT (WM_USER+10) + +static int CheckVirusScanned(HWND hwnd, FileDlgData *dat, int i) +{ + if (dat->send) return 1; + if (dat->fileVirusScanned == NULL) return 0; + if (dat->fileVirusScanned[i]) return 1; + if (db_get_b(NULL, "SRFile", "WarnBeforeOpening", 1) == 0) return 1; + return IDYES == MessageBox(hwnd, TranslateT("This file has not yet been scanned for viruses. Are you certain you want to open it?"), TranslateT("File received"), MB_YESNO|MB_DEFBUTTON2); +} + +#define M_VIRUSSCANDONE (WM_USER+100) +struct virusscanthreadstartinfo { + TCHAR *szFile; + int returnCode; + HWND hwndReply; +}; + +TCHAR* PFTS_StringToTchar(int flags, const PROTOCHAR* s) +{ + if (flags & PFTS_UTF) + return Utf8DecodeW((char*)s); + if (flags & PFTS_UNICODE) + return mir_tstrdup(s); + return mir_a2t((char*)s); +} + +int PFTS_CompareWithTchar(PROTOFILETRANSFERSTATUS *ft, const PROTOCHAR *s, TCHAR *r) +{ + if (ft->flags & PFTS_UTF) { + TCHAR *ts = Utf8DecodeW((char*)s); + int res = _tcscmp(ts, r); + mir_free(ts); + return res; + } + if (ft->flags & PFTS_UNICODE) + return _tcscmp(s, r); + + TCHAR *ts = mir_a2t((char*)s); + int res = _tcscmp(ts, r); + mir_free(ts); + return res; +} + +static void SetOpenFileButtonStyle(HWND hwndButton, int enabled) +{ + EnableWindow(hwndButton, enabled); +} + +void FillSendData(FileDlgData *dat, DBEVENTINFO& dbei) +{ + dbei.cbSize = sizeof(dbei); + dbei.szModule = GetContactProto(dat->hContact); + dbei.eventType = EVENTTYPE_FILE; + dbei.flags = DBEF_SENT; + dbei.timestamp = time(NULL); + char *szFileNames = Utf8EncodeT(dat->szFilenames), *szMsg = Utf8EncodeT(dat->szMsg); + dbei.flags |= DBEF_UTF; + + dbei.cbBlob = int(sizeof(DWORD) + mir_strlen(szFileNames) + mir_strlen(szMsg) + 2); + dbei.pBlob = (PBYTE)mir_alloc(dbei.cbBlob); + *(PDWORD)dbei.pBlob = 0; + mir_strcpy((char*)dbei.pBlob + sizeof(DWORD), szFileNames); + mir_strcpy((char*)dbei.pBlob + sizeof(DWORD) + mir_strlen(szFileNames) + 1, szMsg); + + mir_free(szFileNames), mir_free(szMsg); +} + +static void __cdecl RunVirusScannerThread(struct virusscanthreadstartinfo *info) +{ + DBVARIANT dbv; + if (!db_get_ts(NULL, "SRFile", "ScanCmdLine", &dbv)) { + if (dbv.ptszVal[0]) { + STARTUPINFO si = { 0 }; + si.cb = sizeof(si); + TCHAR *pszReplace = _tcsstr(dbv.ptszVal, _T("%f")); + TCHAR szCmdLine[768]; + if (pszReplace) { + if (info->szFile[_tcslen(info->szFile) - 1] == '\\') + info->szFile[_tcslen(info->szFile) - 1] = '\0'; + *pszReplace = 0; + mir_sntprintf(szCmdLine, SIZEOF(szCmdLine), _T("%s\"%s\"%s"), dbv.ptszVal, info->szFile, pszReplace + 2); + } else + _tcsncpy_s(szCmdLine, dbv.ptszVal, _TRUNCATE); + + PROCESS_INFORMATION pi; + if (CreateProcess(NULL, szCmdLine, NULL, NULL, FALSE, 0, NULL, NULL, &si, &pi)) { + if (WaitForSingleObject(pi.hProcess, 3600 * 1000) == WAIT_OBJECT_0) + PostMessage(info->hwndReply, M_VIRUSSCANDONE, info->returnCode, 0); + CloseHandle(pi.hProcess); + CloseHandle(pi.hThread); + } + } + db_free(&dbv); + } + mir_free(info->szFile); + mir_free(info); +} + +static void SetFilenameControls(HWND hwndDlg, FileDlgData *dat, PROTOFILETRANSFERSTATUS *fts) +{ + TCHAR msg[MAX_PATH]; + TCHAR *fnbuf = NULL, *fn = NULL; + SHFILEINFO shfi = { 0 }; + + if (fts->tszCurrentFile) { + fnbuf = mir_tstrdup(fts->tszCurrentFile); + if ((fn = _tcsrchr(fnbuf, '\\')) == NULL) + fn = fnbuf; + else fn++; + } + + if (dat->hIcon) DestroyIcon(dat->hIcon); dat->hIcon = NULL; + + if (fn && (fts->totalFiles > 1)) { + mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s (%d %s %d)"), + pcli->pfnGetContactDisplayName(fts->hContact, 0), + fn, fts->currentFileNumber + 1, TranslateT("of"), fts->totalFiles); + + SHGetFileInfo(fn, FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); + dat->hIcon = shfi.hIcon; + } + else if (fn) { + mir_sntprintf(msg, SIZEOF(msg), _T("%s: %s"), pcli->pfnGetContactDisplayName(fts->hContact, 0), fn); + + SHGetFileInfo(fn, FILE_ATTRIBUTE_NORMAL, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); + dat->hIcon = shfi.hIcon; + } + else { + mir_tstrncpy(msg, pcli->pfnGetContactDisplayName(fts->hContact, 0), SIZEOF(msg)); + HICON hIcon = LoadSkinIcon(SKINICON_OTHER_DOWNARROW); + dat->hIcon = CopyIcon(hIcon); + IcoLib_ReleaseIcon(hIcon, NULL); + } + + mir_free(fnbuf); + + SendDlgItemMessage(hwndDlg, IDC_FILEICON, STM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIcon); + SetDlgItemText(hwndDlg, IDC_CONTACTNAME, msg); +} + +enum { FTS_TEXT, FTS_PROGRESS, FTS_OPEN }; +static void SetFtStatus(HWND hwndDlg, TCHAR *text, int mode) +{ + SetDlgItemText(hwndDlg, IDC_STATUS, TranslateTS(text)); + SetDlgItemText(hwndDlg, IDC_TRANSFERCOMPLETED, TranslateTS(text)); + + ShowWindow(GetDlgItem(hwndDlg, IDC_STATUS), (mode == FTS_TEXT) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), (mode == FTS_PROGRESS) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_TRANSFERCOMPLETED), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_FILEICON), (mode == FTS_OPEN) ? SW_SHOW : SW_HIDE); +} + +static void HideProgressControls(HWND hwndDlg) +{ + RECT rc; + char buf[64]; + + GetWindowRect(GetDlgItem(hwndDlg, IDC_ALLPRECENTS), &rc); + MapWindowPoints(NULL, hwndDlg, (LPPOINT)&rc, 2); + SetWindowPos(hwndDlg, NULL, 0, 0, 100, rc.bottom + 3, SWP_NOMOVE | SWP_NOZORDER); + ShowWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), SW_HIDE); + + _strtime(buf); + SetDlgItemTextA(hwndDlg, IDC_ALLPRECENTS, buf); + + PostMessage(GetParent(hwndDlg), WM_FT_RESIZE, 0, (LPARAM)hwndDlg); +} + +static int FileTransferDlgResizer(HWND, LPARAM, UTILRESIZECONTROL *urc) +{ + switch (urc->wId) { + case IDC_CONTACTNAME: + case IDC_STATUS: + case IDC_ALLFILESPROGRESS: + case IDC_TRANSFERCOMPLETED: + return RD_ANCHORX_WIDTH | RD_ANCHORY_TOP; + case IDC_FRAME: + return RD_ANCHORX_WIDTH | RD_ANCHORY_BOTTOM; + case IDC_ALLPRECENTS: + case IDCANCEL: + case IDC_OPENFILE: + case IDC_OPENFOLDER: + return RD_ANCHORX_RIGHT | RD_ANCHORY_TOP; + + case IDC_ALLTRANSFERRED: + urc->rcItem.right = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx) / 3; + return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; + + case IDC_ALLSPEED: + urc->rcItem.right = urc->rcItem.right - urc->dlgOriginalSize.cx + urc->dlgNewSize.cx; + urc->rcItem.left = urc->rcItem.left + (urc->rcItem.right - urc->rcItem.left) / 3; + return RD_ANCHORX_CUSTOM | RD_ANCHORY_CUSTOM; + } + return RD_ANCHORX_LEFT | RD_ANCHORY_TOP; +} + +INT_PTR CALLBACK DlgProcFileTransfer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) +{ + FileDlgData *dat = (FileDlgData*)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + + switch (msg) { + case WM_INITDIALOG: + TranslateDialogDefault(hwndDlg); + dat = (FileDlgData*)lParam; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, (LONG_PTR)dat); + dat->hNotifyEvent = HookEventMessage(ME_PROTO_ACK, hwndDlg, HM_RECVEVENT); + dat->transferStatus.currentFileNumber = -1; + if (dat->send) { + if (db_mc_isMeta(dat->hContact)) + dat->hContact = db_mc_getMostOnline(dat->hContact); + dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILET, (WPARAM)dat->szMsg, (LPARAM)dat->files); + SetFtStatus(hwndDlg, LPGENT("Request sent, waiting for acceptance..."), FTS_TEXT); + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + dat->waitingForAcceptance = 1; + // hide "open" button since it may cause potential access violations... + ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFILE), SW_HIDE); + ShowWindow(GetDlgItem(hwndDlg, IDC_OPENFOLDER), SW_HIDE); + } + else { //recv + CreateDirectoryTreeT(dat->szSavePath); + dat->fs = (HANDLE)CallContactService(dat->hContact, PSS_FILEALLOWT, (WPARAM)dat->fs, (LPARAM)dat->szSavePath); + dat->transferStatus.tszWorkingDir = mir_tstrdup(dat->szSavePath); + if (db_get_b(dat->hContact, "CList", "NotOnList", 0)) dat->resumeBehaviour = FILERESUME_ASK; + else dat->resumeBehaviour = db_get_b(NULL, "SRFile", "IfExists", FILERESUME_ASK); + SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); + } + + /* check we actually got an fs handle back from the protocol */ + if (!dat->fs) { + SetFtStatus(hwndDlg, LPGENT("Unable to initiate transfer."), FTS_TEXT); + dat->waitingForAcceptance = 0; + } + { + LOGFONT lf; + HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); + GetObject(hFont, sizeof(lf), &lf); + lf.lfWeight = FW_BOLD; + hFont = CreateFontIndirect(&lf); + SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_SETFONT, (WPARAM)hFont, 0); + + SHFILEINFO shfi = { 0 }; + SHGetFileInfo(_T(""), FILE_ATTRIBUTE_DIRECTORY, &shfi, sizeof(shfi), SHGFI_USEFILEATTRIBUTES | SHGFI_ICON | SHGFI_SMALLICON); + dat->hIconFolder = shfi.hIcon; + } + dat->hIcon = NULL; + { + char *szProto = GetContactProto(dat->hContact); + WORD status = db_get_w(dat->hContact, szProto, "Status", ID_STATUS_ONLINE); + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BM_SETIMAGE, IMAGE_ICON, (LPARAM)LoadSkinnedProtoIcon(szProto, status)); + } + + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Contact menu"), 0); + SendDlgItemMessage(hwndDlg, IDC_CONTACT, BUTTONSETASFLATBTN, TRUE, 0); + + Button_SetIcon_IcoLib(hwndDlg, IDC_OPENFILE, SKINICON_OTHER_DOWNARROW, LPGEN("Open...")); + SendDlgItemMessage(hwndDlg, IDC_OPENFILE, BUTTONSETASPUSHBTN, TRUE, 0); + + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BM_SETIMAGE, IMAGE_ICON, (LPARAM)dat->hIconFolder); + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONADDTOOLTIP, (WPARAM)LPGEN("Open folder"), 0); + SendDlgItemMessage(hwndDlg, IDC_OPENFOLDER, BUTTONSETASFLATBTN, TRUE, 0); + + Button_SetIcon_IcoLib(hwndDlg, IDCANCEL, SKINICON_OTHER_DELETE, LPGEN("Cancel")); + + SetDlgItemText(hwndDlg, IDC_CONTACTNAME, pcli->pfnGetContactDisplayName(dat->hContact, 0)); + + if (!dat->waitingForAcceptance) SetTimer(hwndDlg, 1, 1000, NULL); + return TRUE; + + case WM_TIMER: + memmove(dat->bytesRecvedHistory + 1, dat->bytesRecvedHistory, sizeof(dat->bytesRecvedHistory) - sizeof(dat->bytesRecvedHistory[0])); + dat->bytesRecvedHistory[0] = dat->transferStatus.totalProgress; + if (dat->bytesRecvedHistorySize < SIZEOF(dat->bytesRecvedHistory)) + dat->bytesRecvedHistorySize++; + + { + TCHAR szSpeed[32], szTime[32], szDisplay[96]; + SYSTEMTIME st; + ULARGE_INTEGER li; + FILETIME ft; + + GetSensiblyFormattedSize((dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) / dat->bytesRecvedHistorySize, szSpeed, SIZEOF(szSpeed), 0, 1, NULL); + if (dat->bytesRecvedHistory[0] == dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) + mir_tstrcpy(szTime, _T("??:??:??")); + else { + li.QuadPart = BIGI(10000000)*(dat->transferStatus.currentFileSize - dat->transferStatus.currentFileProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; + FileTimeToSystemTime(&ft, &st); + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); + } + if (dat->bytesRecvedHistory[0] != dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]) { + li.QuadPart = BIGI(10000000)*(dat->transferStatus.totalBytes - dat->transferStatus.totalProgress)*dat->bytesRecvedHistorySize / (dat->bytesRecvedHistory[0] - dat->bytesRecvedHistory[dat->bytesRecvedHistorySize - 1]); + ft.dwHighDateTime = li.HighPart; ft.dwLowDateTime = li.LowPart; + FileTimeToSystemTime(&ft, &st); + GetTimeFormat(LOCALE_USER_DEFAULT, TIME_FORCE24HOURFORMAT | TIME_NOTIMEMARKER, &st, NULL, szTime, SIZEOF(szTime)); + } + + mir_sntprintf(szDisplay, SIZEOF(szDisplay), _T("%s/%s (%s %s)"), szSpeed, TranslateT("sec"), szTime, TranslateT("remaining")); + SetDlgItemText(hwndDlg, IDC_ALLSPEED, szDisplay); + } + break; + + case WM_MEASUREITEM: + return CallService(MS_CLIST_MENUMEASUREITEM, wParam, lParam); + + case WM_DRAWITEM: + return CallService(MS_CLIST_MENUDRAWITEM, wParam, lParam); + + case WM_FT_CLEANUP: + if (!dat->fs) { + PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); + DestroyWindow(hwndDlg); + } + break; + + case WM_COMMAND: + if (CallService(MS_CLIST_MENUPROCESSCOMMAND, MAKEWPARAM(LOWORD(wParam), MPCF_CONTACTMENU), (LPARAM)dat->hContact)) + break; + + switch (LOWORD(wParam)) { + case IDOK: + case IDCANCEL: + PostMessage(GetParent(hwndDlg), WM_FT_REMOVE, 0, (LPARAM)hwndDlg); + DestroyWindow(hwndDlg); + break; + + case IDC_CONTACT: + { + RECT rc; + HMENU hMenu = (HMENU)CallService(MS_CLIST_MENUBUILDCONTACT, (WPARAM)dat->hContact, 0); + GetWindowRect((HWND)lParam, &rc); + TrackPopupMenu(hMenu, 0, rc.left, rc.bottom, 0, hwndDlg, NULL); + DestroyMenu(hMenu); + } + break; + + case IDC_TRANSFERCOMPLETED: + if (dat->transferStatus.currentFileNumber <= 1 && CheckVirusScanned(hwndDlg, dat, 0)) { + ShellExecute(NULL, NULL, dat->files[0], NULL, NULL, SW_SHOW); + break; + } + + case IDC_OPENFOLDER: + if (dat) { + TCHAR *path = dat->transferStatus.tszWorkingDir; + if (!path || !path[0]) { + path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); + TCHAR *p = _tcsrchr(path, '\\'); if (p) *p = 0; + } + + if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); + } + break; + + case IDC_OPENFILE: + TCHAR **files; + if (dat->send) { + if (dat->files == NULL) + files = dat->transferStatus.ptszFiles; + else + files = dat->files; + } + else files = dat->files; + + HMENU hMenu = CreatePopupMenu(); + AppendMenu(hMenu, MF_STRING, 1, TranslateT("Open folder")); + AppendMenu(hMenu, MF_SEPARATOR, 0, 0); + + if (files && *files) { + int limit; + TCHAR *pszFilename, *pszNewFileName; + + if (dat->send) + limit = dat->transferStatus.totalFiles; + else + limit = dat->transferStatus.currentFileNumber; + + // Loop over all transfered files and add them to the menu + for (int i = 0; i < limit; i++) { + pszFilename = _tcsrchr(files[i], '\\'); + if (pszFilename == NULL) + pszFilename = files[i]; + else + pszFilename++; + + if (pszFilename) { + size_t cbFileNameLen = _tcslen(pszFilename); + + pszNewFileName = (TCHAR*)mir_alloc(cbFileNameLen * 2 * sizeof(TCHAR)); + TCHAR *p = pszNewFileName; + for (size_t pszlen = 0; pszlen < cbFileNameLen; pszlen++) { + *p++ = pszFilename[pszlen]; + if (pszFilename[pszlen] == '&') + *p++ = '&'; + } + *p = '\0'; + AppendMenu(hMenu, MF_STRING, i + 10, pszNewFileName); + mir_free(pszNewFileName); + } + } + } + + RECT rc; + GetWindowRect((HWND)lParam, &rc); + CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_CHECKED); + int ret = TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_RIGHTALIGN, rc.right, rc.bottom, 0, hwndDlg, NULL); + CheckDlgButton(hwndDlg, IDC_OPENFILE, BST_UNCHECKED); + DestroyMenu(hMenu); + + if (ret == 1) { + TCHAR *path = dat->transferStatus.tszWorkingDir; + if (!path || !path[0]) { + path = NEWTSTR_ALLOCA(dat->transferStatus.tszCurrentFile); + TCHAR *p = _tcsrchr(path, '\\'); + if (p) + *p = 0; + } + + if (path) ShellExecute(NULL, _T("open"), path, NULL, NULL, SW_SHOW); + } + else if (ret && CheckVirusScanned(hwndDlg, dat, ret)) + ShellExecute(NULL, NULL, files[ret - 10], NULL, NULL, SW_SHOW); + } + break; + + case M_FILEEXISTSDLGREPLY: + EnableWindow(hwndDlg, TRUE); + { + PROTOFILERESUME *pfr = (PROTOFILERESUME*)lParam; + TCHAR *szOriginalFilename = (TCHAR*)wParam; + char *szProto = GetContactProto(dat->hContact); + + switch (pfr->action) { + case FILERESUME_CANCEL: + if (dat->fs) CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); + dat->fs = NULL; + mir_free(szOriginalFilename); + if (pfr->szFilename) mir_free((char*)pfr->szFilename); + mir_free(pfr); + return 0; + case FILERESUME_RESUMEALL: + case FILERESUME_OVERWRITEALL: + dat->resumeBehaviour = pfr->action; + pfr->action &= ~FILERESUMEF_ALL; + break; + case FILERESUME_RENAMEALL: + pfr->action = FILERESUME_RENAME; + { + TCHAR *pszExtension, *pszFilename; + if ((pszFilename = _tcsrchr(szOriginalFilename, '\\')) == NULL) pszFilename = szOriginalFilename; + if ((pszExtension = _tcsrchr(pszFilename + 1, '.')) == NULL) pszExtension = pszFilename + mir_tstrlen(pszFilename); + if (pfr->szFilename) mir_free((TCHAR*)pfr->szFilename); + size_t size = (pszExtension - szOriginalFilename) + 21 + mir_tstrlen(pszExtension); + pfr->szFilename = (TCHAR*)mir_alloc(sizeof(TCHAR)*size); + for (int i = 1;; i++) { + mir_sntprintf((TCHAR*)pfr->szFilename, size, _T("%.*s (%u)%s"), pszExtension - szOriginalFilename, szOriginalFilename, i, pszExtension); + if (_taccess(pfr->szFilename, 0) != 0) + break; + } + } + break; + } + mir_free(szOriginalFilename); + CallProtoService(szProto, PS_FILERESUMET, (WPARAM)dat->fs, (LPARAM)pfr); + if (pfr->szFilename) mir_free((char*)pfr->szFilename); + mir_free(pfr); + } + break; + + case HM_RECVEVENT: + { + ACKDATA *ack = (ACKDATA*)lParam; + if (ack->hProcess != dat->fs) break; + if (ack->type != ACKTYPE_FILE) break; + if (ack->hContact != dat->hContact) break; + + if (dat->waitingForAcceptance) { + SetTimer(hwndDlg, 1, 1000, NULL); + dat->waitingForAcceptance = 0; + } + + switch (ack->result) { + case ACKRESULT_SENTREQUEST: SetFtStatus(hwndDlg, LPGENT("Decision sent"), FTS_TEXT); break; + case ACKRESULT_CONNECTING: SetFtStatus(hwndDlg, LPGENT("Connecting..."), FTS_TEXT); break; + case ACKRESULT_CONNECTPROXY: SetFtStatus(hwndDlg, LPGENT("Connecting to proxy..."), FTS_TEXT); break; + case ACKRESULT_CONNECTED: SetFtStatus(hwndDlg, LPGENT("Connected"), FTS_TEXT); break; + case ACKRESULT_LISTENING: SetFtStatus(hwndDlg, LPGENT("Waiting for connection..."), FTS_TEXT); break; + case ACKRESULT_INITIALISING: SetFtStatus(hwndDlg, LPGENT("Initializing..."), FTS_TEXT); break; + case ACKRESULT_NEXTFILE: + SetFtStatus(hwndDlg, LPGENT("Moving to next file..."), FTS_TEXT); + SetDlgItemTextA(hwndDlg, IDC_FILENAME, ""); + if (dat->transferStatus.currentFileNumber == 1 && dat->transferStatus.totalFiles > 1 && !dat->send) + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + if (dat->transferStatus.currentFileNumber != -1 && dat->files && !dat->send && db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE) == VIRUSSCAN_DURINGDL) { + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) + PostMessage(hwndDlg, M_VIRUSSCANDONE, dat->transferStatus.currentFileNumber, 0); + else { + virusscanthreadstartinfo *vstsi; + vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); + vstsi->hwndReply = hwndDlg; + vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); + vstsi->returnCode = dat->transferStatus.currentFileNumber; + forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); + } + } + break; + + case ACKRESULT_FILERESUME: + UpdateProtoFileTransferStatus(&dat->transferStatus, (PROTOFILETRANSFERSTATUS*)ack->lParam); + { + PROTOFILETRANSFERSTATUS *fts = &dat->transferStatus; + SetFilenameControls(hwndDlg, dat, fts); + if (_taccess(fts->tszCurrentFile, 0)) + break; + + SetFtStatus(hwndDlg, LPGENT("File already exists"), FTS_TEXT); + if (dat->resumeBehaviour == FILERESUME_ASK) { + TDlgProcFileExistsParam param = { hwndDlg, fts }; + ShowWindow(hwndDlg, SW_SHOWNORMAL); + CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILEEXISTS), hwndDlg, DlgProcFileExists, (LPARAM)¶m); + EnableWindow(hwndDlg, FALSE); + } + else { + PROTOFILERESUME *pfr = (PROTOFILERESUME*)mir_alloc(sizeof(PROTOFILERESUME)); + pfr->action = dat->resumeBehaviour; + pfr->szFilename = NULL; + PostMessage(hwndDlg, M_FILEEXISTSDLGREPLY, (WPARAM)mir_tstrdup(fts->tszCurrentFile), (LPARAM)pfr); + } + } + SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, 1); + return TRUE; + + case ACKRESULT_DATA: + { + PROTOFILETRANSFERSTATUS *fts = (PROTOFILETRANSFERSTATUS*)ack->lParam; + TCHAR str[64], str2[64], szSizeDone[32], szSizeTotal[32];//, *contactName; + + if (dat->fileVirusScanned == NULL) + dat->fileVirusScanned = (int*)mir_calloc(sizeof(int) * fts->totalFiles); + + // This needs to be here - otherwise we get holes in the files array + if (!dat->send) { + if (dat->files == NULL) + dat->files = (TCHAR**)mir_calloc((fts->totalFiles + 1) * sizeof(TCHAR*)); + if (fts->currentFileNumber < fts->totalFiles && dat->files[fts->currentFileNumber] == NULL) + dat->files[fts->currentFileNumber] = PFTS_StringToTchar(fts->flags, fts->tszCurrentFile); + } + + /* HACK: for 0.3.3, limit updates to around 1.1 ack per second */ + if (fts->totalProgress != fts->totalBytes && GetTickCount() < (dat->dwTicks + 650)) + break; // the last update was less than a second ago! + dat->dwTicks = GetTickCount(); + + // Update local transfer status with data from protocol + UpdateProtoFileTransferStatus(&dat->transferStatus, fts); + fts = &dat->transferStatus; + + bool firstTime = false; + if ((GetWindowLongPtr(GetDlgItem(hwndDlg, IDC_ALLFILESPROGRESS), GWL_STYLE) & WS_VISIBLE) == 0) { + SetFtStatus(hwndDlg, (fts->flags & PFTS_SENDING) ? LPGENT("Sending...") : LPGENT("Receiving..."), FTS_PROGRESS); + SetFilenameControls(hwndDlg, dat, fts); + firstTime = true; + } + + const unsigned long lastPos = SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_GETPOS, 0, 0); + const unsigned long nextPos = fts->totalBytes ? (BIGI(100) * fts->totalProgress / fts->totalBytes) : 0; + if (lastPos != nextPos || firstTime) { + SendDlgItemMessage(hwndDlg, IDC_ALLFILESPROGRESS, PBM_SETPOS, nextPos, 0); + mir_sntprintf(str, SIZEOF(str), _T("%u%%"), nextPos); + SetDlgItemText(hwndDlg, IDC_ALLPRECENTS, str); + } + + int units; + GetSensiblyFormattedSize(fts->totalBytes, szSizeTotal, SIZEOF(szSizeTotal), 0, 1, &units); + GetSensiblyFormattedSize(fts->totalProgress, szSizeDone, SIZEOF(szSizeDone), units, 0, NULL); + mir_sntprintf(str, SIZEOF(str), _T("%s/%s"), szSizeDone, szSizeTotal); + str2[0] = 0; + GetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str2, SIZEOF(str2)); + if (_tcscmp(str, str2)) + SetDlgItemText(hwndDlg, IDC_ALLTRANSFERRED, str); + } + break; + + case ACKRESULT_SUCCESS: + case ACKRESULT_FAILED: + case ACKRESULT_DENIED: + HideProgressControls(hwndDlg); + KillTimer(hwndDlg, 1); + if (!dat->send) + SetOpenFileButtonStyle(GetDlgItem(hwndDlg, IDC_OPENFILE), 1); + SetDlgItemText(hwndDlg, IDCANCEL, TranslateT("Close")); + if (dat->hNotifyEvent) + UnhookEvent(dat->hNotifyEvent); + dat->hNotifyEvent = NULL; + + if (ack->result == ACKRESULT_DENIED) { + dat->fs = NULL; /* protocol will free structure */ + SkinPlaySound("FileDenied"); + SetFtStatus(hwndDlg, LPGENT("File transfer denied"), FTS_TEXT); + } + else if (ack->result == ACKRESULT_FAILED) { + dat->fs = NULL; /* protocol will free structure */ + SkinPlaySound("FileFailed"); + SetFtStatus(hwndDlg, LPGENT("File transfer failed"), FTS_TEXT); + } + else { + SkinPlaySound("FileDone"); + if (dat->send) { + dat->fs = NULL; /* protocol will free structure */ + SetFtStatus(hwndDlg, LPGENT("Transfer completed."), FTS_TEXT); + + DBEVENTINFO dbei = { 0 }; + FillSendData(dat, dbei); + db_event_add(dat->hContact, &dbei); + if (dbei.pBlob) + mir_free(dbei.pBlob); + dat->files = NULL; //protocol library frees this + } + else { + SetFtStatus(hwndDlg, + (dat->transferStatus.totalFiles == 1) ? + LPGENT("Transfer completed, open file.") : + LPGENT("Transfer completed, open folder."), + FTS_OPEN); + + int useScanner = db_get_b(NULL, "SRFile", "UseScanner", VIRUSSCAN_DISABLE); + if (useScanner != VIRUSSCAN_DISABLE) { + struct virusscanthreadstartinfo *vstsi; + vstsi = (struct virusscanthreadstartinfo*)mir_alloc(sizeof(struct virusscanthreadstartinfo)); + vstsi->hwndReply = hwndDlg; + if (useScanner == VIRUSSCAN_DURINGDL) { + vstsi->returnCode = dat->transferStatus.currentFileNumber; + if (GetFileAttributes(dat->files[dat->transferStatus.currentFileNumber])&FILE_ATTRIBUTE_DIRECTORY) { + PostMessage(hwndDlg, M_VIRUSSCANDONE, vstsi->returnCode, 0); + mir_free(vstsi); + vstsi = NULL; + } + else vstsi->szFile = mir_tstrdup(dat->files[dat->transferStatus.currentFileNumber]); + } + else { + vstsi->szFile = mir_tstrdup(dat->transferStatus.tszWorkingDir); + vstsi->returnCode = -1; + } + SetFtStatus(hwndDlg, LPGENT("Scanning for viruses..."), FTS_TEXT); + if (vstsi) + forkthread((void(*)(void*))RunVirusScannerThread, 0, vstsi); + } + else dat->fs = NULL; /* protocol will free structure */ + + dat->transferStatus.currentFileNumber = dat->transferStatus.totalFiles; + } // else dat->send + + } // else ack->result + + PostMessage(GetParent(hwndDlg), WM_FT_COMPLETED, ack->result, (LPARAM)hwndDlg); + break; + } // switch ack->result + } // case HM_RECVEVENT + break; + + case M_VIRUSSCANDONE: + { + int done = 1; + if ((int)wParam == -1) { + for (int i = 0; i < dat->transferStatus.totalFiles; i++) + dat->fileVirusScanned[i] = 1; + } + else { + dat->fileVirusScanned[wParam] = 1; + for (int i = 0; i < dat->transferStatus.totalFiles; i++) + if (!dat->fileVirusScanned[i]) { + done = 0; + break; + } + } + if (done) { + dat->fs = NULL; /* protocol will free structure */ + SetFtStatus(hwndDlg, LPGENT("Transfer and virus scan complete"), FTS_TEXT); + } + } + break; + + case WM_SIZE: + { + UTILRESIZEDIALOG urd = { 0 }; + urd.cbSize = sizeof(urd); + urd.hwndDlg = hwndDlg; + urd.hInstance = hInst; + urd.lpTemplate = MAKEINTRESOURCEA(IDD_FILETRANSFERINFO); + urd.pfnResizer = FileTransferDlgResizer; + CallService(MS_UTILS_RESIZEDIALOG, 0, (LPARAM)&urd); + } + RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLTRANSFERRED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_ALLSPEED), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_CONTACTNAME), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + RedrawWindow(GetDlgItem(hwndDlg, IDC_STATUS), NULL, NULL, RDW_INVALIDATE | RDW_NOERASE); + break; + + case WM_DESTROY: + KillTimer(hwndDlg, 1); + + HFONT hFont = (HFONT)SendDlgItemMessage(hwndDlg, IDC_CONTACTNAME, WM_GETFONT, 0, 0); + DeleteObject(hFont); + + Button_FreeIcon_IcoLib(hwndDlg, IDC_CONTACT); + Button_FreeIcon_IcoLib(hwndDlg, IDC_OPENFILE); + Button_FreeIcon_IcoLib(hwndDlg, IDCANCEL); + + FreeFileDlgData(dat); + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + break; + } + return FALSE; +} + +void FreeFileDlgData(FileDlgData* dat) +{ + if (dat == NULL) + return; + + if (dat->fs) + CallContactService(dat->hContact, PSS_FILECANCEL, (WPARAM)dat->fs, 0); + if (dat->hPreshutdownEvent) + UnhookEvent(dat->hPreshutdownEvent); + if (dat->hNotifyEvent) + UnhookEvent(dat->hNotifyEvent); + + FreeProtoFileTransferStatus(&dat->transferStatus); + FreeFilesMatrix(&dat->files); + + mir_free(dat->fileVirusScanned); + if (dat->hIcon) + DestroyIcon(dat->hIcon); + if (dat->hIconFolder) + DestroyIcon(dat->hIconFolder); + mir_free(dat); +} diff --git a/src/core/stdfile/src/ftmanager.cpp b/src/core/stdfile/src/ftmanager.cpp new file mode 100644 index 0000000000..9788776091 --- /dev/null +++ b/src/core/stdfile/src/ftmanager.cpp @@ -0,0 +1,534 @@ +/* + +Miranda NG: the free IM client for Microsoft* Windows* + +Copyright (c) 2012-14 Miranda NG project (http://miranda-ng.org), +Copyright (c) 2000-12 Miranda IM project, +all portions of this codebase are copyrighted to the people +listed in contributors.txt. + +This program is free software; you can redistribute it and/or +modify it under the terms of the GNU General Public License +as published by the Free Software Foundation; either version 2 +of the License, or (at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, write to the Free Software +Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +*/ + +#include "commonheaders.h" +#include "file.h" + +static HWND hwndFtMgr = NULL; + +struct TFtMgrData +{ + HWND hwndIncoming; + HWND hwndOutgoing; + + HANDLE hhkPreshutdown; + TBPFLAG errorState; +}; + +#define M_CALCPROGRESS (WM_USER + 200) + +struct TFtProgressData +{ + unsigned int init, run, scan; + unsigned __int64 totalBytes, totalProgress; +}; + +struct TLayoutWindowInfo +{ + HWND hwnd; + RECT rc; +}; + +struct TLayoutWindowList +{ + struct TLayoutWindowInfo **items; + int realCount, limit, increment; + FSortFunc sortFunc; +}; + +struct TFtPageData +{ + struct TLayoutWindowList *wnds; + int runningCount; + int height, dataHeight, scrollPos; +}; + +static void LayoutTransfers(HWND hwnd, struct TFtPageData *dat) +{ + int top = 0; + RECT rc; + GetClientRect(hwnd, &rc); + + dat->scrollPos = GetScrollPos(hwnd, SB_VERT); + dat->height = rc.bottom - rc.top; + + if (dat->wnds->realCount) { + HDWP hdwp = BeginDeferWindowPos(dat->wnds->realCount); + top -= dat->scrollPos; + for (int i = 0; i < dat->wnds->realCount; ++i) { + int height = dat->wnds->items[i]->rc.bottom - dat->wnds->items[i]->rc.top; + hdwp = DeferWindowPos(hdwp, dat->wnds->items[i]->hwnd, NULL, 0, top, rc.right, height, SWP_NOZORDER); + top += height; + } + top += dat->scrollPos; + EndDeferWindowPos(hdwp); + } + + dat->dataHeight = top; + + SCROLLINFO si = { 0 }; + si.cbSize = sizeof(si); + si.fMask = SIF_DISABLENOSCROLL | SIF_PAGE | SIF_RANGE; + si.nPage = dat->height; + si.nMin = 0; + si.nMax = dat->dataHeight; + SetScrollInfo(hwnd, SB_VERT, &si, TRUE); +} + +static INT_PTR CALLBACK FtMgrPageDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + struct TFtPageData *dat = (struct TFtPageData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + int i; + + switch (msg) { + case WM_INITDIALOG: + { + // Force scrollbar visibility + SCROLLINFO si = {0}; + si.cbSize = sizeof(si); + si.fMask = SIF_DISABLENOSCROLL; + SetScrollInfo(hwnd, SB_VERT, &si, TRUE); + + dat = (struct TFtPageData *)mir_alloc(sizeof(struct TFtPageData)); + dat->wnds = (struct TLayoutWindowList *)List_Create(0, 1); + dat->scrollPos = 0; + dat->runningCount = 0; + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); + } + break; + + case WM_FT_ADD: + { + TLayoutWindowInfo *wnd = (struct TLayoutWindowInfo *)mir_alloc(sizeof(struct TLayoutWindowInfo)); + wnd->hwnd = (HWND)lParam; + GetWindowRect(wnd->hwnd, &wnd->rc); + List_Insert((SortedList *)dat->wnds, wnd, dat->wnds->realCount); + LayoutTransfers(hwnd, dat); + dat->runningCount++; + PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); + } + break; + + case WM_FT_RESIZE: + for (i=0; i < dat->wnds->realCount; ++i) + if (dat->wnds->items[i]->hwnd == (HWND)lParam) { + GetWindowRect(dat->wnds->items[i]->hwnd, &dat->wnds->items[i]->rc); + break; + } + LayoutTransfers(hwnd, dat); + break; + + case WM_FT_REMOVE: + for (i=0; i < dat->wnds->realCount; ++i) + if (dat->wnds->items[i]->hwnd == (HWND)lParam) { + mir_free(dat->wnds->items[i]); + List_Remove((SortedList *)dat->wnds, i); + break; + } + LayoutTransfers(hwnd, dat); + break; + + case WM_FT_COMPLETED: + //wParam: { ACKRESULT_SUCCESS | ACKRESULT_FAILED | ACKRESULT_DENIED } + dat->runningCount--; + for (i=0; i < dat->wnds->realCount; i++) { + // no error when canceling (WM_FT_REMOVE is send first, check if hwnd is still registered) + if (dat->wnds->items[i]->hwnd == (HWND)lParam) { + SendMessage(GetParent(hwnd), WM_TIMER, 1, (LPARAM)wParam); + break; + } + } + if (i == dat->wnds->realCount) + PostMessage(GetParent(hwnd), WM_TIMER, 1, NULL); + + if(dat->runningCount == 0 && wParam == ACKRESULT_SUCCESS && db_get_b(NULL, "SRFile", "AutoClose", 0)) + ShowWindow(hwndFtMgr, SW_HIDE); + break; + + case WM_FT_CLEANUP: + for (i=0; i < dat->wnds->realCount; ++i) + SendMessage(dat->wnds->items[i]->hwnd, WM_FT_CLEANUP, wParam, lParam); + break; + + case WM_SIZE: + LayoutTransfers(hwnd, dat); + break; + + case WM_MOUSEWHEEL: + { + int zDelta = GET_WHEEL_DELTA_WPARAM(wParam); + if (zDelta) { + int nScrollLines = 0; + SystemParametersInfo(SPI_GETWHEELSCROLLLINES, 0, (void*)&nScrollLines, 0); + for (i=0; i < (nScrollLines + 1) / 2; i++) + SendMessage(hwnd, WM_VSCROLL, (zDelta < 0) ? SB_LINEDOWN : SB_LINEUP, 0); + } + + SetWindowLongPtr(hwnd, DWLP_MSGRESULT, 0); + return TRUE; + } + + case WM_VSCROLL: + { + int pos = dat->scrollPos; + switch (LOWORD(wParam)) { + case SB_LINEDOWN: + pos += 15; + break; + case SB_LINEUP: + pos -= 15; + break; + case SB_PAGEDOWN: + pos += dat->height - 10; + break; + case SB_PAGEUP: + pos -= dat->height - 10; + break; + case SB_THUMBTRACK: + pos = HIWORD(wParam); + break; + } + + if (pos > dat->dataHeight - dat->height) pos = dat->dataHeight - dat->height; + if (pos < 0) pos = 0; + + if (dat->scrollPos != pos) { + ScrollWindow(hwnd, 0, dat->scrollPos - pos, NULL, NULL); + SetScrollPos(hwnd, SB_VERT, pos, TRUE); + dat->scrollPos = pos; + } + break; + } + + case M_PRESHUTDOWN: + for (i=0; i < dat->wnds->realCount; ++i) + PostMessage(dat->wnds->items[i]->hwnd, WM_COMMAND, MAKEWPARAM(IDCANCEL, BN_CLICKED), 0); + break; + + case M_CALCPROGRESS: + { + TFtProgressData *prg = (TFtProgressData *)wParam; + for (i=0; i < dat->wnds->realCount; ++i) { + FileDlgData *trdat = (FileDlgData *)GetWindowLongPtr(dat->wnds->items[i]->hwnd, GWLP_USERDATA); + if (trdat->transferStatus.totalBytes && trdat->fs && !trdat->send && (trdat->transferStatus.totalBytes == trdat->transferStatus.totalProgress)) + prg->scan++; + else if (trdat->transferStatus.totalBytes && trdat->fs) { // in progress + prg->run++; + prg->totalBytes += trdat->transferStatus.totalBytes; + prg->totalProgress += trdat->transferStatus.totalProgress; + } + else if (trdat->fs) // starting + prg->init++; + } + } + break; + + case WM_DESTROY: + for (i=0; i < dat->wnds->realCount; ++i) + mir_free(dat->wnds->items[i]); + List_Destroy((SortedList *)dat->wnds); + mir_free(dat->wnds); + mir_free(dat); + break; + } + + return FALSE; +} + +static INT_PTR CALLBACK FtMgrDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + struct TFtMgrData *dat = (struct TFtMgrData *)GetWindowLongPtr(hwnd, GWLP_USERDATA); + + switch (msg) { + case WM_INITDIALOG: + { + TCITEM tci = {0}; + HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); + + TranslateDialogDefault(hwnd); + Window_SetIcon_IcoLib(hwnd, SKINICON_EVENT_FILE); + + dat = (struct TFtMgrData *)mir_calloc(sizeof(struct TFtMgrData)); + + SetWindowLongPtr(hwnd, GWLP_USERDATA, (LONG_PTR)dat); + + dat->hhkPreshutdown = HookEventMessage(ME_SYSTEM_PRESHUTDOWN, hwnd, M_PRESHUTDOWN); + + dat->hwndIncoming = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc); + dat->hwndOutgoing = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTPAGE), hwnd, FtMgrPageDlgProc); + ShowWindow(dat->hwndIncoming, SW_SHOW); + + tci.mask = TCIF_PARAM|TCIF_TEXT; + tci.pszText = TranslateT("Incoming"); + tci.lParam = (LPARAM)dat->hwndIncoming; + TabCtrl_InsertItem(hwndTab, 0, &tci); + tci.pszText = TranslateT("Outgoing"); + tci.lParam = (LPARAM)dat->hwndOutgoing; + TabCtrl_InsertItem(hwndTab, 1, &tci); + + // Utils_RestoreWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_"); + SAVEWINDOWPOS swp; + swp.hwnd = hwnd; swp.hContact = NULL; swp.szModule = "SRFile"; swp.szNamePrefix = "FtMgrDlg_"; + CallService(MS_UTILS_RESTOREWINDOWPOSITION, RWPF_NOACTIVATE, (LPARAM)&swp); + + // Fall through to setup initial placement + } + case WM_SIZE: + { + RECT rc, rcButton; + HDWP hdwp; + HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); + + GetWindowRect(GetDlgItem(hwnd, IDCANCEL), &rcButton); + OffsetRect(&rcButton, -rcButton.left, -rcButton.top); + + GetClientRect(hwnd, &rc); + InflateRect(&rc, -6, -6); + + hdwp = BeginDeferWindowPos(3); + + hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDC_CLEAR), NULL, rc.left, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE); + hdwp = DeferWindowPos(hdwp, GetDlgItem(hwnd, IDCANCEL), NULL, rc.right-rcButton.right, rc.bottom-rcButton.bottom, 0, 0, SWP_NOZORDER|SWP_NOSIZE); + + rc.bottom -= rcButton.bottom + 5; + + hdwp = DeferWindowPos(hdwp, hwndTab, NULL, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, SWP_NOZORDER); + + EndDeferWindowPos(hdwp); + + GetWindowRect(hwndTab, &rc); + MapWindowPoints(NULL, hwnd, (LPPOINT)&rc, 2); + TabCtrl_AdjustRect(hwndTab, FALSE, &rc); + InflateRect(&rc, -5, -5); + + hdwp = BeginDeferWindowPos(2); + + hdwp = DeferWindowPos(hdwp, dat->hwndIncoming, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0); + hdwp = DeferWindowPos(hdwp, dat->hwndOutgoing, HWND_TOP, rc.left, rc.top, rc.right-rc.left, rc.bottom-rc.top, 0); + + EndDeferWindowPos(hdwp); + + break; + } + + case WM_MOUSEWHEEL: + if (IsWindowVisible(dat->hwndIncoming)) SendMessage(dat->hwndIncoming, msg, wParam, lParam); + if (IsWindowVisible(dat->hwndOutgoing)) SendMessage(dat->hwndOutgoing, msg, wParam, lParam); + break; + + case WM_FT_SELECTPAGE: + { + TCITEM tci = {0}; + HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); + + if (TabCtrl_GetCurSel(hwndTab) == (int)wParam) break; + + tci.mask = TCIF_PARAM; + + TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); + ShowWindow((HWND)tci.lParam, SW_HIDE); + + TabCtrl_SetCurSel(hwndTab, wParam); + + TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); + ShowWindow((HWND)tci.lParam, SW_SHOW); + } + break; + + case WM_GETMINMAXINFO: + { + LPMINMAXINFO lpmmi = (LPMINMAXINFO)lParam; + lpmmi->ptMinTrackSize.x = 300; + lpmmi->ptMinTrackSize.y = 400; + return 0; + } + + case WM_COMMAND: + switch (LOWORD(wParam)) { + case IDCANCEL: + PostMessage(hwnd, WM_CLOSE , 0, 0); + break; + + case IDC_CLEAR: + PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0); + PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0); + break; + } + break; + + case WM_NOTIFY: + switch (((LPNMHDR)lParam)->idFrom) { + case IDC_TABS: + { + HWND hwndTab = GetDlgItem(hwnd, IDC_TABS); + switch (((LPNMHDR)lParam)->code) { + case TCN_SELCHANGING: + { + TCITEM tci = {0}; + tci.mask = TCIF_PARAM; + TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); + ShowWindow((HWND)tci.lParam, SW_HIDE); + break; + } + + case TCN_SELCHANGE: + { + TCITEM tci = {0}; + tci.mask = TCIF_PARAM; + TabCtrl_GetItem(hwndTab, TabCtrl_GetCurSel(hwndTab), &tci); + ShowWindow((HWND)tci.lParam, SW_SHOW); + break; + } + } + break; + } + } + break; + + case M_PRESHUTDOWN: + SendMessage(dat->hwndIncoming, M_PRESHUTDOWN, 0, 0); + SendMessage(dat->hwndOutgoing, M_PRESHUTDOWN, 0, 0); + DestroyWindow(hwnd); + break; + + case WM_CLOSE: + ShowWindow(hwnd, SW_HIDE); + if (db_get_b(NULL, "SRFile", "AutoClear", 1)) { + PostMessage(dat->hwndIncoming, WM_FT_CLEANUP, 0, 0); + PostMessage(dat->hwndOutgoing, WM_FT_CLEANUP, 0, 0); + } + return TRUE; /* Disable default IDCANCEL notification */ + + case WM_DESTROY: + UnhookEvent(dat->hhkPreshutdown); + Window_FreeIcon_IcoLib(hwnd); + DestroyWindow(dat->hwndIncoming); + DestroyWindow(dat->hwndOutgoing); + mir_free(dat); + SetWindowLongPtr(hwnd, GWLP_USERDATA, 0); + Utils_SaveWindowPosition(hwnd, NULL, "SRFile", "FtMgrDlg_"); + break; + + case WM_ACTIVATE: + dat->errorState = TBPF_NOPROGRESS; + wParam = 1; + break; + + case WM_SHOWWINDOW: + if ( !wParam) { // hiding + KillTimer(hwnd, 1); + break; + } + lParam = 0; + + case WM_TIMER: + if (pTaskbarInterface) { + SetTimer(hwnd, 1, 400, NULL); + if ((lParam == ACKRESULT_FAILED) || (lParam == ACKRESULT_DENIED)) + dat->errorState = TBPF_ERROR; + + TFtProgressData prg = {0}; + SendMessage(dat->hwndIncoming, M_CALCPROGRESS, (WPARAM)&prg, 0); + SendMessage(dat->hwndOutgoing, M_CALCPROGRESS, (WPARAM)&prg, 0); + if (dat->errorState) { + pTaskbarInterface->SetProgressState(hwnd, dat->errorState); + if ( !prg.run) + pTaskbarInterface->SetProgressValue(hwnd, 1, 1); + } + else if (prg.run) + pTaskbarInterface->SetProgressState(hwnd, TBPF_NORMAL); + else if (prg.init || prg.scan) + pTaskbarInterface->SetProgressState(hwnd, TBPF_INDETERMINATE); + else { + pTaskbarInterface->SetProgressState(hwnd, TBPF_NOPROGRESS); + KillTimer(hwnd, 1); + } + + if (prg.run) + pTaskbarInterface->SetProgressValue(hwnd, prg.totalProgress, prg.totalBytes); + } + break; + } + + return FALSE; +} + +HWND FtMgr_Show(bool bForceActivate, bool bFromMenu) +{ + bool bAutoMin = db_get_b(NULL, "SRFile", "AutoMin", 0) != 0; /* lqbe */ + + bool bJustCreated = (hwndFtMgr == NULL); + if (bJustCreated) + hwndFtMgr = CreateDialog(hInst, MAKEINTRESOURCE(IDD_FTMGR), NULL, FtMgrDlgProc); + + if (bFromMenu) { /* lqbe */ + ShowWindow(hwndFtMgr, SW_RESTORE); + ShowWindow(hwndFtMgr, SW_SHOW); + SetForegroundWindow(hwndFtMgr); + return hwndFtMgr; + } + if (bAutoMin && bJustCreated) { /* lqbe */ + ShowWindow(hwndFtMgr, SW_HIDE); + ShowWindow(hwndFtMgr, SW_MINIMIZE); + return hwndFtMgr; + } + if (bForceActivate) { /* lqbe */ + ShowWindow(hwndFtMgr, SW_RESTORE); + ShowWindow(hwndFtMgr, SW_SHOWNOACTIVATE); + SetForegroundWindow(hwndFtMgr); + return hwndFtMgr; + } + if ( !bJustCreated && IsWindowVisible(hwndFtMgr)) + return hwndFtMgr; + + ShowWindow(hwndFtMgr, bAutoMin ? SW_SHOWMINNOACTIVE : SW_SHOWNOACTIVATE); + return hwndFtMgr; +} + +void FtMgr_Destroy() +{ + if (hwndFtMgr) + DestroyWindow(hwndFtMgr); +} + +void FtMgr_ShowPage(int page) +{ + if (hwndFtMgr) + SendMessage(hwndFtMgr, WM_FT_SELECTPAGE, page, 0); +} + +HWND FtMgr_AddTransfer(FileDlgData *fdd) +{ + bool bForceActivate = fdd->send || !db_get_b(NULL, "SRFile", "AutoAccept", 0); + TFtMgrData *dat = (TFtMgrData*)GetWindowLongPtr(FtMgr_Show(bForceActivate, false), GWLP_USERDATA); + if (dat == NULL) + return NULL; + + HWND hwndBox = fdd->send ? dat->hwndOutgoing : dat->hwndIncoming; + HWND hwndFt = CreateDialogParam(hInst, MAKEINTRESOURCE(IDD_FILETRANSFERINFO), hwndBox, DlgProcFileTransfer, (LPARAM)fdd); + ShowWindow(hwndFt, SW_SHOWNA); + SendMessage(hwndBox, WM_FT_ADD, 0, (LPARAM)hwndFt); + FtMgr_ShowPage(fdd->send ? 1 : 0); + return hwndFt; +} diff --git a/src/core/stdfile/src/main.cpp b/src/core/stdfile/src/main.cpp new file mode 100644 index 0000000000..abf3e56402 --- /dev/null +++ b/src/core/stdfile/src/main.cpp @@ -0,0 +1,79 @@ +/* + +Standard file transfers' plugin for Miranda NG + +Copyright (C) 2012-14 George Hazan + +This program is free software; you can redistribute it and/or modify +it under the terms of the GNU General Public License as published by +the Free Software Foundation; either version 2 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License along +with this program; if not, write to the Free Software Foundation, Inc., +51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +*/ + +#include "commonheaders.h" + +int LoadSendRecvFileModule(void); + +CLIST_INTERFACE* pcli; +TIME_API tmi; +HINSTANCE hInst; +int hLangpack; + +ITaskbarList3 * pTaskbarInterface; + +PLUGININFOEX pluginInfo = { + sizeof(PLUGININFOEX), + __PLUGIN_NAME, + MIRANDA_VERSION_DWORD, + __DESCRIPTION, + __AUTHOR, + __AUTHOREMAIL, + __COPYRIGHT, + __AUTHORWEB, + UNICODE_AWARE, + // 39698dce-7ed4-4334-ac4c-ba8b37a86f13 + { 0x39698dce, 0x7ed4, 0x4334, {0xac, 0x4c, 0xba, 0x8b, 0x37, 0xa8, 0x6f, 0x13}} +}; + +BOOL WINAPI DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) +{ + hInst = hinstDLL; + return TRUE; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +extern "C" __declspec(dllexport) const MUUID MirandaInterfaces[] = { MIID_SRFILE, MIID_LAST }; + +extern "C" int __declspec(dllexport) Load(void) +{ + mir_getLP(&pluginInfo); + mir_getTMI(&tmi); + mir_getCLI(); + + if ( IsWinVer7Plus()) + CoCreateInstance(CLSID_TaskbarList, NULL, CLSCTX_ALL, IID_ITaskbarList3, (void**)&pTaskbarInterface); + + LoadSendRecvFileModule(); + return 0; +} + +extern "C" int __declspec(dllexport) Unload(void) +{ + if (pTaskbarInterface) + pTaskbarInterface->Release(); + + return 0; +} diff --git a/src/core/stdfile/src/version.h b/src/core/stdfile/src/version.h new file mode 100644 index 0000000000..9edd6f7c6a --- /dev/null +++ b/src/core/stdfile/src/version.h @@ -0,0 +1,12 @@ +#include + +#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION +#define __VERSION_STRING MIRANDA_VERSION_STRING + +#define __PLUGIN_NAME "Standard File Transfers" +#define __FILENAME "stdfile.dll" +#define __DESCRIPTION "Core module for sending/receiving files." +#define __AUTHOR "Miranda NG Development Team" +#define __AUTHOREMAIL "" +#define __AUTHORWEB "http://miranda-ng.org/p/StdFile/" +#define __COPYRIGHT "© 2012 Miranda NG Development Team" diff --git a/src/core/stdfile/stdfile_10.vcxproj b/src/core/stdfile/stdfile_10.vcxproj index a2fa5b249d..9a0a5214fb 100644 --- a/src/core/stdfile/stdfile_10.vcxproj +++ b/src/core/stdfile/stdfile_10.vcxproj @@ -199,29 +199,27 @@ - - Create - Create - Create - Create + + Create - - - - - - - - + + + + + + + + - - + + + - - + + diff --git a/src/core/stdfile/stdfile_10.vcxproj.filters b/src/core/stdfile/stdfile_10.vcxproj.filters index 596bc83397..b87e47dbdd 100644 --- a/src/core/stdfile/stdfile_10.vcxproj.filters +++ b/src/core/stdfile/stdfile_10.vcxproj.filters @@ -15,31 +15,31 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files @@ -47,18 +47,21 @@ Header Files - + Header Files - + + Header Files + + Header Files - + Resource Files - + Resource Files diff --git a/src/core/stdfile/stdfile_12.vcxproj b/src/core/stdfile/stdfile_12.vcxproj index 8ca6fd4484..9794c5d412 100644 --- a/src/core/stdfile/stdfile_12.vcxproj +++ b/src/core/stdfile/stdfile_12.vcxproj @@ -202,29 +202,27 @@ - - Create - Create - Create - Create + + Create - - - - - - - - + + + + + + + + - - + + + - - + + diff --git a/src/core/stdfile/stdfile_12.vcxproj.filters b/src/core/stdfile/stdfile_12.vcxproj.filters index 596bc83397..b87e47dbdd 100644 --- a/src/core/stdfile/stdfile_12.vcxproj.filters +++ b/src/core/stdfile/stdfile_12.vcxproj.filters @@ -15,31 +15,31 @@ - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files - + Source Files @@ -47,18 +47,21 @@ Header Files - + Header Files - + + Header Files + + Header Files - + Resource Files - + Resource Files diff --git a/src/core/stdfile/version.h b/src/core/stdfile/version.h deleted file mode 100644 index 2cdfc40da1..0000000000 --- a/src/core/stdfile/version.h +++ /dev/null @@ -1,14 +0,0 @@ - -#include - -#define __FILEVERSION_STRING MIRANDA_VERSION_FILEVERSION -#define __VERSION_STRING MIRANDA_VERSION_STRING - -#define __PLUGIN_NAME "Standard File Transfers" -#define __INTERNAL_NAME "stdfile" -#define __FILENAME "stdfile.dll" -#define __DESCRIPTION "Core module for sending/receiving files." -#define __AUTHOR "Miranda NG Development Team" -#define __AUTHOREMAIL "" -#define __AUTHORWEB "http://miranda-ng.org/p/StdFile/" -#define __COPYRIGHT "© 2012 Miranda NG Development Team" diff --git a/src/core/stdfile/version.rc b/src/core/stdfile/version.rc deleted file mode 100644 index d1da5e8d6a..0000000000 --- a/src/core/stdfile/version.rc +++ /dev/null @@ -1,42 +0,0 @@ -// Microsoft Visual C++ generated resource script. -// -#ifdef APSTUDIO_INVOKED -#error this file is not editable by Microsoft Visual C++ -#endif //APSTUDIO_INVOKED - -#include "afxres.h" -#include "version.h" - -#ifdef _WIN32 -LANGUAGE LANG_NEUTRAL, SUBLANG_NEUTRAL -#endif //_WIN32 - -VS_VERSION_INFO VERSIONINFO - FILEVERSION __FILEVERSION_STRING - PRODUCTVERSION __FILEVERSION_STRING - FILEFLAGSMASK 0x17L -#ifdef _DEBUG - FILEFLAGS 0x1L -#else - FILEFLAGS 0x0L -#endif - FILEOS 0x4L - FILETYPE 0x0L - FILESUBTYPE 0x0L -BEGIN - BLOCK "StringFileInfo" - BEGIN - BLOCK "000004b0" - BEGIN - VALUE "FileDescription", __DESCRIPTION - VALUE "InternalName", __PLUGIN_NAME - VALUE "LegalCopyright", __COPYRIGHT - VALUE "OriginalFilename", __FILENAME - VALUE "ProductName", __PLUGIN_NAME - END - END - BLOCK "VarFileInfo" - BEGIN - VALUE "Translation", 0x0, 1200 - END -END -- cgit v1.2.3