OSDN Git Service

Patch #1804762 continued
authorJochen Tucht <jtuc@users.sourceforge.net>
Sun, 14 Oct 2007 08:52:04 +0000 (08:52 +0000)
committerJochen Tucht <jtuc@users.sourceforge.net>
Sun, 14 Oct 2007 08:52:04 +0000 (08:52 +0000)
Src/Common/LanguageSelect.cpp
Src/Common/LanguageSelect.h
Src/Common/MessageBoxDialog.cpp
Src/Common/MessageBoxDialog.h
Src/Common/UniFile.cpp
Src/Common/UniFile.h
Src/Common/coretools.cpp
Src/Common/coretools.h
Src/Common/multiformatText.cpp
Src/Common/multiformatText.h

index 6db4a72..d9250d8 100644 (file)
@@ -1077,10 +1077,10 @@ void CLanguageSelect::LoadAndDisplayLanguages()
        int i=0;
        for (i = 0; i < m_wLangIds.GetSize(); i++)
        {
-               CString Language = GetLanguageString(m_wLangIds[i]);
-               if ( !Language.IsEmpty() )
+               String Language = GetLanguageString(m_wLangIds[i]);
+               if ( !Language.empty() )
                {
-                       int idx = m_ctlLangList.AddString(Language);
+                       int idx = m_ctlLangList.AddString(Language.c_str());
                        m_ctlLangList.SetItemData(idx, i);
                }
        }
@@ -1105,15 +1105,16 @@ int CLanguageSelect::GetLanguageArrayIndex( WORD LangId )
        return -1;
 }
        
-CString CLanguageSelect::GetLanguageString( WORD LangId )
+String CLanguageSelect::GetLanguageString( WORD LangId )
        {
        int idx = GetLanguageArrayIndex(LangId);
        if (idx == -1) return _T("");
 
        // Localized name
-       CString Language = LoadResString(lang_map[idx].m_IdName);
+       String Language = theApp.LoadString(lang_map[idx].m_IdName);
        // Append native name
-       Language += _T(" - ") + GetNativeLanguageNameString(idx);
+       Language += _T(" - ");
+       Language += GetNativeLanguageNameString(idx);
        return Language;
        }
 
index c3ad8ea..7f4687c 100644 (file)
@@ -79,7 +79,7 @@ private:
        UINT    GetDocResId();
        CString GetPath( LPCTSTR FileName) const;
        CString GetLanguagePath(LPCTSTR FileName) const;
-       CString GetLanguageString( WORD LangId );
+       String GetLanguageString( WORD LangId );
        CString GetNativeLanguageNameString( int idx );
        void LoadAndDisplayLanguages();
 
index bb677f9..0ed10a1 100644 (file)
@@ -131,11 +131,11 @@ CMessageBoxDialog::CMessageBoxDialog ( CWnd* pParent, UINT nMessageID,
        else
        {
                // Try to load the title from the resources.
-               VERIFY(m_strTitle.LoadString(nTitleID));
+               m_strTitle = LoadResString(nTitleID);
        }
 
        // Save the information about the message box.
-       VERIFY(m_strMessage.LoadString(nMessageID));
+       m_strMessage = LoadResString(nMessageID);
        m_nStyle                        = nStyle;
        m_nHelp                         = nHelp;
 
@@ -196,9 +196,9 @@ inline UINT CMessageBoxDialog::GetStyle ( )
 /*
  *     Method for setting the message to be displayed in the message box.
  */
-inline void CMessageBoxDialog::SetMessage ( CString strMessage )
+inline void CMessageBoxDialog::SetMessage ( LPCTSTR strMessage )
 {
-       ASSERT(!strMessage.IsEmpty());
+       ASSERT(*strMessage != '\0');
 
        // Save the message text.
        m_strMessage = strMessage;
@@ -209,22 +209,15 @@ inline void CMessageBoxDialog::SetMessage ( CString strMessage )
  */
 inline void CMessageBoxDialog::SetMessage ( UINT nMessageID )
 {
-       // Create a string for storing the message.
-       CString strMessage = _T("");
-
        // Load the message from the resources.
-       VERIFY(strMessage.LoadString(nMessageID));
-
-       ASSERT(!strMessage.IsEmpty());
-
-       // Save the message text.
-       m_strMessage = strMessage;
+       m_strMessage = LoadResString(nMessageID);
+       ASSERT(!m_strMessage.empty());
 }
 
 /*
  *     Method for retrieving the message to be displayed in the message box.
  */
-inline CString CMessageBoxDialog::GetMessage ( )
+inline const String &CMessageBoxDialog::GetMessage ( )
 {
        // Return the message text.
        return m_strMessage;
@@ -233,10 +226,10 @@ inline CString CMessageBoxDialog::GetMessage ( )
 /*
  *     Method for setting the title to be displayed in the message box.
  */
-inline void CMessageBoxDialog::SetTitle ( CString strTitle )
+inline void CMessageBoxDialog::SetTitle ( LPCTSTR strTitle )
 {
        // Check whether a title was given.
-       if ( strTitle.IsEmpty() )
+       if ( *strTitle == '\0' )
        {
                // Use the application name as the title.
                strTitle = AfxGetAppName();
@@ -251,31 +244,24 @@ inline void CMessageBoxDialog::SetTitle ( CString strTitle )
  */
 inline void CMessageBoxDialog::SetTitle ( UINT nTitleID )
 {
-       // Create a string for storing the title.
-       CString strTitle = _T("");
-
        // Check whether an ID was given.
        if ( nTitleID == 0 )
        {
                // Use the application name as the title.
-               strTitle = AfxGetAppName();
+               m_strTitle = AfxGetAppName();
        }
        else
        {
                // Try to load the string from the resources.
-               VERIFY(strTitle.LoadString(nTitleID));
-
-               ASSERT(!strTitle.IsEmpty());
+               m_strTitle = LoadResString(nTitleID);
+               ASSERT(!m_strTitle.empty());
        }
-
-       // Save the title.
-       m_strTitle = strTitle;
 }
 
 /*
  *     Method for retrieving the title to be displayed in the message box.
  */
-inline CString CMessageBoxDialog::GetTitle ( )
+inline const String &CMessageBoxDialog::GetTitle ( )
 {
        // Return the title of the message box.
        return m_strTitle;
@@ -484,7 +470,7 @@ BOOL CMessageBoxDialog::OnInitDialog ( )
        }
 
        // Set the title of the dialog.
-       SetWindowText(m_strTitle);
+       SetWindowText(m_strTitle.c_str());
 
        // Set the help ID of the dialog.
        SetHelpID(m_nHelp);
@@ -757,35 +743,18 @@ void CMessageBoxDialog::OnTimer ( UINT_PTR nIDEvent )
                        // Check whether this button is the default button.
                        if ( m_aButtons.GetAt(i).nID == m_nDefaultButton )
                        {
-                               // Create two strings for the button text.
-                               CString strButtonText   = _T("");
-                               CString strFullText             = _T("");
-
                                // Try to load the text for the button.
-                               VERIFY(strButtonText.LoadString(m_aButtons.GetAt(i).nTitle));
-                               
-                               // Use the button text as the full text.
-                               strFullText = strButtonText;
-
+                               String strButtonText = LoadResString(m_aButtons.GetAt(i).nTitle);
                                // Check whether the timeout is finished.
                                if ( m_nTimeoutSeconds > 0 )
                                {
                                        // Add the remaining seconds to the text of the button.
-                                       strFullText.Format(_T("%s = %d"), strButtonText, 
-                                               m_nTimeoutSeconds);
-                               }
-
-                               // Try to retrieve a handle for the button.
-                               CWnd* pButtonWnd = GetDlgItem(m_aButtons.GetAt(i).nID);
-
-                               ASSERT(pButtonWnd);
-
-                               // Check whether the handle was retrieved successfully.
-                               if ( pButtonWnd != NULL )
-                               {
-                                       // Set the text of the button.
-                                       pButtonWnd->SetWindowText(strFullText);
+                                       TCHAR szTimeoutSeconds[40];
+                                       wsprintf(szTimeoutSeconds, _T(" = %d"), m_nTimeoutSeconds);
+                                       strButtonText += szTimeoutSeconds;
                                }
+                               // Set the text of the button.
+                               SetDlgItemText(m_aButtons.GetAt(i).nID, strButtonText.c_str());
                        }
                }
        }
@@ -864,10 +833,10 @@ CString CMessageBoxDialog::GenerateRegistryKey ( )
                int nChecksum = 0;
 
                // Run through the message string.
-               for ( int i = 0; i < m_strMessage.GetLength(); i++ )
+               for ( int i = 0; i < m_strMessage.length(); i++ )
                {
                        // Get the char at the given position and add it to the checksum.
-                       nChecksum += ((int)m_strMessage.GetAt(i)) * i;
+                       nChecksum += (int)m_strMessage[i] * i;
                }
 
                // Convert the checksum to a string.
@@ -1245,7 +1214,7 @@ void CMessageBoxDialog::CreateIconControl ( )
  */
 void CMessageBoxDialog::CreateMessageControl ( )
 {
-       ASSERT(!m_strMessage.IsEmpty());
+       ASSERT(!m_strMessage.empty());
 
        // Create a DC for accessing the display driver.
        CDC dcDisplay;
@@ -1268,7 +1237,7 @@ void CMessageBoxDialog::CreateMessageControl ( )
        CRect rcMessage(0, 0, nMaxWidth, nMaxWidth);
 
        // Draw the text and retrieve the size of the text.
-       dcDisplay.DrawText(m_strMessage, rcMessage, DT_LEFT | DT_NOPREFIX | 
+       dcDisplay.DrawText(m_strMessage.c_str(), rcMessage, DT_LEFT | DT_NOPREFIX | 
                DT_WORDBREAK | DT_CALCRECT);
 
        // Save the size required for the message.
@@ -1296,7 +1265,7 @@ void CMessageBoxDialog::CreateMessageControl ( )
        }
 
        // Create the static control for the message.
-       m_stcMessage.Create(m_strMessage,  dwStyle, rcDummy, this, 
+       m_stcMessage.Create(m_strMessage.c_str(), dwStyle, rcDummy, this,
                (UINT)IDC_STATIC);
 
        // Check whether the text will be read from right to left.
@@ -1324,14 +1293,13 @@ void CMessageBoxDialog::CreateCheckboxControl ( )
                ( m_nStyle & MB_DONT_ASK_AGAIN ) )
        {
                // Create a variable for storing the title of the checkbox.
-               CString strCheckboxTitle = _T("");
+               String strCheckboxTitle;
 
                // Check which style is used.
                if ( m_nStyle & MB_DONT_DISPLAY_AGAIN )
                {
                        // Load the string for the checkbox.
-                       VERIFY(strCheckboxTitle.LoadString(
-                               IDS_MESSAGEBOX_DONT_DISPLAY_AGAIN));
+                       strCheckboxTitle = LoadResString(IDS_MESSAGEBOX_DONT_DISPLAY_AGAIN);
                }
                else
                {
@@ -1339,12 +1307,11 @@ void CMessageBoxDialog::CreateCheckboxControl ( )
                        if ( m_nStyle & MB_DONT_ASK_AGAIN )
                        {
                                // Load the string for the checkbox.
-                               VERIFY(strCheckboxTitle.LoadString(
-                                       IDS_MESSAGEBOX_DONT_ASK_AGAIN));
+                               strCheckboxTitle = LoadResString(IDS_MESSAGEBOX_DONT_ASK_AGAIN);
                        }
                }
 
-               ASSERT(!strCheckboxTitle.IsEmpty());
+               ASSERT(!strCheckboxTitle.empty());
 
                // Create a handle to access the DC of the dialog.
                CClientDC dc(this);
@@ -1354,7 +1321,7 @@ void CMessageBoxDialog::CreateCheckboxControl ( )
                CFont* pOldFont = dc.SelectObject(pWndFont);
 
                // Retrieve the size of the text.
-               m_sCheckbox = dc.GetTextExtent(strCheckboxTitle);
+               m_sCheckbox = dc.GetTextExtent(strCheckboxTitle.c_str(), strCheckboxTitle.length());
 
                // Add the additional value to the width of the checkbox.
                m_sCheckbox.cx += XDialogUnitToPixel(CX_CHECKBOX_ADDON);
@@ -1369,7 +1336,7 @@ void CMessageBoxDialog::CreateCheckboxControl ( )
                CButton btnCheckbox;
 
                // Create the checkbox.
-               btnCheckbox.Create(strCheckboxTitle, WS_CHILD | WS_VISIBLE | 
+               btnCheckbox.Create(strCheckboxTitle.c_str(), WS_CHILD | WS_VISIBLE | 
                        WS_TABSTOP | BS_AUTOCHECKBOX, rcDummy, this, IDCHECKBOX);
 
                // Check whether the checkbox should be marked checked at startup.
@@ -1413,26 +1380,18 @@ void CMessageBoxDialog::CreateButtonControls ( )
        for ( int i = 0; i < m_aButtons.GetSize(); i++ )
        {
                // Create a string and load the title of the button.
-               CString strButtonTitle;
-               VERIFY(strButtonTitle.LoadString(m_aButtons.GetAt(i).nTitle));
-
-               // Create a string with the text used to determine the length.
-               CString strLengthTest = strButtonTitle;
-
+               String strButtonText = LoadResString(m_aButtons.GetAt(i).nTitle);
                // Check whether there's a timeout set.
                if ( m_nTimeoutSeconds > 0 )
                {
-                       // Create a string with the longest timeout text.
-                       CString strTimeoutText = _T("");
-                       strTimeoutText.Format(_T("%s = %d"), strLengthTest, 
-                               m_nTimeoutSeconds);
-
-                       // Use this text to determine the length of the string.
-                       strLengthTest = strTimeoutText;
+                       // Add the remaining seconds to the text of the button.
+                       TCHAR szTimeoutSeconds[40];
+                       wsprintf(szTimeoutSeconds, _T(" = %d"), m_nTimeoutSeconds);
+                       strButtonText += szTimeoutSeconds;
                }
 
                // Retrieve the size of the text.
-               CSize sButtonText = dc.GetTextExtent(strLengthTest);
+               CSize sButtonText = dc.GetTextExtent(strButtonText.c_str(), strButtonText.length());
 
                // Resize the button.
                m_sButton.cx = max(m_sButton.cx, sButtonText.cx);
@@ -1442,7 +1401,7 @@ void CMessageBoxDialog::CreateButtonControls ( )
                CButton btnControl;
 
                // Create the button.
-               btnControl.Create(strButtonTitle, WS_CHILD | WS_VISIBLE | WS_TABSTOP,
+               btnControl.Create(strButtonText.c_str(), WS_CHILD | WS_VISIBLE | WS_TABSTOP,
                        rcDummy, this, m_aButtons.GetAt(i).nID);
 
                // Set the font of the control.
index d27564b..b791d04 100644 (file)
@@ -116,18 +116,18 @@ public:
        UINT GetStyle ( );
 
        // Methods for setting the message to be displayed in the message box.
-       void SetMessage ( CString strMessage );
+       void SetMessage ( LPCTSTR strMessage );
        void SetMessage ( UINT nMessageID );
 
        // Method for retrieving the message to be displayed in the message box.
-       CString GetMessage ( );
+       const String &GetMessage ( );
 
        // Methods for setting the title to be displayed in the message box.
-       void SetTitle ( CString strTitle );
+       void SetTitle ( LPCTSTR strTitle );
        void SetTitle ( UINT nTitleID );
 
        // Method for retrieving the title to be displayed in the message box.
-       CString GetTitle ( );
+       const String &GetTitle ( );
 
        // Methods for setting the icon to be displayed in the message box.
        void SetMessageIcon ( HICON hIcon );
@@ -193,8 +193,8 @@ private:
        //////////////////////////////////////////////////////////////////////////
        // Private member variables of this dialog.
 
-       CString         m_strMessage;           // Message to be displayed.
-       CString         m_strTitle;                     // Title to be used.
+       String          m_strMessage;           // Message to be displayed.
+       String          m_strTitle;                     // Title to be used.
        UINT            m_nStyle;                       // Style of the message box.
        UINT            m_nHelp;                        // Help context of the message box.
 
index 90fa121..fd6c1ae 100644 (file)
@@ -71,9 +71,9 @@ bool UniLocalFile::DoGetFileStatus()
        m_statusFetched = -1;
        m_lastError.ClearError();
 
-       m_filepath = paths_GetLongPath(m_filepath);
+       m_filepath = paths_GetLongPath(m_filepath.c_str());
 
-       if (_tstati64(m_filepath, &fstats) == 0)
+       if (_tstati64(m_filepath.c_str(), &fstats) == 0)
        {
                m_filesize = fstats.st_size;
                m_statusFetched = 1;
@@ -200,7 +200,7 @@ bool UniMemFile::DoOpen(LPCTSTR filename, DWORD dwOpenAccess, DWORD dwOpenShareM
        m_filename = filename;
        m_filepath = m_filename; // TODO: Make canonical ?
 
-       m_handle = CreateFile(m_filename, dwOpenAccess, dwOpenShareMode, NULL, dwOpenCreationDispostion, 0, 0);
+       m_handle = CreateFile(m_filename.c_str(), dwOpenAccess, dwOpenShareMode, NULL, dwOpenCreationDispostion, 0, 0);
        if (m_handle == INVALID_HANDLE_VALUE)
        {
                LastError(_T("CreateFile"), GetLastError());
@@ -700,7 +700,7 @@ bool UniStdioFile::DoOpen(LPCTSTR filename, LPCTSTR mode)
        // But we don't care since size is set to 0 anyway.
        GetFileStatus();
 
-       m_fp = _tfopen(m_filepath, mode);
+       m_fp = _tfopen(m_filepath.c_str(), mode);
        if (!m_fp)
                return false;
 
index e225963..e1bfba3 100644 (file)
@@ -32,13 +32,15 @@ public:
                UniError() { ClearError(); }
        };
 
+       virtual ~UniFile() { }
+
        virtual bool OpenReadOnly(LPCTSTR filename) = 0;
 
        virtual void Close() = 0;
 
        virtual bool IsOpen() const = 0;
 
-       virtual CString GetFullyQualifiedPath() const = 0;
+       virtual String GetFullyQualifiedPath() const = 0;
 
        virtual const UniError & GetLastUniError() const = 0;
 
@@ -85,7 +87,7 @@ public:
        UniLocalFile();
        void Clear();
 
-       virtual CString GetFullyQualifiedPath() const { return m_filepath; }
+       virtual String GetFullyQualifiedPath() const { return m_filepath; }
 
        virtual const UniError & GetLastUniError() const { return m_lastError; }
 
@@ -107,8 +109,8 @@ protected:
 protected:
        int m_statusFetched; // 0 not fetched, -1 error, +1 success
        __int64 m_filesize;
-       CString m_filepath;
-       CString m_filename;
+       String m_filepath;
+       String m_filename;
        int m_lineno; // current 0-based line of m_current
        UniError m_lastError;
        bool m_readbom; // whether have tested for BOM
@@ -123,6 +125,7 @@ protected:
  */
 class UniMemFile : public UniLocalFile
 {
+       friend class UniMarkdownFile;
 public:
        UniMemFile();
        virtual ~UniMemFile() { Close(); }
index f1d2f59..5ac0fd0 100644 (file)
@@ -24,6 +24,7 @@
 #endif
 
 #include "UnicodeString.h"
+#include "Merge.h"
 #include "coretools.h"
 
 #ifndef countof
@@ -1107,7 +1108,7 @@ BOOL IsLocalPath(LPCTSTR path)
  * @param [in] hModule Module's handle.
  * @return Module's path.
  */
-CString GetModulePath(HMODULE hModule /* = NULL*/)
+String GetModulePath(HMODULE hModule /* = NULL*/)
 {
        TCHAR temp[MAX_PATH] = {0};
        GetModuleFileName(hModule, temp, MAX_PATH);
@@ -1119,12 +1120,12 @@ CString GetModulePath(HMODULE hModule /* = NULL*/)
  * @param [in] fullpath Full path to split.
  * @return Path without filename.
  */
-CString GetPathOnly(LPCTSTR fullpath)
+String GetPathOnly(LPCTSTR fullpath)
 {
        if (!fullpath || !fullpath[0]) return _T("");
        String spath;
        SplitFilename(fullpath, &spath, 0, 0);
-       return spath.c_str();
+       return spath;
 }
 
 /**
@@ -1254,8 +1255,9 @@ void GetDecoratedCmdLine(CString sCmdLine, CString &sDecoratedCmdLine,
 /**
  * @brief Return time displayed appropriately, as string
  */
-CString TimeString(const __int64 * tim)
+String TimeString(const __int64 * tim)
 {
+       USES_CONVERSION;
        if (!tim) return _T("---");
        // _tcsftime does not respect user date customizations from
        // Regional Options/Configuration Regional; COleDateTime::Format does so.
@@ -1266,5 +1268,14 @@ CString TimeString(const __int64 * tim)
                // MSVC7 (VC.NET)
        COleDateTime odt = *tim;
 #endif
-       return odt.Format();
+       // If invalid, return DateTime resource string
+       if (odt.GetStatus() == COleDateTime::null)
+               return String();
+       if (odt.GetStatus() == COleDateTime::invalid)
+               return theApp.LoadString(AFX_IDS_INVALID_DATETIME);
+       COleVariant var;
+       // Don't need to trap error. Should not fail due to type mismatch
+       AfxCheckError(VarBstrFromDate(odt.m_dt, LANG_USER_DEFAULT, 0, &V_BSTR(&var)));
+       var.vt = VT_BSTR;
+       return OLE2CT(V_BSTR(&var));
 }
index f31ad69..19e79b6 100644 (file)
@@ -112,8 +112,8 @@ BOOL FindAnyFile(LPTSTR filespec, LPTSTR name);
 long SwapEndian(long val);
 short int SwapEndian(short int val);
 BOOL MkDirEx(LPCTSTR foldername);
-CString GetModulePath(HMODULE hModule = NULL);
-CString GetPathOnly(LPCTSTR fullpath);
+String GetModulePath(HMODULE hModule = NULL);
+String GetPathOnly(LPCTSTR fullpath);
 float RoundMeasure(float measure, float units);
 
 CString LegalizeFileName(LPCTSTR szFileName);
@@ -128,7 +128,7 @@ BOOL IsLocalPath(LPCTSTR path);
 BOOL GetAppDataPath(CString &sAppDataPath);
 BOOL GetUserProfilePath(CString &sAppDataPath);
 
-CString TimeString(const __int64 * tim);
+String TimeString(const __int64 * tim);
 
 void GetDecoratedCmdLine(CString sCmdLine, CString &sDecoratedCmdLine,
        CString &sExecutable);
index 5f14a64..0f67d94 100644 (file)
@@ -32,6 +32,7 @@
 #include "unicoder.h"
 #include "multiformatText.h"
 #include "files.h"
+#include "paths.h"
 #include "UniFile.h"
 #include "codepage.h"
 
@@ -92,21 +93,11 @@ void storageForPlugins::SetDataFileUnknown(LPCTSTR filename, BOOL bOverwrite /*=
 
 LPCTSTR storageForPlugins::GetDestFileName()
 {
-       if (m_tempFilenameDst.IsEmpty())
+       if (m_tempFilenameDst.empty())
        {
-               TCHAR tempDir[MAX_PATH] = _T("");
-               if (!GetTempPath(countof(tempDir), tempDir))
-                       return NULL;
-
-               if (!GetTempFileName(tempDir, _T ("_WM"), 0, m_tempFilenameDst.GetBuffer(MAX_PATH)))
-               {
-                       m_tempFilenameDst.ReleaseBuffer();
-                       m_tempFilenameDst.Empty();
-                       return NULL;
-               }
-               m_tempFilenameDst.ReleaseBuffer();
+               m_tempFilenameDst = paths_GetTempFileName(paths_GetTempPath(), _T ("_WM"));
        }
-       return m_tempFilenameDst;
+       return m_tempFilenameDst.c_str();
 }
 
 
@@ -118,10 +109,10 @@ void storageForPlugins::ValidateNewFile()
        if (m_nChangedValid == m_nChanged)
        {
                // plugin succeeded, but nothing changed, just delete the new file
-               if (!::DeleteFile(m_tempFilenameDst))
+               if (!::DeleteFile(m_tempFilenameDst.c_str()))
                {
                        LogErrorString(Fmt(_T("DeleteFile(%s) failed: %s")
-                               , m_tempFilenameDst, GetSysError(GetLastError())));
+                               , m_tempFilenameDst.c_str(), GetSysError(GetLastError())));
                }
                // we may reuse the temp filename
                // tempFilenameDst.Empty();
@@ -131,12 +122,12 @@ void storageForPlugins::ValidateNewFile()
                m_nChangedValid = m_nChanged;
                if (m_bOverwriteSourceFile)
                {
-                       if (!::DeleteFile(m_filename))
+                       if (!::DeleteFile(m_filename.c_str()))
                        {
                                LogErrorString(Fmt(_T("DeleteFile(%s) failed: %s")
-                                       , m_filename, GetSysError(GetLastError())));
+                                       , m_filename.c_str(), GetSysError(GetLastError())));
                        }
-                       ::MoveFile(m_tempFilenameDst, m_filename);
+                       ::MoveFile(m_tempFilenameDst.c_str(), m_filename.c_str());
                }
                else
                {
@@ -145,7 +136,7 @@ void storageForPlugins::ValidateNewFile()
                        // for next transformation, we may overwrite/delete the source file
                        m_bOverwriteSourceFile = TRUE;
                }
-               m_tempFilenameDst.Empty();
+               m_tempFilenameDst.erase();
        }
 }
 void storageForPlugins::ValidateNewBuffer()
@@ -166,8 +157,8 @@ void storageForPlugins::ValidateInternal(BOOL bNewIsFile, BOOL bNewIsUnicode)
        {
                if (m_bOverwriteSourceFile)
                {
-                       ::DeleteFile(m_filename);
-                       ::MoveFile(m_tempFilenameDst, m_filename);
+                       ::DeleteFile(m_filename.c_str());
+                       ::MoveFile(m_tempFilenameDst.c_str(), m_filename.c_str());
                }
                else
                {
@@ -176,7 +167,7 @@ void storageForPlugins::ValidateInternal(BOOL bNewIsFile, BOOL bNewIsUnicode)
                        // for next transformation, we may overwrite/delete the source file
                        m_bOverwriteSourceFile = TRUE;
                }
-               m_tempFilenameDst.Empty();
+               m_tempFilenameDst.erase();
        }
 
        // old memory structures are freed
@@ -197,7 +188,7 @@ void storageForPlugins::ValidateInternal(BOOL bNewIsFile, BOOL bNewIsUnicode)
 LPCTSTR storageForPlugins::GetDataFileUnicode()
 {
        if (m_bCurrentIsFile && m_bCurrentIsUnicode)
-               return m_filename;
+               return m_filename.c_str();
 
        MAPPEDFILEDATA fileDataIn = {0};
        UINT nchars;
@@ -208,7 +199,7 @@ LPCTSTR storageForPlugins::GetDataFileUnicode()
        if (m_bCurrentIsFile)
        {
                // Init filedata struct and open file as memory mapped (in file)
-               _tcsncpy(fileDataIn.fileName, m_filename, m_filename.GetLength()+1);
+               _tcsncpy(fileDataIn.fileName, m_filename.c_str(), MAX_PATH);
                fileDataIn.bWritable = FALSE;
                fileDataIn.dwOpenFlags = OPEN_EXISTING;
                BOOL bSuccess = files_openFileMapped(&fileDataIn);
@@ -239,7 +230,7 @@ LPCTSTR storageForPlugins::GetDataFileUnicode()
        // Init filedata struct and open file as memory mapped (out file)
        GetDestFileName();
        MAPPEDFILEDATA fileDataOut = {0};
-       _tcscpy(fileDataOut.fileName, m_tempFilenameDst);
+       _tcsncpy(fileDataOut.fileName, m_tempFilenameDst.c_str(), MAX_PATH);
        fileDataOut.bWritable = TRUE;
        fileDataOut.dwOpenFlags = CREATE_ALWAYS;
        fileDataOut.dwSize = textForeseenSize + 2;  
@@ -276,12 +267,12 @@ LPCTSTR storageForPlugins::GetDataFileUnicode()
        if ((textRealSize == 0) && (textForeseenSize > 0))
        {
                // conversion error
-               ::DeleteFile(m_tempFilenameDst);
+               ::DeleteFile(m_tempFilenameDst.c_str());
                return NULL;
        }
 
        ValidateInternal(TRUE, TRUE);
-       return m_filename;
+       return m_filename.c_str();
 }
 
 
@@ -299,7 +290,7 @@ BSTR * storageForPlugins::GetDataBufferUnicode()
        if (m_bCurrentIsFile) 
        {
                // Init filedata struct and open file as memory mapped (in file)
-               _tcscpy(fileDataIn.fileName, m_filename);
+               _tcsncpy(fileDataIn.fileName, m_filename.c_str(), MAX_PATH);
                fileDataIn.bWritable = FALSE;
                fileDataIn.dwOpenFlags = OPEN_EXISTING;
                BOOL bSuccess = files_openFileMapped(&fileDataIn);
@@ -369,7 +360,7 @@ BSTR * storageForPlugins::GetDataBufferUnicode()
 LPCTSTR storageForPlugins::GetDataFileAnsi()
 {
        if (m_bCurrentIsFile && !m_bCurrentIsUnicode)
-               return m_filename;
+               return m_filename.c_str();
 
        MAPPEDFILEDATA fileDataIn = {0};
        UINT nchars;
@@ -380,7 +371,7 @@ LPCTSTR storageForPlugins::GetDataFileAnsi()
        if (m_bCurrentIsFile)
        {
                // Init filedata struct and open file as memory mapped (in file)
-               _tcsncpy(fileDataIn.fileName, m_filename, m_filename.GetLength()+1);
+               _tcsncpy(fileDataIn.fileName, m_filename.c_str(), MAX_PATH);
                fileDataIn.bWritable = FALSE;
                fileDataIn.dwOpenFlags = OPEN_EXISTING;
                BOOL bSuccess = files_openFileMapped(&fileDataIn);
@@ -413,7 +404,7 @@ LPCTSTR storageForPlugins::GetDataFileAnsi()
        // Init filedata struct and open file as memory mapped (out file)
        GetDestFileName();
        MAPPEDFILEDATA fileDataOut = {0};
-       _tcscpy(fileDataOut.fileName, m_tempFilenameDst);
+       _tcsncpy(fileDataOut.fileName, m_tempFilenameDst.c_str(), MAX_PATH);
        fileDataOut.bWritable = TRUE;
        fileDataOut.dwOpenFlags = CREATE_ALWAYS;
        fileDataOut.dwSize = textForeseenSize;  
@@ -447,12 +438,12 @@ LPCTSTR storageForPlugins::GetDataFileAnsi()
        if ((textRealSize == 0) && (textForeseenSize > 0))
        {
                // conversion error
-               ::DeleteFile(m_tempFilenameDst);
+               ::DeleteFile(m_tempFilenameDst.c_str());
                return NULL;
        }
 
        ValidateInternal(TRUE, FALSE);
-       return m_filename;
+       return m_filename.c_str();
 }
 
 
@@ -470,7 +461,7 @@ COleSafeArray * storageForPlugins::GetDataBufferAnsi()
        if (m_bCurrentIsFile) 
        {
                // Init filedata struct and open file as memory mapped (in file)
-               _tcscpy(fileDataIn.fileName, m_filename);
+               _tcsncpy(fileDataIn.fileName, m_filename.c_str(), MAX_PATH);
                fileDataIn.bWritable = FALSE;
                fileDataIn.dwOpenFlags = OPEN_EXISTING;
                BOOL bSuccess = files_openFileMapped(&fileDataIn);
@@ -606,7 +597,7 @@ static UINT TransformUtf8ToUcs2(LPCSTR pcsUtf, UINT nUtf, LPWSTR psUcs, UINT nUc
 }
 
 
-BOOL UnicodeFileToOlechar(CString & filepath, LPCTSTR filepathDst, int & nFileChanged)
+BOOL UnicodeFileToOlechar(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged)
 {
        UniMemFile ufile;
        if (!ufile.OpenReadOnly(filepath) || !ufile.ReadBom())
@@ -621,7 +612,7 @@ BOOL UnicodeFileToOlechar(CString & filepath, LPCTSTR filepathDst, int & nFileCh
        // Init filedataIn struct and open file as memory mapped (input)
        BOOL bSuccess;
        MAPPEDFILEDATA fileDataIn = {0};
-       _tcsncpy(fileDataIn.fileName, filepath, filepath.GetLength()+1);
+       _tcsncpy(fileDataIn.fileName, filepath, MAX_PATH);
        fileDataIn.bWritable = FALSE;
        fileDataIn.dwOpenFlags = OPEN_EXISTING;
        bSuccess = files_openFileMapped(&fileDataIn);
@@ -703,7 +694,7 @@ BOOL UnicodeFileToOlechar(CString & filepath, LPCTSTR filepathDst, int & nFileCh
  * Returns FALSE if file has Unicode BOM but is not UCS-2LE.
  * Returns TRUE if file is not Unicode, or if converted file successfully.
  */
-BOOL OlecharToUTF8(CString & filepath, LPCTSTR filepathDst, int & nFileChanged, BOOL bWriteBOM)
+BOOL OlecharToUTF8(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged, BOOL bWriteBOM)
 {
        UniMemFile ufile;
        if (!ufile.OpenReadOnly(filepath) || !ufile.ReadBom())
@@ -719,7 +710,7 @@ BOOL OlecharToUTF8(CString & filepath, LPCTSTR filepathDst, int & nFileChanged,
        // Init filedataIn struct and open file as memory mapped (input)
        BOOL bSuccess;
        MAPPEDFILEDATA fileDataIn = {0};
-       _tcsncpy(fileDataIn.fileName, filepath, filepath.GetLength()+1);
+       _tcsncpy(fileDataIn.fileName, filepath, MAX_PATH);
        fileDataIn.bWritable = FALSE;
        fileDataIn.dwOpenFlags = OPEN_EXISTING;
        bSuccess = files_openFileMapped(&fileDataIn);
index 26d5bc9..6fcd044 100644 (file)
@@ -31,8 +31,8 @@ class storageForPlugins
 public:
        ~storageForPlugins()
        {
-               if (!m_tempFilenameDst)
-                       ::DeleteFile(m_tempFilenameDst);
+               if (!m_tempFilenameDst.empty()) // "!m_tempFilenameDst" means "never"
+                       ::DeleteFile(m_tempFilenameDst.c_str());
                m_bstr.Empty();
                m_array.Clear();
        }
@@ -61,7 +61,7 @@ public:
        /// Initial load
        void SetDataFileUnicode(LPCTSTR filename, BOOL bOverwrite = FALSE);
        /// Final save, same format as the original file
-       BOOL SaveAsFile(CString & filename)
+       BOOL SaveAsFile(String & filename)
        {
                LPCTSTR newFilename;
                if (m_bOriginalIsUnicode)
@@ -78,11 +78,11 @@ public:
        }
        /// Get the last valid file after an error
        /// Warning : the format may be different from the original one
-       void GetLastValidFile(CString & filename)
+       void GetLastValidFile(String & filename)
        {
-               if (!m_tempFilenameDst)
-                       ::DeleteFile(m_tempFilenameDst);
-               m_tempFilenameDst.Empty();
+               if (!m_tempFilenameDst.empty())
+                       ::DeleteFile(m_tempFilenameDst.c_str());
+               m_tempFilenameDst.erase();
                filename = this->m_filename;
        }
 
@@ -114,7 +114,7 @@ private:
        // data storage when mode is BUFFER ANSI
        COleSafeArray m_array;
        // data storage when mode is FILE
-       CString m_filename;
+       String m_filename;
        // error during conversion ?
        BOOL m_bError;
        // codepage for ANSI mode
@@ -123,16 +123,16 @@ private:
        // temporary number of transformations, transformed by caller
        int m_nChanged;
        // temporary destination filename
-       CString m_tempFilenameDst;
+       String m_tempFilenameDst;
 };
 
 
 // other conversion functions
 
 /// Convert any unicode file to UCS-2LE
-BOOL UnicodeFileToOlechar(CString & filepath, LPCTSTR filepathDst, int & nFileChanged);
+BOOL UnicodeFileToOlechar(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged);
 /// Convert UCS-2LE file to UTF-8 (for diffutils)
-BOOL OlecharToUTF8(CString & filepath, LPCTSTR filepathDst, int & nFileChanged, BOOL bWriteBOM);
+BOOL OlecharToUTF8(LPCTSTR filepath, LPCTSTR filepathDst, int & nFileChanged, BOOL bWriteBOM);
 
 
 #endif //__MULTIFORMATTEXT_H__
\ No newline at end of file