Remove ATL (part one)

Use std::wstring instead of CStringW
This commit is contained in:
Don HO 2019-08-25 00:14:42 +02:00
parent d5c0ef2c77
commit ec5fa6d2c4
No known key found for this signature in database
GPG Key ID: 6C429F1D8D84F46E
6 changed files with 21 additions and 24 deletions

View File

@ -77,12 +77,10 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params)
// We've received a notification in the queue.
{
DWORD dwAction;
CStringW wstrFilename;
generic_string fn;
// Process all available changes, ignore User actions
while (changes.Pop(dwAction, wstrFilename))
while (changes.Pop(dwAction, fn))
{
generic_string fn = wstrFilename.GetString();
// Fix monitoring files which are under root problem
size_t pos = fn.find(TEXT("\\\\"));
if (pos == 2)

View File

@ -1353,7 +1353,7 @@ DWORD WINAPI FolderUpdater::watching(void *params)
// We've received a notification in the queue.
{
DWORD dwAction;
CStringW wstrFilename;
generic_string wstrFilename;
// Process all available changes, ignore User actions
while (changes.Pop(dwAction, wstrFilename))
{
@ -1364,14 +1364,14 @@ DWORD WINAPI FolderUpdater::watching(void *params)
switch (dwAction)
{
case FILE_ACTION_ADDED:
file2Change.push_back(wstrFilename.GetString());
file2Change.push_back(wstrFilename);
//thisFolderUpdater->updateTree(dwAction, file2Change);
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_ADDFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
oldName = TEXT("");
break;
case FILE_ACTION_REMOVED:
file2Change.push_back(wstrFilename.GetString());
file2Change.push_back(wstrFilename);
//thisFolderUpdater->updateTree(dwAction, file2Change);
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RMFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
oldName = TEXT("");
@ -1382,14 +1382,14 @@ DWORD WINAPI FolderUpdater::watching(void *params)
break;
case FILE_ACTION_RENAMED_OLD_NAME:
oldName = wstrFilename.GetString();
oldName = wstrFilename;
break;
case FILE_ACTION_RENAMED_NEW_NAME:
if (not oldName.empty())
{
file2Change.push_back(oldName);
file2Change.push_back(wstrFilename.GetString());
file2Change.push_back(wstrFilename);
//thisFolderUpdater->updateTree(dwAction, file2Change);
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RNFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
}

View File

@ -85,13 +85,13 @@ void CReadDirectoryChanges::AddDirectory( LPCTSTR szDirectory, BOOL bWatchSubtre
QueueUserAPC(CReadChangesServer::AddDirectoryProc, m_hThread, (ULONG_PTR)pRequest);
}
void CReadDirectoryChanges::Push(DWORD dwAction, CStringW& wstrFilename)
void CReadDirectoryChanges::Push(DWORD dwAction, std::wstring& wstrFilename)
{
TDirectoryChangeNotification dirChangeNotif = TDirectoryChangeNotification(dwAction, wstrFilename);
m_Notifications.push(dirChangeNotif);
}
bool CReadDirectoryChanges::Pop(DWORD& dwAction, CStringW& wstrFilename)
bool CReadDirectoryChanges::Pop(DWORD& dwAction, std::wstring& wstrFilename)
{
TDirectoryChangeNotification pair;
if (!m_Notifications.pop(pair))

View File

@ -44,7 +44,6 @@
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
#include <atlbase.h>
#include <atlstr.h>
#include <vector>
#include <list>
@ -53,7 +52,7 @@ using namespace std;
#include "ThreadSafeQueue.h"
typedef pair<DWORD,CStringW> TDirectoryChangeNotification;
typedef pair<DWORD, std::wstring> TDirectoryChangeNotification;
namespace ReadDirectoryChangesPrivate
{
@ -98,7 +97,7 @@ namespace ReadDirectoryChangesPrivate
/// // We've received a notification in the queue.
/// {
/// DWORD dwAction;
/// CStringW wstrFilename;
/// std::wstring wstrFilename;
/// while (changes.Pop(dwAction, wstrFilename))
/// wprintf(L"%s %s\n", ExplainAction(dwAction), wstrFilename);
/// }
@ -143,10 +142,10 @@ public:
/// </summary>
HANDLE GetWaitHandle() { return m_Notifications.GetWaitHandle(); }
bool Pop(DWORD& dwAction, CStringW& wstrFilename);
bool Pop(DWORD& dwAction, std::wstring& wstrFilename);
// "Push" is for usage by ReadChangesRequest. Not intended for external usage.
void Push(DWORD dwAction, CStringW& wstrFilename);
void Push(DWORD dwAction, std::wstring& wstrFilename);
unsigned int GetThreadId() { return m_dwThreadId; }

View File

@ -71,7 +71,7 @@ bool CReadChangesRequest::OpenDirectory()
return true;
m_hDirectory = ::CreateFileW(
m_wstrDirectory, // pointer to the file name
m_wstrDirectory.c_str(), // pointer to the file name
FILE_LIST_DIRECTORY, // access (read/write) mode
FILE_SHARE_READ // share mode
| FILE_SHARE_WRITE
@ -144,15 +144,15 @@ void CReadChangesRequest::ProcessNotification()
{
FILE_NOTIFY_INFORMATION& fni = (FILE_NOTIFY_INFORMATION&)*pBase;
CStringW wstrFilename(fni.FileName, fni.FileNameLength/sizeof(wchar_t));
std::wstring wstrFilename(fni.FileName, fni.FileNameLength/sizeof(wchar_t));
// Handle a trailing backslash, such as for a root directory.
if (wstrFilename.Right(1) != L"\\")
if (!wstrFilename.empty() && wstrFilename.back() != L'\\')
wstrFilename = m_wstrDirectory + L"\\" + wstrFilename;
else
wstrFilename = m_wstrDirectory + wstrFilename;
// If it could be a short filename, expand it.
LPCWSTR wszFilename = PathFindFileNameW(wstrFilename);
LPCWSTR wszFilename = PathFindFileNameW(wstrFilename.c_str());
int len = lstrlenW(wszFilename);
// The maximum length of an 8.3 filename is twelve, including the dot.
if (len <= 12 && wcschr(wszFilename, L'~'))
@ -160,7 +160,7 @@ void CReadChangesRequest::ProcessNotification()
// Convert to the long filename form. Unfortunately, this
// does not work for deletions, so it's an imperfect fix.
wchar_t wbuf[MAX_PATH];
if (::GetLongPathNameW(wstrFilename, wbuf, _countof(wbuf)) > 0)
if (::GetLongPathNameW(wstrFilename.c_str(), wbuf, _countof(wbuf)) > 0)
wstrFilename = wbuf;
}

View File

@ -75,9 +75,9 @@ protected:
LPOVERLAPPED lpOverlapped); // I/O information buffer
// Parameters from the caller for ReadDirectoryChangesW().
DWORD m_dwFilterFlags;
BOOL m_bIncludeChildren;
CStringW m_wstrDirectory;
DWORD m_dwFilterFlags;
BOOL m_bIncludeChildren;
std::wstring m_wstrDirectory;
// Result of calling CreateFile().
HANDLE m_hDirectory;