Remove ATL (part one)
Use std::wstring instead of CStringW
This commit is contained in:
parent
d5c0ef2c77
commit
ec5fa6d2c4
@ -77,12 +77,10 @@ DWORD WINAPI Notepad_plus::monitorFileOnChange(void * params)
|
|||||||
// We've received a notification in the queue.
|
// We've received a notification in the queue.
|
||||||
{
|
{
|
||||||
DWORD dwAction;
|
DWORD dwAction;
|
||||||
CStringW wstrFilename;
|
generic_string fn;
|
||||||
// Process all available changes, ignore User actions
|
// 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
|
// Fix monitoring files which are under root problem
|
||||||
size_t pos = fn.find(TEXT("\\\\"));
|
size_t pos = fn.find(TEXT("\\\\"));
|
||||||
if (pos == 2)
|
if (pos == 2)
|
||||||
|
@ -1353,7 +1353,7 @@ DWORD WINAPI FolderUpdater::watching(void *params)
|
|||||||
// We've received a notification in the queue.
|
// We've received a notification in the queue.
|
||||||
{
|
{
|
||||||
DWORD dwAction;
|
DWORD dwAction;
|
||||||
CStringW wstrFilename;
|
generic_string wstrFilename;
|
||||||
// Process all available changes, ignore User actions
|
// Process all available changes, ignore User actions
|
||||||
while (changes.Pop(dwAction, wstrFilename))
|
while (changes.Pop(dwAction, wstrFilename))
|
||||||
{
|
{
|
||||||
@ -1364,14 +1364,14 @@ DWORD WINAPI FolderUpdater::watching(void *params)
|
|||||||
switch (dwAction)
|
switch (dwAction)
|
||||||
{
|
{
|
||||||
case FILE_ACTION_ADDED:
|
case FILE_ACTION_ADDED:
|
||||||
file2Change.push_back(wstrFilename.GetString());
|
file2Change.push_back(wstrFilename);
|
||||||
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
||||||
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_ADDFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_ADDFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
||||||
oldName = TEXT("");
|
oldName = TEXT("");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_ACTION_REMOVED:
|
case FILE_ACTION_REMOVED:
|
||||||
file2Change.push_back(wstrFilename.GetString());
|
file2Change.push_back(wstrFilename);
|
||||||
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
||||||
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RMFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RMFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
||||||
oldName = TEXT("");
|
oldName = TEXT("");
|
||||||
@ -1382,14 +1382,14 @@ DWORD WINAPI FolderUpdater::watching(void *params)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_ACTION_RENAMED_OLD_NAME:
|
case FILE_ACTION_RENAMED_OLD_NAME:
|
||||||
oldName = wstrFilename.GetString();
|
oldName = wstrFilename;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case FILE_ACTION_RENAMED_NEW_NAME:
|
case FILE_ACTION_RENAMED_NEW_NAME:
|
||||||
if (not oldName.empty())
|
if (not oldName.empty())
|
||||||
{
|
{
|
||||||
file2Change.push_back(oldName);
|
file2Change.push_back(oldName);
|
||||||
file2Change.push_back(wstrFilename.GetString());
|
file2Change.push_back(wstrFilename);
|
||||||
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
//thisFolderUpdater->updateTree(dwAction, file2Change);
|
||||||
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RNFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
::SendMessage((thisFolderUpdater->_pFileBrowser)->getHSelf(), FB_RNFILE, reinterpret_cast<WPARAM>(nullptr), reinterpret_cast<LPARAM>(&file2Change));
|
||||||
}
|
}
|
||||||
|
@ -85,13 +85,13 @@ void CReadDirectoryChanges::AddDirectory( LPCTSTR szDirectory, BOOL bWatchSubtre
|
|||||||
QueueUserAPC(CReadChangesServer::AddDirectoryProc, m_hThread, (ULONG_PTR)pRequest);
|
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);
|
TDirectoryChangeNotification dirChangeNotif = TDirectoryChangeNotification(dwAction, wstrFilename);
|
||||||
m_Notifications.push(dirChangeNotif);
|
m_Notifications.push(dirChangeNotif);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CReadDirectoryChanges::Pop(DWORD& dwAction, CStringW& wstrFilename)
|
bool CReadDirectoryChanges::Pop(DWORD& dwAction, std::wstring& wstrFilename)
|
||||||
{
|
{
|
||||||
TDirectoryChangeNotification pair;
|
TDirectoryChangeNotification pair;
|
||||||
if (!m_Notifications.pop(pair))
|
if (!m_Notifications.pop(pair))
|
||||||
|
@ -44,7 +44,6 @@
|
|||||||
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
|
#define _ATL_CSTRING_EXPLICIT_CONSTRUCTORS // some CString constructors will be explicit
|
||||||
|
|
||||||
#include <atlbase.h>
|
#include <atlbase.h>
|
||||||
#include <atlstr.h>
|
|
||||||
|
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list>
|
#include <list>
|
||||||
@ -53,7 +52,7 @@ using namespace std;
|
|||||||
|
|
||||||
#include "ThreadSafeQueue.h"
|
#include "ThreadSafeQueue.h"
|
||||||
|
|
||||||
typedef pair<DWORD,CStringW> TDirectoryChangeNotification;
|
typedef pair<DWORD, std::wstring> TDirectoryChangeNotification;
|
||||||
|
|
||||||
namespace ReadDirectoryChangesPrivate
|
namespace ReadDirectoryChangesPrivate
|
||||||
{
|
{
|
||||||
@ -98,7 +97,7 @@ namespace ReadDirectoryChangesPrivate
|
|||||||
/// // We've received a notification in the queue.
|
/// // We've received a notification in the queue.
|
||||||
/// {
|
/// {
|
||||||
/// DWORD dwAction;
|
/// DWORD dwAction;
|
||||||
/// CStringW wstrFilename;
|
/// std::wstring wstrFilename;
|
||||||
/// while (changes.Pop(dwAction, wstrFilename))
|
/// while (changes.Pop(dwAction, wstrFilename))
|
||||||
/// wprintf(L"%s %s\n", ExplainAction(dwAction), wstrFilename);
|
/// wprintf(L"%s %s\n", ExplainAction(dwAction), wstrFilename);
|
||||||
/// }
|
/// }
|
||||||
@ -143,10 +142,10 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
HANDLE GetWaitHandle() { return m_Notifications.GetWaitHandle(); }
|
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.
|
// "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; }
|
unsigned int GetThreadId() { return m_dwThreadId; }
|
||||||
|
|
||||||
|
@ -71,7 +71,7 @@ bool CReadChangesRequest::OpenDirectory()
|
|||||||
return true;
|
return true;
|
||||||
|
|
||||||
m_hDirectory = ::CreateFileW(
|
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_LIST_DIRECTORY, // access (read/write) mode
|
||||||
FILE_SHARE_READ // share mode
|
FILE_SHARE_READ // share mode
|
||||||
| FILE_SHARE_WRITE
|
| FILE_SHARE_WRITE
|
||||||
@ -144,15 +144,15 @@ void CReadChangesRequest::ProcessNotification()
|
|||||||
{
|
{
|
||||||
FILE_NOTIFY_INFORMATION& fni = (FILE_NOTIFY_INFORMATION&)*pBase;
|
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.
|
// 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;
|
wstrFilename = m_wstrDirectory + L"\\" + wstrFilename;
|
||||||
else
|
else
|
||||||
wstrFilename = m_wstrDirectory + wstrFilename;
|
wstrFilename = m_wstrDirectory + wstrFilename;
|
||||||
|
|
||||||
// If it could be a short filename, expand it.
|
// If it could be a short filename, expand it.
|
||||||
LPCWSTR wszFilename = PathFindFileNameW(wstrFilename);
|
LPCWSTR wszFilename = PathFindFileNameW(wstrFilename.c_str());
|
||||||
int len = lstrlenW(wszFilename);
|
int len = lstrlenW(wszFilename);
|
||||||
// The maximum length of an 8.3 filename is twelve, including the dot.
|
// The maximum length of an 8.3 filename is twelve, including the dot.
|
||||||
if (len <= 12 && wcschr(wszFilename, L'~'))
|
if (len <= 12 && wcschr(wszFilename, L'~'))
|
||||||
@ -160,7 +160,7 @@ void CReadChangesRequest::ProcessNotification()
|
|||||||
// Convert to the long filename form. Unfortunately, this
|
// Convert to the long filename form. Unfortunately, this
|
||||||
// does not work for deletions, so it's an imperfect fix.
|
// does not work for deletions, so it's an imperfect fix.
|
||||||
wchar_t wbuf[MAX_PATH];
|
wchar_t wbuf[MAX_PATH];
|
||||||
if (::GetLongPathNameW(wstrFilename, wbuf, _countof(wbuf)) > 0)
|
if (::GetLongPathNameW(wstrFilename.c_str(), wbuf, _countof(wbuf)) > 0)
|
||||||
wstrFilename = wbuf;
|
wstrFilename = wbuf;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,9 +75,9 @@ protected:
|
|||||||
LPOVERLAPPED lpOverlapped); // I/O information buffer
|
LPOVERLAPPED lpOverlapped); // I/O information buffer
|
||||||
|
|
||||||
// Parameters from the caller for ReadDirectoryChangesW().
|
// Parameters from the caller for ReadDirectoryChangesW().
|
||||||
DWORD m_dwFilterFlags;
|
DWORD m_dwFilterFlags;
|
||||||
BOOL m_bIncludeChildren;
|
BOOL m_bIncludeChildren;
|
||||||
CStringW m_wstrDirectory;
|
std::wstring m_wstrDirectory;
|
||||||
|
|
||||||
// Result of calling CreateFile().
|
// Result of calling CreateFile().
|
||||||
HANDLE m_hDirectory;
|
HANDLE m_hDirectory;
|
||||||
|
Loading…
Reference in New Issue
Block a user