From e63926f79d51119b829d683983e562527f7dd10a Mon Sep 17 00:00:00 2001 From: Rozhuk Ivan Date: Thu, 4 Dec 2014 23:42:36 +0000 Subject: Db_autobackups: multiple changes + varios fixs git-svn-id: http://svn.miranda-ng.org/main/trunk@11245 1316c22d-e87f-b044-9b9b-93d7a3e3ba9c --- plugins/Db_autobackups/src/backup.cpp | 385 +++++++++++++++-------------- plugins/Db_autobackups/src/headers.h | 33 +-- plugins/Db_autobackups/src/main.cpp | 210 +++++++--------- plugins/Db_autobackups/src/options.cpp | 84 +++++-- plugins/Db_autobackups/src/options.h | 12 +- plugins/FloatingContacts/src/filedrop.cpp | 2 - plugins/IEView/src/IEView.cpp | 2 - plugins/MenuItemEx/src/main.cpp | 23 +- plugins/Non-IM Contact/src/contactinfo.cpp | 40 ++- plugins/Popup/src/popup_wnd2.cpp | 2 +- plugins/Scriver/src/msgs.cpp | 2 - plugins/TabSRMM/src/msgs.cpp | 2 - plugins/WebView/src/webview_getdata.cpp | 12 +- plugins/mTextControl/src/richeditutils.cpp | 2 - 14 files changed, 395 insertions(+), 416 deletions(-) (limited to 'plugins') diff --git a/plugins/Db_autobackups/src/backup.cpp b/plugins/Db_autobackups/src/backup.cpp index a79d1fb311..691a5271b3 100644 --- a/plugins/Db_autobackups/src/backup.cpp +++ b/plugins/Db_autobackups/src/backup.cpp @@ -1,146 +1,154 @@ #include "headers.h" #include "..\Zlib\src\zip.h" -TCHAR dbname[MAX_PATH]; -HWND progress_dialog; -static UINT_PTR timer_id; +static UINT_PTR timer_id = 0; +static LONG m_state = 0; + + +LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) +{ + switch (msg) { + case WM_COMMAND: + { + TCHAR* ptszPath = (TCHAR*)PUGetPluginData(hWnd); + if (ptszPath != 0) + ShellExecute(0, _T("open"), ptszPath, NULL, NULL, SW_SHOW); + + PUDeletePopup(hWnd); + break; + } + case WM_CONTEXTMENU: + PUDeletePopup(hWnd); + break; + case UM_FREEPLUGINDATA: + mir_free(PUGetPluginData(hWnd)); + break; + } + return DefWindowProc(hWnd, msg, wParam, lParam); +} +void ShowPopup(TCHAR* ptszText, TCHAR* ptszHeader, TCHAR* ptszPath) +{ + POPUPDATAT ppd = { 0 }; + + _tcsncpy_s(ppd.lptzText, ptszText, _TRUNCATE); + _tcsncpy_s(ppd.lptzContactName, ptszHeader, _TRUNCATE); + if (ptszPath != NULL) + ppd.PluginData = (void*)mir_tstrdup(ptszPath); + ppd.PluginWindowProc = DlgProcPopup; + ppd.lchIcon = Skin_GetIconByHandle(iconList[0].hIcolib); + + PUAddPopupT(&ppd); +} INT_PTR CALLBACK DlgProcProgress(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - switch(msg) { + switch (msg) { case WM_INITDIALOG: - { - HWND prog = GetDlgItem(hwndDlg, IDC_PROGRESS); - TranslateDialogDefault( hwndDlg ); - SendMessage(prog, PBM_SETPOS, 0, 0); - } + TranslateDialogDefault(hwndDlg); + SendMessage(GetDlgItem(hwndDlg, IDC_PROGRESS), PBM_SETPOS, 0, 0); break; case WM_COMMAND: - if ( HIWORD( wParam ) == BN_CLICKED && LOWORD( wParam ) == IDCANCEL ) { - // in the progress dialog, use the user data to indicate that the user has pressed cancel - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 1); - return TRUE; - } + if (HIWORD(wParam) != BN_CLICKED || LOWORD(wParam) != IDCANCEL) + break; + // in the progress dialog, use the user data to indicate that the user has pressed cancel + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 1); + return TRUE; break; } return FALSE; } TCHAR* DoubleSlash(TCHAR *sorce) { - TCHAR *ret = (TCHAR*)mir_calloc(MAX_PATH); - TCHAR *r, *s; - for (s = sorce, r = ret; *s && r - ret < MAX_PATH - 1; s++, r++){ + TCHAR *ret, *r, *s; + + ret = (TCHAR*)mir_alloc((MAX_PATH * sizeof(TCHAR))); + if (ret == NULL) + return NULL; + for (s = sorce, r = ret; *s && (r - ret) < (MAX_PATH - 1); s ++, r ++) { if (*s != _T('\\')) *r = *s; - else - { + else { *r = _T('\\'); r++; *r = _T('\\'); } } + r[0] = 0; return ret; } -bool MakeZip(LPCTSTR tszSource, LPCTSTR tszDest) +bool MakeZip(TCHAR *tszSource, TCHAR *tszDest, TCHAR *dbname, HWND progress_dialog) { bool ret = false; + HANDLE hSrc; + zipFile hZip; + SYSTEMTIME st; + WIN32_FILE_ATTRIBUTE_DATA fad = { 0 }; + zip_fileinfo fi = { 0 }; + HWND hProgBar; + DWORD dwTotalBytes = 0, dwRead; + MSG msg; + char buf[(256 * 1024)]; // 256 KB ptrA szSourceName(mir_u2a(dbname)); - ptrT tszDestPath(DoubleSlash((TCHAR*)tszDest)); + ptrT tszDestPath(DoubleSlash(tszDest)); - WIN32_FILE_ATTRIBUTE_DATA fad = {0}; - SYSTEMTIME st; - GetFileAttributesEx(tszSource, GetFileExInfoStandard, &fad); - FileTimeToLocalFileTime(&fad.ftLastWriteTime, &fad.ftLastWriteTime); - FileTimeToSystemTime(&fad.ftLastWriteTime, &st); - - HANDLE hSrc = CreateFile( tszSource, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL ); + hSrc = CreateFile(tszSource, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if (hSrc == INVALID_HANDLE_VALUE) return ret; - - if (zipFile hZip = zipOpen2_64(tszDestPath, APPEND_STATUS_CREATE, NULL, NULL)) - { - zip_fileinfo fi = {0}; - fi.tmz_date.tm_sec = st.wSecond; - fi.tmz_date.tm_min = st.wMinute; - fi.tmz_date.tm_hour = st.wHour; - fi.tmz_date.tm_mday = st.wDay; - fi.tmz_date.tm_mon = st.wMonth-1; - fi.tmz_date.tm_year = st.wYear; - - int res = zipOpenNewFileInZip( hZip, szSourceName, &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION ); - if (res == ZIP_OK) - { - DWORD buf_length = 256 * 1024; // 256 KB - HWND hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS); - DWORD dwTotalBytes = 0; - MSG msg; - if (void* buf = mir_alloc( buf_length )) - { - while (GetWindowLongPtr(progress_dialog, GWLP_USERDATA) != 1) - { - DWORD dwRead = 0; - if (!ReadFile(hSrc, buf, buf_length, &dwRead, NULL)) - break; - - if (dwRead == 0) // EOF - { - ret = true; - break; - } - res = zipWriteInFileInZip(hZip, buf, dwRead); - if (res != ZIP_OK) - break; - - while(PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0) - { - if (!IsDialogMessage(progress_dialog, &msg)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } - dwTotalBytes += dwRead; - SendMessage(hProgBar, PBM_SETPOS, (WPARAM)(100.0 * double(dwTotalBytes) / double(fad.nFileSizeLow)), 0); + if (GetFileAttributesEx(tszSource, GetFileExInfoStandard, &fad) == FALSE || + fad.nFileSizeLow == 0) + goto err_out; + FileTimeToLocalFileTime(&fad.ftLastWriteTime, &fad.ftLastWriteTime); + FileTimeToSystemTime(&fad.ftLastWriteTime, &st); + hZip = zipOpen2_64(tszDestPath, APPEND_STATUS_CREATE, NULL, NULL); + if (hZip == NULL) + goto err_out; + fi.tmz_date.tm_sec = st.wSecond; + fi.tmz_date.tm_min = st.wMinute; + fi.tmz_date.tm_hour = st.wHour; + fi.tmz_date.tm_mday = st.wDay; + fi.tmz_date.tm_mon = (st.wMonth - 1); + fi.tmz_date.tm_year = st.wYear; + + if (zipOpenNewFileInZip(hZip, szSourceName, &fi, NULL, 0, NULL, 0, "", Z_DEFLATED, Z_BEST_COMPRESSION) == ZIP_OK) { + hProgBar = GetDlgItem(progress_dialog, IDC_PROGRESS); + while (GetWindowLongPtr(progress_dialog, GWLP_USERDATA) != 1) { + if (!ReadFile(hSrc, buf, sizeof(buf), &dwRead, NULL)) + break; + if (dwRead == 0) { // EOF + ret = true; + break; + } + if (zipWriteInFileInZip(hZip, buf, dwRead) != ZIP_OK) + break; + dwTotalBytes += dwRead; + SendMessage(hProgBar, PBM_SETPOS, (WPARAM)((100 * dwTotalBytes) / fad.nFileSizeLow), 0); + while (PeekMessage(&msg, progress_dialog, 0, 0, PM_REMOVE) != 0) { + if (!IsDialogMessage(progress_dialog, &msg)) { + TranslateMessage(&msg); + DispatchMessage(&msg); } - mir_free(buf); } - zipCloseFileInZip(hZip); } - char szComment[128]; - mir_snprintf(szComment, SIZEOF(szComment), "%s\r\n%s %s %d.%d.%d.%d\r\n", Translate("Miranda NG database"), Translate("Created by:"), __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM); - zipClose( hZip, szComment); + zipCloseFileInZip(hZip); + } + if (ret) { + mir_snprintf(buf, SIZEOF(buf), "%s\r\n%s %s %d.%d.%d.%d\r\n", + Translate("Miranda NG database"), Translate("Created by:"), + __PLUGIN_NAME, __MAJOR_VERSION, __MINOR_VERSION, __RELEASE_NUM, __BUILD_NUM); + } else { + buf[0] = 0; } + zipClose(hZip, buf); + +err_out: CloseHandle(hSrc); + return ret; } -INT_PTR DBSaveAs(WPARAM wParam, LPARAM lParam) -{ - TCHAR fname_buff[MAX_PATH], tszFilter[200]; - OPENFILENAME ofn = {0}; - CallService(MS_DB_GETPROFILENAMET,MAX_PATH,(LPARAM)fname_buff); - - mir_sntprintf(tszFilter, SIZEOF(tszFilter), _T("%s (*.dat)%c*.dat%c%s (*.zip)%c*.zip%c%s (*.*)%c*%c"), - TranslateT("Miranda NG databases"), 0, 0, - TranslateT("Compressed Miranda NG databases"), 0, 0, - TranslateT("All files"), 0, 0); - - ofn.lStructSize = sizeof(ofn); - ofn.lpstrFile = fname_buff; - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT; - ofn.lpstrFilter = tszFilter; - ofn.nFilterIndex = 1; - ofn.lpstrDefExt = _T("dat"); - - if (GetSaveFileName(&ofn)) - mir_forkthread(BackupThread, (void*)fname_buff); - - return 0; -} struct backupFile { @@ -153,86 +161,79 @@ int Comp(const void *i, const void *j) backupFile *pi = (backupFile*)i; backupFile *pj = (backupFile*)j; - if (pi->CreationTime.dwHighDateTime > pj->CreationTime.dwHighDateTime || (pi->CreationTime.dwHighDateTime == pj->CreationTime.dwHighDateTime && pi->CreationTime.dwLowDateTime > pj->CreationTime.dwLowDateTime)) + if (pi->CreationTime.dwHighDateTime > pj->CreationTime.dwHighDateTime || + (pi->CreationTime.dwHighDateTime == pj->CreationTime.dwHighDateTime && pi->CreationTime.dwLowDateTime > pj->CreationTime.dwLowDateTime)) return -1; else return 1; } -int RotateBackups() +int RotateBackups(TCHAR *backupfolder, TCHAR *dbname) { - TCHAR backupfilename1[MAX_PATH] = {0}, backupfolderTmp[MAX_PATH] = {0}; - unsigned int i = 0; + size_t i = 0; + backupFile *bf = NULL, *bftmp; + HANDLE hFind; WIN32_FIND_DATA FindFileData; - TCHAR *backupfolder = Utils_ReplaceVarsT(options.folder); + TCHAR backupfolderTmp[MAX_PATH]; mir_sntprintf(backupfolderTmp, SIZEOF(backupfolderTmp), _T("%s\\%s*"), backupfolder, dbname); - HANDLE hFind = FindFirstFile(backupfolderTmp, &FindFileData); + hFind = FindFirstFile(backupfolderTmp, &FindFileData); if (hFind == INVALID_HANDLE_VALUE) - return 0; - - backupFile *bf = (backupFile*)mir_calloc(sizeof(backupFile)); - - while(bf) - { - if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { - if (FindNextFile(hFind, &FindFileData)) - continue; - else break; - } - _tcscpy(bf[i].Name, FindFileData.cFileName); + goto err_out; + do { + if (FindFileData.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) + continue; + bftmp = (backupFile*)mir_realloc(bf, ((i + 1) * sizeof(backupFile))); + if (bftmp == NULL) + goto err_out; + bf = bftmp; + _tcsncpy_s(bf[i].Name, FindFileData.cFileName, _TRUNCATE); bf[i].CreationTime = FindFileData.ftCreationTime; - if (FindNextFile(hFind, &FindFileData)) - bf = (backupFile*)mir_realloc(bf, (++i + 1) * sizeof(backupFile)); - else break; - } - FindClose(hFind); - if (i > 0) - qsort(bf, i + 1, sizeof(backupFile), Comp); //Sort the list of found files by date in descending order + } while (FindNextFile(hFind, &FindFileData)); - for(;i >= options.num_backups - 1; i--){ - mir_sntprintf(backupfilename1, MAX_PATH, _T("%s\\%s"), backupfolder, bf[i].Name); - DeleteFile(backupfilename1); + if (i > 0) + qsort(bf, (i + 1), sizeof(backupFile), Comp); //Sort the list of found files by date in descending order + for (; i >= (options.num_backups - 1); i --) { + mir_sntprintf(backupfolderTmp, SIZEOF(backupfolderTmp), _T("%s\\%s"), backupfolder, bf[i].Name); + DeleteFile(backupfolderTmp); } - mir_free(backupfolder); +err_out: + FindClose(hFind); mir_free(bf); return 0; } -void BackupThread(void* backup_filename) -{ - Backup((TCHAR*)backup_filename); -} int Backup(TCHAR* backup_filename) { - TCHAR source_file[MAX_PATH] = { 0 }, dest_file[MAX_PATH] = { 0 }; bool bZip = false; + TCHAR dbname[MAX_PATH], source_file[MAX_PATH] = { 0 }, dest_file[MAX_PATH]; + HWND progress_dialog; + SYSTEMTIME st; - CallService(MS_DB_GETPROFILENAMET, MAX_PATH, (LPARAM)dbname); + CallService(MS_DB_GETPROFILENAMET, SIZEOF(dbname), (LPARAM)dbname); - if (backup_filename == NULL) - { - TCHAR buffer[MAX_COMPUTERNAME_LENGTH + 1]; - DWORD size = sizeof(buffer); - bZip = options.use_zip != 0; + if (backup_filename == NULL) { + int err; + TCHAR *backupfolder, buffer[MAX_COMPUTERNAME_LENGTH + 1]; + DWORD size = SIZEOF(buffer); - TCHAR *backupfolder = Utils_ReplaceVarsT(options.folder); + bZip = options.use_zip != 0; + backupfolder = Utils_ReplaceVarsT(options.folder); // ensure the backup folder exists (either create it or return non-zero signifying error) - int err = CreateDirectoryTreeT(backupfolder); - if (err != ERROR_ALREADY_EXISTS && err != 0) + err = CreateDirectoryTreeT(backupfolder); + if (err != ERROR_ALREADY_EXISTS && err != 0) { + mir_free(backupfolder); return 1; + } + RotateBackups(backupfolder, dbname); - SYSTEMTIME st; GetLocalTime(&st); GetComputerName(buffer, &size); mir_sntprintf(dest_file, MAX_PATH, _T("%s\\%s_%02d.%02d.%02d@%02d-%02d-%02d_%s.%s"), backupfolder, dbname, st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond, buffer, bZip ? _T("zip") : _T("dat")); mir_free(backupfolder); - RotateBackups(); - } - else - { - mir_tstrncpy(dest_file, backup_filename, MAX_PATH); + } else { + _tcsncpy_s(dest_file, backup_filename, _TRUNCATE); if (!_tcscmp(_tcsrchr(backup_filename, _T('.')), _T(".zip"))) bZip = true; } @@ -240,23 +241,20 @@ int Backup(TCHAR* backup_filename) ShowPopup(dbname, TranslateT("Backup in progress"), NULL); if (!options.disable_progress) - progress_dialog = CreateDialog(hInst, MAKEINTRESOURCE(IDD_COPYPROGRESS), 0, DlgProcProgress); + progress_dialog = CreateDialog(g_hInstance, MAKEINTRESOURCE(IDD_COPYPROGRESS), 0, DlgProcProgress); SetDlgItemText(progress_dialog, IDC_PROGRESSMESSAGE, TranslateT("Copying database file...")); - mir_sntprintf(source_file, MAX_PATH, _T("%s\\%s"), profilePath, dbname); + mir_sntprintf(source_file, SIZEOF(source_file), _T("%s\\%s"), profilePath, dbname); TCHAR *pathtmp = Utils_ReplaceVarsT(source_file); BOOL res = 0; if (bZip) - res = MakeZip(pathtmp, dest_file); + res = MakeZip(pathtmp, dest_file, dbname, progress_dialog); else res = CopyFile(pathtmp, dest_file, 0); - if (res) - { - if (!bZip) - { // Set the backup file to the current time for rotator's correct work + if (res) { + if (!bZip) { // Set the backup file to the current time for rotator's correct work FILETIME ft; - SYSTEMTIME st; HANDLE hFile = CreateFile(dest_file, FILE_WRITE_ATTRIBUTES, NULL, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); GetSystemTime(&st); SystemTimeToFileTime(&st, &ft); @@ -266,31 +264,29 @@ int Backup(TCHAR* backup_filename) SendMessage(GetDlgItem(progress_dialog, IDC_PROGRESS), PBM_SETPOS, (WPARAM)(100), 0); UpdateWindow(progress_dialog); db_set_dw(0, "AutoBackups", "LastBackupTimestamp", (DWORD)time(0)); - if (!options.disable_popups) - { + if (!options.disable_popups) { size_t dest_file_len = mir_tstrlen(dest_file); TCHAR *puText; - if (dest_file_len > 50) - { - int i; + if (dest_file_len > 50) { + size_t i; puText = (TCHAR*)mir_alloc(sizeof(TCHAR) * (dest_file_len + 2)); - for (i = (int)dest_file_len - 1; dest_file[i] != _T('\\'); i--); - - mir_tstrncpy(puText, dest_file, i + 2); + for (i = (dest_file_len - 1); dest_file[i] != _T('\\'); i--) + ; + //_tcsncpy_s(dest_file, backup_filename, _TRUNCATE); + mir_tstrncpy(puText, dest_file, (i + 2)); mir_tstrcat(puText, _T("\n")); - mir_tstrcat(puText, dest_file + i + 1); - } - else + mir_tstrcat(puText, (dest_file + i + 1)); + } else puText = mir_tstrdup(dest_file); // Now we need to know, which folder we made a backup. Let's break unnecessary variables :) - while (dest_file[--dest_file_len] != L'\\'); + while (dest_file[-- dest_file_len] != L'\\') + ; dest_file[dest_file_len] = 0; ShowPopup(puText, TranslateT("Database backed up"), dest_file); mir_free(puText); } - } - else + } else DeleteFile(dest_file); mir_free(pathtmp); @@ -298,31 +294,44 @@ int Backup(TCHAR* backup_filename) return 0; } +void BackupThread(void *backup_filename) +{ + Backup((TCHAR*)backup_filename); +} + +void BackupStart(TCHAR *backup_filename) +{ + TCHAR *tm = NULL; + LONG cur_state; + + cur_state = InterlockedCompareExchange((volatile LONG*)&m_state, 1, 0); + if (cur_state != 0) { /* Backup allready in process. */ + /* Show error message :) */ + return; + } + if (backup_filename != NULL) + tm = mir_tstrdup(backup_filename); + if (mir_forkthread(BackupThread, (void*)tm) == INVALID_HANDLE_VALUE) { + InterlockedExchange((volatile LONG*)&m_state, 0); /* Backup done. */ + mir_free(tm); + } +} + VOID CALLBACK TimerProc(HWND hwnd, UINT uMsg, UINT_PTR idEvent, DWORD dwTime) { time_t t = time(NULL); time_t diff = t - (time_t)db_get_dw(0, "AutoBackups", "LastBackupTimestamp", 0); - if (diff > (time_t)(options.period * (options.period_type == PT_MINUTES ? 60 : (options.period_type == PT_HOURS ? 60 * 60 : 60 * 60 * 24 )))) - mir_forkthread(BackupThread, NULL); + if (diff > (time_t)(options.period * (options.period_type == PT_MINUTES ? 60 : (options.period_type == PT_HOURS ? (60 * 60) : (60 * 60 * 24))))) + BackupStart(NULL); } int SetBackupTimer(void) { - if (options.backup_types & BT_PERIODIC) - { - if (timer_id == 0) - timer_id = SetTimer(0, timer_id, 1000 * 60, TimerProc); - } - else if (timer_id != 0) - { + if (timer_id != 0) { KillTimer(0, timer_id); timer_id = 0; } - return 0; -} - -INT_PTR ABService(WPARAM wParam, LPARAM lParam) -{ - mir_forkthread(BackupThread, (void*)wParam); + if (options.backup_types & BT_PERIODIC) + timer_id = SetTimer(0, 0, (1000 * 60), TimerProc); return 0; } diff --git a/plugins/Db_autobackups/src/headers.h b/plugins/Db_autobackups/src/headers.h index faec38492e..cb03254a30 100644 --- a/plugins/Db_autobackups/src/headers.h +++ b/plugins/Db_autobackups/src/headers.h @@ -22,25 +22,30 @@ #include "resource.h" #include "version.h" + #define MS_AB_BACKUP "AB/Backup" #define MS_AB_SAVEAS "AB/SaveAs" -#define SUB_DIR L"\\AutoBackups" -#define DIR L"%miranda_userdata%" +#define SUB_DIR L"\\AutoBackups" +#define DIR L"%miranda_userdata%" + + +int SetBackupTimer(void); +int OptionsInit(WPARAM wParam, LPARAM lParam); +int LoadOptions(void); +void BackupStart(TCHAR *backup_filename); + + +extern HINSTANCE g_hInstance; +extern TCHAR *profilePath; + + +static IconItem iconList[] = { + { LPGEN("Backup profile"), "backup", IDI_ICON1 }, + { LPGEN("Save profile as..."), "saveas", IDI_ICON1 } +}; -void ShowPopup(TCHAR* ptszText, TCHAR* ptszHeader, TCHAR* ptszPath); -INT_PTR DBSaveAs(WPARAM wParam, LPARAM lParam); -INT_PTR ABService(WPARAM wParam, LPARAM lParam); -int Backup(TCHAR* backup_filename); -int SetBackupTimer(void); -int OptionsInit(WPARAM wParam, LPARAM lParam); -int LoadOptions(void); -HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle); -void BackupThread(void* backup_filename); -bool MakeZip(LPCTSTR szSource, LPCTSTR szDest); -extern HINSTANCE hInst; -extern TCHAR* profilePath; #endif diff --git a/plugins/Db_autobackups/src/main.cpp b/plugins/Db_autobackups/src/main.cpp index 2b684a610a..2f9f0d58b0 100644 --- a/plugins/Db_autobackups/src/main.cpp +++ b/plugins/Db_autobackups/src/main.cpp @@ -1,11 +1,9 @@ #include "headers.h" -HINSTANCE hInst; - -TCHAR *profilePath; -int hLangpack; - -HANDLE hFolder; +int hLangpack; +HINSTANCE g_hInstance; +TCHAR *profilePath; +HANDLE hFolder; PLUGININFOEX pluginInfo={ sizeof(PLUGININFOEX), @@ -21,27 +19,95 @@ PLUGININFOEX pluginInfo={ {0x81c220a6, 0x226, 0x4ad6, {0xbf, 0xca, 0x21, 0x7b, 0x17, 0xa1, 0x60, 0x53}} }; -static IconItem iconList[] = { - { LPGEN("Backup profile"), "backup", IDI_ICON1 }, - { LPGEN("Save profile as..."), "saveas", IDI_ICON1 } -}; +int ModulesLoad(WPARAM, LPARAM); +int PreShutdown(WPARAM, LPARAM); + + +BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID Reserved) +{ + switch (dwReason) { + case DLL_PROCESS_ATTACH: + g_hInstance = hInstance; + DisableThreadLibraryCalls(hInstance); + break; + case DLL_PROCESS_DETACH: + /* Nothink to do. */ + break; + } + + return TRUE; +} + +extern "C" __declspec(dllexport) PLUGININFOEX* MirandaPluginInfoEx(DWORD mirandaVersion) +{ + return &pluginInfo; +} + +extern "C" __declspec(dllexport) int Load(void) +{ + mir_getLP(&pluginInfo); + + HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); + HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoad); + + Icon_Register(g_hInstance, LPGEN("Database")"/"LPGEN("Database backups"), iconList, SIZEOF(iconList)); + + return 0; +} + +extern "C" __declspec(dllexport) int Unload(void) +{ + return 0; +} + + static int FoldersGetBackupPath(WPARAM, LPARAM) { - FoldersGetCustomPathT(hFolder, options.folder, MAX_PATH, DIR SUB_DIR); + FoldersGetCustomPathT(hFolder, options.folder, SIZEOF(options.folder), DIR SUB_DIR); + return 0; +} +INT_PTR ABService(WPARAM wParam, LPARAM lParam) +{ + BackupStart(NULL); + return 0; +} +INT_PTR DBSaveAs(WPARAM wParam, LPARAM lParam) +{ + TCHAR fname_buff[MAX_PATH], tszFilter[200]; + OPENFILENAME ofn = {0}; + CallService(MS_DB_GETPROFILENAMET, SIZEOF(fname_buff), (LPARAM)fname_buff); + + mir_sntprintf(tszFilter, SIZEOF(tszFilter), _T("%s (*.dat)%c*.dat%c%s (*.zip)%c*.zip%c%s (*.*)%c*%c"), + TranslateT("Miranda NG databases"), 0, 0, + TranslateT("Compressed Miranda NG databases"), 0, 0, + TranslateT("All files"), 0, 0); + + ofn.lStructSize = sizeof(ofn); + ofn.lpstrFile = fname_buff; + ofn.nMaxFile = SIZEOF(fname_buff); + ofn.Flags = OFN_NOREADONLYRETURN | OFN_OVERWRITEPROMPT; + ofn.lpstrFilter = tszFilter; + ofn.nFilterIndex = 1; + ofn.lpstrDefExt = _T("dat"); + + if (GetSaveFileName(&ofn)) + BackupStart(fname_buff); return 0; } -static void FoldersInit(void) +int ModulesLoad(WPARAM, LPARAM) { + profilePath = Utils_ReplaceVarsT(_T("%miranda_userdata%")); + if (hFolder = FoldersRegisterCustomPathT(LPGEN("Database backups"), LPGEN("Backup folder"), DIR SUB_DIR)) { HookEvent(ME_FOLDERS_PATH_CHANGED, FoldersGetBackupPath); FoldersGetBackupPath(0, 0); } -} -static void MenuInit(void) -{ + CreateServiceFunction(MS_AB_BACKUP, ABService); + CreateServiceFunction(MS_AB_SAVEAS, DBSaveAs); + CLISTMENUITEM mi = { sizeof(mi) }; mi.pszPopupName = LPGEN("Database"); @@ -56,18 +122,12 @@ static void MenuInit(void) mi.icolibItem = iconList[1].hIcolib; mi.position = 500100001; Menu_AddMainMenuItem(&mi); -} -static int ModulesLoad(WPARAM, LPARAM) -{ - profilePath = Utils_ReplaceVarsT(_T("%miranda_userdata%")); - - MenuInit(); - FoldersInit(); + HookEvent(ME_OPT_INITIALISE, OptionsInit); LoadOptions(); if (options.backup_types & BT_START) - mir_forkthread(BackupThread, NULL); + BackupStart(NULL); return 0; } @@ -77,110 +137,8 @@ int PreShutdown(WPARAM, LPARAM) { if (options.backup_types & BT_EXIT) { options.disable_popups = 1; // Don't try to show popups on exit - mir_forkthread(BackupThread, NULL); + BackupStart(NULL); } return 0; } -void SysInit() -{ - mir_getLP(&pluginInfo); - OleInitialize(0); - - CreateServiceFunction(MS_AB_BACKUP, ABService); - CreateServiceFunction(MS_AB_SAVEAS, DBSaveAs); - - HookEvent(ME_OPT_INITIALISE, OptionsInit); - HookEvent(ME_SYSTEM_PRESHUTDOWN, PreShutdown); - HookEvent(ME_SYSTEM_MODULESLOADED, ModulesLoad); - - Icon_Register(hInst, LPGEN("Database")"/"LPGEN("Database backups"), iconList, SIZEOF(iconList)); -} - -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) int Load(void) -{ - SysInit(); - return 0; -} - -extern "C" __declspec(dllexport) int Unload(void) -{ - OleUninitialize(); - return 0; -} - -LRESULT CALLBACK DlgProcPopup(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) -{ - switch (msg) - { - case WM_COMMAND: - { - TCHAR* ptszPath = (TCHAR*)PUGetPluginData(hWnd); - if (ptszPath != 0) - ShellExecute(0, _T("open"), ptszPath, NULL, NULL, SW_SHOW); - - PUDeletePopup(hWnd); - break; - } - case WM_CONTEXTMENU: - PUDeletePopup(hWnd); - break; - - case UM_FREEPLUGINDATA: - TCHAR* ptszPath = (TCHAR*)PUGetPluginData(hWnd); - mir_free(ptszPath); - break; - } - return DefWindowProc(hWnd, msg, wParam, lParam); -} - -void ShowPopup(TCHAR* ptszText, TCHAR* ptszHeader, TCHAR* ptszPath) -{ - POPUPDATAT ppd = {0}; - - mir_tstrcpy(ppd.lptzText, ptszText); - mir_tstrcpy(ppd.lptzContactName, ptszHeader); - if (ptszPath != NULL) - ppd.PluginData = (void*)mir_tstrdup(ptszPath); - ppd.PluginWindowProc = DlgProcPopup; - ppd.lchIcon = Skin_GetIconByHandle(iconList[0].hIcolib); - - PUAddPopupT(&ppd); -} - -HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle) -{ - HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, - TOOLTIPS_CLASS, NULL, - WS_POPUP | TTS_NOPREFIX, - CW_USEDEFAULT, CW_USEDEFAULT, - CW_USEDEFAULT, CW_USEDEFAULT, - hwndParent, NULL, hInst, NULL); - - SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); - - TOOLINFO ti = {0}; - ti.cbSize = sizeof(TOOLINFO); - ti.uFlags = TTF_SUBCLASS | TTF_CENTERTIP; - ti.hwnd = hwndParent; - ti.hinst = hInst; - ti.lpszText = ptszText; - GetClientRect (hwndParent, &ti.rect); - ti.rect.left = -80; - - SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); - SendMessage(hwndTT, TTM_SETTITLE, 1, (LPARAM)ptszTitle); - SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, (LPARAM)650); - return hwndTT; -} diff --git a/plugins/Db_autobackups/src/options.cpp b/plugins/Db_autobackups/src/options.cpp index 6457bf6426..9ae294ea0f 100644 --- a/plugins/Db_autobackups/src/options.cpp +++ b/plugins/Db_autobackups/src/options.cpp @@ -1,7 +1,37 @@ #include "headers.h" -HWND hPathTip; -Options options; +HWND hPathTip; +Options options; + + + +HWND CreateToolTip(HWND hwndParent, LPTSTR ptszText, LPTSTR ptszTitle) +{ + HWND hwndTT = CreateWindowEx(WS_EX_TOPMOST, + TOOLTIPS_CLASS, NULL, + (WS_POPUP | TTS_NOPREFIX), + CW_USEDEFAULT, CW_USEDEFAULT, + CW_USEDEFAULT, CW_USEDEFAULT, + hwndParent, NULL, g_hInstance, NULL); + + SetWindowPos(hwndTT, HWND_TOPMOST, 0, 0, 0, 0, (SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE)); + + TOOLINFO ti = { 0 }; + ti.cbSize = sizeof(TOOLINFO); + ti.uFlags = TTF_SUBCLASS | TTF_CENTERTIP; + ti.hwnd = hwndParent; + ti.hinst = g_hInstance; + ti.lpszText = ptszText; + GetClientRect (hwndParent, &ti.rect); + ti.rect.left = -80; + + SendMessage(hwndTT, TTM_ADDTOOL, 0, (LPARAM) (LPTOOLINFO) &ti); + SendMessage(hwndTT, TTM_SETTITLE, 1, (LPARAM)ptszTitle); + SendMessage(hwndTT, TTM_SETMAXTIPWIDTH, 0, (LPARAM)650); + + return hwndTT; +} + int LoadOptions(void) { @@ -16,9 +46,9 @@ int LoadOptions(void) TCHAR *tmp = Utils_ReplaceVarsT(dbv.ptszVal); if (_tcslen(tmp) >= 2 && tmp[1] == ':') - _tcsncpy(options.folder, dbv.ptszVal, MAX_PATH-1); + _tcsncpy_s(options.folder, dbv.ptszVal, _TRUNCATE); else - mir_sntprintf(options.folder, MAX_PATH, _T("%s\\%s"), profilePath, dbv.ptszVal); + mir_sntprintf(options.folder, SIZEOF(options.folder), _T("%s\\%s"), profilePath, dbv.ptszVal); db_free(&dbv); mir_free(tmp); @@ -40,11 +70,12 @@ int SaveOptions(void) TCHAR prof_dir[MAX_PATH]; db_set_b(0, "AutoBackups", "BackupType", (BYTE)options.backup_types); - if (options.period < 1) options.period = 1; + if (options.period < 1) + options.period = 1; db_set_w(0, "AutoBackups", "Period", (WORD)options.period); db_set_b(0, "AutoBackups", "PeriodType", (BYTE)options.period_type); - mir_sntprintf(prof_dir, MAX_PATH, _T("%s\\"), profilePath); + mir_sntprintf(prof_dir, SIZEOF(prof_dir), _T("%s\\"), profilePath); size_t prof_len = _tcslen(prof_dir); size_t opt_len = _tcslen(options.folder); @@ -54,11 +85,9 @@ int SaveOptions(void) db_set_ts(0, "AutoBackups", "Folder", options.folder); TCHAR *tmp = Utils_ReplaceVarsT(options.folder); - if (_tcslen(tmp) < 2 || tmp[1] != ':') - { - TCHAR *buf = mir_tstrdup(options.folder); - mir_sntprintf(options.folder, MAX_PATH, _T("%s\\%s"), profilePath, buf); - mir_free(buf); + if (_tcslen(tmp) < 2 || tmp[1] != ':') { + _tcsncpy_s(prof_dir, options.folder, _TRUNCATE); + mir_sntprintf(options.folder, SIZEOF(options.folder), _T("%s\\%s"), profilePath, prof_dir); } mir_free(tmp); db_set_w(0, "AutoBackups", "NumBackups", (WORD)options.num_backups); @@ -155,17 +184,17 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP ShowWindow(GetDlgItem(hwndDlg, IDC_LNK_FOLDERS), SW_SHOW); } else { - TCHAR tszTooltipText[1024]; + TCHAR tszTooltipText[4096]; mir_sntprintf(tszTooltipText, SIZEOF(tszTooltipText), _T("%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s\n%s - %s"), - _T("%miranda_path%"), TranslateT("path to Miranda root folder"), - _T("%miranda_profilesdir%"), TranslateT("path to folder containing Miranda profiles"), + _T("%miranda_path%"), TranslateT("path to Miranda root folder"), + _T("%miranda_profilesdir%"), TranslateT("path to folder containing Miranda profiles"), _T("%miranda_profilename%"), TranslateT("name of current Miranda profile (filename, without extension)"), - _T("%miranda_userdata%"), TranslateT("will return parsed string %miranda_profilesdir%\\%miranda_profilename%"), - _T("%appdata%"), TranslateT("same as environment variable %APPDATA% for currently logged-on Windows user"), - _T("%username%"), TranslateT("username for currently logged-on Windows user"), - _T("%mydocuments%"), TranslateT("\"My Documents\" folder for currently logged-on Windows user"), - _T("%desktop%"), TranslateT("\"Desktop\" folder for currently logged-on Windows user"), - _T("%xxxxxxx%"), TranslateT("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)") + _T("%miranda_userdata%"), TranslateT("will return parsed string %miranda_profilesdir%\\%miranda_profilename%"), + _T("%appdata%"), TranslateT("same as environment variable %APPDATA% for currently logged-on Windows user"), + _T("%username%"), TranslateT("username for currently logged-on Windows user"), + _T("%mydocuments%"), TranslateT("\"My Documents\" folder for currently logged-on Windows user"), + _T("%desktop%"), TranslateT("\"Desktop\" folder for currently logged-on Windows user"), + _T("%xxxxxxx%"), TranslateT("any environment variable defined in current Windows session (like %systemroot%, %allusersprofile%, etc.)") ); hPathTip = CreateToolTip(GetDlgItem(hwndDlg, IDC_ED_FOLDER), tszTooltipText, TranslateT("Variables")); } @@ -259,7 +288,7 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP break; } case IDC_BUT_NOW: - mir_forkthread(BackupThread, NULL); + BackupStart(NULL); break; case IDC_CHK_NOPROG: new_options.disable_progress = IsDlgButtonChecked(hwndDlg, IDC_CHK_NOPROG); @@ -312,9 +341,9 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP TCHAR *tmp = Utils_ReplaceVarsT(folder_buff); if (_tcslen(tmp) >= 2 && tmp[1] == ':') - _tcsncpy(backupfolder, tmp, MAX_PATH-1); + _tcsncpy_s(backupfolder, tmp, _TRUNCATE); else - mir_sntprintf(backupfolder, MAX_PATH, _T("%s\\%s"), profilePath, tmp); + mir_sntprintf(backupfolder, SIZEOF(backupfolder), _T("%s\\%s"), profilePath, tmp); mir_free(tmp); int err = CreateDirectoryTreeT(backupfolder); @@ -326,11 +355,10 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP } if (folder_ok) { - _tcsncpy(new_options.folder, folder_buff, MAX_PATH-1); + _tcsncpy_s(new_options.folder, folder_buff, _TRUNCATE); memcpy(&options, &new_options, sizeof(Options)); SaveOptions(); - } - else { + } else { memcpy(&new_options, &options, sizeof(Options)); SetDlgState(hwndDlg); } @@ -355,13 +383,15 @@ INT_PTR CALLBACK DlgProcOptions(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lP int OptionsInit(WPARAM wParam, LPARAM lParam) { OPTIONSDIALOGPAGE odp = { sizeof(odp) }; + odp.position = -790000000; - odp.hInstance = hInst; + odp.hInstance = g_hInstance; odp.pszTemplate = MAKEINTRESOURCEA(IDD_OPTIONS); odp.pszTitle = LPGEN("Automatic backups"); odp.pszGroup = LPGEN("Database"); odp.flags = ODPF_BOLDGROUPS; odp.pfnDlgProc = DlgProcOptions; Options_AddPage(wParam, &odp); + return 0; } diff --git a/plugins/Db_autobackups/src/options.h b/plugins/Db_autobackups/src/options.h index 86aa4509a6..27ddff4eef 100644 --- a/plugins/Db_autobackups/src/options.h +++ b/plugins/Db_autobackups/src/options.h @@ -26,14 +26,14 @@ typedef enum { BT_DISABLED = 0, BT_START = 1, BT_EXIT = 2, BT_PERIODIC = 4} Back typedef enum { PT_DAYS, PT_HOURS, PT_MINUTES} PeriodType; typedef struct Options_tag { - int backup_types; + int backup_types; unsigned int period; PeriodType period_type; - TCHAR folder[MAX_PATH]; - unsigned int num_backups; - BOOL disable_progress; - BOOL disable_popups; - BOOL use_zip; + TCHAR folder[MAX_PATH]; + size_t num_backups; + BOOL disable_progress; + BOOL disable_popups; + BOOL use_zip; } Options; extern Options options; \ No newline at end of file diff --git a/plugins/FloatingContacts/src/filedrop.cpp b/plugins/FloatingContacts/src/filedrop.cpp index 1a869d6433..64ee8db693 100644 --- a/plugins/FloatingContacts/src/filedrop.cpp +++ b/plugins/FloatingContacts/src/filedrop.cpp @@ -332,12 +332,10 @@ static int CountDroppedFiles( char **ppDroppedItems, int nCount ) // Init/destroy void InitFileDropping() { - OleInitialize( NULL ); } void FreeFileDropping(void) { - OleUninitialize(); } void RegisterFileDropping( HWND hwnd, CDropTarget* pdropTarget ) diff --git a/plugins/IEView/src/IEView.cpp b/plugins/IEView/src/IEView.cpp index a2a7a13721..0916e68899 100644 --- a/plugins/IEView/src/IEView.cpp +++ b/plugins/IEView/src/IEView.cpp @@ -360,8 +360,6 @@ void IEView::init() isInited = true; InitializeCriticalSection(&mutex); - if (FAILED(OleInitialize(NULL))) - MessageBox(NULL, TranslateT("OleInitialize failed."), TranslateT("ERROR"), MB_OK); } void IEView::release() diff --git a/plugins/MenuItemEx/src/main.cpp b/plugins/MenuItemEx/src/main.cpp index 4eec8a98c1..8e1dc6778a 100644 --- a/plugins/MenuItemEx/src/main.cpp +++ b/plugins/MenuItemEx/src/main.cpp @@ -268,24 +268,21 @@ BOOL isMetaContact(MCONTACT hContact) return FALSE; } -void GetID(MCONTACT hContact, LPSTR szProto, LPSTR szID) +void GetID(MCONTACT hContact, LPSTR szProto, LPSTR szID, size_t dwIDSize) { DBVARIANT dbv_uniqueid; LPSTR uID = (LPSTR)CallProtoService(szProto, PS_GETCAPS, PFLAG_UNIQUEIDSETTING, 0); if (uID == (LPSTR)CALLSERVICE_NOTFOUND) uID = NULL; - *szID = '\0'; - + szID[0] = 0; if (uID && db_get(hContact, szProto, uID, &dbv_uniqueid) == 0) { if (dbv_uniqueid.type == DBVT_DWORD) - wsprintfA(szID, "%u", dbv_uniqueid.dVal); //!!!!!!!!! + mir_snprintf(szID, dwIDSize, "%u", dbv_uniqueid.dVal); else if (dbv_uniqueid.type == DBVT_WORD) - wsprintfA(szID, "%u", dbv_uniqueid.wVal); //!!!!!!!!! - else if (dbv_uniqueid.type == DBVT_BLOB) - wsprintfA(szID, "%s", dbv_uniqueid.cpbVal); //!!!!!!!!! + mir_snprintf(szID, dwIDSize, "%u", dbv_uniqueid.wVal); else - wsprintfA(szID, "%s", dbv_uniqueid.pszVal); //!!!!!!!! + strncpy_s(szID, dwIDSize, (char*)dbv_uniqueid.cpbVal, _TRUNCATE); db_free(&dbv_uniqueid); } @@ -512,7 +509,7 @@ void ModifyCopyID(MCONTACT hContact, BOOL bShowID, BOOL bTrimID) TCHAR buffer[256]; char szID[256]; - GetID(hContact, szProto, (LPSTR)&szID); + GetID(hContact, szProto, (LPSTR)&szID, SIZEOF(szID)); if (szID[0]) { if (bShowID) { if (bTrimID && (strlen(szID) > MAX_IDLEN)) { @@ -589,7 +586,7 @@ void ModifyCopyMirVer(MCONTACT hContact) INT_PTR onCopyID(WPARAM wparam, LPARAM lparam) { - char szID[128] = { 0 }, buffer[256] = { 0 }; + char szID[256], buffer[256]; MCONTACT hContact = (MCONTACT)wparam; if (isMetaContact(hContact)) { @@ -603,7 +600,7 @@ INT_PTR onCopyID(WPARAM wparam, LPARAM lparam) if (szProto == NULL) return 0; - GetID(hContact, szProto, (LPSTR)&szID); + GetID(hContact, szProto, (LPSTR)&szID, SIZEOF(szID)); if (db_get_dw(NULL, MODULENAME, "flags", vf_default) & VF_CIDN) { PROTOACCOUNT *pa = ProtoGetAccount(szProto); @@ -612,8 +609,8 @@ INT_PTR onCopyID(WPARAM wparam, LPARAM lparam) mir_snprintf(buffer, SIZEOF(buffer), "%s: %s", pa->szProtoName, szID); else mir_snprintf(buffer, SIZEOF(buffer), "%s: %s", szProto, szID); - } - else strcpy(buffer, szID); + } else + strcpy(buffer, szID); CopyToClipboard((HWND)lparam, buffer, 0); if (CTRL_IS_PRESSED && bPopupService) diff --git a/plugins/Non-IM Contact/src/contactinfo.cpp b/plugins/Non-IM Contact/src/contactinfo.cpp index 8638bc5e48..265a2f1ae6 100644 --- a/plugins/Non-IM Contact/src/contactinfo.cpp +++ b/plugins/Non-IM Contact/src/contactinfo.cpp @@ -81,29 +81,27 @@ LRESULT CALLBACK ButtWndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lPar int BrowseForFolder(HWND hwnd,char *szPath) { int result=0; - - if (SUCCEEDED(OleInitialize(NULL))) { - LPMALLOC pMalloc; - if (SUCCEEDED(CoGetMalloc(1,&pMalloc))) { - ptrT tszPath( mir_a2t(szPath)); - BROWSEINFO bi={0}; - bi.hwndOwner = hwnd; - bi.pszDisplayName = tszPath; - bi.lpszTitle = TranslateT("Select Folder"); - bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS; // Use this combo instead of BIF_USENEWUI - bi.lParam = (LPARAM)szPath; - - ITEMIDLIST *pidlResult = SHBrowseForFolder(&bi); - if (pidlResult) { - SHGetPathFromIDListA(pidlResult, szPath); - mir_strcat(szPath,"\\"); - result = 1; - } - pMalloc->Free(pidlResult); - pMalloc->Release(); + LPMALLOC pMalloc; + + if (SUCCEEDED(CoGetMalloc(1,&pMalloc))) { + ptrT tszPath( mir_a2t(szPath)); + BROWSEINFO bi={0}; + bi.hwndOwner = hwnd; + bi.pszDisplayName = tszPath; + bi.lpszTitle = TranslateT("Select Folder"); + bi.ulFlags = BIF_EDITBOX | BIF_RETURNONLYFSDIRS; // Use this combo instead of BIF_USENEWUI + bi.lParam = (LPARAM)szPath; + + ITEMIDLIST *pidlResult = SHBrowseForFolder(&bi); + if (pidlResult) { + SHGetPathFromIDListA(pidlResult, szPath); + mir_strcat(szPath,"\\"); + result = 1; } - OleUninitialize(); + pMalloc->Free(pidlResult); + pMalloc->Release(); } + return result; } diff --git a/plugins/Popup/src/popup_wnd2.cpp b/plugins/Popup/src/popup_wnd2.cpp index 6eeef7e451..355ce59753 100644 --- a/plugins/Popup/src/popup_wnd2.cpp +++ b/plugins/Popup/src/popup_wnd2.cpp @@ -1360,7 +1360,7 @@ LRESULT CALLBACK PopupWnd2::WindowProc(HWND hwnd, UINT message, WPARAM wParam, L void WindowThread(void *arg) { - OleInitialize(NULL); // we may need OLE in this thread for smiley substitution + Coinitializе(NULL); // we may need OLE in this thread for smiley substitution PopupWnd2 *wnd = (PopupWnd2 *)arg; wnd->buildMText(); diff --git a/plugins/Scriver/src/msgs.cpp b/plugins/Scriver/src/msgs.cpp index b194f65386..aa2fdfc480 100644 --- a/plugins/Scriver/src/msgs.cpp +++ b/plugins/Scriver/src/msgs.cpp @@ -503,7 +503,6 @@ int OnUnloadModule(void) ReleaseIcons(); FreeMsgLogIcons(); FreeLibrary(GetModuleHandleA("Msftedit.dll")); - OleUninitialize(); RichUtil_Unload(); FreeGlobals(); return 0; @@ -522,7 +521,6 @@ int OnLoadModule(void) InitGlobals(); RichUtil_Load(); - OleInitialize(NULL); InitStatusIcons(); RegisterIcons(); RegisterFontServiceFonts(); diff --git a/plugins/TabSRMM/src/msgs.cpp b/plugins/TabSRMM/src/msgs.cpp index bea7f95208..ec1145b851 100644 --- a/plugins/TabSRMM/src/msgs.cpp +++ b/plugins/TabSRMM/src/msgs.cpp @@ -367,7 +367,6 @@ int SplitmsgShutdown(void) delete Win7Taskbar; delete mREOLECallback; - OleUninitialize(); DestroyMenu(PluginConfig.g_hMenuContext); if (PluginConfig.g_hMenuContainer) DestroyMenu(PluginConfig.g_hMenuContainer); @@ -454,7 +453,6 @@ int LoadSendRecvMessageModule(void) Utils::loadSystemLibrary(L"\\Msftedit.dll"); - OleInitialize(NULL); mREOLECallback = new REOLECallback; Win7Taskbar = new CTaskbarInteract; Win7Taskbar->updateMetrics(); diff --git a/plugins/WebView/src/webview_getdata.cpp b/plugins/WebView/src/webview_getdata.cpp index f2683750e1..df85b2d813 100644 --- a/plugins/WebView/src/webview_getdata.cpp +++ b/plugins/WebView/src/webview_getdata.cpp @@ -146,17 +146,9 @@ void GetData(void *param) db_set_ts(hContact, "CList", "StatusMsg", statusText); } if (nlhrReply->dataLength) { - size_t cbLen = mir_strlen(nlhrReply->pData); - char *szInfo = (char*)malloc(cbLen + 2); - mir_strncpy(szInfo, nlhrReply->pData, cbLen); - downloadsize = (ULONG)mir_strlen(nlhrReply->pData); - trunccount = 0; - mir_strncpy(truncated2, szInfo, MAXSIZE2); - free(szInfo); - - //////////////////////////////////////////// - sprintf(truncated2, "%s", nlhrReply->pData); + downloadsize = (ULONG)mir_strlen(nlhrReply->pData); + strncpy_s(truncated2, nlhrReply->pData, _TRUNCATE); AlreadyDownloading = 1; } // END DATELENGTH } // END REPLY diff --git a/plugins/mTextControl/src/richeditutils.cpp b/plugins/mTextControl/src/richeditutils.cpp index 7ffa31c1bd..c0f1a5342a 100644 --- a/plugins/mTextControl/src/richeditutils.cpp +++ b/plugins/mTextControl/src/richeditutils.cpp @@ -122,7 +122,6 @@ LRESULT CALLBACK RichEditProxyWndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM void LoadRichEdit() { - OleInitialize(NULL); reOleCallback = new CREOleCallback; WNDCLASSEX wcl; @@ -144,7 +143,6 @@ void LoadRichEdit() void UnloadRichEdit() { delete reOleCallback; - OleUninitialize(); } HWND CreateProxyWindow(ITextServices *ts) -- cgit v1.2.3