mirror of
https://github.com/notepad-plus-plus/notepad-plus-plus.git
synced 2025-07-25 23:05:13 +02:00
Refactoring for the better performance & smaller binary size
1. remove deprecated std::codecvt 2. replace s2ws -> string2wstring and ws2s -> wstring2string Fix #15898, close #15913
This commit is contained in:
parent
4972dcf4b3
commit
af9af11aec
@ -18,7 +18,6 @@
|
||||
#include <shlwapi.h>
|
||||
#include <uxtheme.h>
|
||||
#include <cassert>
|
||||
#include <codecvt>
|
||||
#include <locale>
|
||||
#include "StaticDialog.h"
|
||||
#include "CustomFileDialog.h"
|
||||
@ -142,8 +141,7 @@ void writeLog(const wchar_t* logFileName, const char* log2write)
|
||||
SYSTEMTIME currentTime = {};
|
||||
::GetLocalTime(¤tTime);
|
||||
wstring dateTimeStrW = getDateTimeStrFrom(L"yyyy-MM-dd HH:mm:ss", currentTime);
|
||||
wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
string log2writeStr = converter.to_bytes(dateTimeStrW);
|
||||
string log2writeStr = wstring2string(dateTimeStrW, CP_UTF8);
|
||||
log2writeStr += " ";
|
||||
log2writeStr += log2write;
|
||||
log2writeStr += "\n";
|
||||
@ -1239,22 +1237,6 @@ bool isAssoCommandExisting(LPCTSTR FullPathName)
|
||||
return isAssoCmdExist;
|
||||
}
|
||||
|
||||
std::wstring s2ws(const std::string& str)
|
||||
{
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX("Error in Notepad++ string conversion s2ws!", L"Error in Notepad++ string conversion s2ws!");
|
||||
|
||||
return converterX.from_bytes(str);
|
||||
}
|
||||
|
||||
std::string ws2s(const std::wstring& wstr)
|
||||
{
|
||||
using convert_typeX = std::codecvt_utf8<wchar_t>;
|
||||
std::wstring_convert<convert_typeX, wchar_t> converterX("Error in Notepad++ string conversion ws2s!", L"Error in Notepad++ string conversion ws2s!");
|
||||
|
||||
return converterX.to_bytes(wstr);
|
||||
}
|
||||
|
||||
bool deleteFileOrFolder(const wstring& f2delete)
|
||||
{
|
||||
auto len = f2delete.length();
|
||||
|
@ -181,9 +181,6 @@ HWND CreateToolTipRect(int toolID, HWND hWnd, HINSTANCE hInst, const PTSTR pszTe
|
||||
bool isCertificateValidated(const std::wstring & fullFilePath, const std::wstring & subjectName2check);
|
||||
bool isAssoCommandExisting(LPCTSTR FullPathName);
|
||||
|
||||
std::wstring s2ws(const std::string& str);
|
||||
std::string ws2s(const std::wstring& wstr);
|
||||
|
||||
bool deleteFileOrFolder(const std::wstring& f2delete);
|
||||
|
||||
void getFilesInFolder(std::vector<std::wstring>& files, const std::wstring& extTypeFilter, const std::wstring& inFolder);
|
||||
|
@ -15,7 +15,6 @@
|
||||
// along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <shlwapi.h>
|
||||
#include "FileInterface.h"
|
||||
#include "Parameters.h"
|
||||
@ -27,8 +26,7 @@ Win32_IO_File::Win32_IO_File(const wchar_t *fname)
|
||||
if (fname)
|
||||
{
|
||||
std::wstring fn = fname;
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
_path = converter.to_bytes(fn);
|
||||
_path = wstring2string(fn, CP_UTF8);
|
||||
|
||||
WIN32_FILE_ATTRIBUTE_DATA attributes_original{};
|
||||
attributes_original.dwFileAttributes = INVALID_FILE_ATTRIBUTES;
|
||||
@ -127,8 +125,7 @@ void Win32_IO_File::close()
|
||||
if ((dwRet == 0) || (dwRet >= cchPathBuf))
|
||||
{
|
||||
// probably insufficient path-buffer length, the classic style must suffice
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
curFilePath = converter.from_bytes(_path);
|
||||
curFilePath = string2wstring(_path, CP_UTF8);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -156,8 +153,7 @@ Please try using another storage and also check if your saved data is not corrup
|
||||
std::wstring nppIssueLog = nppParam.getUserPath();
|
||||
pathAppend(nppIssueLog, nppFlushFileBuffersFailsLog);
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string errNumberMsgA = converter.to_bytes(errNumberMsg);
|
||||
std::string errNumberMsgA = wstring2string(errNumberMsg, CP_UTF8);
|
||||
|
||||
writeLog(nppIssueLog.c_str(), errNumberMsgA.c_str());
|
||||
}
|
||||
@ -239,8 +235,7 @@ bool Win32_IO_File::write(const void *wbuf, size_t buf_size)
|
||||
std::string msg = _path;
|
||||
msg += " written failed: ";
|
||||
std::wstring lastErrorMsg = GetLastErrorAsString(::GetLastError());
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
msg += converter.to_bytes(lastErrorMsg);
|
||||
msg += wstring2string(lastErrorMsg, CP_UTF8);
|
||||
writeLog(nppIssueLog.c_str(), msg.c_str());
|
||||
}
|
||||
|
||||
|
@ -112,7 +112,7 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
if (doLogCertifError)
|
||||
{
|
||||
string dmsg("VerifyLibrary: ");
|
||||
dmsg += ws2s(filepath);
|
||||
dmsg += wstring2string(filepath, CP_UTF8);
|
||||
writeLog(L"c:\\tmp\\certifError.log", dmsg.c_str());
|
||||
}
|
||||
|
||||
@ -208,14 +208,14 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
|
||||
if (!result)
|
||||
{
|
||||
throw string("Checking certificate of ") + ws2s(filepath) + " : " + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("Checking certificate of ") + wstring2string(filepath, CP_UTF8) + " : " + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
// Get signer information size.
|
||||
result = ::CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, NULL, &dwSignerInfo);
|
||||
if (!result)
|
||||
{
|
||||
throw string("CryptMsgGetParam first call: ") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("CryptMsgGetParam first call: ") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
// Get Signer Information.
|
||||
@ -228,7 +228,7 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
result = ::CryptMsgGetParam(hMsg, CMSG_SIGNER_INFO_PARAM, 0, (PVOID)pSignerInfo, &dwSignerInfo);
|
||||
if (!result)
|
||||
{
|
||||
throw string("CryptMsgGetParam: ") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("CryptMsgGetParam: ") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
// Get the signer certificate from temporary certificate store.
|
||||
@ -238,10 +238,10 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
PCCERT_CONTEXT context = ::CertFindCertificateInStore(hStore, X509_ASN_ENCODING | PKCS_7_ASN_ENCODING, 0, CERT_FIND_SUBJECT_CERT, (PVOID)&cert_info, NULL);
|
||||
if (!context)
|
||||
{
|
||||
throw string("Certificate context: ") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("Certificate context: ") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
// Getting the full subject
|
||||
// Getting the full subject
|
||||
auto subject_sze = ::CertNameToStr(X509_ASN_ENCODING, &context->pCertInfo->Subject, CERT_X500_NAME_STR, NULL, 0);
|
||||
if (subject_sze <= 1)
|
||||
{
|
||||
@ -259,13 +259,13 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
DWORD key_id_sze = 0;
|
||||
if (!::CertGetCertificateContextProperty(context, CERT_KEY_IDENTIFIER_PROP_ID, NULL, &key_id_sze))
|
||||
{
|
||||
throw string("x509 property not found") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("x509 property not found") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
std::unique_ptr<BYTE[]> key_id_buff(new BYTE[key_id_sze]);
|
||||
if (!::CertGetCertificateContextProperty(context, CERT_KEY_IDENTIFIER_PROP_ID, key_id_buff.get(), &key_id_sze))
|
||||
{
|
||||
throw string("Getting certificate property problem.") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("Getting certificate property problem.") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
wstringstream ss;
|
||||
@ -277,20 +277,20 @@ bool SecurityGuard::verifySignedLibrary(const std::wstring& filepath)
|
||||
key_id_hex = ss.str();
|
||||
|
||||
if (doLogCertifError)
|
||||
writeLog(L"c:\\tmp\\certifError.log", ws2s(key_id_hex).c_str());
|
||||
writeLog(L"c:\\tmp\\certifError.log", wstring2string(key_id_hex, CP_UTF8).c_str());
|
||||
|
||||
// Getting the display name
|
||||
auto sze = ::CertGetNameString(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, NULL, 0);
|
||||
if (sze <= 1)
|
||||
{
|
||||
throw string("Getting data size problem.") + ws2s(GetLastErrorAsString(GetLastError()));
|
||||
throw string("Getting data size problem.") + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8);
|
||||
}
|
||||
|
||||
// Get display name.
|
||||
std::unique_ptr<wchar_t[]> display_name_buffer(new wchar_t[sze]);
|
||||
if (::CertGetNameString(context, CERT_NAME_SIMPLE_DISPLAY_TYPE, 0, NULL, display_name_buffer.get(), sze) <= 1)
|
||||
{
|
||||
throw string("Cannot get certificate info." + ws2s(GetLastErrorAsString(GetLastError())));
|
||||
throw string("Cannot get certificate info." + wstring2string(GetLastErrorAsString(GetLastError()), CP_UTF8));
|
||||
}
|
||||
display_name = display_name_buffer.get();
|
||||
|
||||
|
@ -147,7 +147,7 @@ private:
|
||||
std::wstring msg = L"An exception occurred due to plugin: ";
|
||||
msg += pluginName;
|
||||
msg += L"\r\n\r\nException reason: ";
|
||||
msg += s2ws(e.what());
|
||||
msg += string2wstring(e.what(), CP_UTF8);
|
||||
|
||||
::MessageBox(NULL, msg.c_str(), L"Plugin Exception", MB_OK);
|
||||
}
|
||||
|
@ -18,7 +18,6 @@
|
||||
#include <algorithm>
|
||||
#include <time.h>
|
||||
#include <locale>
|
||||
#include <codecvt>
|
||||
#include <sys/stat.h>
|
||||
#include "Buffer.h"
|
||||
#include "Scintilla.h"
|
||||
@ -168,8 +167,7 @@ void Buffer::updateTimeStamp()
|
||||
wstring nppIssueLog = nppParam.getUserPath();
|
||||
pathAppend(nppIssueLog, issueFn);
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string msg = converter.to_bytes(_fullPathName);
|
||||
std::string msg = wstring2string(_fullPathName, CP_UTF8);
|
||||
char buf[1024];
|
||||
sprintf(buf, " in updateTimeStamp(): timeStampLive (%lu/%lu) < _timeStamp (%lu/%lu)", timeStampLive.dwLowDateTime, timeStampLive.dwHighDateTime, _timeStamp.dwLowDateTime, _timeStamp.dwHighDateTime);
|
||||
msg += buf;
|
||||
@ -343,8 +341,7 @@ bool Buffer::checkFileState() // returns true if the status has been changed (it
|
||||
wstring nppIssueLog = nppParam.getUserPath();
|
||||
pathAppend(nppIssueLog, issueFn);
|
||||
|
||||
std::wstring_convert<std::codecvt_utf8_utf16<wchar_t>> converter;
|
||||
std::string msg = converter.to_bytes(_fullPathName);
|
||||
std::string msg = wstring2string(_fullPathName, CP_UTF8);
|
||||
char buf[1024];
|
||||
sprintf(buf, " in checkFileState(): attributes.ftLastWriteTime (%lu/%lu) < _timeStamp (%lu/%lu)", attributes.ftLastWriteTime.dwLowDateTime, attributes.ftLastWriteTime.dwHighDateTime, _timeStamp.dwLowDateTime, _timeStamp.dwHighDateTime);
|
||||
msg += buf;
|
||||
|
@ -4154,7 +4154,7 @@ void FindReplaceDlg::setStatusbarMessageWithRegExprErr(ScintillaEditView* pEditV
|
||||
std::wstring result = pNativeSpeaker->getLocalizedStrFromID("find-status-invalid-re", L"Find: Invalid Regular Expression");
|
||||
string s = msg;
|
||||
|
||||
setStatusbarMessage(result, FSNotFound, s2ws(s));
|
||||
setStatusbarMessage(result, FSNotFound, string2wstring(s, CP_UTF8));
|
||||
}
|
||||
|
||||
wstring FindReplaceDlg::getScopeInfoForStatusBar(FindOption const *pFindOpt) const
|
||||
|
@ -634,7 +634,7 @@ intptr_t CALLBACK GeneralSubDlg::run_dlgProc(UINT message, WPARAM wParam, LPARAM
|
||||
if (nppParam.getNativeLangA()) // if nativeLangA is not NULL, then we can be sure the default language (English) is not used
|
||||
{
|
||||
string fn = localizationSwitcher.getFileName();
|
||||
wstring fnW = s2ws(fn);
|
||||
wstring fnW = string2wstring(fn, CP_UTF8);
|
||||
lang = localizationSwitcher.getLangFromXmlFileName(fnW.c_str());
|
||||
}
|
||||
auto index = ::SendDlgItemMessage(_hSelf, IDC_COMBO_LOCALIZATION, CB_FINDSTRINGEXACT, static_cast<WPARAM>(-1), reinterpret_cast<LPARAM>(lang.c_str()));
|
||||
|
@ -25,7 +25,7 @@
|
||||
<ItemDefinitionGroup Label="Globals">
|
||||
<ClCompile>
|
||||
<AdditionalIncludeDirectories>..\src;..\src\MISC;..\src\MISC\Common;..\src\MISC\Exception;..\src\MISC\PluginsManager;..\src\MISC\Process;..\src\MISC\RegExt;..\src\MISC\md5;..\src\MISC\sha1;..\src\MISC\sha2;..\src\MISC\sha512;..\src\MISC\SysMsg;..\src\ScintillaComponent;..\src\Win32Explr;..\src\WinControls;..\src\WinControls\AboutDlg;..\src\WinControls\AnsiCharPanel;..\src\WinControls\ClipboardHistory;..\src\WinControls\ColourPicker;..\src\WinControls\ContextMenu;..\src\WinControls\DockingWnd;..\src\WinControls\DocumentMap;..\src\WinControls\FileBrowser;..\src\WinControls\FindCharsInRange;..\src\WinControls\FunctionList;..\src\WinControls\Grid;..\src\WinControls\ImageListSet;..\src\WinControls\OpenSaveFileDialog;..\src\WinControls\PluginsAdmin;..\src\WinControls\Preference;..\src\WinControls\ProjectPanel;..\src\WinControls\ReadDirectoryChanges;..\src\WinControls\shortcut;..\src\WinControls\SplitterContainer;..\src\WinControls\StaticDialog;..\src\WinControls\StaticDialog\RunDlg;..\src\WinControls\StatusBar;..\src\WinControls\TabBar;..\src\WinControls\TaskList;..\src\WinControls\ToolBar;..\src\WinControls\ToolTip;..\src\WinControls\TrayIcon;..\src\WinControls\TreeView;..\src\WinControls\VerticalFileSwitcher;..\src\WinControls\WindowsDlg;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
|
||||
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_WIN7;NTDDI_VERSION=NTDDI_WIN7;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<PreprocessorDefinitions>WIN32;_WIN32_WINNT=_WIN32_WINNT_WIN7;NTDDI_VERSION=NTDDI_WIN7;_WINDOWS;OEMRESOURCE;NOMINMAX;_USE_64BIT_TIME_T;TIXML_USE_STL;TIXMLA_USE_STL;_CRT_NONSTDC_NO_DEPRECATE;_CRT_SECURE_NO_WARNINGS;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES;_CRT_SECURE_CPP_OVERLOAD_STANDARD_NAMES_COUNT;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ExceptionHandling>Async</ExceptionHandling>
|
||||
<WarningLevel>Level4</WarningLevel>
|
||||
<TreatWarningAsError>true</TreatWarningAsError>
|
||||
|
Loading…
x
Reference in New Issue
Block a user