mirror of
https://github.com/winscp/winscp.git
synced 2026-10-24 02:28:55 +03:00
Getting rid of MFC string loading code
Source commit: 3c7399548535aeb9ebb738e2fdde52431d0ba83f
This commit is contained in:
@@ -180,9 +180,6 @@ public:
|
||||
// printf-like formatting using variable arguments parameter
|
||||
void FormatV(LPCTSTR lpszFormat, va_list argList);
|
||||
|
||||
// load from string resource
|
||||
BOOL LoadString(UINT nID);
|
||||
|
||||
// Implementation
|
||||
protected:
|
||||
UnicodeString m_Data;
|
||||
@@ -230,7 +227,7 @@ public:
|
||||
// Attributes
|
||||
int m_cause;
|
||||
LONG m_lOsError;
|
||||
CString m_strFileName;
|
||||
UnicodeString m_strFileName;
|
||||
|
||||
// Operations
|
||||
// convert a OS dependent error code to a Cause
|
||||
@@ -241,8 +238,7 @@ public:
|
||||
|
||||
// Implementation
|
||||
public:
|
||||
BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
|
||||
PUINT pnHelpContext = NULL);
|
||||
UnicodeString GetErrorMessage();
|
||||
};
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -375,10 +371,6 @@ private:
|
||||
#include <afx.inl>
|
||||
#endif
|
||||
|
||||
#ifdef WINSCP
|
||||
extern HINSTANCE afxCurrentResourceHandle;
|
||||
#endif
|
||||
|
||||
#endif // __AFX_H__
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -27,9 +27,7 @@ FILES = filecore.obj filex.obj filest.obj
|
||||
|
||||
MISC = strcore.obj strex.obj timecore.obj
|
||||
|
||||
WINMISC = winstr.obj
|
||||
|
||||
CPP_OBJS=$(FILES) $(MISC) $(WINMISC)
|
||||
CPP_OBJS=$(FILES) $(MISC)
|
||||
|
||||
OBJS=$(CPP_OBJS)
|
||||
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
// Microsoft Foundation Classes product.
|
||||
|
||||
#include "stdafx.h"
|
||||
#include <SysUtils.hpp>
|
||||
#include <StrUtils.hpp>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// CFileException
|
||||
@@ -21,23 +23,14 @@ void CFileException::ThrowOsError(LONG lOsError,
|
||||
lOsError, lpszFileName);
|
||||
}
|
||||
|
||||
BOOL CFileException::GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
|
||||
PUINT pnHelpContext)
|
||||
UnicodeString CFileException::GetErrorMessage()
|
||||
{
|
||||
ASSERT(lpszError != NULL && AfxIsValidString(lpszError, nMaxError));
|
||||
|
||||
if (pnHelpContext != NULL)
|
||||
*pnHelpContext = m_cause + AFX_IDP_FILE_NONE;
|
||||
|
||||
CString strMessage;
|
||||
CString strFileName = m_strFileName;
|
||||
UnicodeString strFileName = m_strFileName;
|
||||
if (strFileName.IsEmpty())
|
||||
strFileName.LoadString(AFX_IDS_UNNAMED_FILE);
|
||||
strMessage.LoadString(m_cause + AFX_IDP_FILE_NONE);
|
||||
strMessage.Replace(L"%1", strFileName);
|
||||
lstrcpyn(lpszError, strMessage, nMaxError);
|
||||
|
||||
return TRUE;
|
||||
strFileName = LoadStr(AFX_IDS_UNNAMED_FILE);
|
||||
UnicodeString strMessage = LoadStr(m_cause + AFX_IDP_FILE_NONE);
|
||||
strMessage = ReplaceStr(strMessage, L"%1", strFileName.c_str());
|
||||
return strMessage;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -16,15 +16,10 @@
|
||||
|
||||
// public headers
|
||||
#include "afxres.h"
|
||||
inline HINSTANCE AFXAPI AfxGetResourceHandle()
|
||||
{ ASSERT(afxCurrentResourceHandle != NULL);
|
||||
return afxCurrentResourceHandle; }
|
||||
|
||||
int AFXAPI AfxLoadString(UINT nIDS, LPTSTR lpszBuf, UINT nMaxBuf = 256);
|
||||
BOOL AFXAPI AfxFullPath(LPTSTR lpszPathOut, LPCTSTR lpszFileIn);
|
||||
|
||||
#include <stddef.h>
|
||||
#include <limits.h>
|
||||
#include <malloc.h>
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
@@ -11,8 +11,6 @@
|
||||
#include "stdafx.h"
|
||||
#include <SysUtils.hpp>
|
||||
|
||||
HINSTANCE afxCurrentResourceHandle;
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
// Construction/Destruction
|
||||
|
||||
@@ -34,7 +32,7 @@ CString::CString(LPCTSTR lpsz)
|
||||
if (lpsz != NULL && HIWORD(lpsz) == NULL)
|
||||
{
|
||||
UINT nID = LOWORD((DWORD)lpsz);
|
||||
LoadString(nID);
|
||||
m_Data = LoadStr(nID);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -201,12 +201,11 @@ void CString::Format(LPCTSTR lpszFormat, ...)
|
||||
|
||||
void CString::Format(UINT nFormatID, ...)
|
||||
{
|
||||
CString strFormat;
|
||||
strFormat.LoadString(nFormatID);
|
||||
UnicodeString strFormat = LoadStr(nFormatID);
|
||||
|
||||
va_list argList;
|
||||
va_start(argList, nFormatID);
|
||||
FormatV(strFormat, argList);
|
||||
FormatV(strFormat.c_str(), argList);
|
||||
va_end(argList);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
// This is a part of the Microsoft Foundation Classes C++ library.
|
||||
// Copyright (C) 1992-1998 Microsoft Corporation
|
||||
// All rights reserved.
|
||||
//
|
||||
// This source code is only intended as a supplement to the
|
||||
// Microsoft Foundation Classes Reference and related
|
||||
// electronic documentation provided with the library.
|
||||
// See these sources for detailed information regarding the
|
||||
// Microsoft Foundation Classes product.
|
||||
|
||||
#include "stdafx.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Windows extensions to strings
|
||||
|
||||
#define CHAR_FUDGE 1 // one TCHAR unused is good enough
|
||||
|
||||
BOOL CString::LoadString(UINT nID)
|
||||
{
|
||||
// try fixed buffer first (to avoid wasting space in the heap)
|
||||
TCHAR szTemp[256];
|
||||
int nLen = AfxLoadString(nID, szTemp, std::size(szTemp));
|
||||
if (std::size(szTemp) - nLen > CHAR_FUDGE)
|
||||
{
|
||||
*this = szTemp;
|
||||
return nLen > 0;
|
||||
}
|
||||
|
||||
// Shouldn't happen as we do not have such long string in FileZilla
|
||||
// try buffer size of 512, then larger size until entire string is retrieved
|
||||
int nSize = 256;
|
||||
do
|
||||
{
|
||||
nSize += 256;
|
||||
m_Data.SetLength(nSize - 1);
|
||||
nLen = AfxLoadString(nID, m_Data.c_str(), nSize);
|
||||
} while (nSize - nLen <= CHAR_FUDGE);
|
||||
m_Data.SetLength(nLen);
|
||||
|
||||
return nLen > 0;
|
||||
}
|
||||
|
||||
int AFXAPI AfxLoadString(UINT nID, LPTSTR lpszBuf, UINT nMaxBuf)
|
||||
{
|
||||
ASSERT(AfxIsValidAddress(lpszBuf, nMaxBuf*sizeof(TCHAR)));
|
||||
int nLen = ::LoadString(AfxGetResourceHandle(), nID, lpszBuf, nMaxBuf);
|
||||
if (nLen == 0)
|
||||
lpszBuf[0] = '\0';
|
||||
return nLen;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
@@ -196,11 +196,6 @@ void CoreFinalize()
|
||||
CryptographyFinalize();
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void CoreSetResourceModule(void * ResourceHandle)
|
||||
{
|
||||
TFileZillaIntf::SetResourceModule(ResourceHandle);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void CoreMaintenanceTask()
|
||||
{
|
||||
DontSaveRandomSeed();
|
||||
|
||||
@@ -14,7 +14,6 @@ extern TApplicationLog * ApplicationLog;
|
||||
//---------------------------------------------------------------------------
|
||||
void CoreInitialize();
|
||||
void CoreFinalize();
|
||||
void CoreSetResourceModule(void * ResourceHandle);
|
||||
void CoreMaintenanceTask();
|
||||
void CoreUpdateFinalStaticUsage();
|
||||
//---------------------------------------------------------------------------
|
||||
|
||||
@@ -1669,9 +1669,6 @@ int CAsyncSslSocketLayer::ProvideClientCert(
|
||||
{
|
||||
CAsyncSslSocketLayer * Layer = LookupLayer(Ssl);
|
||||
|
||||
CString Message;
|
||||
Message.LoadString(NEED_CLIENT_CERTIFICATE);
|
||||
|
||||
int Level;
|
||||
int Result;
|
||||
if ((Layer->FCertificate == NULL) || (Layer->FPrivateKey == NULL))
|
||||
@@ -1688,7 +1685,7 @@ int CAsyncSslSocketLayer::ProvideClientCert(
|
||||
Result = 1;
|
||||
}
|
||||
|
||||
Layer->LogSocketMessageRaw(Level, Message.c_str());
|
||||
Layer->LogSocketMessageRaw(Level, LoadStr(NEED_CLIENT_CERTIFICATE).c_str());
|
||||
|
||||
return Result;
|
||||
}
|
||||
|
||||
@@ -16,11 +16,6 @@ void __fastcall TFileZillaIntf::Finalize()
|
||||
// noop
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TFileZillaIntf::SetResourceModule(void * ResourceHandle)
|
||||
{
|
||||
afxCurrentResourceHandle = static_cast<HINSTANCE>(ResourceHandle);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TFileZillaIntf::TFileZillaIntf() :
|
||||
FFileZillaApi(NULL),
|
||||
FIntern(new TFileZillaIntern(this)),
|
||||
|
||||
@@ -158,7 +158,6 @@ public:
|
||||
|
||||
static void __fastcall Initialize();
|
||||
static void __fastcall Finalize();
|
||||
static void __fastcall SetResourceModule(void * ResourceHandle);
|
||||
|
||||
__fastcall TFileZillaIntf();
|
||||
virtual __fastcall ~TFileZillaIntf();
|
||||
|
||||
@@ -202,8 +202,7 @@ CFtpControlSocket::~CFtpControlSocket()
|
||||
|
||||
void CFtpControlSocket::ShowStatus(UINT nID, int type) const
|
||||
{
|
||||
CString str;
|
||||
str.LoadString(nID);
|
||||
CString str = CString(LoadStr(nID));
|
||||
ShowStatus(str, type);
|
||||
}
|
||||
|
||||
@@ -231,13 +230,10 @@ void CFtpControlSocket::ShowStatus(CString status, int type) const
|
||||
|
||||
void CFtpControlSocket::ShowTimeoutError(UINT nID) const
|
||||
{
|
||||
CString str1;
|
||||
str1.LoadString(IDS_ERRORMSG_TIMEOUT);
|
||||
CString str2;
|
||||
str2.LoadString(nID);
|
||||
CString message;
|
||||
message.Format(L"%s (%s)", str1.c_str(), str2.c_str());
|
||||
ShowStatus(message, FZ_LOG_ERROR);
|
||||
UnicodeString str1 = LoadStr(IDS_ERRORMSG_TIMEOUT);
|
||||
UnicodeString str2 = LoadStr(nID);
|
||||
UnicodeString message = FORMAT(L"%s (%s)", (str1, str2));
|
||||
ShowStatus(CString(message), FZ_LOG_ERROR);
|
||||
}
|
||||
|
||||
t_server CFtpControlSocket::GetCurrentServer()
|
||||
|
||||
@@ -204,10 +204,8 @@ void CTransferSocket::OnReceive(int nErrorCode)
|
||||
}
|
||||
catch (CFileException * e)
|
||||
{
|
||||
LPTSTR msg = new TCHAR[BUFSIZE];
|
||||
if (e->GetErrorMessage(msg, BUFSIZE))
|
||||
m_pOwner->ShowStatus(msg, FZ_LOG_ERROR);
|
||||
delete [] msg;
|
||||
UnicodeString Error = e->GetErrorMessage();
|
||||
m_pOwner->ShowStatus(CString(Error), FZ_LOG_ERROR);
|
||||
CloseAndEnsureSendClose(CSMODE_TRANSFERERROR);
|
||||
return;
|
||||
}
|
||||
@@ -901,9 +899,8 @@ int CTransferSocket::ReadDataFromFile(char *buffer, int len)
|
||||
}
|
||||
catch (CFileException* e)
|
||||
{
|
||||
TCHAR error[BUFSIZE];
|
||||
if (e->GetErrorMessage(error, BUFSIZE))
|
||||
m_pOwner->ShowStatus(error, FZ_LOG_ERROR);
|
||||
UnicodeString Error = e->GetErrorMessage();
|
||||
m_pOwner->ShowStatus(CString(Error), FZ_LOG_ERROR);
|
||||
CloseOnShutDownOrError(CSMODE_TRANSFERERROR);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@@ -525,7 +525,6 @@ __fastcall TGUIConfiguration::TGUIConfiguration(): TConfiguration()
|
||||
FLocales = new TObjectList();
|
||||
FLastLocalesExts = L"*";
|
||||
FCopyParamList = new TCopyParamList();
|
||||
CoreSetResourceModule(GetResourceModule());
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
__fastcall TGUIConfiguration::~TGUIConfiguration()
|
||||
@@ -1067,15 +1066,9 @@ HANDLE __fastcall TGUIConfiguration::ChangeResourceModule(HANDLE Instance)
|
||||
TLibModule * MainModule = FindModule(HInstance);
|
||||
HANDLE Result = reinterpret_cast<HANDLE>(MainModule->ResInstance);
|
||||
MainModule->ResInstance = reinterpret_cast<unsigned>(Instance);
|
||||
CoreSetResourceModule(Instance);
|
||||
return Result;
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
HANDLE __fastcall TGUIConfiguration::GetResourceModule()
|
||||
{
|
||||
return reinterpret_cast<HANDLE>(FindModule(HInstance)->ResInstance);
|
||||
}
|
||||
//---------------------------------------------------------------------------
|
||||
void __fastcall TGUIConfiguration::SetResourceModule(HINSTANCE Instance)
|
||||
{
|
||||
HANDLE PrevHandle = ChangeResourceModule(Instance);
|
||||
|
||||
@@ -205,7 +205,6 @@ protected:
|
||||
UnicodeString __fastcall GetAppliedLocaleHex();
|
||||
virtual HINSTANCE __fastcall LoadNewResourceModule(LCID Locale,
|
||||
UnicodeString & FileName);
|
||||
HANDLE __fastcall GetResourceModule();
|
||||
void __fastcall SetResourceModule(HINSTANCE Instance);
|
||||
TObjectList * __fastcall GetLocales();
|
||||
void __fastcall AddLocale(LCID Locale, const UnicodeString & Name);
|
||||
|
||||
Reference in New Issue
Block a user