From f17466bd1efebfb4c1f9031b11bc40fcf51ef53a Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 13 Aug 2018 21:26:28 +0300 Subject: Msg_Export: - bCreatePathToFile replaced with CreateDirectoryTreeW() call; - g_bUseIntViewer exported from FileViewer.cpp; - more code cleaning --- plugins/Msg_Export/src/FileViewer.cpp | 555 ++++++++++++---------------------- plugins/Msg_Export/src/FileViewer.h | 3 +- plugins/Msg_Export/src/main.cpp | 9 +- plugins/Msg_Export/src/options.cpp | 4 +- plugins/Msg_Export/src/utils.cpp | 227 +------------- plugins/Msg_Export/src/utils.h | 3 - 6 files changed, 212 insertions(+), 589 deletions(-) diff --git a/plugins/Msg_Export/src/FileViewer.cpp b/plugins/Msg_Export/src/FileViewer.cpp index 3cbfbdcdcd..4f36f9fbd3 100755 --- a/plugins/Msg_Export/src/FileViewer.cpp +++ b/plugins/Msg_Export/src/FileViewer.cpp @@ -1,20 +1,20 @@ - -//This file is part of Msg_Export a Miranda IM plugin -//Copyright (C)2002 Kennet Nielsen ( http://sourceforge.net/projects/msg-export/ ) +///////////////////////////////////////////////////////////////////////////////////////// +// This file is part of Msg_Export a Miranda IM plugin +// Copyright (C)2002 Kennet Nielsen ( http://sourceforge.net/projects/msg-export/ ) // -//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 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. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. #include "stdafx.h" @@ -24,12 +24,9 @@ static UINT UM_FIND_CMD = RegisterWindowMessage(FINDMSGSTRING); #define ID_FV_COLOR 0x0020 #define ID_FV_SYNTAX_HL 0x0030 #define ID_FV_SAVE_AS_RTF 0x0040 -// ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX); -// ASSERT(IDM_ABOUTBOX < 0xF000); - // Specifies if history is opened internaly or externaly -bool bUseIntViewer = true; +bool g_bUseIntViewer = true; // External program used to view files wstring sFileViewerPrg; @@ -37,26 +34,26 @@ wstring sFileViewerPrg; // handle to the RichEditDll. We need to load this dll to use a RichEdit. HMODULE hRichEditDll = nullptr; - #define CONT(i) ((in[i]&0xc0) == 0x80) #define VAL(i, s) ((in[i]&0x3f) << s) -void swap(char &c1, char &c2) { +void swap(char &c1, char &c2) +{ char ch; ch = c1; c1 = c2; c2 = ch; } -int DecodeUTF8(const char *pcBuff, int /*iBufSize*/, char *pcOutBuf) { +int DecodeUTF8(const char *pcBuff, int /*iBufSize*/, char *pcOutBuf) +{ int iBytesInOut = 0; - int /*cp,*/i; char ch, *p; - //Parse UTF-8 sequence - //Support only chars up to three bytes (UCS-4 - go away!) - //Warning: Partial decoding is possible! - i = 0; + // Parse UTF-8 sequence + // Support only chars up to three bytes (UCS-4 - go away!) + // Warning: Partial decoding is possible! + int i = 0; ch = pcBuff[i]; if (!(ch & 0x80)) { pcOutBuf[iBytesInOut++] = ch; @@ -93,7 +90,7 @@ int DecodeUTF8(const char *pcBuff, int /*iBufSize*/, char *pcOutBuf) { int __utf8_get_char(const char *in, int *chr) -{ /* 2-byte, 0x80-0x7ff */ +{ return DecodeUTF8(in, 256, (char *)chr); } @@ -174,19 +171,11 @@ public: }; int CLStreamRTFInfo::nOptimalReadLen = 3300; -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : nWriteHeader // Type : Private / Public / Protected // Parameters : pszTarget - ? // nLen - ? -// Returns : int -// Description : -// -// References : - -// Remarks : - -// Created : 030204, 04 February 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// int CLStreamRTFInfo::nWriteHeader(char *pszTarget, int nLen) { @@ -201,8 +190,7 @@ int CLStreamRTFInfo::nWriteHeader(char *pszTarget, int nLen) GetRValue(cMyText), GetGValue(cMyText), GetBValue(cMyText), GetRValue(cYourText), GetGValue(cYourText), GetBValue(cYourText)); - if (nSrcLen > nLen) - { + if (nSrcLen > nLen) { MessageBox(nullptr, TranslateT("Failed to write to the Rich Edit the buffer was to small."), MSG_BOX_TITEL, MB_OK); return 0; // target buffer to small } @@ -215,27 +203,19 @@ int CLStreamRTFInfo::nWriteHeader(char *pszTarget, int nLen) const char szNewLine[] = "\n\\par "; const char szRtfEnd[] = "\r\n\\par }\r\n\0"; -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : nLoadFileStream // Type : Private / Public / Protected // Parameters : pbBuff - ? // cb - ? // Returns : int -// Description : -// -// References : - -// Remarks : - -// Created : 030204, 04 February 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) { if (bTailWriten) return 0; - if (nOptimalReadLen < 500) - { + if (nOptimalReadLen < 500) { MessageBox(nullptr, TranslateT("Error: Optimal buffer size decreased to a too low size!"), MSG_BOX_TITEL, MB_OK); return 0; } @@ -248,10 +228,8 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) DWORD dwCurrent = 0; DWORD n = 0; - if (!bHeaderWriten) - { - if (dwRead >= 3) - { + if (!bHeaderWriten) { + if (dwRead >= 3) { bUtf8File = bIsUtf8Header(abBuf); if (bUtf8File) n = 3; @@ -262,15 +240,12 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) nNickLen = WideCharToMultiByte(bUtf8File ? CP_UTF8 : CP_ACP, 0, sMyNick.c_str(), (int)sMyNick.length(), szMyNick, sizeof(szMyNick), NULL, NULL); } - else - { - if (bCheckFirstForNick) - { + else { + if (bCheckFirstForNick) { // Test against "<<" also if (((memcmp(abBuf, szMyNick, nNickLen) == 0) || (abBuf[0] == '<' && abBuf[1] == '<') - ) != bLastColorMyNick) - { + ) != bLastColorMyNick) { // we shut only get here if we need to change color !! bLastColorMyNick = !bLastColorMyNick; // change color @@ -282,12 +257,10 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) bool bIsFileEnd = dwRead < dwToRead; - for (; n < dwRead; n++) - { + for (; n < dwRead; n++) { // worst case is a file ending with \n or a unicode letter. resulting in a big unicode string // here we need szNewLine and szRtfEnd. the 10 is a small safty margin. - if (dwCurrent + (sizeof(szNewLine) + sizeof(szRtfEnd) + 10) > (DWORD)cb) - { + if (dwCurrent + (sizeof(szNewLine) + sizeof(szRtfEnd) + 10) > (DWORD)cb) { // oh no !!! we have almost reached the end of the windows supplyed buffer // we are writing to. we need to abort mision *S*!! // and rewinde file @@ -297,13 +270,11 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) return dwCurrent; } - if (abBuf[n] == '\n') - { + if (abBuf[n] == '\n') { memcpy(&pbBuff[dwCurrent], szNewLine, sizeof(szNewLine) - 1); dwCurrent += sizeof(szNewLine) - 1; - if (n + 1 >= dwRead) - { + if (n + 1 >= dwRead) { // this is an anoing case because here we have read \n as the last char in the file // this means that the if the next data read from file begins with it has // to be highlighted @@ -315,15 +286,12 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) if (abBuf[n + 1] == ' ' || abBuf[n + 1] == '\t' || abBuf[n + 1] == '\r') continue; - if (n + nNickLen >= dwRead) - { - if (!bIsFileEnd) - { + if (n + nNickLen >= dwRead) { + if (!bIsFileEnd) { // here we have a problem we haven't read this data yet // the data we need to compare to is still in the file. // we can't read more data from the file because the we // might just move the problem. if file contains \n\n\n\n\n ... - LONG lExtraRead = (n + 1) - dwRead; if (lExtraRead >= 0) MessageBox(nullptr, TranslateT("Internal error! (lExtraRead >= 0)"), MSG_BOX_TITEL, MB_OK); @@ -334,19 +302,8 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) if (!bLastColorMyNick) continue; - // else the last color user was my nick - // we needd to change color to the other user color. - - - /* old code !! - DWORD dwAddedToBuf; - if ( !ReadFile(hFile, &abBuf[dwRead], dwNeeded, &dwAddedToBuf, (LPOVERLAPPED)NULL)) - return 0; - dwToRead += dwNeeded; - dwRead += dwAddedToBuf;*/ } - else - { + else { // the data we need is here just compare if (((memcmp(&abBuf[n + 1], szMyNick, nNickLen) == 0) || (abBuf[n + 1] == '<' && abBuf[n + 2] == '<') @@ -361,12 +318,10 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) dwCurrent += 5; continue; } - else if (abBuf[n] == '\\' || abBuf[n] == '}' || abBuf[n] == '{') - { + else if (abBuf[n] == '\\' || abBuf[n] == '}' || abBuf[n] == '{') { pbBuff[dwCurrent++] = '\\'; } - else if (bUtf8File && (abBuf[n] & 0x80)) - { + else if (bUtf8File && (abBuf[n] & 0x80)) { int nValue; int nLen = __utf8_get_char((const char *)&abBuf[n], &nValue); if (nLen + n > dwRead) { @@ -374,85 +329,53 @@ int CLStreamRTFInfo::nLoadFileStream(LPBYTE pbBuff, LONG cb) break; } dwCurrent += sprintf((char*)&pbBuff[dwCurrent], "\\u%d?", nValue); //!!!!!!!!! - //continue; - /* // Then we have an extended char in the UTF8 file. - // we need to convert this to UCS-2 and then to \uN in the RTF - int nUtf8Len = 1; - while( ( (n + nUtf8Len) < dwRead) && ((abBuf[ n + nUtf8Len ] & 0xC0) == 0x80)) - nUtf8Len++; - wchar_t szWstr[2]; - if (MultiByteToWideChar( CP_UTF8, 0, (char*)&abBuf[n], nUtf8Len, szWstr, 2) == 1 ) - { - if ((int)(szWstr[0]) != nValue ) - __utf8_get_char( (const char *)&abBuf[n], &nValue); - - // dwCurrent += sprintf( (char*)&pbBuff[dwCurrent], "\\u%d?", (int)(szWstr[0])); - // n += nUtf8Len - 1; - // continue; - }*/ + n += nLen - 1; continue; } pbBuff[dwCurrent++] = abBuf[n]; } - if (bIsFileEnd) - {// write end + if (bIsFileEnd) {// write end memcpy(&pbBuff[dwCurrent], szRtfEnd, sizeof(szRtfEnd) - 1); dwCurrent += sizeof(szRtfEnd) - 1; bTailWriten = true; } - //memcpy( pbBuff, abBuf, dwRead); + return dwCurrent; } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : UpdateFileViews // Type : Global // Parameters : pszFile - File which has been updated // Returns : void // Description : Send a message to alle to windows that need updating -// -// References : - -// Remarks : - -// Created : 021213, 13 December 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void UpdateFileViews(const wchar_t *pszFile) { mir_cslock lck(csHistoryList); list< CLHistoryDlg* >::const_iterator iterator; - for (iterator = clHistoryDlgList.begin(); iterator != clHistoryDlgList.end(); ++iterator) - { + for (iterator = clHistoryDlgList.begin(); iterator != clHistoryDlgList.end(); ++iterator) { CLHistoryDlg* pcl = (*iterator); - if (pcl->sPath == pszFile) - { + if (pcl->sPath == pszFile) { PostMessage(pcl->hWnd, WM_RELOAD_FILE, 0, 0); } } } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bOpenExternaly // Type : Global // Parameters : hContact - ? // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 021010, 10 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bOpenExternaly(MCONTACT hContact) { wstring sPath = GetFilePathFromUser(hContact); - if (sFileViewerPrg.empty()) - { + if (sFileViewerPrg.empty()) { SHELLEXECUTEINFO st = { 0 }; st.cbSize = sizeof(st); st.fMask = SEE_MASK_INVOKEIDLIST; @@ -481,53 +404,35 @@ bool bOpenExternaly(MCONTACT hContact) nullptr, nullptr, &sStartupInfo, - &stProcesses)) - { + &stProcesses)) { DisplayLastError(LPGENW("Failed to execute external file view")); } return true; } - -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bGetInternalViewer // Type : Global // Parameters : None // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 021016, 16 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bUseInternalViewer() { - return bUseIntViewer; + return g_bUseIntViewer; } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bUseInternalViewer // Type : Global // Parameters : bNew - ? // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 021016, 16 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bUseInternalViewer(bool bNew) { - bUseIntViewer = bNew; - if (bUseIntViewer && !hRichEditDll) - { + g_bUseIntViewer = bNew; + if (g_bUseIntViewer && !hRichEditDll) { hRichEditDll = LoadLibraryA("Msftedit.dll"); - if (!hRichEditDll) - { + if (!hRichEditDll) { DisplayLastError(LPGENW("Failed to load Rich Edit (Msftedit.dll)")); return false; } @@ -535,8 +440,7 @@ bool bUseInternalViewer(bool bNew) return true; } - -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : RichEditStreamLoadFile // Type : Global // Parameters : dwCookie - ? @@ -544,13 +448,6 @@ bool bUseInternalViewer(bool bNew) // cb - ? // pcb - ? // Returns : DWORD CALLBACK -// Description : -// -// References : - -// Remarks : - -// Created : 021010, 10 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// DWORD CALLBACK RichEditStreamLoadFile(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) { @@ -572,36 +469,12 @@ DWORD CALLBACK RichEditStreamSaveFile(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb return *pcb != cb; } -/* -DWORD dwCurPos = 0; -DWORD dwDataRead = 0; -BYTE * pabFileData = NULL; - -DWORD CALLBACK RichEditStreamLoadFile(DWORD_PTR dwCookie, LPBYTE pbBuff, LONG cb, LONG *pcb) -{ -*pcb = 0; -while( dwCurPos < dwDataRead && *pcb < cb ) -{ -pbBuff[ *pcb ] = pabFileData[ dwCurPos ]; -dwCurPos++; -(*pcb)++; -} -return (DWORD) ( *pcb >= 0 ? NOERROR : ( *pcb = 0, E_FAIL)); -} -*/ -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bLoadFile // Type : Global // Parameters : hwndDlg - ? // hContact - ? // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 021010, 10 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) { @@ -687,26 +560,18 @@ bool bLoadFile(HWND hwndDlg, CLHistoryDlg * pclDlg) return true; } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bAdvancedCopy // Type : Global // Parameters : hwnd - handle to RichEdit control // Returns : Returns true if text was copied to the clipboard -// Description : -// -// References : - -// Remarks : - -// Created : 030730, 30 juli 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bAdvancedCopy(HWND hwnd) { CHARRANGE sSelectRange; SendMessage(hwnd, EM_EXGETSEL, 0, (LPARAM)&sSelectRange); int nSelLenght = sSelectRange.cpMax - sSelectRange.cpMin + 1; // +1 for null termination - if (nSelLenght > 1) - { + if (nSelLenght > 1) { if (OpenClipboard(nullptr)) { EmptyClipboard(); @@ -743,44 +608,37 @@ bool bAdvancedCopy(HWND hwnd) return false; } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : EditSubclassProc // Type : Global // Parameters : hwnd - ? // uMsg - ? // wParam - ? // lParam - ? -// Returns : LRESULT CALLBACK -// Description : -// -// References : - -// Remarks : - -// Created : 021013, 13 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// LRESULT CALLBACK EditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) { CLHistoryDlg *pclDlg = (CLHistoryDlg*)GetWindowLongPtr(hwnd, GWLP_USERDATA); switch (msg) { case WM_CONTEXTMENU: - { - HMENU nMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_FV_EDIT)); - HMENU nSubMenu = GetSubMenu(nMenu, 0); - POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; - - if (pt.x == -1 && pt.y == -1) { - DWORD dwStart, dwEnd; - SendMessage(hwnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); - SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)dwEnd); - ClientToScreen(hwnd, &pt); - } - TrackPopupMenu(nSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, nullptr); + { + HMENU nMenu = LoadMenu(g_plugin.getInst(), MAKEINTRESOURCE(IDR_FV_EDIT)); + HMENU nSubMenu = GetSubMenu(nMenu, 0); + POINT pt = { GET_X_LPARAM(lParam), GET_Y_LPARAM(lParam) }; + + if (pt.x == -1 && pt.y == -1) { + DWORD dwStart, dwEnd; + SendMessage(hwnd, EM_GETSEL, (WPARAM)&dwStart, (LPARAM)&dwEnd); + SendMessage(hwnd, EM_POSFROMCHAR, (WPARAM)&pt, (LPARAM)dwEnd); + ClientToScreen(hwnd, &pt); + } + TrackPopupMenu(nSubMenu, TPM_RIGHTBUTTON, pt.x, pt.y, 0, hwnd, nullptr); - DestroyMenu(nSubMenu); - DestroyMenu(nMenu); + DestroyMenu(nSubMenu); + DestroyMenu(nMenu); + } return TRUE; - } + case WM_GETDLGCODE: return DLGC_WANTARROWS; @@ -836,18 +694,10 @@ LRESULT CALLBACK EditSubclassProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPa return mir_callNextSubclass(hwnd, EditSubclassProc, msg, wParam, lParam); } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : SetWindowsCtrls // Type : Global // Parameters : hwndDlg - ? -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 021001, 01 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void SetWindowsCtrls(HWND hwndDlg) { @@ -883,23 +733,14 @@ void SetWindowsCtrls(HWND hwndDlg) nCurLeft += nButtonSpace + nButtonWidth; SetWindowPos(hButton, nullptr, nCurLeft, nButtonTop, 0, 0, SWP_NOZORDER | SWP_NOSIZE); - } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : SetRichEditFont // Type : Global // Parameters : hRichEdit - RichEdit to set the font in // bUseSyntaxHL - Is Syntax hilighting is used the color // will not be set -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 030205, 05 February 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// void SetRichEditFont(HWND hRichEdit, bool bUseSyntaxHL) { @@ -918,25 +759,13 @@ void SetRichEditFont(HWND hRichEdit, bool bUseSyntaxHL) } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : DlgProcFileViewer // Type : Global -// Parameters : hwndDlg - ? -// msg - ? -// wParam - ? -// lParam - ? -// Returns : static BOOL CALLBACK -// Description : -// -// References : - -// Remarks : - -// Created : 020929, 29 September 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, LPARAM lParam) { - CLHistoryDlg * pclDlg = (CLHistoryDlg *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); + CLHistoryDlg *pclDlg = (CLHistoryDlg *)GetWindowLongPtr(hwndDlg, GWLP_USERDATA); switch (msg) { case WM_INITDIALOG: @@ -1006,14 +835,14 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, return TRUE; case WM_NCDESTROY: - { - mir_cslock lck(csHistoryList); - clHistoryDlgList.remove(pclDlg); + { + mir_cslock lck(csHistoryList); + clHistoryDlgList.remove(pclDlg); - delete pclDlg; - SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); - } - return 0; + delete pclDlg; + SetWindowLongPtr(hwndDlg, GWLP_USERDATA, 0); + } + return 0; case WM_DESTROY: Utils_SaveWindowPosition(hwndDlg, pclDlg->hContact, MODULENAME, szFileViewDB); @@ -1021,114 +850,117 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, return 0; case WM_SYSCOMMAND: - { - HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE); - bool bUseSyntaxHL = (GetMenuState(hSysMenu, ID_FV_SYNTAX_HL, MF_BYCOMMAND) & MF_CHECKED) != 0; - HWND hRichEdit = GetDlgItem(hwndDlg, IDC_RICHEDIT); - - if ((wParam & 0xFFF0) == ID_FV_FONT) { - LOGFONT lf = { 0 }; - lf.lfHeight = 14L; - - DWORD dwEffects = db_get_dw(NULL, MODULENAME, szFileViewDB "TEffects", 0); - lf.lfWeight = (dwEffects & CFE_BOLD) ? FW_BOLD : 0; - lf.lfUnderline = (dwEffects & CFE_UNDERLINE) != 0; - lf.lfStrikeOut = (dwEffects & CFE_STRIKEOUT) != 0; - lf.lfItalic = (dwEffects & CFE_ITALIC) != 0; - - wcsncpy_s(lf.lfFaceName, _DBGetStringW(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); - CHOOSEFONT cf = { 0 }; - cf.lStructSize = sizeof(cf); - cf.hwndOwner = hwndDlg; - cf.lpLogFont = &lf; - cf.rgbColors = db_get_dw(NULL, MODULENAME, szFileViewDB "TColor", 0); - cf.Flags = CF_EFFECTS | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; - - if (ChooseFont(&cf)) { - dwEffects = (lf.lfWeight == FW_BOLD ? CFE_BOLD : 0) | - (lf.lfItalic ? CFE_ITALIC : 0) | - (lf.lfStrikeOut ? CFE_STRIKEOUT : 0) | - (lf.lfUnderline ? CFE_UNDERLINE : 0); - - db_set_dw(NULL, MODULENAME, szFileViewDB "TEffects", dwEffects); - db_set_dw(NULL, MODULENAME, szFileViewDB "THeight", cf.iPointSize * 2); - db_set_dw(NULL, MODULENAME, szFileViewDB "TColor", cf.rgbColors); - db_set_ws(NULL, MODULENAME, szFileViewDB "TFace", lf.lfFaceName); - SetRichEditFont(hRichEdit, bUseSyntaxHL); - } - return TRUE; - } - if ((wParam & 0xFFF0) == ID_FV_COLOR) { - BYTE bUseCC = !db_get_b(NULL, MODULENAME, szFileViewDB "UseCC", 0); - if (bUseCC) { - CHOOSECOLOR cc = { 0 }; - cc.lStructSize = sizeof(cc); - cc.hwndOwner = hwndDlg; - cc.rgbResult = db_get_dw(NULL, MODULENAME, szFileViewDB "CustomC", RGB(255, 255, 255)); - cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT; - static COLORREF MyCustColors[16] = { 0xFFFFFFFF }; - cc.lpCustColors = MyCustColors; - if (ChooseColor(&cc)) { - SendMessage(hRichEdit, EM_SETBKGNDCOLOR, 0, cc.rgbResult); - db_set_dw(NULL, MODULENAME, szFileViewDB "CustomC", cc.rgbResult); - } - else { - CommDlgExtendedError(); - return TRUE; + { + HMENU hSysMenu = GetSystemMenu(hwndDlg, FALSE); + bool bUseSyntaxHL = (GetMenuState(hSysMenu, ID_FV_SYNTAX_HL, MF_BYCOMMAND) & MF_CHECKED) != 0; + HWND hRichEdit = GetDlgItem(hwndDlg, IDC_RICHEDIT); + + if ((wParam & 0xFFF0) == ID_FV_FONT) { + LOGFONT lf = { 0 }; + lf.lfHeight = 14L; + + DWORD dwEffects = db_get_dw(NULL, MODULENAME, szFileViewDB "TEffects", 0); + lf.lfWeight = (dwEffects & CFE_BOLD) ? FW_BOLD : 0; + lf.lfUnderline = (dwEffects & CFE_UNDERLINE) != 0; + lf.lfStrikeOut = (dwEffects & CFE_STRIKEOUT) != 0; + lf.lfItalic = (dwEffects & CFE_ITALIC) != 0; + + wcsncpy_s(lf.lfFaceName, _DBGetStringW(NULL, MODULENAME, szFileViewDB "TFace", L"Courier New").c_str(), _TRUNCATE); + CHOOSEFONT cf = { 0 }; + cf.lStructSize = sizeof(cf); + cf.hwndOwner = hwndDlg; + cf.lpLogFont = &lf; + cf.rgbColors = db_get_dw(NULL, MODULENAME, szFileViewDB "TColor", 0); + cf.Flags = CF_EFFECTS | CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT; + + if (ChooseFont(&cf)) { + dwEffects = (lf.lfWeight == FW_BOLD ? CFE_BOLD : 0) | + (lf.lfItalic ? CFE_ITALIC : 0) | + (lf.lfStrikeOut ? CFE_STRIKEOUT : 0) | + (lf.lfUnderline ? CFE_UNDERLINE : 0); + + db_set_dw(NULL, MODULENAME, szFileViewDB "TEffects", dwEffects); + db_set_dw(NULL, MODULENAME, szFileViewDB "THeight", cf.iPointSize * 2); + db_set_dw(NULL, MODULENAME, szFileViewDB "TColor", cf.rgbColors); + db_set_ws(NULL, MODULENAME, szFileViewDB "TFace", lf.lfFaceName); + SetRichEditFont(hRichEdit, bUseSyntaxHL); } + return TRUE; } - else SendMessage(hRichEdit, EM_SETBKGNDCOLOR, TRUE, 0); - - CheckMenuItem(hSysMenu, ID_FV_COLOR, MF_BYCOMMAND | (bUseCC ? MF_CHECKED : 0)); - db_set_b(NULL, MODULENAME, szFileViewDB "UseCC", bUseCC); - return TRUE; - } - if ((wParam & 0xFFF0) == ID_FV_SYNTAX_HL) { - // we use the current state from the menu not the DB value - // because we want to toggel the option for this window - // still the new option selected will be stored. - // so user may open 2 windows, now he can set SyntaxHL in both. - - bUseSyntaxHL = !bUseSyntaxHL; - CheckMenuItem(hSysMenu, ID_FV_SYNTAX_HL, MF_BYCOMMAND | (bUseSyntaxHL ? MF_CHECKED : 0)); - db_set_b(NULL, MODULENAME, szFileViewDB "UseSyntaxHL", bUseSyntaxHL); + + if ((wParam & 0xFFF0) == ID_FV_COLOR) { + BYTE bUseCC = !db_get_b(NULL, MODULENAME, szFileViewDB "UseCC", 0); + if (bUseCC) { + CHOOSECOLOR cc = { 0 }; + cc.lStructSize = sizeof(cc); + cc.hwndOwner = hwndDlg; + cc.rgbResult = db_get_dw(NULL, MODULENAME, szFileViewDB "CustomC", RGB(255, 255, 255)); + cc.Flags = CC_ANYCOLOR | CC_FULLOPEN | CC_RGBINIT; + static COLORREF MyCustColors[16] = { 0xFFFFFFFF }; + cc.lpCustColors = MyCustColors; + if (ChooseColor(&cc)) { + SendMessage(hRichEdit, EM_SETBKGNDCOLOR, 0, cc.rgbResult); + db_set_dw(NULL, MODULENAME, szFileViewDB "CustomC", cc.rgbResult); + } + else { + CommDlgExtendedError(); + return TRUE; + } + } + else SendMessage(hRichEdit, EM_SETBKGNDCOLOR, TRUE, 0); - if (bUseSyntaxHL) - bLoadFile(hwndDlg, pclDlg); - else - SetRichEditFont(hRichEdit, bUseSyntaxHL); + CheckMenuItem(hSysMenu, ID_FV_COLOR, MF_BYCOMMAND | (bUseCC ? MF_CHECKED : 0)); + db_set_b(NULL, MODULENAME, szFileViewDB "UseCC", bUseCC); + return TRUE; + } + + if ((wParam & 0xFFF0) == ID_FV_SYNTAX_HL) { + // we use the current state from the menu not the DB value + // because we want to toggel the option for this window + // still the new option selected will be stored. + // so user may open 2 windows, now he can set SyntaxHL in both. + + bUseSyntaxHL = !bUseSyntaxHL; + CheckMenuItem(hSysMenu, ID_FV_SYNTAX_HL, MF_BYCOMMAND | (bUseSyntaxHL ? MF_CHECKED : 0)); + db_set_b(NULL, MODULENAME, szFileViewDB "UseSyntaxHL", bUseSyntaxHL); + + if (bUseSyntaxHL) + bLoadFile(hwndDlg, pclDlg); + else + SetRichEditFont(hRichEdit, bUseSyntaxHL); - return TRUE; - } - if ((wParam & 0xFFF0) == ID_FV_SAVE_AS_RTF) { - wstring sFile = pclDlg->sPath; - sFile += L".rtf"; - HANDLE hFile = CreateFile(sFile.c_str(), GENERIC_WRITE, - FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - - if (hFile == INVALID_HANDLE_VALUE) { - DisplayLastError(LPGENW("Failed to create file")); return TRUE; } + + if ((wParam & 0xFFF0) == ID_FV_SAVE_AS_RTF) { + wstring sFile = pclDlg->sPath; + sFile += L".rtf"; + HANDLE hFile = CreateFile(sFile.c_str(), GENERIC_WRITE, + FILE_SHARE_READ, nullptr, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); + + if (hFile == INVALID_HANDLE_VALUE) { + DisplayLastError(LPGENW("Failed to create file")); + return TRUE; + } - EDITSTREAM eds; - eds.dwCookie = (DWORD_PTR)hFile; - eds.dwError = 0; - eds.pfnCallback = RichEditStreamSaveFile; - LRESULT nWriteOk = SendMessage(hRichEdit, EM_STREAMOUT, (WPARAM)SF_RTF, (LPARAM)&eds); - if (nWriteOk <= 0 || eds.dwError != 0) { - DisplayLastError(TranslateT("Failed to save file")); + EDITSTREAM eds; + eds.dwCookie = (DWORD_PTR)hFile; + eds.dwError = 0; + eds.pfnCallback = RichEditStreamSaveFile; + LRESULT nWriteOk = SendMessage(hRichEdit, EM_STREAMOUT, (WPARAM)SF_RTF, (LPARAM)&eds); + if (nWriteOk <= 0 || eds.dwError != 0) { + DisplayLastError(TranslateT("Failed to save file")); + CloseHandle(hFile); + return TRUE; + } CloseHandle(hFile); + wstring sReport = TranslateT("History was saved successfully in file\r\n"); + sReport += sFile; + MessageBox(nullptr, sReport.c_str(), MSG_BOX_TITEL, MB_OK); return TRUE; } - CloseHandle(hFile); - wstring sReport = TranslateT("History was saved successfully in file\r\n"); - sReport += sFile; - MessageBox(nullptr, sReport.c_str(), MSG_BOX_TITEL, MB_OK); - return TRUE; + return FALSE; } - return FALSE; - } case WM_COMMAND: switch (LOWORD(wParam)) { @@ -1178,18 +1010,11 @@ static INT_PTR CALLBACK DlgProcFileViewer(HWND hwndDlg, UINT msg, WPARAM wParam, return FALSE; } -///////////////////////////////////////////////////////////////////// +///////////////////////////////////////////////////////////////////////////////////////// // Member Function : bShowFileViewer // Type : Global // Parameters : hContact - ? // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 020929, 29 September 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bShowFileViewer(MCONTACT hContact) { diff --git a/plugins/Msg_Export/src/FileViewer.h b/plugins/Msg_Export/src/FileViewer.h index 4e238bdf54..400938080e 100755 --- a/plugins/Msg_Export/src/FileViewer.h +++ b/plugins/Msg_Export/src/FileViewer.h @@ -25,7 +25,8 @@ bool bOpenExternaly(MCONTACT hContact); bool bShowFileViewer(MCONTACT hContact); bool bUseInternalViewer(bool bNew); -bool bUseInternalViewer(); + +extern bool g_bUseIntViewer; extern wstring sFileViewerPrg; diff --git a/plugins/Msg_Export/src/main.cpp b/plugins/Msg_Export/src/main.cpp index 08cb626d0e..84fb32e7ec 100755 --- a/plugins/Msg_Export/src/main.cpp +++ b/plugins/Msg_Export/src/main.cpp @@ -59,11 +59,10 @@ CMPlugin::CMPlugin() : static INT_PTR ShowExportHistory(WPARAM wParam, LPARAM /*lParam*/) { - if (bUseInternalViewer()) { + if (g_bUseIntViewer) bShowFileViewer(wParam); - return 0; - } - bOpenExternaly(wParam); + else + bOpenExternaly(wParam); return 0; } @@ -151,7 +150,7 @@ int CMPlugin::Load() g_sTimeFormat = _DBGetStringW(NULL, MODULENAME, "TimeFormat", L"d s"); sFileViewerPrg = _DBGetStringW(NULL, MODULENAME, "FileViewerPrg", L""); - bUseInternalViewer(getBool("UseInternalViewer", bUseInternalViewer())); + g_bUseIntViewer = getBool("UseInternalViewer", true); g_bUseJson = getBool("UseJson", false); g_bAppendNewLine = getBool("AppendNewLine", true); diff --git a/plugins/Msg_Export/src/options.cpp b/plugins/Msg_Export/src/options.cpp index 4710593346..6434b40661 100755 --- a/plugins/Msg_Export/src/options.cpp +++ b/plugins/Msg_Export/src/options.cpp @@ -273,7 +273,7 @@ public: cmbFileViewer.AddString(L"C:\\WinNT\\Notepad.exe"); cmbFileViewer.AddString(L"C:\\Program Files\\Notepad++\\notepad++.exe"); - CheckDlgButton(m_hwnd, IDC_USE_INTERNAL_VIEWER, bUseInternalViewer() ? BST_CHECKED : BST_UNCHECKED); + CheckDlgButton(m_hwnd, IDC_USE_INTERNAL_VIEWER, g_bUseIntViewer ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(m_hwnd, IDC_REPLACE_MIRANDA_HISTORY, g_bReplaceHistory ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(m_hwnd, IDC_APPEND_NEWLINE, g_bAppendNewLine ? BST_CHECKED : BST_UNCHECKED); CheckDlgButton(m_hwnd, IDC_USE_UTF8_IN_NEW_FILES, g_bUseUtf8InNewFiles ? BST_CHECKED : BST_UNCHECKED); @@ -312,7 +312,7 @@ public: g_plugin.setWString("FileViewerPrg", sFileViewerPrg.c_str()); bUseInternalViewer(IsDlgButtonChecked(m_hwnd, IDC_USE_INTERNAL_VIEWER) == BST_CHECKED); - g_plugin.setByte("UseInternalViewer", bUseInternalViewer()); + g_plugin.setByte("UseInternalViewer", g_bUseIntViewer); bool bNewRp = IsDlgButtonChecked(m_hwnd, IDC_REPLACE_MIRANDA_HISTORY) == BST_CHECKED; if (g_bReplaceHistory != bNewRp) { diff --git a/plugins/Msg_Export/src/utils.cpp b/plugins/Msg_Export/src/utils.cpp index ed9a47da33..51d9991ed3 100755 --- a/plugins/Msg_Export/src/utils.cpp +++ b/plugins/Msg_Export/src/utils.cpp @@ -101,13 +101,6 @@ bool bIsUtf8Header(BYTE * pucByteOrder) // Type : Global // Parameters : pszToCheck - ? // Returns : int -// Description : -// -// References : - -// Remarks : - -// Created : 030107, 07 January 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// int nGetFormatCount(const wchar_t *pszToCheck) { @@ -127,13 +120,6 @@ int nGetFormatCount(const wchar_t *pszToCheck) // Type : Global // Parameters : dwError - ? // Returns : string -// Description : -// -// References : - -// Remarks : - -// Created : 021012, 12 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// wstring sGetErrorString(DWORD dwError) { @@ -186,11 +172,6 @@ void DisplayLastError(const wchar_t *pszError) // Returns : string // Description : Reads a string from the database // Just like those in database.h -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// wstring _DBGetStringW(MCONTACT hContact, const char *szModule, const char *szSetting, const wchar_t *pszError) { @@ -227,11 +208,6 @@ string _DBGetStringA(MCONTACT hContact, const char *szModule, const char *szSett // Returns : void // Description : will replace all acurances of a string with another string // used to replace %user%, and other user -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wstring &sNew) { @@ -248,45 +224,6 @@ void ReplaceAll(wstring &sSrc, const wchar_t *pszReplace, const wchar_t *pszNew) ReplaceAll(sSrc, pszReplace, sNew); } -///////////////////////////////////////////////////////////////////// -// Member Function : bCreatePathToFile -// Type : Global -// Parameters : sFilePath - File name to create path to ( file name may be empty ( i.e. c:\Folder\ ) -// Returns : Returns true if the path is created or already exists -// Description : -// -// References : - -// Remarks : - -// Created : 020525, 25 May 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// - -bool bCreatePathToFile(wstring sFilePath) -{ - string::size_type nPos = sFilePath.rfind('\\'); - if (nPos != string::npos) { - if (nPos + 1 < sFilePath.size()) - sFilePath.erase(nPos + 1); - } - else // cant find - return false; - - // create directory - if (!CreateDirectory(sFilePath.c_str(), nullptr)) { - DWORD dwE = GetLastError(); - if (dwE == 183) // Cannot create a file when that file already exists. - return true; - - if (!bCreatePathToFile(sFilePath.substr(0, nPos))) - return false; - - // try again - if (!CreateDirectory(sFilePath.c_str(), nullptr)) - return false; - } - return true; -} - ///////////////////////////////////////////////////////////////////// // Member Function : bWriteToFile // Type : Global @@ -294,15 +231,8 @@ bool bCreatePathToFile(wstring sFilePath) // pszSrc - in UTF8 or ANSII // nLen - ? // Returns : Returns true if all the data was written to the file -// Description : -// -// References : - -// Remarks : - -// Created : 020629, 29 June 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// -bool bWriteToFile(HANDLE hFile, const char *pszSrc, int nLen = -1) +static bool bWriteToFile(HANDLE hFile, const char *pszSrc, int nLen = -1) { if (nLen < 0) nLen = (int)mir_strlen(pszSrc); @@ -319,13 +249,6 @@ bool bWriteToFile(HANDLE hFile, const char *pszSrc, int nLen = -1) // pszSrc - ? // bUtf8File - ? // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 060130, 30 januar 2006 -// Developer : KN -///////////////////////////////////////////////////////////////////// static bool bWriteTextToFile(HANDLE hFile, const wchar_t *pszSrc, bool bUtf8File, int nLen = -1) { @@ -341,8 +264,7 @@ static bool bWriteTextToFile(HANDLE hFile, const wchar_t *pszSrc, bool bUtf8File return bWriteToFile(hFile, pszAstr, -1); } - T2Utf pszUtf8(pszSrc); - return bWriteToFile(hFile, pszUtf8, -1); + return bWriteToFile(hFile, T2Utf(pszSrc), -1); } @@ -357,8 +279,7 @@ static bool bWriteTextToFile(HANDLE hFile, const char *pszSrc, bool bUtf8File, i pszSrc = tmp; } - ptrA pszUtf8(mir_utf8encode(pszSrc)); - return bWriteToFile(hFile, pszUtf8, -1); + return bWriteToFile(hFile, ptrA(mir_utf8encode(pszSrc)), -1); } ///////////////////////////////////////////////////////////////////// @@ -367,13 +288,6 @@ static bool bWriteTextToFile(HANDLE hFile, const char *pszSrc, bool bUtf8File, i // Parameters : hFile - ? // nIndent - ? // Returns : Returns true if all the data was written to the file -// Description : -// -// References : - -// Remarks : - -// Created : 020629, 29 June 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// const char szNewLineIndent[] = "\r\n "; bool bWriteNewLine(HANDLE hFile, DWORD dwIndent) @@ -390,14 +304,6 @@ bool bWriteNewLine(HANDLE hFile, DWORD dwIndent) // Parameters : hFile - ? // - ? // nSize - ? -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 021203, 03 December 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bWriteHexToFile(HANDLE hFile, void * pData, int nSize) { @@ -418,11 +324,6 @@ bool bWriteHexToFile(HANDLE hFile, void * pData, int nSize) // Returns : void // Description : Used to set the internal path. // Handles the reading from the mirandaboot.ini to get the %dbpath% -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bReadMirandaDirAndPath() { @@ -443,14 +344,6 @@ bool bReadMirandaDirAndPath() // Member Function : ReplaceDBPath // Type : Global // Parameters : sRet - ? -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 021020, 20 October 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void ReplaceDBPath(wstring &sRet) { @@ -471,13 +364,6 @@ void ReplaceDBPath(wstring &sRet) // Type : Global // Parameters : hContact - Handle to user // Returns : string contaning the compleate file name and path -// Description : -// -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// wstring GetFilePathFromUser(MCONTACT hContact) { @@ -498,7 +384,7 @@ wstring GetFilePathFromUser(MCONTACT hContact) if (!sPrevFileName.empty()) { ReplaceDBPath(sPrevFileName); - // Here we will try to avoide the (Unknown Contact) in cases where the protocol for + // Here we will try to avoid the (Unknown Contact) in cases where the protocol for // this user has been removed. if (bNickUsed && (wcsstr(Clist_GetContactDisplayName(hContact), LPGENW("(Unknown Contact)")) != nullptr)) return sPrevFileName; // Then the filename must have changed from a correct path to one including the (Unknown Contact) @@ -540,7 +426,7 @@ wstring GetFilePathFromUser(MCONTACT hContact) if (!MoveFile(sPrevFileName.c_str(), sFilePath.c_str())) { // this might be because the new path isent created // so we will try to create it - bCreatePathToFile(sFilePath); + CreateDirectoryTreeW(sFilePath.c_str()); while (!MoveFile(sPrevFileName.c_str(), sFilePath.c_str())) { mir_snwprintf(szTemp, @@ -565,18 +451,12 @@ wstring GetFilePathFromUser(MCONTACT hContact) return sFilePath; } - ///////////////////////////////////////////////////////////////////// // Member Function : FileNickFromHandle // Type : Global // Parameters : hContact - ? // Returns : string // Description : Replaceses invalid file name chars -// References : - -// Remarks : - -// Created : 030107, 07 January 2003 -// Developer : KN -///////////////////////////////////////////////////////////////////// wstring FileNickFromHandle(MCONTACT hContact) { @@ -596,12 +476,6 @@ wstring FileNickFromHandle(MCONTACT hContact) // sNew - ? // Returns : void // Description : Removes any ':' in the new string -// -// References : - -// Remarks : - -// Created : 040205, 05 februar 2004 -// Developer : KN -///////////////////////////////////////////////////////////////////// void ReplaceAllNoColon(wstring &sSrc, const wchar_t *pszReplace, wstring &sNew) { @@ -617,13 +491,6 @@ void ReplaceAllNoColon(wstring &sSrc, const wchar_t *pszReplace, wstring &sNew) // Parameters : hContact - Handle to user // sTarget - String with either %user% or %UIN%, to replace in // Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 020525, 25 May 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void ReplaceDefines(MCONTACT hContact, wstring & sTarget) { @@ -706,14 +573,6 @@ void ReplaceDefines(MCONTACT hContact, wstring & sTarget) // Member Function : ReplaceTimeVariables // Type : Global // Parameters : sRet - ? -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 040219, 19 februar 2004 -// Developer : KN -///////////////////////////////////////////////////////////////////// void ReplaceTimeVariables(wstring &sRet) { @@ -739,12 +598,6 @@ void ReplaceTimeVariables(wstring &sRet) // Parameters : None // Returns : void // Description : updates clFileTo1ColWidth, -// -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void UpdateFileToColWidth() { @@ -764,14 +617,6 @@ void UpdateFileToColWidth() // Parameters : pszError - ? // sFile - ? // dbei - ? -// Returns : void -// Description : -// -// References : - -// Remarks : - -// Created : 021203, 03 December 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// void DisplayErrorDialog(const wchar_t *pszError, wstring &sFilePath, DBEVENTINFO *dbei) { @@ -834,13 +679,6 @@ void DisplayErrorDialog(const wchar_t *pszError, wstring &sFilePath, DBEVENTINFO // sFilePath - path to file // dbei - Event to export // Returns : false on serious error, when file should be closed to not lost/overwrite any data -// Description : -// -// References : - -// Remarks : - -// Created : 050429, 29 april 2005 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVENTINFO &dbei, bool bAppendOnly) { @@ -987,7 +825,7 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVE int nLen = (int)mir_strlen(pszData); if ((pszData - (char *)dbei.pBlob) + nLen < (int)dbei.cbBlob) { if (bWriteTextToFile(hFile, pszType, bWriteUTF8Format) && - bWriteIndentedToFile(hFile, nIndent, pszData, bWriteUTF8Format)) { + bWriteIndentedToFile(hFile, nIndent, _A2T(pszData), bWriteUTF8Format)) { pszData += nLen + 1; if ((pszData - (char *)dbei.pBlob) >= (int)dbei.cbBlob) { bWriteOk = true; @@ -997,7 +835,7 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVE if ((pszData - (char *)dbei.pBlob) + nLen < (int)dbei.cbBlob) { if (bWriteNewLine(hFile, nIndent) && bWriteTextToFile(hFile, LPGENW("Description: "), bWriteUTF8Format) && - bWriteIndentedToFile(hFile, nIndent, pszData, bWriteUTF8Format)) { + bWriteIndentedToFile(hFile, nIndent, _A2T(pszData), bWriteUTF8Format)) { bWriteOk = true; } } @@ -1056,7 +894,7 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVE if (*pszCurBlobPos) { if (!bWriteNewLine(hFile, nIndent) || !bWriteTextToFile(hFile, TranslateW(pszTypes[i]), bWriteUTF8Format) || - !bWriteIndentedToFile(hFile, nIndent, pszCurBlobPos, bWriteUTF8Format)) { + !bWriteIndentedToFile(hFile, nIndent, _A2T(pszCurBlobPos), bWriteUTF8Format)) { break; } pszCurBlobPos += mir_strlen(pszCurBlobPos); @@ -1112,14 +950,14 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVE else bWriteTextToFile(hFile, LPGENW("No from address"), bWriteUTF8Format); if (!bWriteNewLine(hFile, nIndent) || - !bWriteIndentedToFile(hFile, nIndent, pszStr, bWriteUTF8Format)) { + !bWriteIndentedToFile(hFile, nIndent, _A2T(pszStr), bWriteUTF8Format)) { DisplayErrorDialog(LPGENW("Failed to write EmailExpress to the file :\n"), sFilePath, &dbei); } } break; case ICQEVENTTYPE_SMS: - if (!bWriteIndentedToFile(hFile, nIndent, (const char*)dbei.pBlob, bWriteUTF8Format)) + if (!bWriteIndentedToFile(hFile, nIndent, _A2T((const char*)dbei.pBlob), bWriteUTF8Format)) DisplayErrorDialog(LPGENW("Failed to write SMS to the file :\n"), sFilePath, &dbei); break; @@ -1148,23 +986,17 @@ bool ExportDBEventInfo(MCONTACT hContact, HANDLE hFile, wstring sFilePath, DBEVE // Returns : int // Description : Called when an event is added to the DB // Or from the Export All funktion -// References : - -// Remarks : - -// Created : 020422, 22 April 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// HANDLE openCreateFile(wstring sFilePath) { - GetLastError();// Clear last error !! + SetLastError(0); HANDLE hFile = CreateFile(sFilePath.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); if (hFile == INVALID_HANDLE_VALUE) { // this might be because the path isent created // so we will try to create it - if (bCreatePathToFile(sFilePath)) { + if (!CreateDirectoryTreeW(sFilePath.c_str())) hFile = CreateFile(sFilePath.c_str(), GENERIC_WRITE | GENERIC_READ, FILE_SHARE_READ, nullptr, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr); - } } return hFile; @@ -1215,7 +1047,7 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, wstring sFil dbei.pBlob = (PBYTE)malloc(dbei.cbBlob + 2); dbei.pBlob[dbei.cbBlob] = 0; dbei.pBlob[dbei.cbBlob + 1] = 0; - // Double null terminate, this shut pervent most errors + // Double null terminate, this should prevent most errors // where the blob received has an invalid format } @@ -1229,22 +1061,6 @@ bool bExportEvent(MCONTACT hContact, MEVENT hDbEvent, HANDLE hFile, wstring sFil return result; } -#ifdef _UNICODE -bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const char *pszSrc, bool bUtf8File) -{ - int nLen = (int)mir_strlen(pszSrc); - wchar_t * pszWstr = new wchar_t[nLen + 1]; - bool bRet = false; - if (MultiByteToWideChar(CP_ACP, 0, pszSrc, nLen, pszWstr, nLen) == nLen) { - pszWstr[nLen] = NULL; - bRet = bWriteIndentedToFile(hFile, nIndent, pszWstr, bUtf8File); - } - delete[] pszWstr; - - return bRet; -} -#endif - ///////////////////////////////////////////////////////////////////// // Member Function : bWriteIndentedToFile // Type : Global @@ -1252,13 +1068,6 @@ bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const char *pszSrc, bool bU // nIndent - ? // pszSrc - // Returns : Returns true if -// Description : -// -// References : - -// Remarks : - -// Created : 020629, 29 June 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const wchar_t *pszSrc, bool bUtf8File) { @@ -1337,17 +1146,9 @@ bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const wchar_t *pszSrc, bool // lparam - 0 // Returns : int // Description : Called when an contact is about to be deleted -// -// References : - -// Remarks : - -// Created : 021222, 22 December 2002 -// Developer : KN -///////////////////////////////////////////////////////////////////// -int nContactDeleted(WPARAM wparam, LPARAM /*lparam*/) +int nContactDeleted(WPARAM hContact, LPARAM) { - MCONTACT hContact = (MCONTACT)wparam; - HWND hInternalWindow = WindowList_Find(hInternalWindowList, hContact); if (hInternalWindow) CloseWindow(hInternalWindow); diff --git a/plugins/Msg_Export/src/utils.h b/plugins/Msg_Export/src/utils.h index 25b9fac08a..6dfc7250bd 100755 --- a/plugins/Msg_Export/src/utils.h +++ b/plugins/Msg_Export/src/utils.h @@ -71,9 +71,6 @@ wstring GetFilePathFromUser(MCONTACT hContact); void ReplaceDefines(MCONTACT hContact, wstring & sTarget); void ReplaceTimeVariables(wstring &sRet); -bool bCreatePathToFile(wstring sFilePath); - -bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const char *pszSrc, bool bUtf8File); bool bWriteIndentedToFile(HANDLE hFile, int nIndent, const wchar_t *pszSrc, bool bUtf8File); bool bWriteNewLine(HANDLE hFile, DWORD dwIndent); bool bIsUtf8Header(BYTE * pucByteOrder); -- cgit v1.2.3