mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-15 00:11:40 -06:00
4.30 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
bcd1db2f5a
commit
e18587ba51
164
Windows/CommonDialog.cpp
Executable file
164
Windows/CommonDialog.cpp
Executable file
@@ -0,0 +1,164 @@
|
||||
// Windows/CommonDialog.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Common/MyCom.h"
|
||||
#include "CommonDialog.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows{
|
||||
|
||||
#ifndef _UNICODE
|
||||
class CDoubleZeroStringListA
|
||||
{
|
||||
CRecordVector<int> m_Indexes;
|
||||
AString m_String;
|
||||
public:
|
||||
void Add(LPCSTR s);
|
||||
void SetForBuffer(LPSTR buffer);
|
||||
};
|
||||
|
||||
void CDoubleZeroStringListA::Add(LPCSTR s)
|
||||
{
|
||||
m_String += s;
|
||||
m_Indexes.Add(m_String.Length());
|
||||
m_String += ' ';
|
||||
}
|
||||
|
||||
void CDoubleZeroStringListA::SetForBuffer(LPSTR buffer)
|
||||
{
|
||||
strcpy(buffer, m_String);
|
||||
for (int i = 0; i < m_Indexes.Size(); i++)
|
||||
buffer[m_Indexes[i]] = '\0';
|
||||
}
|
||||
#endif
|
||||
|
||||
class CDoubleZeroStringListW
|
||||
{
|
||||
CRecordVector<int> m_Indexes;
|
||||
UString m_String;
|
||||
public:
|
||||
void Add(LPCWSTR s);
|
||||
void SetForBuffer(LPWSTR buffer);
|
||||
};
|
||||
|
||||
void CDoubleZeroStringListW::Add(LPCWSTR s)
|
||||
{
|
||||
m_String += s;
|
||||
m_Indexes.Add(m_String.Length());
|
||||
m_String += L' ';
|
||||
}
|
||||
|
||||
void CDoubleZeroStringListW::SetForBuffer(LPWSTR buffer)
|
||||
{
|
||||
wcscpy(buffer, m_String);
|
||||
for (int i = 0; i < m_Indexes.Size(); i++)
|
||||
buffer[m_Indexes[i]] = L'\0';
|
||||
}
|
||||
|
||||
bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, LPCWSTR s, UString &resPath)
|
||||
{
|
||||
const int kBufferSize = MAX_PATH * 2;
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
CHAR buffer[kBufferSize];
|
||||
strcpy(buffer, GetSystemString(fullFileName));
|
||||
OPENFILENAME info;
|
||||
info.lStructSize = sizeof(info);
|
||||
info.hwndOwner = hwnd;
|
||||
info.hInstance = 0;
|
||||
const int kFilterBufferSize = MAX_PATH;
|
||||
CHAR filterBuffer[kFilterBufferSize];
|
||||
CDoubleZeroStringListA doubleZeroStringList;
|
||||
doubleZeroStringList.Add(GetSystemString(s));
|
||||
doubleZeroStringList.Add("*.*");
|
||||
doubleZeroStringList.SetForBuffer(filterBuffer);
|
||||
info.lpstrFilter = filterBuffer;
|
||||
|
||||
info.lpstrCustomFilter = NULL;
|
||||
info.nMaxCustFilter = 0;
|
||||
info.nFilterIndex = 0;
|
||||
|
||||
info.lpstrFile = buffer;
|
||||
info.nMaxFile = kBufferSize;
|
||||
|
||||
info.lpstrFileTitle = NULL;
|
||||
info.nMaxFileTitle = 0;
|
||||
|
||||
info.lpstrInitialDir= NULL;
|
||||
|
||||
info.lpstrTitle = 0;
|
||||
AString titleA;
|
||||
if (title != 0)
|
||||
{
|
||||
titleA = GetSystemString(title);
|
||||
info.lpstrTitle = titleA;
|
||||
}
|
||||
|
||||
info.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
|
||||
info.nFileOffset = 0;
|
||||
info.nFileExtension = 0;
|
||||
info.lpstrDefExt = NULL;
|
||||
|
||||
info.lCustData = 0;
|
||||
info.lpfnHook = NULL;
|
||||
info.lpTemplateName = NULL;
|
||||
|
||||
bool res = BOOLToBool(::GetOpenFileNameA(&info));
|
||||
resPath = GetUnicodeString(buffer);
|
||||
return res;
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
WCHAR buffer[kBufferSize];
|
||||
wcscpy(buffer, fullFileName);
|
||||
OPENFILENAMEW info;
|
||||
info.lStructSize = sizeof(info);
|
||||
info.hwndOwner = hwnd;
|
||||
info.hInstance = 0;
|
||||
const int kFilterBufferSize = MAX_PATH;
|
||||
WCHAR filterBuffer[kFilterBufferSize];
|
||||
CDoubleZeroStringListW doubleZeroStringList;
|
||||
doubleZeroStringList.Add(s);
|
||||
doubleZeroStringList.Add(L"*.*");
|
||||
doubleZeroStringList.SetForBuffer(filterBuffer);
|
||||
info.lpstrFilter = filterBuffer;
|
||||
|
||||
info.lpstrCustomFilter = NULL;
|
||||
info.nMaxCustFilter = 0;
|
||||
info.nFilterIndex = 0;
|
||||
|
||||
info.lpstrFile = buffer;
|
||||
info.nMaxFile = kBufferSize;
|
||||
|
||||
info.lpstrFileTitle = NULL;
|
||||
info.nMaxFileTitle = 0;
|
||||
|
||||
info.lpstrInitialDir= NULL;
|
||||
|
||||
info.lpstrTitle = title;
|
||||
|
||||
info.Flags = OFN_EXPLORER | OFN_HIDEREADONLY;
|
||||
info.nFileOffset = 0;
|
||||
info.nFileExtension = 0;
|
||||
info.lpstrDefExt = NULL;
|
||||
|
||||
info.lCustData = 0;
|
||||
info.lpfnHook = NULL;
|
||||
info.lpTemplateName = NULL;
|
||||
|
||||
bool res = BOOLToBool(::GetOpenFileNameW(&info));
|
||||
resPath = buffer;
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
17
Windows/CommonDialog.h
Executable file
17
Windows/CommonDialog.h
Executable file
@@ -0,0 +1,17 @@
|
||||
// Windows/CommonDialog.h
|
||||
|
||||
#ifndef __WINDOWS_COMMONDIALOG_H
|
||||
#define __WINDOWS_COMMONDIALOG_H
|
||||
|
||||
#include <windows.h>
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
namespace NWindows{
|
||||
|
||||
bool MyGetOpenFileName(HWND hwnd, LPCWSTR title, LPCWSTR fullFileName, LPCWSTR s, UString &resPath);
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,23 +1,63 @@
|
||||
// Windows/Control/ComboBox.cpp
|
||||
|
||||
// #define _UNICODE
|
||||
// #define UNICODE
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#include "Windows/Control/ComboBox.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NControl {
|
||||
|
||||
int CComboBox::GetLBText(int index, CSysString &string)
|
||||
LRESULT CComboBox::GetLBText(int index, CSysString &s)
|
||||
{
|
||||
string.Empty();
|
||||
int aLength = GetLBTextLen(index);
|
||||
if (aLength == CB_ERR)
|
||||
return aLength;
|
||||
aLength = GetLBText(index, string.GetBuffer(aLength));
|
||||
string.ReleaseBuffer();
|
||||
return aLength;
|
||||
s.Empty();
|
||||
LRESULT len = GetLBTextLen(index);
|
||||
if (len == CB_ERR)
|
||||
return len;
|
||||
len = GetLBText(index, s.GetBuffer((int)len + 1));
|
||||
s.ReleaseBuffer();
|
||||
return len;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
LRESULT CComboBox::AddString(LPCWSTR s)
|
||||
{
|
||||
if (g_IsNT)
|
||||
return SendMessageW(CB_ADDSTRING, 0, (LPARAM)s);
|
||||
return AddString(GetSystemString(s));
|
||||
}
|
||||
|
||||
LRESULT CComboBox::GetLBText(int index, UString &s)
|
||||
{
|
||||
s.Empty();
|
||||
if (g_IsNT)
|
||||
{
|
||||
LRESULT len = SendMessageW(CB_GETLBTEXTLEN, index, 0);
|
||||
if (len == CB_ERR)
|
||||
return len;
|
||||
len = SendMessageW(CB_GETLBTEXT, index, (LPARAM)s.GetBuffer((int)len + 1));
|
||||
s.ReleaseBuffer();
|
||||
return len;
|
||||
}
|
||||
AString sa;
|
||||
int len = GetLBText(index, sa);
|
||||
if (len == CB_ERR)
|
||||
return len;
|
||||
s = GetUnicodeString(sa);
|
||||
return s.Length();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -14,22 +14,21 @@ namespace NControl {
|
||||
class CComboBox: public CWindow
|
||||
{
|
||||
public:
|
||||
void ResetContent()
|
||||
{ SendMessage(CB_RESETCONTENT, 0, 0); }
|
||||
int AddString(LPCTSTR string)
|
||||
{ return SendMessage(CB_ADDSTRING, 0, (LPARAM)string); }
|
||||
int SetCurSel(int index)
|
||||
{ return SendMessage(CB_SETCURSEL, index, 0); }
|
||||
int GetCurSel()
|
||||
{ return SendMessage(CB_GETCURSEL, 0, 0); }
|
||||
int GetCount()
|
||||
{ return SendMessage(CB_GETCOUNT, 0, 0); }
|
||||
void ResetContent() { SendMessage(CB_RESETCONTENT, 0, 0); }
|
||||
LRESULT AddString(LPCTSTR string) { return SendMessage(CB_ADDSTRING, 0, (LPARAM)string); }
|
||||
#ifndef _UNICODE
|
||||
LRESULT AddString(LPCWSTR string);
|
||||
#endif
|
||||
int SetCurSel(int index) { return SendMessage(CB_SETCURSEL, index, 0); }
|
||||
int GetCurSel() { return SendMessage(CB_GETCURSEL, 0, 0); }
|
||||
int GetCount() { return SendMessage(CB_GETCOUNT, 0, 0); }
|
||||
|
||||
int GetLBTextLen(int index)
|
||||
{ return SendMessage(CB_GETLBTEXTLEN, index, 0); }
|
||||
int GetLBText(int index, LPTSTR string)
|
||||
{ return SendMessage(CB_GETLBTEXT, index, (LPARAM)string); }
|
||||
int GetLBText(int index, CSysString &string);
|
||||
LRESULT GetLBTextLen(int index) { return SendMessage(CB_GETLBTEXTLEN, index, 0); }
|
||||
LRESULT GetLBText(int index, LPTSTR string) { return SendMessage(CB_GETLBTEXT, index, (LPARAM)string); }
|
||||
LRESULT GetLBText(int index, CSysString &s);
|
||||
#ifndef _UNICODE
|
||||
LRESULT GetLBText(int index, UString &s);
|
||||
#endif
|
||||
|
||||
int SetItemData(int index, LPARAM lParam)
|
||||
{ return SendMessage(CB_SETITEMDATA, index, lParam); }
|
||||
|
||||
@@ -2,9 +2,15 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Windows/Control/Dialog.h"
|
||||
|
||||
extern HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NControl {
|
||||
@@ -81,8 +87,7 @@ bool CDialog::OnButtonClicked(int buttonID, HWND buttonHWND)
|
||||
|
||||
bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
|
||||
{
|
||||
HWND aHWND = CreateDialogParam(g_hInstance,
|
||||
templateName, parentWindow, DialogProcedure, LPARAM(this));
|
||||
HWND aHWND = CreateDialogParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
if (aHWND == 0)
|
||||
return false;
|
||||
Attach(aHWND);
|
||||
@@ -91,16 +96,50 @@ bool CModelessDialog::Create(LPCTSTR templateName, HWND parentWindow)
|
||||
|
||||
INT_PTR CModalDialog::Create(LPCTSTR templateName, HWND parentWindow)
|
||||
{
|
||||
return DialogBoxParam(g_hInstance,
|
||||
templateName, parentWindow, DialogProcedure, LPARAM(this));
|
||||
return DialogBoxParam(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
bool CModelessDialog::Create(LPCWSTR templateName, HWND parentWindow)
|
||||
{
|
||||
HWND aHWND;
|
||||
if (g_IsNT)
|
||||
aHWND = CreateDialogParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
else
|
||||
{
|
||||
AString name;
|
||||
LPCSTR templateNameA;
|
||||
if (IS_INTRESOURCE(templateName))
|
||||
templateNameA = (LPCSTR)templateName;
|
||||
else
|
||||
{
|
||||
name = GetSystemString(templateName);
|
||||
templateNameA = name;
|
||||
}
|
||||
aHWND = CreateDialogParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
}
|
||||
if (aHWND == 0)
|
||||
return false;
|
||||
Attach(aHWND);
|
||||
return true;
|
||||
}
|
||||
|
||||
/*
|
||||
INT_PTR CModalDialog::Create(LPCWSTR templateName, HWND parentWindow)
|
||||
{
|
||||
return DialogBoxParamW(g_hInstance,
|
||||
templateName, parentWindow, DialogProcedure, LPARAM(this));
|
||||
if (g_IsNT)
|
||||
return DialogBoxParamW(g_hInstance, templateName, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
AString name;
|
||||
LPCSTR templateNameA;
|
||||
if (IS_INTRESOURCE(templateName))
|
||||
templateNameA = (LPCSTR)templateName;
|
||||
else
|
||||
{
|
||||
name = GetSystemString(templateName);
|
||||
templateNameA = name;
|
||||
}
|
||||
return DialogBoxParamA(g_hInstance, templateNameA, parentWindow, DialogProcedure, (LPARAM)this);
|
||||
}
|
||||
*/
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
@@ -102,6 +102,9 @@ class CModelessDialog: public CDialog
|
||||
{
|
||||
public:
|
||||
bool Create(LPCTSTR templateName, HWND parentWindow);
|
||||
#ifndef _UNICODE
|
||||
bool Create(LPCWSTR templateName, HWND parentWindow);
|
||||
#endif
|
||||
virtual void OnOK() { Destroy(); }
|
||||
virtual void OnCancel() { Destroy(); }
|
||||
};
|
||||
@@ -110,7 +113,12 @@ class CModalDialog: public CDialog
|
||||
{
|
||||
public:
|
||||
INT_PTR Create(LPCTSTR templateName, HWND parentWindow);
|
||||
// INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
|
||||
INT_PTR Create(UINT resID, HWND parentWindow)
|
||||
{ return Create(MAKEINTRESOURCEW(resID), parentWindow); }
|
||||
#ifndef _UNICODE
|
||||
INT_PTR Create(LPCWSTR templateName, HWND parentWindow);
|
||||
#endif
|
||||
|
||||
bool End(INT_PTR result)
|
||||
{ return BOOLToBool(::EndDialog(_window, result)); }
|
||||
virtual void OnOK() { End(IDOK); }
|
||||
|
||||
@@ -18,18 +18,35 @@ public:
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam);
|
||||
|
||||
|
||||
bool SetUnicodeFormat(bool fUnicode)
|
||||
{ return BOOLToBool(ListView_SetUnicodeFormat(_window, BOOLToBool(fUnicode))); }
|
||||
|
||||
bool DeleteAllItems()
|
||||
{ return BOOLToBool(ListView_DeleteAllItems(_window)); }
|
||||
int InsertColumn(int columnIndex, const LVCOLUMN *columnInfo)
|
||||
{ return ListView_InsertColumn(_window, columnIndex, columnInfo); }
|
||||
#ifndef _UNICODE
|
||||
int InsertColumn(int columnIndex, const LVCOLUMNW *columnInfo)
|
||||
{ return (int)SendMessage(LVM_INSERTCOLUMNW, (WPARAM)columnIndex, (LPARAM)columnInfo); }
|
||||
#endif
|
||||
bool DeleteColumn(int columnIndex)
|
||||
{ return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); }
|
||||
|
||||
int InsertItem(const LVITEM* item)
|
||||
{ return ListView_InsertItem(_window, item); }
|
||||
#ifndef _UNICODE
|
||||
int InsertItem(const LV_ITEMW* item)
|
||||
{ return (int)SendMessage(LVM_INSERTITEMW, 0, (LPARAM)item); }
|
||||
#endif
|
||||
|
||||
bool SetItem(const LVITEM* item)
|
||||
{ return BOOLToBool(ListView_SetItem(_window, item)); }
|
||||
#ifndef _UNICODE
|
||||
bool SetItem(const LV_ITEMW* item)
|
||||
{ return BOOLToBool((BOOL)SendMessage(LVM_SETITEMW, 0, (LPARAM)item)); }
|
||||
#endif
|
||||
|
||||
bool DeleteItem(int itemIndex)
|
||||
{ return BOOLToBool(ListView_DeleteItem(_window, itemIndex)); }
|
||||
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Windows/Control/PropertyPage.h"
|
||||
#include "../../Common/Vector.h"
|
||||
#ifndef _UNICODE
|
||||
#include "../../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
extern HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NControl {
|
||||
@@ -55,5 +64,102 @@ bool CPropertyPage::OnNotify(UINT controlID, LPNMHDR lParam)
|
||||
return true;
|
||||
}
|
||||
|
||||
int MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
AStringVector titles;
|
||||
#endif
|
||||
#ifndef _UNICODE
|
||||
CRecordVector<PROPSHEETPAGEA> pagesA;
|
||||
#endif
|
||||
CRecordVector<PROPSHEETPAGEW> pagesW;
|
||||
|
||||
int i;
|
||||
#ifndef _UNICODE
|
||||
for (i = 0; i < pagesInfo.Size(); i++)
|
||||
titles.Add(GetSystemString(pagesInfo[i].Title));
|
||||
#endif
|
||||
|
||||
for (i = 0; i < pagesInfo.Size(); i++)
|
||||
{
|
||||
const CPageInfo &pageInfo = pagesInfo[i];
|
||||
#ifndef _UNICODE
|
||||
{
|
||||
PROPSHEETPAGE page;
|
||||
page.dwSize = sizeof(page);
|
||||
page.dwFlags = PSP_HASHELP;
|
||||
page.hInstance = g_hInstance;
|
||||
page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID);
|
||||
page.pszIcon = NULL;
|
||||
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
|
||||
|
||||
if (titles[i].IsEmpty())
|
||||
page.pszTitle = NULL;
|
||||
else
|
||||
{
|
||||
page.dwFlags |= PSP_USETITLE;
|
||||
page.pszTitle = titles[i];
|
||||
}
|
||||
page.lParam = (LPARAM)pageInfo.Page;
|
||||
page.pfnCallback = NULL;
|
||||
pagesA.Add(page);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
PROPSHEETPAGEW page;
|
||||
page.dwSize = sizeof(page);
|
||||
page.dwFlags = PSP_HASHELP;
|
||||
page.hInstance = g_hInstance;
|
||||
page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID);
|
||||
page.pszIcon = NULL;
|
||||
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
|
||||
|
||||
if (pageInfo.Title.IsEmpty())
|
||||
page.pszTitle = NULL;
|
||||
else
|
||||
{
|
||||
page.dwFlags |= PSP_USETITLE;
|
||||
page.pszTitle = pageInfo.Title;
|
||||
}
|
||||
page.lParam = (LPARAM)pageInfo.Page;
|
||||
page.pfnCallback = NULL;
|
||||
pagesW.Add(page);
|
||||
}
|
||||
}
|
||||
|
||||
int res;
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
PROPSHEETHEADER sheet;
|
||||
sheet.dwSize = sizeof(sheet);
|
||||
sheet.dwFlags = PSH_PROPSHEETPAGE;
|
||||
sheet.hwndParent = hwndParent;
|
||||
sheet.hInstance = g_hInstance;
|
||||
AString titleA = GetSystemString(title);
|
||||
sheet.pszCaption = titleA;
|
||||
sheet.nPages = pagesInfo.Size();
|
||||
sheet.nStartPage = 0;
|
||||
sheet.ppsp = &pagesA.Front();
|
||||
sheet.pfnCallback = NULL;
|
||||
res = ::PropertySheetA(&sheet);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
PROPSHEETHEADERW sheet;
|
||||
sheet.dwSize = sizeof(sheet);
|
||||
sheet.dwFlags = PSH_PROPSHEETPAGE;
|
||||
sheet.hwndParent = hwndParent;
|
||||
sheet.hInstance = g_hInstance;
|
||||
sheet.pszCaption = title;
|
||||
sheet.nPages = pagesInfo.Size();
|
||||
sheet.nStartPage = 0;
|
||||
sheet.ppsp = &pagesW.Front();
|
||||
sheet.pfnCallback = NULL;
|
||||
res = ::PropertySheetW(&sheet);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
@@ -33,6 +33,14 @@ public:
|
||||
virtual void OnReset(const PSHNOTIFY *aPSHNOTIFY) { OnReset(); }
|
||||
};
|
||||
|
||||
struct CPageInfo
|
||||
{
|
||||
CPropertyPage *Page;
|
||||
UString Title;
|
||||
UINT ID;
|
||||
};
|
||||
|
||||
int MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndParent, const UString &title);
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -18,12 +18,24 @@ public:
|
||||
{ return BOOLToBool(SendMessage(SB_SETPARTS, numParts, (LPARAM)edgePostions)); }
|
||||
bool SetText(LPCTSTR text)
|
||||
{ return CWindow::SetText(text); }
|
||||
|
||||
bool SetText(int index, LPCTSTR text, UINT type)
|
||||
{ return BOOLToBool(SendMessage(SB_SETTEXT, index | type, (LPARAM)text)); }
|
||||
bool SetText(int index, LPCTSTR text)
|
||||
{ return SetText(index, text, 0); }
|
||||
void Simple(bool simple)
|
||||
{ SendMessage(SB_SIMPLE, BoolToBOOL(simple), 0); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool Create(LONG style, LPCWSTR text, HWND hwndParent, UINT id)
|
||||
{ return (_window = ::CreateStatusWindowW(style, text, hwndParent, id)) != 0; }
|
||||
bool SetText(LPCWSTR text)
|
||||
{ return CWindow::SetText(text); }
|
||||
bool SetText(int index, LPCWSTR text, UINT type)
|
||||
{ return BOOLToBool(SendMessage(SB_SETTEXTW, index | type, (LPARAM)text)); }
|
||||
bool SetText(int index, LPCWSTR text)
|
||||
{ return SetText(index, text, 0); }
|
||||
#endif
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -23,6 +23,10 @@ public:
|
||||
{ return HIMAGELIST(SendMessage(TB_SETIMAGELIST, listIndex, (LPARAM)imageList)); }
|
||||
bool AddButton(UINT numButtons, LPTBBUTTON buttons)
|
||||
{ return BOOLToBool(SendMessage(TB_ADDBUTTONS, numButtons, (LPARAM)buttons)); }
|
||||
#ifndef _UNICODE
|
||||
bool AddButtonW(UINT numButtons, LPTBBUTTON buttons)
|
||||
{ return BOOLToBool(SendMessage(TB_ADDBUTTONSW, numButtons, (LPARAM)buttons)); }
|
||||
#endif
|
||||
};
|
||||
|
||||
}}
|
||||
|
||||
@@ -2,11 +2,22 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Windows/Control/Window2.h"
|
||||
|
||||
// extern HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
#ifndef _UNICODE
|
||||
ATOM MyRegisterClass(CONST WNDCLASSW *wndClass);
|
||||
#endif
|
||||
|
||||
namespace NControl {
|
||||
|
||||
static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message,
|
||||
@@ -17,12 +28,17 @@ static LRESULT CALLBACK WindowProcedure(HWND aHWND, UINT message,
|
||||
tempWindow.SetUserDataLongPtr(
|
||||
LONG_PTR(((LPCREATESTRUCT)lParam)->lpCreateParams));
|
||||
CWindow2 *window = (CWindow2*)(tempWindow.GetUserDataLongPtr());
|
||||
if (window == NULL)
|
||||
return DefWindowProc(aHWND, message, wParam, lParam);
|
||||
if (message == WM_NCCREATE)
|
||||
if (window != NULL && message == WM_NCCREATE)
|
||||
window->Attach(aHWND);
|
||||
if (window == 0)
|
||||
return DefWindowProc(aHWND, message, wParam, lParam);
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (g_IsNT)
|
||||
return DefWindowProcW(aHWND, message, wParam, lParam);
|
||||
else
|
||||
#endif
|
||||
return DefWindowProc(aHWND, message, wParam, lParam);
|
||||
}
|
||||
return window->OnMessage(message, wParam, lParam);
|
||||
}
|
||||
|
||||
@@ -55,6 +71,68 @@ bool CWindow2::CreateEx(DWORD exStyle, LPCTSTR className,
|
||||
idOrHMenu, instance, this);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
bool CWindow2::CreateEx(DWORD exStyle, LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance)
|
||||
{
|
||||
bool needRegister;
|
||||
if(g_IsNT)
|
||||
{
|
||||
WNDCLASSW windowClass;
|
||||
needRegister = ::GetClassInfoW(instance, className, &windowClass) == 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
WNDCLASSA windowClassA;
|
||||
AString classNameA;
|
||||
LPCSTR classNameP;
|
||||
if (IS_INTRESOURCE(className))
|
||||
classNameP = (LPCSTR)className;
|
||||
else
|
||||
{
|
||||
classNameA = GetSystemString(className);
|
||||
classNameP = classNameA;
|
||||
}
|
||||
needRegister = ::GetClassInfoA(instance, classNameP, &windowClassA) == 0;
|
||||
}
|
||||
if (needRegister)
|
||||
{
|
||||
WNDCLASSW windowClass;
|
||||
// windowClass.style = CS_HREDRAW | CS_VREDRAW;
|
||||
windowClass.style = 0;
|
||||
windowClass.lpfnWndProc = WindowProcedure;
|
||||
windowClass.cbClsExtra = NULL;
|
||||
windowClass.cbWndExtra = NULL;
|
||||
windowClass.hInstance = instance;
|
||||
windowClass.hIcon = NULL;
|
||||
windowClass.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
windowClass.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1);
|
||||
windowClass.lpszMenuName = NULL;
|
||||
windowClass.lpszClassName = className;
|
||||
if (MyRegisterClass(&windowClass) == 0)
|
||||
return false;
|
||||
}
|
||||
return CWindow::CreateEx(exStyle, className, windowName,
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, this);
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
LRESULT CWindow2::DefProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (g_IsNT)
|
||||
return DefWindowProcW(_window, message, wParam, lParam);
|
||||
else
|
||||
#endif
|
||||
return DefWindowProc(_window, message, wParam, lParam);
|
||||
}
|
||||
|
||||
LRESULT CWindow2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{
|
||||
LRESULT result;
|
||||
|
||||
@@ -11,12 +11,11 @@ namespace NControl {
|
||||
|
||||
class CWindow2: public CWindow
|
||||
{
|
||||
LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
public:
|
||||
CWindow2(HWND newWindow = NULL): CWindow(newWindow){};
|
||||
virtual ~CWindow2() {};
|
||||
|
||||
LRESULT DefProc(UINT message, WPARAM wParam, LPARAM lParam)
|
||||
{ return ::DefWindowProc(_window, message, wParam, lParam); }
|
||||
|
||||
bool CreateEx(DWORD exStyle, LPCTSTR className,
|
||||
LPCTSTR windowName, DWORD style,
|
||||
@@ -24,6 +23,14 @@ public:
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance);
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CreateEx(DWORD exStyle, LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance);
|
||||
#endif
|
||||
|
||||
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
|
||||
virtual bool OnCreate(CREATESTRUCT *createStruct) { return true; }
|
||||
// virtual LRESULT OnCommand(WPARAM wParam, LPARAM lParam);
|
||||
|
||||
@@ -8,6 +8,10 @@
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NDLL {
|
||||
|
||||
@@ -54,25 +58,21 @@ bool CLibrary::Load(LPCTSTR fileName)
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
static inline UINT GetCurrentCodePage()
|
||||
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
CSysString GetSysPath(LPCWSTR sysPath)
|
||||
{ return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }
|
||||
|
||||
bool CLibrary::LoadEx(LPCWSTR fileName, DWORD flags)
|
||||
{
|
||||
HMODULE module = ::LoadLibraryExW(fileName, NULL, flags);
|
||||
if (module != 0)
|
||||
return LoadOperations(module);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return LoadEx(UnicodeStringToMultiByte(fileName, GetCurrentCodePage()), flags);
|
||||
if (g_IsNT)
|
||||
return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));
|
||||
return LoadEx(GetSysPath(fileName), flags);
|
||||
}
|
||||
bool CLibrary::Load(LPCWSTR fileName)
|
||||
{
|
||||
HMODULE module = ::LoadLibraryW(fileName);
|
||||
if (module != 0)
|
||||
return LoadOperations(module);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return Load(UnicodeStringToMultiByte(fileName, GetCurrentCodePage()));
|
||||
if (g_IsNT)
|
||||
return LoadOperations(::LoadLibraryW(fileName));
|
||||
return Load(GetSysPath(fileName));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -93,15 +93,17 @@ bool MyGetModuleFileName(HMODULE hModule, CSysString &result)
|
||||
bool MyGetModuleFileName(HMODULE hModule, UString &result)
|
||||
{
|
||||
result.Empty();
|
||||
wchar_t fullPath[MAX_PATH + 2];
|
||||
DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);
|
||||
if (size <= MAX_PATH && size != 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
result = fullPath;
|
||||
return true;
|
||||
}
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
wchar_t fullPath[MAX_PATH + 2];
|
||||
DWORD size = ::GetModuleFileNameW(hModule, fullPath, MAX_PATH + 1);
|
||||
if (size <= MAX_PATH && size != 0)
|
||||
{
|
||||
result = fullPath;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
CSysString resultSys;
|
||||
if (!MyGetModuleFileName(hModule, resultSys))
|
||||
return false;
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NError {
|
||||
|
||||
@@ -14,16 +18,9 @@ bool MyFormatMessage(DWORD messageID, CSysString &message)
|
||||
{
|
||||
LPVOID msgBuf;
|
||||
if(::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
messageID,
|
||||
0, // Default language
|
||||
(LPTSTR) &msgBuf,
|
||||
0,
|
||||
NULL) == 0)
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)
|
||||
return false;
|
||||
|
||||
message = (LPCTSTR)msgBuf;
|
||||
::LocalFree(msgBuf);
|
||||
return true;
|
||||
@@ -32,27 +29,21 @@ bool MyFormatMessage(DWORD messageID, CSysString &message)
|
||||
#ifndef _UNICODE
|
||||
bool MyFormatMessage(DWORD messageID, UString &message)
|
||||
{
|
||||
LPVOID msgBuf;
|
||||
if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM |
|
||||
FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL,
|
||||
messageID,
|
||||
0, // Default language
|
||||
(LPWSTR) &msgBuf,
|
||||
0,
|
||||
NULL) == 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
LPVOID msgBuf;
|
||||
if(::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
|
||||
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
|
||||
NULL, messageID, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)
|
||||
return false;
|
||||
CSysString messageSys;
|
||||
bool result = MyFormatMessage(messageID, messageSys);
|
||||
message = GetUnicodeString(messageSys);
|
||||
return result;
|
||||
message = (LPCWSTR)msgBuf;
|
||||
::LocalFree(msgBuf);
|
||||
return true;
|
||||
}
|
||||
message = (LPCWSTR)msgBuf;
|
||||
::LocalFree(msgBuf);
|
||||
return true;
|
||||
CSysString messageSys;
|
||||
bool result = MyFormatMessage(messageID, messageSys);
|
||||
message = GetUnicodeString(messageSys);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
49
Windows/FileDevice.cpp
Executable file
49
Windows/FileDevice.cpp
Executable file
@@ -0,0 +1,49 @@
|
||||
// Windows/FileDevice.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FileDevice.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NDevice {
|
||||
|
||||
bool CFileBase::GetLengthSmart(UInt64 &length)
|
||||
{
|
||||
PARTITION_INFORMATION partInfo;
|
||||
if (GetPartitionInfo(&partInfo))
|
||||
{
|
||||
length = partInfo.PartitionLength.QuadPart;
|
||||
return true;
|
||||
}
|
||||
DISK_GEOMETRY geom;
|
||||
if (!GetGeometry(&geom))
|
||||
if (!GetCdRomGeometry(&geom))
|
||||
return false;
|
||||
length = geom.Cylinders.QuadPart * geom.TracksPerCylinder * geom.SectorsPerTrack * geom.BytesPerSector;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
bool CInFile::Open(LPCTSTR fileName)
|
||||
{ return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
bool CInFile::Open(LPCWSTR fileName)
|
||||
{ return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
|
||||
#endif
|
||||
|
||||
bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
DWORD processedLoc = 0;
|
||||
bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));
|
||||
processedSize = (UInt32)processedLoc;
|
||||
return res;
|
||||
}
|
||||
|
||||
}}}
|
||||
119
Windows/FileDevice.h
Executable file
119
Windows/FileDevice.h
Executable file
@@ -0,0 +1,119 @@
|
||||
// Windows/FileDevice.h
|
||||
|
||||
#ifndef __WINDOWS_FILEDEVICE_H
|
||||
#define __WINDOWS_FILEDEVICE_H
|
||||
|
||||
#include "FileIO.h"
|
||||
#include "Defs.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NDevice {
|
||||
|
||||
typedef struct _GET_LENGTH_INFORMATION
|
||||
{
|
||||
LARGE_INTEGER Length;
|
||||
} GET_LENGTH_INFORMATION, *PGET_LENGTH_INFORMATION;
|
||||
|
||||
#define IOCTL_DISK_GET_LENGTH_INFO CTL_CODE(IOCTL_DISK_BASE, 0x0017, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
|
||||
/*
|
||||
typedef struct _DISK_GEOMETRY_EX {
|
||||
DISK_GEOMETRY Geometry; // Standard disk geometry: may be faked by driver.
|
||||
LARGE_INTEGER DiskSize; // Must always be correct
|
||||
BYTE Data[1]; // Partition, Detect info
|
||||
} DISK_GEOMETRY_EX, *PDISK_GEOMETRY_EX;
|
||||
*/
|
||||
|
||||
#define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
|
||||
#define IOCTL_CDROM_GET_DRIVE_GEOMETRY CTL_CODE(IOCTL_CDROM_BASE, 0x0013, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
#define IOCTL_CDROM_MEDIA_REMOVAL CTL_CODE(IOCTL_CDROM_BASE, 0x0201, METHOD_BUFFERED, FILE_READ_ACCESS)
|
||||
|
||||
class CFileBase: public NIO::CFileBase
|
||||
{
|
||||
public:
|
||||
bool DeviceIoControl(DWORD controlCode, LPVOID inBuffer, DWORD inSize,
|
||||
LPVOID outBuffer, DWORD outSize, LPDWORD bytesReturned, LPOVERLAPPED overlapped) const
|
||||
{
|
||||
return BOOLToBool(::DeviceIoControl(_handle, controlCode, inBuffer, inSize,
|
||||
outBuffer, outSize, bytesReturned, overlapped));
|
||||
}
|
||||
|
||||
bool DeviceIoControl(DWORD controlCode, LPVOID inBuffer,
|
||||
DWORD inSize, LPVOID outBuffer, DWORD outSize) const
|
||||
{
|
||||
DWORD ret;
|
||||
return DeviceIoControl(controlCode, inBuffer, inSize, outBuffer, outSize, &ret, 0);
|
||||
}
|
||||
|
||||
bool DeviceIoControlIn(DWORD controlCode, LPVOID inBuffer, DWORD inSize) const
|
||||
{ return DeviceIoControl(controlCode, inBuffer, inSize, NULL, 0); }
|
||||
|
||||
bool DeviceIoControlOut(DWORD controlCode, LPVOID outBuffer, DWORD outSize) const
|
||||
{ return DeviceIoControl(controlCode, NULL, 0, outBuffer, outSize); }
|
||||
|
||||
bool GetGeometry(DISK_GEOMETRY *res) const
|
||||
{ return DeviceIoControlOut(IOCTL_DISK_GET_DRIVE_GEOMETRY, res, sizeof(*res)); }
|
||||
|
||||
bool GetCdRomGeometry(DISK_GEOMETRY *res) const
|
||||
{ return DeviceIoControlOut(IOCTL_CDROM_GET_DRIVE_GEOMETRY, res, sizeof(*res)); }
|
||||
|
||||
/*
|
||||
bool GetCdRomGeometryEx(DISK_GEOMETRY_EX *res) const
|
||||
{ return DeviceIoControlOut(IOCTL_CDROM_GET_DRIVE_GEOMETRY, res, sizeof(*res)); }
|
||||
*/
|
||||
|
||||
bool CdRomLock(bool lock) const
|
||||
{
|
||||
PREVENT_MEDIA_REMOVAL rem;
|
||||
rem.PreventMediaRemoval = BoolToBOOL(lock);
|
||||
return DeviceIoControlIn(IOCTL_CDROM_MEDIA_REMOVAL, &rem, sizeof(rem));
|
||||
}
|
||||
|
||||
bool GetLengthInfo(UInt64 &length) const
|
||||
{
|
||||
GET_LENGTH_INFORMATION lengthInfo;
|
||||
bool res = DeviceIoControlOut(IOCTL_DISK_GET_LENGTH_INFO, &lengthInfo, sizeof(lengthInfo));
|
||||
length = lengthInfo.Length.QuadPart;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool GetLengthSmart(UInt64 &length);
|
||||
|
||||
|
||||
bool FormatTracks(const FORMAT_PARAMETERS *formatParams,
|
||||
BAD_TRACK_NUMBER *badTrackNumbers, DWORD numBadTrackNumbers,
|
||||
DWORD &numBadTrackNumbersReturned)
|
||||
{
|
||||
DWORD ret;
|
||||
bool res = DeviceIoControl(IOCTL_DISK_FORMAT_TRACKS, badTrackNumbers, sizeof(*formatParams),
|
||||
badTrackNumbers, numBadTrackNumbers * sizeof(*badTrackNumbers), &ret, NULL);
|
||||
numBadTrackNumbersReturned = ret / sizeof(*badTrackNumbers);
|
||||
return res;
|
||||
}
|
||||
|
||||
bool Performance(DISK_PERFORMANCE *res)
|
||||
{ return DeviceIoControlOut(IOCTL_DISK_PERFORMANCE, LPVOID(res), sizeof(*res)); }
|
||||
|
||||
bool GetPartitionInfo(PARTITION_INFORMATION *res)
|
||||
{ return DeviceIoControlOut(IOCTL_DISK_GET_PARTITION_INFO, LPVOID(res), sizeof(*res)); }
|
||||
|
||||
bool Verify(const VERIFY_INFORMATION *verifyInformation)
|
||||
{ return DeviceIoControlIn(IOCTL_DISK_VERIFY, LPVOID(verifyInformation), sizeof(*verifyInformation)); }
|
||||
};
|
||||
|
||||
class CInFile: public CFileBase
|
||||
{
|
||||
public:
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName);
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
bool Read(void *data, UInt32 size, UInt32 &processedSize);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
#endif
|
||||
@@ -10,25 +10,32 @@
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NDirectory {
|
||||
|
||||
#ifndef _UNICODE
|
||||
static inline UINT GetCurrentCodePage()
|
||||
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
static UString GetUnicodePath(const CSysString &sysPath)
|
||||
{ return MultiByteToUnicodeString(sysPath, GetCurrentCodePage()); }
|
||||
static CSysString GetSysPath(LPCWSTR sysPath)
|
||||
{ return UnicodeStringToMultiByte(sysPath, GetCurrentCodePage()); }
|
||||
#endif
|
||||
|
||||
bool MyGetWindowsDirectory(CSysString &path)
|
||||
{
|
||||
DWORD needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
UINT needLength = ::GetWindowsDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
|
||||
bool MyGetSystemDirectory(CSysString &path)
|
||||
{
|
||||
DWORD needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
UINT needLength = ::GetSystemDirectory(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
@@ -36,31 +43,31 @@ bool MyGetSystemDirectory(CSysString &path)
|
||||
#ifndef _UNICODE
|
||||
bool MyGetWindowsDirectory(UString &path)
|
||||
{
|
||||
DWORD needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
if (needLength != 0)
|
||||
return (needLength <= MAX_PATH);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
if (g_IsNT)
|
||||
{
|
||||
UINT needLength = ::GetWindowsDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
CSysString sysPath;
|
||||
if (!MyGetWindowsDirectory(sysPath))
|
||||
return false;
|
||||
path = MultiByteToUnicodeString(sysPath, GetCurrentCodePage());
|
||||
path = GetUnicodePath(sysPath);
|
||||
return true;
|
||||
}
|
||||
|
||||
bool MyGetSystemDirectory(UString &path)
|
||||
{
|
||||
DWORD needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
if (needLength != 0)
|
||||
return (needLength <= MAX_PATH);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
if (g_IsNT)
|
||||
{
|
||||
UINT needLength = ::GetSystemDirectoryW(path.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
CSysString sysPath;
|
||||
if (!MyGetSystemDirectory(sysPath))
|
||||
return false;
|
||||
path = MultiByteToUnicodeString(sysPath, GetCurrentCodePage());
|
||||
path = GetUnicodePath(sysPath);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -68,50 +75,34 @@ bool MyGetSystemDirectory(UString &path)
|
||||
#ifndef _UNICODE
|
||||
bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes)
|
||||
{
|
||||
if (::SetFileAttributesW(fileName, fileAttributes))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return MySetFileAttributes(UnicodeStringToMultiByte(fileName,
|
||||
GetCurrentCodePage()), fileAttributes);
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::SetFileAttributesW(fileName, fileAttributes));
|
||||
return MySetFileAttributes(GetSysPath(fileName), fileAttributes);
|
||||
}
|
||||
|
||||
bool MyRemoveDirectory(LPCWSTR pathName)
|
||||
{
|
||||
if (::RemoveDirectoryW(pathName))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return MyRemoveDirectory(UnicodeStringToMultiByte(pathName,
|
||||
GetCurrentCodePage()));
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::RemoveDirectoryW(pathName));
|
||||
return MyRemoveDirectory(GetSysPath(pathName));
|
||||
}
|
||||
|
||||
bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName)
|
||||
{
|
||||
if (::MoveFileW(existFileName, newFileName))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
UINT codePage = GetCurrentCodePage();
|
||||
return MyMoveFile(UnicodeStringToMultiByte(existFileName, codePage),
|
||||
UnicodeStringToMultiByte(newFileName, codePage));
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::MoveFileW(existFileName, newFileName));
|
||||
return MyMoveFile(GetSysPath(existFileName), GetSysPath(newFileName));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool MyCreateDirectory(LPCTSTR pathName)
|
||||
{
|
||||
return BOOLToBool(::CreateDirectory(pathName, NULL));
|
||||
}
|
||||
bool MyCreateDirectory(LPCTSTR pathName) { return BOOLToBool(::CreateDirectory(pathName, NULL)); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyCreateDirectory(LPCWSTR pathName)
|
||||
{
|
||||
if (::CreateDirectoryW(pathName, NULL))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return MyCreateDirectory(UnicodeStringToMultiByte(pathName,
|
||||
GetCurrentCodePage()));
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::CreateDirectoryW(pathName, NULL));
|
||||
return MyCreateDirectory(GetSysPath(pathName));
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -246,19 +237,17 @@ bool DeleteFileAlways(LPCTSTR name)
|
||||
#ifndef _UNICODE
|
||||
bool DeleteFileAlways(LPCWSTR name)
|
||||
{
|
||||
if(!MySetFileAttributes(name, 0))
|
||||
return false;
|
||||
if (::DeleteFileW(name))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return DeleteFileAlways(UnicodeStringToMultiByte(name,
|
||||
GetCurrentCodePage()));
|
||||
if (g_IsNT)
|
||||
{
|
||||
if(!MySetFileAttributes(name, 0))
|
||||
return false;
|
||||
return BOOLToBool(::DeleteFileW(name));
|
||||
}
|
||||
return DeleteFileAlways(GetSysPath(name));
|
||||
}
|
||||
#endif
|
||||
|
||||
static bool RemoveDirectorySubItems2(const CSysString pathPrefix,
|
||||
const NFind::CFileInfo &fileInfo)
|
||||
static bool RemoveDirectorySubItems2(const CSysString pathPrefix, const NFind::CFileInfo &fileInfo)
|
||||
{
|
||||
if(fileInfo.IsDirectory())
|
||||
return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);
|
||||
@@ -282,8 +271,7 @@ bool RemoveDirectoryWithSubItems(const CSysString &path)
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
static bool RemoveDirectorySubItems2(const UString pathPrefix,
|
||||
const NFind::CFileInfoW &fileInfo)
|
||||
static bool RemoveDirectorySubItems2(const UString pathPrefix, const NFind::CFileInfoW &fileInfo)
|
||||
{
|
||||
if(fileInfo.IsDirectory())
|
||||
return RemoveDirectoryWithSubItems(pathPrefix + fileInfo.Name);
|
||||
@@ -310,21 +298,17 @@ bool RemoveDirectoryWithSubItems(const UString &path)
|
||||
|
||||
bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath)
|
||||
{
|
||||
DWORD needLength = ::GetShortPathName(longPath,
|
||||
shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
DWORD needLength = ::GetShortPathName(longPath, shortPath.GetBuffer(MAX_PATH + 1), MAX_PATH + 1);
|
||||
shortPath.ReleaseBuffer();
|
||||
if (needLength == 0 || needLength >= MAX_PATH)
|
||||
return false;
|
||||
return true;
|
||||
return (needLength > 0 && needLength < MAX_PATH);
|
||||
}
|
||||
|
||||
bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,
|
||||
int &fileNamePartStartIndex)
|
||||
bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex)
|
||||
{
|
||||
resultPath.Empty();
|
||||
LPTSTR fileNamePointer = 0;
|
||||
LPTSTR buffer = resultPath.GetBuffer(MAX_PATH);
|
||||
DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1,
|
||||
buffer, &fileNamePointer);
|
||||
DWORD needLength = ::GetFullPathName(fileName, MAX_PATH + 1, buffer, &fileNamePointer);
|
||||
resultPath.ReleaseBuffer();
|
||||
if (needLength == 0 || needLength >= MAX_PATH)
|
||||
return false;
|
||||
@@ -336,39 +320,32 @@ bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath,
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,
|
||||
int &fileNamePartStartIndex)
|
||||
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex)
|
||||
{
|
||||
resultPath.Empty();
|
||||
LPWSTR fileNamePointer = 0;
|
||||
LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);
|
||||
DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1,
|
||||
buffer, &fileNamePointer);
|
||||
resultPath.ReleaseBuffer();
|
||||
if (needLength == 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
LPWSTR fileNamePointer = 0;
|
||||
LPWSTR buffer = resultPath.GetBuffer(MAX_PATH);
|
||||
DWORD needLength = ::GetFullPathNameW(fileName, MAX_PATH + 1, buffer, &fileNamePointer);
|
||||
resultPath.ReleaseBuffer();
|
||||
if (needLength == 0 || needLength >= MAX_PATH)
|
||||
return false;
|
||||
|
||||
const UINT currentPage = GetCurrentCodePage();
|
||||
if (fileNamePointer == 0)
|
||||
fileNamePartStartIndex = MyStringLen(fileName);
|
||||
else
|
||||
fileNamePartStartIndex = (int)(fileNamePointer - buffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
CSysString sysPath;
|
||||
if (!MyGetFullPathName(UnicodeStringToMultiByte(fileName,
|
||||
currentPage), sysPath, fileNamePartStartIndex))
|
||||
if (!MyGetFullPathName(GetSysPath(fileName), sysPath, fileNamePartStartIndex))
|
||||
return false;
|
||||
UString resultPath1 = MultiByteToUnicodeString(
|
||||
sysPath.Left(fileNamePartStartIndex), currentPage);
|
||||
UString resultPath2 = MultiByteToUnicodeString(
|
||||
sysPath.Mid(fileNamePartStartIndex), currentPage);
|
||||
UString resultPath1 = GetUnicodePath(sysPath.Left(fileNamePartStartIndex));
|
||||
UString resultPath2 = GetUnicodePath(sysPath.Mid(fileNamePartStartIndex));
|
||||
fileNamePartStartIndex = resultPath1.Length();
|
||||
resultPath = resultPath1 + resultPath2;
|
||||
return true;
|
||||
}
|
||||
else if (needLength >= MAX_PATH)
|
||||
return false;
|
||||
if (fileNamePointer == 0)
|
||||
fileNamePartStartIndex = MyStringLen(fileName);
|
||||
else
|
||||
fileNamePartStartIndex = fileNamePointer - buffer;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -430,8 +407,7 @@ bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName)
|
||||
|
||||
bool MyGetCurrentDirectory(CSysString &path)
|
||||
{
|
||||
DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1,
|
||||
path.GetBuffer(MAX_PATH + 1));
|
||||
DWORD needLength = ::GetCurrentDirectory(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
@@ -439,26 +415,22 @@ bool MyGetCurrentDirectory(CSysString &path)
|
||||
#ifndef _UNICODE
|
||||
bool MySetCurrentDirectory(LPCWSTR path)
|
||||
{
|
||||
if (::SetCurrentDirectoryW(path))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return MySetCurrentDirectory(UnicodeStringToMultiByte(path,
|
||||
GetCurrentCodePage()));
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::SetCurrentDirectoryW(path));
|
||||
return MySetCurrentDirectory(GetSysPath(path));
|
||||
}
|
||||
bool MyGetCurrentDirectory(UString &path)
|
||||
{
|
||||
DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1,
|
||||
path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
if (needLength != 0)
|
||||
return (needLength <= MAX_PATH);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
if (g_IsNT)
|
||||
{
|
||||
DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
CSysString sysPath;
|
||||
if (!MyGetCurrentDirectory(sysPath))
|
||||
return false;
|
||||
path = MultiByteToUnicodeString(sysPath, GetCurrentCodePage());
|
||||
path = GetUnicodePath(sysPath);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -469,39 +441,35 @@ bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension,
|
||||
{
|
||||
LPTSTR filePartPointer;
|
||||
DWORD value = ::SearchPath(path, fileName, extension,
|
||||
MAX_PATH, resultPath.GetBuffer(MAX_PATH), &filePartPointer);
|
||||
MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);
|
||||
filePart = (UINT32)(filePartPointer - (LPCTSTR)resultPath);
|
||||
resultPath.ReleaseBuffer();
|
||||
if (value == 0 || value > MAX_PATH)
|
||||
return false;
|
||||
return true;
|
||||
return (value > 0 && value <= MAX_PATH);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,
|
||||
UString &resultPath, UINT32 &filePart)
|
||||
{
|
||||
LPWSTR filePartPointer = 0;
|
||||
DWORD value = ::SearchPathW(path, fileName, extension,
|
||||
MAX_PATH, resultPath.GetBuffer(MAX_PATH), &filePartPointer);
|
||||
resultPath.ReleaseBuffer();
|
||||
if (value != 0)
|
||||
return (value <= MAX_PATH);
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
if (g_IsNT)
|
||||
{
|
||||
LPWSTR filePartPointer = 0;
|
||||
DWORD value = ::SearchPathW(path, fileName, extension,
|
||||
MAX_PATH, resultPath.GetBuffer(MAX_PATH + 1), &filePartPointer);
|
||||
filePart = (UINT32)(filePartPointer - (LPCWSTR)resultPath);
|
||||
resultPath.ReleaseBuffer();
|
||||
return (value > 0 && value <= MAX_PATH);
|
||||
}
|
||||
|
||||
const UINT currentPage = GetCurrentCodePage();
|
||||
CSysString sysPath;
|
||||
if (!MySearchPath(
|
||||
path != 0 ? (LPCTSTR)UnicodeStringToMultiByte(path, currentPage): 0,
|
||||
fileName != 0 ? (LPCTSTR)UnicodeStringToMultiByte(fileName, currentPage): 0,
|
||||
extension != 0 ? (LPCTSTR)UnicodeStringToMultiByte(extension, currentPage): 0,
|
||||
path != 0 ? (LPCTSTR)GetSysPath(path): 0,
|
||||
fileName != 0 ? (LPCTSTR)GetSysPath(fileName): 0,
|
||||
extension != 0 ? (LPCTSTR)GetSysPath(extension): 0,
|
||||
sysPath, filePart))
|
||||
return false;
|
||||
UString resultPath1 = MultiByteToUnicodeString(
|
||||
sysPath.Left(filePart), currentPage);
|
||||
UString resultPath2 = MultiByteToUnicodeString(
|
||||
sysPath.Mid(filePart), currentPage);
|
||||
UString resultPath1 = GetUnicodePath(sysPath.Left(filePart));
|
||||
UString resultPath2 = GetUnicodePath(sysPath.Mid(filePart));
|
||||
filePart = resultPath1.Length();
|
||||
resultPath = resultPath1 + resultPath2;
|
||||
return true;
|
||||
@@ -510,8 +478,7 @@ bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension,
|
||||
|
||||
bool MyGetTempPath(CSysString &path)
|
||||
{
|
||||
DWORD needLength = ::GetTempPath(MAX_PATH + 1,
|
||||
path.GetBuffer(MAX_PATH));
|
||||
DWORD needLength = ::GetTempPath(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
@@ -520,27 +487,23 @@ bool MyGetTempPath(CSysString &path)
|
||||
bool MyGetTempPath(UString &path)
|
||||
{
|
||||
path.Empty();
|
||||
DWORD needLength = ::GetTempPathW(MAX_PATH + 1,
|
||||
path.GetBuffer(MAX_PATH));
|
||||
path.ReleaseBuffer();
|
||||
if (needLength == 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
CSysString sysPath;
|
||||
if (!MyGetTempPath(sysPath))
|
||||
return false;
|
||||
path = MultiByteToUnicodeString(sysPath, GetCurrentCodePage());
|
||||
return true;
|
||||
DWORD needLength = ::GetTempPathW(MAX_PATH + 1, path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
}
|
||||
return (needLength > 0 && needLength <= MAX_PATH);
|
||||
CSysString sysPath;
|
||||
if (!MyGetTempPath(sysPath))
|
||||
return false;
|
||||
path = GetUnicodePath(sysPath);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)
|
||||
{
|
||||
UINT number = ::GetTempFileName(dirPath, prefix, 0,
|
||||
path.GetBuffer(MAX_PATH));
|
||||
UINT number = ::GetTempFileName(dirPath, prefix, 0, path.GetBuffer(MAX_PATH + 1));
|
||||
path.ReleaseBuffer();
|
||||
return number;
|
||||
}
|
||||
@@ -548,22 +511,18 @@ UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &path)
|
||||
#ifndef _UNICODE
|
||||
UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &path)
|
||||
{
|
||||
UINT number = ::GetTempFileNameW(dirPath, prefix, 0,
|
||||
path.GetBuffer(MAX_PATH));
|
||||
path.ReleaseBuffer();
|
||||
if (number == 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
if (::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
{
|
||||
const UINT currentPage = GetCurrentCodePage();
|
||||
CSysString sysPath;
|
||||
number = MyGetTempFileName(
|
||||
dirPath ? (LPCTSTR)UnicodeStringToMultiByte(dirPath, currentPage): 0,
|
||||
prefix ? (LPCTSTR)UnicodeStringToMultiByte(prefix, currentPage): 0,
|
||||
sysPath);
|
||||
path = MultiByteToUnicodeString(sysPath, currentPage);
|
||||
}
|
||||
UINT number = ::GetTempFileNameW(dirPath, prefix, 0, path.GetBuffer(MAX_PATH));
|
||||
path.ReleaseBuffer();
|
||||
return number;
|
||||
}
|
||||
CSysString sysPath;
|
||||
UINT number = MyGetTempFileName(
|
||||
dirPath ? (LPCTSTR)GetSysPath(dirPath): 0,
|
||||
prefix ? (LPCTSTR)GetSysPath(prefix): 0,
|
||||
sysPath);
|
||||
path = GetUnicodePath(sysPath);
|
||||
return number;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NFind {
|
||||
@@ -41,8 +45,7 @@ static void ConvertWIN32_FIND_DATA_To_FileInfo(
|
||||
fileInfo.CreationTime = findData.ftCreationTime;
|
||||
fileInfo.LastAccessTime = findData.ftLastAccessTime;
|
||||
fileInfo.LastWriteTime = findData.ftLastWriteTime;
|
||||
fileInfo.Size = (((UINT64)findData.nFileSizeHigh) << 32) +
|
||||
findData.nFileSizeLow;
|
||||
fileInfo.Size = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
|
||||
fileInfo.Name = findData.cFileName;
|
||||
#ifndef _WIN32_WCE
|
||||
fileInfo.ReparseTag = findData.dwReserved0;
|
||||
@@ -53,8 +56,7 @@ static void ConvertWIN32_FIND_DATA_To_FileInfo(
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
static inline UINT GetCurrentCodePage()
|
||||
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
|
||||
static void ConvertWIN32_FIND_DATA_To_FileInfo(
|
||||
const WIN32_FIND_DATAW &findData,
|
||||
@@ -64,8 +66,7 @@ static void ConvertWIN32_FIND_DATA_To_FileInfo(
|
||||
fileInfo.CreationTime = findData.ftCreationTime;
|
||||
fileInfo.LastAccessTime = findData.ftLastAccessTime;
|
||||
fileInfo.LastWriteTime = findData.ftLastWriteTime;
|
||||
fileInfo.Size = (((UINT64)findData.nFileSizeHigh) << 32) +
|
||||
findData.nFileSizeLow;
|
||||
fileInfo.Size = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
|
||||
fileInfo.Name = findData.cFileName;
|
||||
#ifndef _WIN32_WCE
|
||||
fileInfo.ReparseTag = findData.dwReserved0;
|
||||
@@ -82,8 +83,7 @@ static void ConvertWIN32_FIND_DATA_To_FileInfo(
|
||||
fileInfo.CreationTime = findData.ftCreationTime;
|
||||
fileInfo.LastAccessTime = findData.ftLastAccessTime;
|
||||
fileInfo.LastWriteTime = findData.ftLastWriteTime;
|
||||
fileInfo.Size = (((UINT64)findData.nFileSizeHigh) << 32) +
|
||||
findData.nFileSizeLow;
|
||||
fileInfo.Size = (((UInt64)findData.nFileSizeHigh) << 32) + findData.nFileSizeLow;
|
||||
fileInfo.Name = GetUnicodeString(findData.cFileName, GetCurrentCodePage());
|
||||
#ifndef _WIN32_WCE
|
||||
fileInfo.ReparseTag = findData.dwReserved0;
|
||||
@@ -110,8 +110,7 @@ bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
|
||||
Close();
|
||||
WIN32_FIND_DATA findData;
|
||||
_handle = ::FindFirstFile(wildcard, &findData);
|
||||
_handleAllocated = (_handle != INVALID_HANDLE_VALUE);
|
||||
if (_handleAllocated)
|
||||
if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE))
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
return _handleAllocated;
|
||||
}
|
||||
@@ -120,24 +119,20 @@ bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
|
||||
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
|
||||
{
|
||||
Close();
|
||||
WIN32_FIND_DATAW findDataW;
|
||||
::SetLastError(0);
|
||||
_handle = ::FindFirstFileW(wildcard, &findDataW);
|
||||
if ((_handle == INVALID_HANDLE_VALUE || _handle == 0) &&
|
||||
::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
if (g_IsNT)
|
||||
{
|
||||
WIN32_FIND_DATA findData;
|
||||
_handle = ::FindFirstFile(UnicodeStringToMultiByte(wildcard,
|
||||
GetCurrentCodePage()), &findData);
|
||||
_handleAllocated = (_handle != INVALID_HANDLE_VALUE);
|
||||
if (_handleAllocated)
|
||||
WIN32_FIND_DATAW findData;
|
||||
_handle = ::FindFirstFileW(wildcard, &findData);
|
||||
if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE))
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
_handleAllocated = (_handle != INVALID_HANDLE_VALUE);
|
||||
if (_handleAllocated)
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findDataW, fileInfo);
|
||||
WIN32_FIND_DATAA findData;
|
||||
_handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,
|
||||
GetCurrentCodePage()), &findData);
|
||||
if (_handleAllocated = (_handle != INVALID_HANDLE_VALUE))
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
}
|
||||
return _handleAllocated;
|
||||
}
|
||||
@@ -155,18 +150,20 @@ bool CFindFile::FindNext(CFileInfo &fileInfo)
|
||||
#ifndef _UNICODE
|
||||
bool CFindFile::FindNext(CFileInfoW &fileInfo)
|
||||
{
|
||||
WIN32_FIND_DATAW findDataW;
|
||||
if (::FindNextFileW(_handle, &findDataW))
|
||||
if (g_IsNT)
|
||||
{
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findDataW, fileInfo);
|
||||
return true;
|
||||
WIN32_FIND_DATAW findData;
|
||||
if (!::FindNextFileW(_handle, &findData))
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIN32_FIND_DATAA findData;
|
||||
if (!::FindNextFileA(_handle, &findData))
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
}
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
WIN32_FIND_DATA findData;
|
||||
if (!::FindNextFile(_handle, &findData))
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(findData, fileInfo);
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
@@ -290,14 +287,9 @@ HANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree,
|
||||
HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree,
|
||||
DWORD notifyFilter)
|
||||
{
|
||||
::SetLastError(0);
|
||||
_handle = ::FindFirstChangeNotificationW(pathName,
|
||||
BoolToBOOL(watchSubtree), notifyFilter);
|
||||
if ((_handle == 0 || _handle == INVALID_HANDLE_VALUE) &&
|
||||
::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return FindFirst(UnicodeStringToMultiByte(pathName,
|
||||
GetCurrentCodePage()), watchSubtree, notifyFilter);
|
||||
return _handle;
|
||||
if (g_IsNT)
|
||||
return (_handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter));
|
||||
return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -330,6 +322,44 @@ bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetLogicalDriveStrings(UStringVector &driveStrings)
|
||||
{
|
||||
driveStrings.Clear();
|
||||
if (g_IsNT)
|
||||
{
|
||||
UINT32 size = GetLogicalDriveStringsW(0, NULL);
|
||||
if (size == 0)
|
||||
return false;
|
||||
UString buffer;
|
||||
UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));
|
||||
if(newSize == 0)
|
||||
return false;
|
||||
if(newSize > size)
|
||||
return false;
|
||||
UString string;
|
||||
for(UINT32 i = 0; i < newSize; i++)
|
||||
{
|
||||
WCHAR c = buffer[i];
|
||||
if(c == L'\0')
|
||||
{
|
||||
driveStrings.Add(string);
|
||||
string.Empty();
|
||||
}
|
||||
else
|
||||
string += c;
|
||||
}
|
||||
return string.IsEmpty();
|
||||
}
|
||||
CSysStringVector driveStringsA;
|
||||
bool res = MyGetLogicalDriveStrings(driveStringsA);
|
||||
for (int i = 0; i < driveStringsA.Size(); i++)
|
||||
driveStrings.Add(GetUnicodeString(driveStringsA[i]));
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
}}}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#define __WINDOWS_FILEFIND_H
|
||||
|
||||
#include "../Common/String.h"
|
||||
#include "../Common/Types.h"
|
||||
#include "FileName.h"
|
||||
#include "Defs.h"
|
||||
|
||||
@@ -30,7 +31,7 @@ public:
|
||||
FILETIME CreationTime;
|
||||
FILETIME LastAccessTime;
|
||||
FILETIME LastWriteTime;
|
||||
UINT64 Size;
|
||||
UInt64 Size;
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
UINT32 ReparseTag;
|
||||
@@ -38,7 +39,6 @@ public:
|
||||
DWORD ObjectID;
|
||||
#endif
|
||||
|
||||
|
||||
bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
|
||||
bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
|
||||
bool IsDirectory() const { return MatchesMask(FILE_ATTRIBUTE_DIRECTORY); }
|
||||
@@ -51,7 +51,6 @@ public:
|
||||
bool IsSparse() const { return MatchesMask(FILE_ATTRIBUTE_SPARSE_FILE); }
|
||||
bool IsSystem() const { return MatchesMask(FILE_ATTRIBUTE_SYSTEM); }
|
||||
bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
|
||||
|
||||
};
|
||||
|
||||
class CFileInfo: public CFileInfoBase
|
||||
@@ -144,27 +143,30 @@ public:
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
|
||||
#ifndef _UNICODE
|
||||
bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
inline bool MyGetCompressedFileSize(LPCTSTR fileName, UINT64 &size)
|
||||
inline bool MyGetCompressedFileSize(LPCTSTR fileName, UInt64 &size)
|
||||
{
|
||||
DWORD highPart;
|
||||
DWORD lowPart = ::GetCompressedFileSize(fileName, &highPart);
|
||||
if (lowPart == INVALID_FILE_SIZE)
|
||||
if (::GetLastError() != NO_ERROR)
|
||||
return false;
|
||||
size = (UINT64(highPart) << 32) | lowPart;
|
||||
size = (UInt64(highPart) << 32) | lowPart;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool MyGetCompressedFileSizeW(LPCWSTR fileName, UINT64 &size)
|
||||
inline bool MyGetCompressedFileSizeW(LPCWSTR fileName, UInt64 &size)
|
||||
{
|
||||
DWORD highPart;
|
||||
DWORD lowPart = ::GetCompressedFileSizeW(fileName, &highPart);
|
||||
if (lowPart == INVALID_FILE_SIZE)
|
||||
if (::GetLastError() != NO_ERROR)
|
||||
return false;
|
||||
size = (UINT64(highPart) << 32) | lowPart;
|
||||
size = (UInt64(highPart) << 32) | lowPart;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,14 +8,15 @@
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NIO {
|
||||
|
||||
CFileBase::~CFileBase()
|
||||
{
|
||||
Close();
|
||||
}
|
||||
CFileBase::~CFileBase() { Close(); }
|
||||
|
||||
bool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,
|
||||
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
@@ -24,25 +25,23 @@ bool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,
|
||||
_handle = ::CreateFile(fileName, desiredAccess, shareMode,
|
||||
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
|
||||
flagsAndAttributes, (HANDLE) NULL);
|
||||
_fileIsOpen = _handle != INVALID_HANDLE_VALUE;
|
||||
return _fileIsOpen;
|
||||
return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,
|
||||
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{
|
||||
Close();
|
||||
// MessageBoxW(0, fileName, 0, 0);
|
||||
// ::SetLastError(ERROR_CALL_NOT_IMPLEMENTED);
|
||||
_handle = ::CreateFileW(fileName, desiredAccess, shareMode,
|
||||
if (g_IsNT)
|
||||
{
|
||||
Close();
|
||||
_handle = ::CreateFileW(fileName, desiredAccess, shareMode,
|
||||
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
|
||||
flagsAndAttributes, (HANDLE) NULL);
|
||||
if ((_handle == INVALID_HANDLE_VALUE || _handle == 0) &&
|
||||
::GetLastError() == ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),
|
||||
desiredAccess, shareMode, creationDisposition, flagsAndAttributes);
|
||||
return (_fileIsOpen = _handle != INVALID_HANDLE_VALUE);
|
||||
return (_fileIsOpen = (_handle != INVALID_HANDLE_VALUE));
|
||||
}
|
||||
return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),
|
||||
desiredAccess, shareMode, creationDisposition, flagsAndAttributes);
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -55,46 +54,46 @@ bool CFileBase::Close()
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CFileBase::GetPosition(UINT64 &position) const
|
||||
bool CFileBase::GetPosition(UInt64 &position) const
|
||||
{
|
||||
return Seek(0, FILE_CURRENT, position);
|
||||
}
|
||||
|
||||
bool CFileBase::GetLength(UINT64 &length) const
|
||||
bool CFileBase::GetLength(UInt64 &length) const
|
||||
{
|
||||
DWORD sizeHigh;
|
||||
DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);
|
||||
if(sizeLow == 0xFFFFFFFF)
|
||||
if(::GetLastError() != NO_ERROR )
|
||||
if(::GetLastError() != NO_ERROR)
|
||||
return false;
|
||||
length = (((UINT64)sizeHigh) << 32) + sizeLow;
|
||||
length = (((UInt64)sizeHigh) << 32) + sizeLow;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileBase::Seek(INT64 distanceToMove, DWORD moveMethod, UINT64 &newPosition) const
|
||||
bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const
|
||||
{
|
||||
LARGE_INTEGER *pointer = (LARGE_INTEGER *)&distanceToMove;
|
||||
pointer->LowPart = ::SetFilePointer(_handle, pointer->LowPart,
|
||||
&pointer->HighPart, moveMethod);
|
||||
if (pointer->LowPart == 0xFFFFFFFF)
|
||||
LARGE_INTEGER value;
|
||||
value.QuadPart = distanceToMove;
|
||||
value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);
|
||||
if (value.LowPart == 0xFFFFFFFF)
|
||||
if(::GetLastError() != NO_ERROR)
|
||||
return false;
|
||||
newPosition = *((UINT64 *)pointer);
|
||||
newPosition = value.QuadPart;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool CFileBase::Seek(UINT64 position, UINT64 &newPosition)
|
||||
bool CFileBase::Seek(UInt64 position, UInt64 &newPosition)
|
||||
{
|
||||
return Seek(position, FILE_BEGIN, newPosition);
|
||||
}
|
||||
|
||||
bool CFileBase::SeekToBegin()
|
||||
{
|
||||
UINT64 newPosition;
|
||||
UInt64 newPosition;
|
||||
return Seek(0, newPosition);
|
||||
}
|
||||
|
||||
bool CFileBase::SeekToEnd(UINT64 &newPosition)
|
||||
bool CFileBase::SeekToEnd(UInt64 &newPosition)
|
||||
{
|
||||
return Seek(0, FILE_END, newPosition);
|
||||
}
|
||||
@@ -109,41 +108,27 @@ bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const
|
||||
fileInfo.LastAccessTime = winFileInfo.ftLastAccessTime;
|
||||
fileInfo.LastWriteTime = winFileInfo.ftLastWriteTime;
|
||||
fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;
|
||||
fileInfo.Size = (((UINT64)winFileInfo.nFileSizeHigh) << 32) +
|
||||
winFileInfo.nFileSizeLow;
|
||||
fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) + winFileInfo.nFileSizeLow;
|
||||
fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;
|
||||
fileInfo.FileIndex = (((UINT64)winFileInfo.nFileIndexHigh) << 32) +
|
||||
winFileInfo.nFileIndexLow;
|
||||
fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;
|
||||
return true;
|
||||
}
|
||||
|
||||
/////////////////////////
|
||||
// CInFile
|
||||
|
||||
bool CInFile::Open(LPCTSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{
|
||||
return Create(fileName, GENERIC_READ, shareMode,
|
||||
creationDisposition, flagsAndAttributes);
|
||||
}
|
||||
bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
bool CInFile::Open(LPCTSTR fileName)
|
||||
{
|
||||
return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
|
||||
}
|
||||
{ return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CInFile::Open(LPCWSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{
|
||||
return Create(fileName, GENERIC_READ, shareMode,
|
||||
creationDisposition, flagsAndAttributes);
|
||||
}
|
||||
bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
bool CInFile::Open(LPCWSTR fileName)
|
||||
{
|
||||
return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL);
|
||||
}
|
||||
{ return Open(fileName, FILE_SHARE_READ, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
|
||||
#endif
|
||||
|
||||
// ReadFile and WriteFile functions in Windows have BUG:
|
||||
@@ -151,24 +136,24 @@ bool CInFile::Open(LPCWSTR fileName)
|
||||
// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
|
||||
// (Insufficient system resources exist to complete the requested service).
|
||||
|
||||
static UINT32 kChunkSizeMax = (1 << 24);
|
||||
static UInt32 kChunkSizeMax = (1 << 24);
|
||||
|
||||
bool CInFile::ReadPart(void *data, UINT32 size, UINT32 &processedSize)
|
||||
bool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
if (size > kChunkSizeMax)
|
||||
size = kChunkSizeMax;
|
||||
DWORD processedLoc = 0;
|
||||
bool res = BOOLToBool(::ReadFile(_handle, data, size, &processedLoc, NULL));
|
||||
processedSize = (UINT32)processedLoc;
|
||||
processedSize = (UInt32)processedLoc;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CInFile::Read(void *data, UINT32 size, UINT32 &processedSize)
|
||||
bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
processedSize = 0;
|
||||
do
|
||||
{
|
||||
UINT32 processedLoc = 0;
|
||||
UInt32 processedLoc = 0;
|
||||
bool res = ReadPart(data, size, processedLoc);
|
||||
processedSize += processedLoc;
|
||||
if (!res)
|
||||
@@ -185,77 +170,53 @@ bool CInFile::Read(void *data, UINT32 size, UINT32 &processedSize)
|
||||
/////////////////////////
|
||||
// COutFile
|
||||
|
||||
bool COutFile::Open(LPCTSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{
|
||||
return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
|
||||
creationDisposition, flagsAndAttributes);
|
||||
}
|
||||
bool COutFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
static inline DWORD GetCreationDisposition(bool createAlways)
|
||||
{ return createAlways? CREATE_ALWAYS: CREATE_NEW; }
|
||||
{ return createAlways? CREATE_ALWAYS: CREATE_NEW; }
|
||||
|
||||
bool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)
|
||||
{
|
||||
return Open(fileName, FILE_SHARE_READ,
|
||||
creationDisposition, FILE_ATTRIBUTE_NORMAL);
|
||||
}
|
||||
{ return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }
|
||||
|
||||
bool COutFile::Create(LPCTSTR fileName, bool createAlways)
|
||||
{
|
||||
return Open(fileName, GetCreationDisposition(createAlways));
|
||||
}
|
||||
{ return Open(fileName, GetCreationDisposition(createAlways)); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
bool COutFile::Open(LPCWSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{
|
||||
return CFileBase::Create(fileName, GENERIC_WRITE, shareMode,
|
||||
creationDisposition, flagsAndAttributes);
|
||||
}
|
||||
bool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
|
||||
bool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)
|
||||
{
|
||||
return Open(fileName, FILE_SHARE_READ,
|
||||
creationDisposition, FILE_ATTRIBUTE_NORMAL);
|
||||
}
|
||||
{ return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }
|
||||
|
||||
bool COutFile::Create(LPCWSTR fileName, bool createAlways)
|
||||
{
|
||||
return Open(fileName, GetCreationDisposition(createAlways));
|
||||
}
|
||||
{ return Open(fileName, GetCreationDisposition(createAlways)); }
|
||||
|
||||
#endif
|
||||
|
||||
bool COutFile::SetTime(const FILETIME *creationTime,
|
||||
const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)
|
||||
{
|
||||
return BOOLToBool(::SetFileTime(_handle, creationTime,
|
||||
lastAccessTime, lastWriteTime));
|
||||
}
|
||||
bool COutFile::SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime)
|
||||
{ return BOOLToBool(::SetFileTime(_handle, creationTime, lastAccessTime, lastWriteTime)); }
|
||||
|
||||
bool COutFile::SetLastWriteTime(const FILETIME *lastWriteTime)
|
||||
{
|
||||
return SetTime(NULL, NULL, lastWriteTime);
|
||||
}
|
||||
{ return SetTime(NULL, NULL, lastWriteTime); }
|
||||
|
||||
bool COutFile::WritePart(const void *data, UINT32 size, UINT32 &processedSize)
|
||||
bool COutFile::WritePart(const void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
if (size > kChunkSizeMax)
|
||||
size = kChunkSizeMax;
|
||||
DWORD processedLoc = 0;
|
||||
bool res = BOOLToBool(::WriteFile(_handle, data, size, &processedLoc, NULL));
|
||||
processedSize = (UINT32)processedLoc;
|
||||
processedSize = (UInt32)processedLoc;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool COutFile::Write(const void *data, UINT32 size, UINT32 &processedSize)
|
||||
bool COutFile::Write(const void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
processedSize = 0;
|
||||
do
|
||||
{
|
||||
UINT32 processedLoc = 0;
|
||||
UInt32 processedLoc = 0;
|
||||
bool res = WritePart(data, size, processedLoc);
|
||||
processedSize += processedLoc;
|
||||
if (!res)
|
||||
@@ -269,14 +230,11 @@ bool COutFile::Write(const void *data, UINT32 size, UINT32 &processedSize)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool COutFile::SetEndOfFile()
|
||||
{
|
||||
return BOOLToBool(::SetEndOfFile(_handle));
|
||||
}
|
||||
bool COutFile::SetEndOfFile() { return BOOLToBool(::SetEndOfFile(_handle)); }
|
||||
|
||||
bool COutFile::SetLength(UINT64 length)
|
||||
bool COutFile::SetLength(UInt64 length)
|
||||
{
|
||||
UINT64 newPosition;
|
||||
UInt64 newPosition;
|
||||
if(!Seek(length, newPosition))
|
||||
return false;
|
||||
if(newPosition != length)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
#ifndef __WINDOWS_FILEIO_H
|
||||
#define __WINDOWS_FILEIO_H
|
||||
|
||||
#include "../Common/Types.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NIO {
|
||||
@@ -14,9 +16,9 @@ struct CByHandleFileInfo
|
||||
FILETIME LastAccessTime;
|
||||
FILETIME LastWriteTime;
|
||||
DWORD VolumeSerialNumber;
|
||||
UINT64 Size;
|
||||
UInt64 Size;
|
||||
DWORD NumberOfLinks;
|
||||
UINT64 FileIndex;
|
||||
UInt64 FileIndex;
|
||||
};
|
||||
|
||||
class CFileBase
|
||||
@@ -32,19 +34,18 @@ protected:
|
||||
#endif
|
||||
|
||||
public:
|
||||
CFileBase():
|
||||
_fileIsOpen(false){};
|
||||
CFileBase(): _fileIsOpen(false){};
|
||||
virtual ~CFileBase();
|
||||
|
||||
virtual bool Close();
|
||||
|
||||
bool GetPosition(UINT64 &position) const;
|
||||
bool GetLength(UINT64 &length) const;
|
||||
bool GetPosition(UInt64 &position) const;
|
||||
bool GetLength(UInt64 &length) const;
|
||||
|
||||
bool Seek(INT64 distanceToMove, DWORD moveMethod, UINT64 &newPosition) const;
|
||||
bool Seek(UINT64 position, UINT64 &newPosition);
|
||||
bool Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const;
|
||||
bool Seek(UInt64 position, UInt64 &newPosition);
|
||||
bool SeekToBegin();
|
||||
bool SeekToEnd(UINT64 &newPosition);
|
||||
bool SeekToEnd(UInt64 &newPosition);
|
||||
|
||||
bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
|
||||
};
|
||||
@@ -52,16 +53,14 @@ public:
|
||||
class CInFile: public CFileBase
|
||||
{
|
||||
public:
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName);
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
bool ReadPart(void *data, UINT32 size, UINT32 &processedSize);
|
||||
bool Read(void *data, UINT32 size, UINT32 &processedSize);
|
||||
bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
|
||||
bool Read(void *data, UInt32 size, UInt32 &processedSize);
|
||||
};
|
||||
|
||||
class COutFile: public CFileBase
|
||||
@@ -69,14 +68,12 @@ class COutFile: public CFileBase
|
||||
// DWORD m_CreationDisposition;
|
||||
public:
|
||||
// COutFile(): m_CreationDisposition(CREATE_NEW){};
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName, DWORD creationDisposition);
|
||||
bool Create(LPCTSTR fileName, bool createAlways);
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool Open(LPCWSTR fileName, DWORD shareMode,
|
||||
DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCWSTR fileName, DWORD creationDisposition);
|
||||
bool Create(LPCWSTR fileName, bool createAlways);
|
||||
#endif
|
||||
@@ -88,13 +85,12 @@ public:
|
||||
{ m_CreationDisposition = CREATE_ALWAYS; }
|
||||
*/
|
||||
|
||||
bool SetTime(const FILETIME *creationTime,
|
||||
const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);
|
||||
bool SetTime(const FILETIME *creationTime, const FILETIME *lastAccessTime, const FILETIME *lastWriteTime);
|
||||
bool SetLastWriteTime(const FILETIME *lastWriteTime);
|
||||
bool WritePart(const void *data, UINT32 size, UINT32 &processedSize);
|
||||
bool Write(const void *data, UINT32 size, UINT32 &processedSize);
|
||||
bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
|
||||
bool Write(const void *data, UInt32 size, UInt32 &processedSize);
|
||||
bool SetEndOfFile();
|
||||
bool SetLength(UINT64 length);
|
||||
bool SetLength(UInt64 length);
|
||||
};
|
||||
|
||||
}}}
|
||||
|
||||
@@ -5,6 +5,10 @@
|
||||
#include "FileSystem.h"
|
||||
#include "Defs.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NSystem {
|
||||
@@ -29,6 +33,41 @@ bool MyGetVolumeInformation(
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetVolumeInformation(
|
||||
LPCWSTR rootPathName,
|
||||
UString &volumeName,
|
||||
LPDWORD volumeSerialNumber,
|
||||
LPDWORD maximumComponentLength,
|
||||
LPDWORD fileSystemFlags,
|
||||
UString &fileSystemName)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
bool result = BOOLToBool(GetVolumeInformationW(
|
||||
rootPathName,
|
||||
volumeName.GetBuffer(MAX_PATH), MAX_PATH,
|
||||
volumeSerialNumber,
|
||||
maximumComponentLength,
|
||||
fileSystemFlags,
|
||||
fileSystemName.GetBuffer(MAX_PATH), MAX_PATH));
|
||||
volumeName.ReleaseBuffer();
|
||||
fileSystemName.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
AString volumeNameA, fileSystemNameA;
|
||||
bool result = MyGetVolumeInformation(GetSystemString(rootPathName), volumeNameA,
|
||||
volumeSerialNumber, maximumComponentLength, fileSystemFlags,fileSystemNameA);
|
||||
if (result)
|
||||
{
|
||||
volumeName = GetUnicodeString(volumeNameA);
|
||||
fileSystemName = GetUnicodeString(fileSystemNameA);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
typedef BOOL (WINAPI * GetDiskFreeSpaceExPointer)(
|
||||
LPCTSTR lpDirectoryName, // directory name
|
||||
PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller
|
||||
@@ -37,7 +76,7 @@ typedef BOOL (WINAPI * GetDiskFreeSpaceExPointer)(
|
||||
);
|
||||
|
||||
bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
|
||||
UINT64 &clusterSize, UINT64 &totalSize, UINT64 &freeSize)
|
||||
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize)
|
||||
{
|
||||
GetDiskFreeSpaceExPointer pGetDiskFreeSpaceEx =
|
||||
(GetDiskFreeSpaceExPointer)GetProcAddress(
|
||||
@@ -46,11 +85,13 @@ bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
|
||||
bool sizeIsDetected = false;
|
||||
if (pGetDiskFreeSpaceEx)
|
||||
{
|
||||
UINT64 i64FreeBytesToCaller;
|
||||
ULARGE_INTEGER i64FreeBytesToCaller, totalSize2, freeSize2;
|
||||
sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(rootPathName,
|
||||
(PULARGE_INTEGER)&i64FreeBytesToCaller,
|
||||
(PULARGE_INTEGER)&totalSize,
|
||||
(PULARGE_INTEGER)&freeSize));
|
||||
&i64FreeBytesToCaller,
|
||||
&totalSize2,
|
||||
&freeSize2));
|
||||
totalSize = totalSize2.QuadPart;
|
||||
freeSize = freeSize2.QuadPart;
|
||||
}
|
||||
|
||||
DWORD numSectorsPerCluster;
|
||||
@@ -65,13 +106,21 @@ bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
|
||||
&totalNumberOfClusters))
|
||||
return false;
|
||||
|
||||
clusterSize = UINT64(bytesPerSector) * UINT64(numSectorsPerCluster);
|
||||
clusterSize = (UInt64)bytesPerSector * (UInt64)numSectorsPerCluster;
|
||||
if (!sizeIsDetected)
|
||||
{
|
||||
totalSize = clusterSize * UINT64(totalNumberOfClusters);
|
||||
freeSize = clusterSize * UINT64(numberOfFreeClusters);
|
||||
totalSize = clusterSize * (UInt64)totalNumberOfClusters;
|
||||
freeSize = clusterSize * (UInt64)numberOfFreeClusters;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetDiskFreeSpace(LPCWSTR rootPathName,
|
||||
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize)
|
||||
{
|
||||
return MyGetDiskFreeSpace(GetSystemString(rootPathName), clusterSize, totalSize, freeSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
}}}
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
#define __WINDOWS_FILESYSTEM_H
|
||||
|
||||
#include "../Common/String.h"
|
||||
#include "../Common/Types.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
@@ -17,8 +22,28 @@ bool MyGetVolumeInformation(
|
||||
LPDWORD fileSystemFlags,
|
||||
CSysString &fileSystemName);
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetVolumeInformation(
|
||||
LPCWSTR rootPathName,
|
||||
UString &volumeName,
|
||||
LPDWORD volumeSerialNumber,
|
||||
LPDWORD maximumComponentLength,
|
||||
LPDWORD fileSystemFlags,
|
||||
UString &fileSystemName);
|
||||
#endif
|
||||
|
||||
inline UINT MyGetDriveType(LPCTSTR pathName) { return GetDriveType(pathName); }
|
||||
#ifndef _UNICODE
|
||||
inline UINT MyGetDriveType(LPCWSTR pathName) { return GetDriveType(GetSystemString(pathName)); }
|
||||
#endif
|
||||
|
||||
bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
|
||||
UINT64 &clusterSize, UINT64 &totalSize, UINT64 &freeSize);
|
||||
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MyGetDiskFreeSpace(LPCWSTR rootPathName,
|
||||
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
|
||||
#endif
|
||||
|
||||
}}}
|
||||
|
||||
|
||||
78
Windows/MemoryLock.cpp
Executable file
78
Windows/MemoryLock.cpp
Executable file
@@ -0,0 +1,78 @@
|
||||
// Common/MemoryLock.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NSecurity {
|
||||
|
||||
#ifndef _UNICODE
|
||||
typedef BOOL (WINAPI * OpenProcessTokenP)(HANDLE ProcessHandle, DWORD DesiredAccess, PHANDLE TokenHandle);
|
||||
typedef BOOL (WINAPI * LookupPrivilegeValueP)(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid);
|
||||
typedef BOOL (WINAPI * AdjustTokenPrivilegesP)(HANDLE TokenHandle, BOOL DisableAllPrivileges,
|
||||
PTOKEN_PRIVILEGES NewState, DWORD BufferLength, PTOKEN_PRIVILEGES PreviousState,PDWORD ReturnLength);
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
bool EnableLockMemoryPrivilege(
|
||||
#else
|
||||
static bool EnableLockMemoryPrivilege2(HMODULE hModule,
|
||||
#endif
|
||||
bool enable)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (hModule == NULL)
|
||||
return false;
|
||||
OpenProcessTokenP openProcessToken = (OpenProcessTokenP)GetProcAddress(hModule, "OpenProcessToken");
|
||||
LookupPrivilegeValueP lookupPrivilegeValue = (LookupPrivilegeValueP)GetProcAddress(hModule, "LookupPrivilegeValueA" );
|
||||
AdjustTokenPrivilegesP adjustTokenPrivileges = (AdjustTokenPrivilegesP)GetProcAddress(hModule, "AdjustTokenPrivileges");
|
||||
if (openProcessToken == NULL || adjustTokenPrivileges == NULL || lookupPrivilegeValue == NULL)
|
||||
return false;
|
||||
#endif
|
||||
|
||||
HANDLE token;
|
||||
if (!
|
||||
#ifdef _UNICODE
|
||||
::OpenProcessToken
|
||||
#else
|
||||
openProcessToken
|
||||
#endif
|
||||
(::GetCurrentProcess(), TOKEN_ADJUST_PRIVILEGES, &token))
|
||||
return false;
|
||||
TOKEN_PRIVILEGES tp;
|
||||
bool res = false;
|
||||
if (
|
||||
#ifdef _UNICODE
|
||||
::LookupPrivilegeValue
|
||||
#else
|
||||
lookupPrivilegeValue
|
||||
#endif
|
||||
(NULL, SE_LOCK_MEMORY_NAME, &(tp.Privileges[0].Luid)))
|
||||
{
|
||||
tp.PrivilegeCount = 1;
|
||||
tp.Privileges[0].Attributes = enable ? SE_PRIVILEGE_ENABLED: 0;
|
||||
if (
|
||||
#ifdef _UNICODE
|
||||
::AdjustTokenPrivileges
|
||||
#else
|
||||
adjustTokenPrivileges
|
||||
#endif
|
||||
(token, FALSE, &tp, 0, NULL, NULL))
|
||||
res = (GetLastError() == ERROR_SUCCESS);
|
||||
}
|
||||
::CloseHandle(token);
|
||||
return res;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool EnableLockMemoryPrivilege(bool enable)
|
||||
{
|
||||
HMODULE hModule = LoadLibrary(TEXT("Advapi32.dll"));
|
||||
if(hModule == NULL)
|
||||
return false;
|
||||
bool res = EnableLockMemoryPrivilege2(hModule, enable);
|
||||
::FreeLibrary(hModule);
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
}}
|
||||
13
Windows/MemoryLock.h
Executable file
13
Windows/MemoryLock.h
Executable file
@@ -0,0 +1,13 @@
|
||||
// Windows/MemoryLock.h
|
||||
|
||||
#ifndef __WINDOWS_MEMORYLOCK_H
|
||||
#define __WINDOWS_MEMORYLOCK_H
|
||||
|
||||
namespace NWindows {
|
||||
namespace NSecurity {
|
||||
|
||||
bool EnableLockMemoryPrivilege(bool enable = true);
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
178
Windows/Menu.cpp
Executable file
178
Windows/Menu.cpp
Executable file
@@ -0,0 +1,178 @@
|
||||
// Windows/Menu.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Windows/Menu.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
static void ConvertItemToSysForm(const CMenuItem &item, MENUITEMINFOW &si)
|
||||
{
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cbSize = sizeof(si);
|
||||
si.fMask = item.fMask;
|
||||
si.fType = item.fType;
|
||||
si.fState = item.fState;
|
||||
si.wID = item.wID;
|
||||
si.hSubMenu = item.hSubMenu;
|
||||
si.hbmpChecked = item.hbmpChecked;
|
||||
si.hbmpUnchecked = item.hbmpUnchecked;
|
||||
si.dwItemData = item.dwItemData;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
static void ConvertItemToSysForm(const CMenuItem &item, MENUITEMINFOA &si)
|
||||
{
|
||||
ZeroMemory(&si, sizeof(si));
|
||||
si.cbSize = sizeof(si);
|
||||
si.fMask = item.fMask;
|
||||
si.fType = item.fType;
|
||||
si.fState = item.fState;
|
||||
si.wID = item.wID;
|
||||
si.hSubMenu = item.hSubMenu;
|
||||
si.hbmpChecked = item.hbmpChecked;
|
||||
si.hbmpUnchecked = item.hbmpUnchecked;
|
||||
si.dwItemData = item.dwItemData;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ConvertItemToMyForm(const MENUITEMINFOW &si, CMenuItem &item)
|
||||
{
|
||||
item.fMask = si.fMask;
|
||||
item.fType = si.fType;
|
||||
item.fState = si.fState;
|
||||
item.wID = si.wID;
|
||||
item.hSubMenu = si.hSubMenu;
|
||||
item.hbmpChecked = si.hbmpChecked;
|
||||
item.hbmpUnchecked = si.hbmpUnchecked;
|
||||
item.dwItemData = si.dwItemData;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
static void ConvertItemToMyForm(const MENUITEMINFOA &si, CMenuItem &item)
|
||||
{
|
||||
item.fMask = si.fMask;
|
||||
item.fType = si.fType;
|
||||
item.fState = si.fState;
|
||||
item.wID = si.wID;
|
||||
item.hSubMenu = si.hSubMenu;
|
||||
item.hbmpChecked = si.hbmpChecked;
|
||||
item.hbmpUnchecked = si.hbmpUnchecked;
|
||||
item.dwItemData = si.dwItemData;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CMenu::GetItem(UINT itemIndex, bool byPosition, CMenuItem &item)
|
||||
{
|
||||
const UINT kMaxSize = 512;
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
CHAR s[kMaxSize + 1];
|
||||
MENUITEMINFOA si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
if (item.IsString())
|
||||
{
|
||||
si.cch = kMaxSize;
|
||||
si.dwTypeData = s;
|
||||
}
|
||||
if(GetItemInfo(itemIndex, byPosition, &si))
|
||||
{
|
||||
ConvertItemToMyForm(si, item);
|
||||
if (item.IsString())
|
||||
item.StringValue = GetUnicodeString(s);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
wchar_t s[kMaxSize + 1];
|
||||
MENUITEMINFOW si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
if (item.IsString())
|
||||
{
|
||||
si.cch = kMaxSize;
|
||||
si.dwTypeData = s;
|
||||
}
|
||||
if(GetItemInfo(itemIndex, byPosition, &si))
|
||||
{
|
||||
ConvertItemToMyForm(si, item);
|
||||
if (item.IsString())
|
||||
item.StringValue = s;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
bool CMenu::SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
MENUITEMINFOA si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
AString s;
|
||||
if (item.IsString())
|
||||
{
|
||||
s = GetSystemString(item.StringValue);
|
||||
si.dwTypeData = (LPTSTR)(LPCTSTR)s;
|
||||
}
|
||||
return SetItemInfo(itemIndex, byPosition, &si);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
MENUITEMINFOW si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
if (item.IsString())
|
||||
si.dwTypeData = (LPWSTR)(LPCWSTR)item.StringValue;
|
||||
return SetItemInfo(itemIndex, byPosition, &si);
|
||||
}
|
||||
}
|
||||
|
||||
bool CMenu::InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
MENUITEMINFOA si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
AString s;
|
||||
if (item.IsString())
|
||||
{
|
||||
s = GetSystemString(item.StringValue);
|
||||
si.dwTypeData = (LPTSTR)(LPCTSTR)s;
|
||||
}
|
||||
return InsertItem(itemIndex, byPosition, &si);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
MENUITEMINFOW si;
|
||||
ConvertItemToSysForm(item, si);
|
||||
if (item.IsString())
|
||||
si.dwTypeData = (LPWSTR)(LPCWSTR)item.StringValue;
|
||||
return InsertItem(itemIndex, byPosition, &si);
|
||||
}
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CMenu::AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem)
|
||||
{
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::AppendMenuW(_menu, flags, newItemID, newItem));
|
||||
else
|
||||
return AppendItem(flags, newItemID, GetSystemString(newItem));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
@@ -8,6 +8,26 @@
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
struct CMenuItem
|
||||
{
|
||||
UString StringValue;
|
||||
UINT fMask;
|
||||
UINT fType;
|
||||
UINT fState;
|
||||
UINT wID;
|
||||
HMENU hSubMenu;
|
||||
HBITMAP hbmpChecked;
|
||||
HBITMAP hbmpUnchecked;
|
||||
ULONG_PTR dwItemData;
|
||||
// LPTSTR dwTypeData;
|
||||
// UINT cch;
|
||||
// HBITMAP hbmpItem;
|
||||
bool IsString() const // change it MIIM_STRING
|
||||
{ return ((fMask & MIIM_TYPE) != 0 && (fType == MFT_STRING)); }
|
||||
CMenuItem(): fMask(0), fType(0), fState(0), wID(0), hSubMenu(0), hbmpChecked(0),
|
||||
hbmpUnchecked(0), dwItemData(0) {}
|
||||
};
|
||||
|
||||
class CMenu
|
||||
{
|
||||
HMENU _menu;
|
||||
@@ -61,6 +81,11 @@ public:
|
||||
UINT GetItemState(UINT id, UINT flags)
|
||||
{ return ::GetMenuState(_menu, id, flags); }
|
||||
|
||||
bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo)
|
||||
{ return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo)
|
||||
{ return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
|
||||
bool AppendItem(UINT flags, UINT_PTR newItemID, LPCTSTR newItem)
|
||||
{ return BOOLToBool(::AppendMenu(_menu, flags, newItemID, newItem)); }
|
||||
|
||||
@@ -68,18 +93,24 @@ public:
|
||||
{ return BOOLToBool(::InsertMenu(_menu, position, flags, idNewItem, newItem)); }
|
||||
|
||||
bool InsertItem(UINT itemIndex, bool byPosition, LPCMENUITEMINFO itemInfo)
|
||||
{ return BOOLToBool(::InsertMenuItem(_menu, itemIndex,
|
||||
BoolToBOOL(byPosition), itemInfo)); }
|
||||
{ return BOOLToBool(::InsertMenuItem(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
|
||||
bool RemoveItem(UINT item, UINT flags)
|
||||
{ return BOOLToBool(::RemoveMenu(_menu, item, flags)); }
|
||||
|
||||
bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo)
|
||||
{ return BOOLToBool(::GetMenuItemInfo(_menu, itemIndex,
|
||||
BoolToBOOL(byPosition), itemInfo)); }
|
||||
bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFO itemInfo)
|
||||
{ return BOOLToBool(::SetMenuItemInfo(_menu, itemIndex,
|
||||
BoolToBOOL(byPosition), itemInfo)); }
|
||||
#ifndef _UNICODE
|
||||
bool GetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo)
|
||||
{ return BOOLToBool(::GetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
bool InsertItem(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo)
|
||||
{ return BOOLToBool(::InsertMenuItemW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
bool SetItemInfo(UINT itemIndex, bool byPosition, LPMENUITEMINFOW itemInfo)
|
||||
{ return BOOLToBool(::SetMenuItemInfoW(_menu, itemIndex, BoolToBOOL(byPosition), itemInfo)); }
|
||||
bool AppendItem(UINT flags, UINT_PTR newItemID, LPCWSTR newItem);
|
||||
#endif
|
||||
|
||||
bool GetItem(UINT itemIndex, bool byPosition, CMenuItem &item);
|
||||
bool SetItem(UINT itemIndex, bool byPosition, const CMenuItem &item);
|
||||
bool InsertItem(UINT itemIndex, bool byPosition, const CMenuItem &item);
|
||||
|
||||
int Track(UINT flags, int x, int y, HWND hWnd)
|
||||
{ return ::TrackPopupMenuEx(_menu, flags, x, y, hWnd, NULL); }
|
||||
|
||||
242
Windows/Net.cpp
242
Windows/Net.cpp
@@ -4,6 +4,14 @@
|
||||
|
||||
#include "Windows/Net.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NNet {
|
||||
|
||||
@@ -15,8 +23,17 @@ DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResourc
|
||||
return result;
|
||||
}
|
||||
|
||||
static void SetComplexString(bool &defined, CSysString &destString,
|
||||
LPCTSTR srsString)
|
||||
#ifndef _UNICODE
|
||||
DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCEW netResource)
|
||||
{
|
||||
Close();
|
||||
DWORD result = ::WNetOpenEnumW(scope, type, usage, netResource, &_handle);
|
||||
_handleAllocated = (result == NO_ERROR);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
static void SetComplexString(bool &defined, CSysString &destString, LPCTSTR srsString)
|
||||
{
|
||||
defined = (srsString != 0);
|
||||
if (defined)
|
||||
@@ -25,8 +42,7 @@ static void SetComplexString(bool &defined, CSysString &destString,
|
||||
destString.Empty();
|
||||
}
|
||||
|
||||
static void ConvertNETRESOURCEToCResource(const NETRESOURCE &netResource,
|
||||
CResource &resource)
|
||||
static void ConvertNETRESOURCEToCResource(const NETRESOURCE &netResource, CResource &resource)
|
||||
{
|
||||
resource.Scope = netResource.dwScope;
|
||||
resource.Type = netResource.dwType;
|
||||
@@ -38,8 +54,7 @@ static void ConvertNETRESOURCEToCResource(const NETRESOURCE &netResource,
|
||||
SetComplexString(resource.ProviderIsDefined, resource.Provider, netResource.lpProvider);
|
||||
}
|
||||
|
||||
static void SetComplexString2(LPTSTR *destString, bool defined,
|
||||
const CSysString &srcString)
|
||||
static void SetComplexString2(LPTSTR *destString, bool defined, const CSysString &srcString)
|
||||
{
|
||||
if (defined)
|
||||
*destString = (TCHAR *)(const TCHAR *)srcString;
|
||||
@@ -47,8 +62,7 @@ static void SetComplexString2(LPTSTR *destString, bool defined,
|
||||
*destString = 0;
|
||||
}
|
||||
|
||||
static void ConvertCResourceToNETRESOURCE(const CResource &resource,
|
||||
NETRESOURCE &netResource)
|
||||
static void ConvertCResourceToNETRESOURCE(const CResource &resource, NETRESOURCE &netResource)
|
||||
{
|
||||
netResource.dwScope = resource.Scope;
|
||||
netResource.dwType = resource.Type;
|
||||
@@ -60,8 +74,69 @@ static void ConvertCResourceToNETRESOURCE(const CResource &resource,
|
||||
SetComplexString2(&netResource.lpProvider, resource.ProviderIsDefined, resource.Provider);
|
||||
}
|
||||
|
||||
DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage,
|
||||
const CResource *resource)
|
||||
#ifndef _UNICODE
|
||||
|
||||
static void SetComplexString(bool &defined, UString &destString, LPCWSTR srsString)
|
||||
{
|
||||
defined = (srsString != 0);
|
||||
if (defined)
|
||||
destString = srsString;
|
||||
else
|
||||
destString.Empty();
|
||||
}
|
||||
|
||||
static void ConvertNETRESOURCEToCResource(const NETRESOURCEW &netResource, CResourceW &resource)
|
||||
{
|
||||
resource.Scope = netResource.dwScope;
|
||||
resource.Type = netResource.dwType;
|
||||
resource.DisplayType = netResource.dwDisplayType;
|
||||
resource.Usage = netResource.dwUsage;
|
||||
SetComplexString(resource.LocalNameIsDefined, resource.LocalName, netResource.lpLocalName);
|
||||
SetComplexString(resource.RemoteNameIsDefined, resource.RemoteName, netResource.lpRemoteName);
|
||||
SetComplexString(resource.CommentIsDefined, resource.Comment, netResource.lpComment);
|
||||
SetComplexString(resource.ProviderIsDefined, resource.Provider, netResource.lpProvider);
|
||||
}
|
||||
|
||||
static void SetComplexString2(LPWSTR *destString, bool defined, const UString &srcString)
|
||||
{
|
||||
if (defined)
|
||||
*destString = (WCHAR *)(const WCHAR *)srcString;
|
||||
else
|
||||
*destString = 0;
|
||||
}
|
||||
|
||||
static void ConvertCResourceToNETRESOURCE(const CResourceW &resource, NETRESOURCEW &netResource)
|
||||
{
|
||||
netResource.dwScope = resource.Scope;
|
||||
netResource.dwType = resource.Type;
|
||||
netResource.dwDisplayType = resource.DisplayType;
|
||||
netResource.dwUsage = resource.Usage;
|
||||
SetComplexString2(&netResource.lpLocalName, resource.LocalNameIsDefined, resource.LocalName);
|
||||
SetComplexString2(&netResource.lpRemoteName, resource.RemoteNameIsDefined, resource.RemoteName);
|
||||
SetComplexString2(&netResource.lpComment, resource.CommentIsDefined, resource.Comment);
|
||||
SetComplexString2(&netResource.lpProvider, resource.ProviderIsDefined, resource.Provider);
|
||||
}
|
||||
|
||||
static void ConvertResourceWToResource(const CResourceW &resourceW, CResource &resource)
|
||||
{
|
||||
*(CResourceBase *)&resource = *(CResourceBase *)&resourceW;
|
||||
resource.LocalName = GetSystemString(resourceW.LocalName);
|
||||
resource.RemoteName = GetSystemString(resourceW.RemoteName);
|
||||
resource.Comment = GetSystemString(resourceW.Comment);
|
||||
resource.Provider = GetSystemString(resourceW.Provider);
|
||||
}
|
||||
|
||||
static void ConvertResourceToResourceW(const CResource &resource, CResourceW &resourceW)
|
||||
{
|
||||
*(CResourceBase *)&resourceW = *(CResourceBase *)&resource;
|
||||
resourceW.LocalName = GetUnicodeString(resource.LocalName);
|
||||
resourceW.RemoteName = GetUnicodeString(resource.RemoteName);
|
||||
resourceW.Comment = GetUnicodeString(resource.Comment);
|
||||
resourceW.Provider = GetUnicodeString(resource.Provider);
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, const CResource *resource)
|
||||
{
|
||||
NETRESOURCE netResource;
|
||||
LPNETRESOURCE pointer;
|
||||
@@ -75,6 +150,35 @@ DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage,
|
||||
return Open(scope, type, usage, pointer);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD CEnum::Open(DWORD scope, DWORD type, DWORD usage, const CResourceW *resource)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
NETRESOURCEW netResource;
|
||||
LPNETRESOURCEW pointer;
|
||||
if (resource == 0)
|
||||
pointer = 0;
|
||||
else
|
||||
{
|
||||
ConvertCResourceToNETRESOURCE(*resource, netResource);
|
||||
pointer = &netResource;
|
||||
}
|
||||
return Open(scope, type, usage, pointer);
|
||||
}
|
||||
CResource *pointer;
|
||||
CResource resourceA;
|
||||
if (resource == 0)
|
||||
pointer = 0;
|
||||
else
|
||||
{
|
||||
ConvertResourceWToResource(*resource, resourceA);
|
||||
pointer = &resourceA;
|
||||
}
|
||||
return Open(scope, type, usage, pointer);
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD CEnum::Close()
|
||||
{
|
||||
if(!_handleAllocated)
|
||||
@@ -89,6 +193,13 @@ DWORD CEnum::Next(LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize)
|
||||
return ::WNetEnumResource(_handle, lpcCount, lpBuffer, lpBufferSize);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD CEnum::NextW(LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize)
|
||||
{
|
||||
return ::WNetEnumResourceW(_handle, lpcCount, lpBuffer, lpBufferSize);
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD CEnum::Next(CResource &resource)
|
||||
{
|
||||
CByteBuffer byteBuffer;
|
||||
@@ -107,6 +218,34 @@ DWORD CEnum::Next(CResource &resource)
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD CEnum::Next(CResourceW &resource)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
CByteBuffer byteBuffer;
|
||||
const DWORD kBufferSize = 16384;
|
||||
byteBuffer.SetCapacity(kBufferSize);
|
||||
LPNETRESOURCEW lpnrLocal = (LPNETRESOURCEW) (BYTE *)(byteBuffer);
|
||||
ZeroMemory(lpnrLocal, kBufferSize);
|
||||
DWORD bufferSize = kBufferSize;
|
||||
DWORD numEntries = 1;
|
||||
DWORD result = NextW(&numEntries, lpnrLocal, &bufferSize);
|
||||
if (result != NO_ERROR)
|
||||
return result;
|
||||
if (numEntries != 1)
|
||||
return (DWORD)E_FAIL;
|
||||
ConvertNETRESOURCEToCResource(lpnrLocal[0], resource);
|
||||
return result;
|
||||
}
|
||||
CResource resourceA;
|
||||
DWORD result = Next(resourceA);
|
||||
ConvertResourceToResourceW(resourceA, resource);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
DWORD GetResourceParent(const CResource &resource, CResource &parentResource)
|
||||
{
|
||||
CByteBuffer byteBuffer;
|
||||
@@ -124,6 +263,33 @@ DWORD GetResourceParent(const CResource &resource, CResource &parentResource)
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD GetResourceParent(const CResourceW &resource, CResourceW &parentResource)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
CByteBuffer byteBuffer;
|
||||
const DWORD kBufferSize = 16384;
|
||||
byteBuffer.SetCapacity(kBufferSize);
|
||||
LPNETRESOURCEW lpnrLocal = (LPNETRESOURCEW) (BYTE *)(byteBuffer);
|
||||
ZeroMemory(lpnrLocal, kBufferSize);
|
||||
DWORD bufferSize = kBufferSize;
|
||||
NETRESOURCEW netResource;
|
||||
ConvertCResourceToNETRESOURCE(resource, netResource);
|
||||
DWORD result = ::WNetGetResourceParentW(&netResource, lpnrLocal, &bufferSize);
|
||||
if (result != NO_ERROR)
|
||||
return result;
|
||||
ConvertNETRESOURCEToCResource(lpnrLocal[0], parentResource);
|
||||
return result;
|
||||
}
|
||||
CResource resourceA, parentResourceA;
|
||||
ConvertResourceWToResource(resource, resourceA);
|
||||
DWORD result = GetResourceParent(resourceA, parentResourceA);
|
||||
ConvertResourceToResourceW(parentResourceA, parentResource);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD GetResourceInformation(const CResource &resource,
|
||||
CResource &destResource, CSysString &systemPathPart)
|
||||
{
|
||||
@@ -146,6 +312,40 @@ DWORD GetResourceInformation(const CResource &resource,
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD GetResourceInformation(const CResourceW &resource,
|
||||
CResourceW &destResource, UString &systemPathPart)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
CByteBuffer byteBuffer;
|
||||
const DWORD kBufferSize = 16384;
|
||||
byteBuffer.SetCapacity(kBufferSize);
|
||||
LPNETRESOURCEW lpnrLocal = (LPNETRESOURCEW) (BYTE *)(byteBuffer);
|
||||
ZeroMemory(lpnrLocal, kBufferSize);
|
||||
DWORD bufferSize = kBufferSize;
|
||||
NETRESOURCEW netResource;
|
||||
ConvertCResourceToNETRESOURCE(resource, netResource);
|
||||
LPWSTR lplpSystem;
|
||||
DWORD result = ::WNetGetResourceInformationW(&netResource,
|
||||
lpnrLocal, &bufferSize, &lplpSystem);
|
||||
if (result != NO_ERROR)
|
||||
return result;
|
||||
if (lplpSystem != 0)
|
||||
systemPathPart = lplpSystem;
|
||||
ConvertNETRESOURCEToCResource(lpnrLocal[0], destResource);
|
||||
return result;
|
||||
}
|
||||
CResource resourceA, destResourceA;
|
||||
ConvertResourceWToResource(resource, resourceA);
|
||||
AString systemPathPartA;
|
||||
DWORD result = GetResourceInformation(resourceA, destResourceA, systemPathPartA);
|
||||
ConvertResourceToResourceW(destResourceA, destResource);
|
||||
systemPathPart = GetUnicodeString(systemPathPartA);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD AddConnection2(const CResource &resource,
|
||||
LPCTSTR password, LPCTSTR userName, DWORD flags)
|
||||
{
|
||||
@@ -155,4 +355,26 @@ DWORD AddConnection2(const CResource &resource,
|
||||
password, userName, flags);
|
||||
}
|
||||
|
||||
DWORD AddConnection2(const CResource &resource, LPCTSTR password, LPCTSTR userName, DWORD flags);
|
||||
|
||||
#ifndef _UNICODE
|
||||
DWORD AddConnection2(const CResourceW &resource, LPCWSTR password, LPCWSTR userName, DWORD flags)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
NETRESOURCEW netResource;
|
||||
ConvertCResourceToNETRESOURCE(resource, netResource);
|
||||
return ::WNetAddConnection2W(&netResource,password, userName, flags);
|
||||
}
|
||||
CResource resourceA;
|
||||
ConvertResourceWToResource(resource, resourceA);
|
||||
CSysString passwordA = GetSystemString(password);
|
||||
CSysString userNameA = GetSystemString(userName);
|
||||
return AddConnection2(resourceA,
|
||||
password ? (LPCTSTR)passwordA: 0,
|
||||
userName ? (LPCTSTR)userNameA: 0,
|
||||
flags);
|
||||
}
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
namespace NWindows {
|
||||
namespace NNet {
|
||||
|
||||
struct CResource
|
||||
struct CResourceBase
|
||||
{
|
||||
DWORD Scope;
|
||||
DWORD Type;
|
||||
@@ -19,33 +19,68 @@ struct CResource
|
||||
bool RemoteNameIsDefined;
|
||||
bool CommentIsDefined;
|
||||
bool ProviderIsDefined;
|
||||
};
|
||||
|
||||
struct CResource: public CResourceBase
|
||||
{
|
||||
CSysString LocalName;
|
||||
CSysString RemoteName;
|
||||
CSysString Comment;
|
||||
CSysString Provider;
|
||||
};
|
||||
|
||||
#ifdef _UNICODE
|
||||
typedef CResource CResourceW;
|
||||
#else
|
||||
struct CResourceW: public CResourceBase
|
||||
{
|
||||
UString LocalName;
|
||||
UString RemoteName;
|
||||
UString Comment;
|
||||
UString Provider;
|
||||
};
|
||||
#endif
|
||||
|
||||
class CEnum
|
||||
{
|
||||
HANDLE _handle;
|
||||
bool _handleAllocated;
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResource);
|
||||
DWORD Next(LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize);
|
||||
#ifndef _UNICODE
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCEW netResource);
|
||||
DWORD NextW(LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize);
|
||||
#endif
|
||||
protected:
|
||||
bool IsHandleAllocated() const { return _handleAllocated; }
|
||||
public:
|
||||
CEnum(): _handleAllocated(false) {}
|
||||
~CEnum() { Close(); }
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, LPNETRESOURCE netResource);
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, const CResource *resource);
|
||||
DWORD Close();
|
||||
DWORD Next(LPDWORD lpcCount, LPVOID lpBuffer, LPDWORD lpBufferSize);
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, const CResource *resource);
|
||||
DWORD Next(CResource &resource);
|
||||
#ifndef _UNICODE
|
||||
DWORD Open(DWORD scope, DWORD type, DWORD usage, const CResourceW *resource);
|
||||
DWORD Next(CResourceW &resource);
|
||||
#endif
|
||||
};
|
||||
|
||||
DWORD GetResourceParent(const CResource &resource, CResource &parentResource);
|
||||
#ifndef _UNICODE
|
||||
DWORD GetResourceParent(const CResourceW &resource, CResourceW &parentResource);
|
||||
#endif
|
||||
|
||||
DWORD GetResourceInformation(const CResource &resource,
|
||||
CResource &destResource, CSysString &systemPathPart);
|
||||
DWORD AddConnection2(const CResource &resource,
|
||||
LPCTSTR password, LPCTSTR userName, DWORD flags);
|
||||
#ifndef _UNICODE
|
||||
DWORD GetResourceInformation(const CResourceW &resource,
|
||||
CResourceW &destResource, UString &systemPathPart);
|
||||
#endif
|
||||
|
||||
DWORD AddConnection2(const CResource &resource, LPCTSTR password, LPCTSTR userName, DWORD flags);
|
||||
#ifndef _UNICODE
|
||||
DWORD AddConnection2(const CResourceW &resource, LPCWSTR password, LPCWSTR userName, DWORD flags);
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
|
||||
@@ -2,8 +2,15 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Windows/Registry.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NRegistry {
|
||||
|
||||
@@ -86,11 +93,10 @@ LONG CKey::RecurseDeleteKey(LPCTSTR subKeyName)
|
||||
if (res != ERROR_SUCCESS)
|
||||
return res;
|
||||
FILETIME fileTime;
|
||||
const UINT32 kBufferSize = MAX_PATH + 1; // 256 in ATL
|
||||
const UInt32 kBufferSize = MAX_PATH + 1; // 256 in ATL
|
||||
DWORD size = kBufferSize;
|
||||
TCHAR buffer[kBufferSize];
|
||||
while (RegEnumKeyEx(key._object, 0, buffer, &size, NULL, NULL, NULL,
|
||||
&fileTime) == ERROR_SUCCESS)
|
||||
while (RegEnumKeyEx(key._object, 0, buffer, &size, NULL, NULL, NULL, &fileTime) == ERROR_SUCCESS)
|
||||
{
|
||||
res = key.RecurseDeleteKey(buffer);
|
||||
if (res != ERROR_SUCCESS)
|
||||
@@ -105,57 +111,81 @@ LONG CKey::RecurseDeleteKey(LPCTSTR subKeyName)
|
||||
/////////////////////////
|
||||
// Value Functions
|
||||
|
||||
static inline UINT32 BoolToUINT32(bool value)
|
||||
{ return (value ? 1: 0); }
|
||||
|
||||
static inline bool UINT32ToBool(UINT32 value)
|
||||
{ return (value != 0); }
|
||||
static inline UInt32 BoolToUINT32(bool value) { return (value ? 1: 0); }
|
||||
static inline bool UINT32ToBool(UInt32 value) { return (value != 0); }
|
||||
|
||||
|
||||
LONG CKey::DeleteValue(LPCTSTR value)
|
||||
LONG CKey::DeleteValue(LPCTSTR name)
|
||||
{
|
||||
MYASSERT(_object != NULL);
|
||||
return RegDeleteValue(_object, (LPTSTR)value);
|
||||
return ::RegDeleteValue(_object, name);
|
||||
}
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR valueName, UINT32 value)
|
||||
#ifndef _UNICODE
|
||||
LONG CKey::DeleteValue(LPCWSTR name)
|
||||
{
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, valueName, NULL, REG_DWORD,
|
||||
(BYTE * const)&value, sizeof(UINT32));
|
||||
if (g_IsNT)
|
||||
return ::RegDeleteValueW(_object, name);
|
||||
return DeleteValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name));
|
||||
}
|
||||
#endif
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR valueName, bool value)
|
||||
LONG CKey::SetValue(LPCTSTR name, UInt32 value)
|
||||
{
|
||||
return SetValue(valueName, BoolToUINT32(value));
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, name, NULL, REG_DWORD,
|
||||
(BYTE * const)&value, sizeof(UInt32));
|
||||
}
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR valueName, LPCTSTR value)
|
||||
LONG CKey::SetValue(LPCTSTR name, bool value)
|
||||
{
|
||||
return SetValue(name, BoolToUINT32(value));
|
||||
}
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR name, LPCTSTR value)
|
||||
{
|
||||
MYASSERT(value != NULL);
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, valueName, NULL, REG_SZ,
|
||||
return RegSetValueEx(_object, name, NULL, REG_SZ,
|
||||
(const BYTE * )value, (lstrlen(value) + 1) * sizeof(TCHAR));
|
||||
}
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR valueName, const CSysString &value)
|
||||
/*
|
||||
LONG CKey::SetValue(LPCTSTR name, const CSysString &value)
|
||||
{
|
||||
MYASSERT(value != NULL);
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, valueName, NULL, REG_SZ,
|
||||
return RegSetValueEx(_object, name, NULL, REG_SZ,
|
||||
(const BYTE *)(const TCHAR *)value, (value.Length() + 1) * sizeof(TCHAR));
|
||||
}
|
||||
*/
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR valueName, const void *value, UINT32 size)
|
||||
#ifndef _UNICODE
|
||||
|
||||
LONG CKey::SetValue(LPCWSTR name, LPCWSTR value)
|
||||
{
|
||||
MYASSERT(value != NULL);
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, valueName, NULL, REG_BINARY,
|
||||
if (g_IsNT)
|
||||
return RegSetValueExW(_object, name, NULL, REG_SZ,
|
||||
(const BYTE * )value, (wcslen(value) + 1) * sizeof(wchar_t));
|
||||
return SetValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name),
|
||||
value == 0 ? 0 : (LPCSTR)GetSystemString(value));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
LONG CKey::SetValue(LPCTSTR name, const void *value, UInt32 size)
|
||||
{
|
||||
MYASSERT(value != NULL);
|
||||
MYASSERT(_object != NULL);
|
||||
return RegSetValueEx(_object, name, NULL, REG_BINARY,
|
||||
(const BYTE *)value, size);
|
||||
}
|
||||
|
||||
LONG SetValue(HKEY parentKey, LPCTSTR keyName,
|
||||
LPCTSTR valueName, LPCTSTR value)
|
||||
LONG SetValue(HKEY parentKey, LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value)
|
||||
{
|
||||
MYASSERT(value != NULL);
|
||||
CKey key;
|
||||
@@ -175,92 +205,120 @@ LONG CKey::SetKeyValue(LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value)
|
||||
return res;
|
||||
}
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, UINT32 &value)
|
||||
LONG CKey::QueryValue(LPCTSTR name, UInt32 &value)
|
||||
{
|
||||
DWORD type = NULL;
|
||||
DWORD count = sizeof(DWORD);
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)valueName, NULL, &type,
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type,
|
||||
(LPBYTE)&value, &count);
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (type == REG_DWORD));
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (count == sizeof(UINT32)));
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (count == sizeof(UInt32)));
|
||||
return res;
|
||||
}
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, bool &value)
|
||||
LONG CKey::QueryValue(LPCTSTR name, bool &value)
|
||||
{
|
||||
UINT32 uintValue = BoolToUINT32(value);
|
||||
LONG res = QueryValue(valueName, uintValue);
|
||||
UInt32 uintValue = BoolToUINT32(value);
|
||||
LONG res = QueryValue(name, uintValue);
|
||||
value = UINT32ToBool(uintValue);
|
||||
return res;
|
||||
}
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, LPTSTR value, UINT32 &count)
|
||||
LONG CKey::QueryValue(LPCTSTR name, LPTSTR value, UInt32 &count)
|
||||
{
|
||||
MYASSERT(count != NULL);
|
||||
DWORD type = NULL;
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)valueName, NULL, &type,
|
||||
(LPBYTE)value, (DWORD *)&count);
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (type == REG_SZ) ||
|
||||
(type == REG_MULTI_SZ) || (type == REG_EXPAND_SZ));
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (type == REG_SZ) || (type == REG_MULTI_SZ) || (type == REG_EXPAND_SZ));
|
||||
return res;
|
||||
}
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, CSysString &value)
|
||||
LONG CKey::QueryValue(LPCTSTR name, CSysString &value)
|
||||
{
|
||||
value.Empty();
|
||||
DWORD type = NULL;
|
||||
UINT32 currentSize = 0;
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)valueName, NULL, &type,
|
||||
NULL, (DWORD *)¤tSize);
|
||||
UInt32 currentSize = 0;
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, NULL, (DWORD *)¤tSize);
|
||||
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
|
||||
return res;
|
||||
res = QueryValue(valueName, value.GetBuffer(currentSize), currentSize);
|
||||
res = QueryValue(name, value.GetBuffer(currentSize), currentSize);
|
||||
value.ReleaseBuffer();
|
||||
return res;
|
||||
}
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, void *value, UINT32 &count)
|
||||
#ifndef _UNICODE
|
||||
LONG CKey::QueryValue(LPCWSTR name, LPWSTR value, UInt32 &count)
|
||||
{
|
||||
MYASSERT(count != NULL);
|
||||
DWORD type = NULL;
|
||||
LONG res = RegQueryValueExW(_object, name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (type == REG_SZ) || (type == REG_MULTI_SZ) || (type == REG_EXPAND_SZ));
|
||||
return res;
|
||||
}
|
||||
LONG CKey::QueryValue(LPCWSTR name, UString &value)
|
||||
{
|
||||
value.Empty();
|
||||
DWORD type = NULL;
|
||||
UInt32 currentSize = 0;
|
||||
|
||||
LONG res;
|
||||
if (g_IsNT)
|
||||
{
|
||||
res = RegQueryValueExW(_object, name, NULL, &type, NULL, (DWORD *)¤tSize);
|
||||
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
|
||||
return res;
|
||||
res = QueryValue(name, value.GetBuffer(currentSize), currentSize);
|
||||
value.ReleaseBuffer();
|
||||
}
|
||||
else
|
||||
{
|
||||
AString vTemp;
|
||||
res = QueryValue(name == 0 ? 0 : (LPCSTR)GetSystemString(name), vTemp);
|
||||
value = GetUnicodeString(vTemp);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
#endif
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR name, void *value, UInt32 &count)
|
||||
{
|
||||
DWORD type = NULL;
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)valueName, NULL, &type,
|
||||
(LPBYTE)value, (DWORD *)&count);
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, (LPBYTE)value, (DWORD *)&count);
|
||||
MYASSERT((res!=ERROR_SUCCESS) || (type == REG_BINARY));
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
LONG CKey::QueryValue(LPCTSTR valueName, CByteBuffer &value, UINT32 &dataSize)
|
||||
LONG CKey::QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize)
|
||||
{
|
||||
DWORD type = NULL;
|
||||
dataSize = 0;
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)valueName, NULL, &type,
|
||||
NULL, (DWORD *)&dataSize);
|
||||
LONG res = RegQueryValueEx(_object, (LPTSTR)name, NULL, &type, NULL, (DWORD *)&dataSize);
|
||||
if (res != ERROR_SUCCESS && res != ERROR_MORE_DATA)
|
||||
return res;
|
||||
value.SetCapacity(dataSize);
|
||||
return QueryValue(valueName, (BYTE *)value, dataSize);
|
||||
return QueryValue(name, (BYTE *)value, dataSize);
|
||||
}
|
||||
|
||||
LONG CKey::EnumKeys(CSysStringVector &keyNames)
|
||||
{
|
||||
keyNames.Clear();
|
||||
CSysString keyName;
|
||||
for(UINT32 index = 0; true; index++)
|
||||
for(UInt32 index = 0; true; index++)
|
||||
{
|
||||
const UINT32 kBufferSize = MAX_PATH + 1; // 256 in ATL
|
||||
const UInt32 kBufferSize = MAX_PATH + 1; // 256 in ATL
|
||||
FILETIME lastWriteTime;
|
||||
UINT32 aNameSize = kBufferSize;
|
||||
LONG aResult = ::RegEnumKeyEx(_object, index, keyName.GetBuffer(kBufferSize),
|
||||
(DWORD *)&aNameSize, NULL, NULL, NULL, &lastWriteTime);
|
||||
UInt32 nameSize = kBufferSize;
|
||||
LONG result = ::RegEnumKeyEx(_object, index, keyName.GetBuffer(kBufferSize),
|
||||
(DWORD *)&nameSize, NULL, NULL, NULL, &lastWriteTime);
|
||||
keyName.ReleaseBuffer();
|
||||
if(aResult == ERROR_NO_MORE_ITEMS)
|
||||
if(result == ERROR_NO_MORE_ITEMS)
|
||||
break;
|
||||
if(aResult != ERROR_SUCCESS)
|
||||
return aResult;
|
||||
if(result != ERROR_SUCCESS)
|
||||
return result;
|
||||
keyNames.Add(keyName);
|
||||
}
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
}}
|
||||
|
||||
@@ -5,14 +5,14 @@
|
||||
|
||||
#include "Common/Buffer.h"
|
||||
#include "Common/String.h"
|
||||
#include "Common/Types.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NRegistry {
|
||||
|
||||
const TCHAR kKeyNameDelimiter = TEXT('\\');
|
||||
|
||||
LONG SetValue(HKEY parentKey, LPCTSTR keyName,
|
||||
LPCTSTR valueName, LPCTSTR value);
|
||||
LONG SetValue(HKEY parentKey, LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value);
|
||||
|
||||
class CKey
|
||||
{
|
||||
@@ -38,22 +38,36 @@ public:
|
||||
LONG DeleteSubKey(LPCTSTR subKeyName);
|
||||
LONG RecurseDeleteKey(LPCTSTR subKeyName);
|
||||
|
||||
LONG DeleteValue(LPCTSTR value);
|
||||
LONG SetValue(LPCTSTR valueName, UINT32 value);
|
||||
LONG DeleteValue(LPCTSTR name);
|
||||
#ifndef _UNICODE
|
||||
LONG DeleteValue(LPCWSTR name);
|
||||
#endif
|
||||
|
||||
LONG SetValue(LPCTSTR valueName, UInt32 value);
|
||||
LONG SetValue(LPCTSTR valueName, bool value);
|
||||
LONG SetValue(LPCTSTR valueName, LPCTSTR value);
|
||||
LONG SetValue(LPCTSTR valueName, const CSysString &value);
|
||||
LONG SetValue(LPCTSTR valueName, const void *value, UINT32 size);
|
||||
// LONG SetValue(LPCTSTR valueName, const CSysString &value);
|
||||
#ifndef _UNICODE
|
||||
LONG SetValue(LPCWSTR name, LPCWSTR value);
|
||||
// LONG SetValue(LPCWSTR name, const UString &value);
|
||||
#endif
|
||||
|
||||
LONG SetValue(LPCTSTR name, const void *value, UInt32 size);
|
||||
|
||||
LONG SetKeyValue(LPCTSTR keyName, LPCTSTR valueName, LPCTSTR value);
|
||||
|
||||
LONG QueryValue(LPCTSTR valueName, UINT32 &value);
|
||||
LONG QueryValue(LPCTSTR valueName, bool &value);
|
||||
LONG QueryValue(LPCTSTR valueName, LPTSTR value, UINT32 &dataSize);
|
||||
LONG QueryValue(LPCTSTR valueName, CSysString &value);
|
||||
LONG QueryValue(LPCTSTR name, UInt32 &value);
|
||||
LONG QueryValue(LPCTSTR name, bool &value);
|
||||
LONG QueryValue(LPCTSTR name, LPTSTR value, UInt32 &dataSize);
|
||||
LONG QueryValue(LPCTSTR name, CSysString &value);
|
||||
|
||||
LONG QueryValue(LPCTSTR valueName, void *value, UINT32 &dataSize);
|
||||
LONG QueryValue(LPCTSTR valueName, CByteBuffer &value, UINT32 &dataSize);
|
||||
#ifndef _UNICODE
|
||||
LONG QueryValue(LPCWSTR name, LPWSTR value, UInt32 &dataSize);
|
||||
LONG QueryValue(LPCWSTR name, UString &value);
|
||||
#endif
|
||||
|
||||
LONG QueryValue(LPCTSTR name, void *value, UInt32 &dataSize);
|
||||
LONG QueryValue(LPCTSTR name, CByteBuffer &value, UInt32 &dataSize);
|
||||
|
||||
LONG EnumKeys(CSysStringVector &keyNames);
|
||||
};
|
||||
|
||||
@@ -8,6 +8,9 @@
|
||||
#endif
|
||||
|
||||
extern HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
@@ -20,7 +23,8 @@ CSysString MyLoadString(UINT resourceID)
|
||||
{
|
||||
size += 256;
|
||||
len = ::LoadString(g_hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
} while (size - len <= 1);
|
||||
}
|
||||
while (size - len <= 1);
|
||||
s.ReleaseBuffer();
|
||||
return s;
|
||||
}
|
||||
@@ -28,23 +32,22 @@ CSysString MyLoadString(UINT resourceID)
|
||||
#ifndef _UNICODE
|
||||
UString MyLoadStringW(UINT resourceID)
|
||||
{
|
||||
UString s;
|
||||
int size = 256;
|
||||
int len;
|
||||
do
|
||||
if (g_IsNT)
|
||||
{
|
||||
size += 256;
|
||||
len = ::LoadStringW(g_hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
if (len == 0)
|
||||
UString s;
|
||||
int size = 256;
|
||||
int len;
|
||||
do
|
||||
{
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
break;
|
||||
return GetUnicodeString(MyLoadString(resourceID));
|
||||
}
|
||||
} while (size - len <= 1);
|
||||
s.ReleaseBuffer();
|
||||
return s;
|
||||
size += 256;
|
||||
len = ::LoadStringW(g_hInstance, resourceID, s.GetBuffer(size - 1), size);
|
||||
}
|
||||
while (size - len <= 1);
|
||||
s.ReleaseBuffer();
|
||||
return s;
|
||||
}
|
||||
return GetUnicodeString(MyLoadString(resourceID));
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
181
Windows/Security.cpp
Executable file
181
Windows/Security.cpp
Executable file
@@ -0,0 +1,181 @@
|
||||
// Windows/Security.h
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Windows/Security.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
#include "Common/StringConvert.h"
|
||||
#include "Defs.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NSecurity {
|
||||
|
||||
/*
|
||||
bool MyLookupAccountSid(LPCTSTR systemName, PSID sid,
|
||||
CSysString &accountName, CSysString &domainName, PSID_NAME_USE sidNameUse)
|
||||
{
|
||||
DWORD accountNameSize = 0, domainNameSize = 0;
|
||||
|
||||
if (!::LookupAccountSid(systemName, sid,
|
||||
accountName.GetBuffer(0), &accountNameSize,
|
||||
domainName.GetBuffer(0), &domainNameSize, sidNameUse))
|
||||
{
|
||||
if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER)
|
||||
return false;
|
||||
}
|
||||
bool result = BOOLToBool(::LookupAccountSid(systemName, sid,
|
||||
accountName.GetBuffer(accountNameSize), &accountNameSize,
|
||||
domainName.GetBuffer(domainNameSize), &domainNameSize, sidNameUse));
|
||||
accountName.ReleaseBuffer();
|
||||
domainName.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
*/
|
||||
|
||||
static void SetLsaString(LPWSTR src, PLSA_UNICODE_STRING dest)
|
||||
{
|
||||
int len = wcslen(src);
|
||||
dest->Length = len * sizeof(WCHAR);
|
||||
dest->MaximumLength = (len + 1) * sizeof(WCHAR);
|
||||
dest->Buffer = src;
|
||||
}
|
||||
|
||||
/*
|
||||
static void MyLookupSids(CPolicy &policy, PSID ps)
|
||||
{
|
||||
LSA_REFERENCED_DOMAIN_LIST *referencedDomains = NULL;
|
||||
LSA_TRANSLATED_NAME *names = NULL;
|
||||
NTSTATUS nts = policy.LookupSids(1, &ps, &referencedDomains, &names);
|
||||
int res = LsaNtStatusToWinError(nts);
|
||||
LsaFreeMemory(referencedDomains);
|
||||
LsaFreeMemory(names);
|
||||
}
|
||||
*/
|
||||
|
||||
#ifndef _UNICODE
|
||||
typedef BOOL (WINAPI * LookupAccountNameWP)(
|
||||
LPCWSTR lpSystemName,
|
||||
LPCWSTR lpAccountName,
|
||||
PSID Sid,
|
||||
LPDWORD cbSid,
|
||||
LPWSTR ReferencedDomainName,
|
||||
LPDWORD cchReferencedDomainName,
|
||||
PSID_NAME_USE peUse
|
||||
);
|
||||
#endif
|
||||
|
||||
static PSID GetSid(LPWSTR accountName)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
HMODULE hModule = GetModuleHandle(TEXT("Advapi32.dll"));
|
||||
if (hModule == NULL)
|
||||
return NULL;
|
||||
LookupAccountNameWP lookupAccountNameW = (LookupAccountNameWP)GetProcAddress(hModule, "LookupAccountNameW");
|
||||
if (lookupAccountNameW == NULL)
|
||||
return NULL;
|
||||
#endif
|
||||
|
||||
DWORD sidLen = 0, domainLen = 0;
|
||||
SID_NAME_USE sidNameUse;
|
||||
if (!
|
||||
#ifdef _UNICODE
|
||||
::LookupAccountNameW
|
||||
#else
|
||||
lookupAccountNameW
|
||||
#endif
|
||||
(NULL, accountName, NULL, &sidLen, NULL, &domainLen, &sidNameUse))
|
||||
{
|
||||
if(::GetLastError() == ERROR_INSUFFICIENT_BUFFER)
|
||||
{
|
||||
PSID pSid = ::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sidLen);
|
||||
LPWSTR domainName = (LPWSTR)::HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, (domainLen + 1) * sizeof(WCHAR));
|
||||
BOOL res =
|
||||
#ifdef _UNICODE
|
||||
::LookupAccountNameW
|
||||
#else
|
||||
lookupAccountNameW
|
||||
#endif
|
||||
(NULL, accountName, pSid, &sidLen, domainName, &domainLen, &sidNameUse);
|
||||
::HeapFree(GetProcessHeap(), 0, domainName);
|
||||
if (res)
|
||||
return pSid;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
bool AddLockMemoryPrivilege()
|
||||
{
|
||||
CPolicy policy;
|
||||
LSA_OBJECT_ATTRIBUTES attr;
|
||||
attr.Length = sizeof(attr);
|
||||
attr.RootDirectory = NULL;
|
||||
attr.ObjectName = NULL;
|
||||
attr.Attributes = 0;
|
||||
attr.SecurityDescriptor = NULL;
|
||||
attr.SecurityQualityOfService = NULL;
|
||||
if (policy.Open(NULL, &attr,
|
||||
// GENERIC_WRITE)
|
||||
POLICY_ALL_ACCESS)
|
||||
// STANDARD_RIGHTS_REQUIRED,
|
||||
// GENERIC_READ | GENERIC_EXECUTE | POLICY_VIEW_LOCAL_INFORMATION | POLICY_LOOKUP_NAMES)
|
||||
!= 0)
|
||||
return false;
|
||||
LSA_UNICODE_STRING userRights;
|
||||
UString s = GetUnicodeString(SE_LOCK_MEMORY_NAME);
|
||||
SetLsaString((LPWSTR)(LPCWSTR)s, &userRights);
|
||||
WCHAR userName[256 + 2];
|
||||
DWORD size = 256;
|
||||
if (!GetUserNameW(userName, &size))
|
||||
return false;
|
||||
PSID psid = GetSid(userName);
|
||||
if (psid == NULL)
|
||||
return false;
|
||||
bool res = false;
|
||||
|
||||
/*
|
||||
PLSA_UNICODE_STRING userRightsArray;
|
||||
ULONG countOfRights;
|
||||
NTSTATUS status = policy.EnumerateAccountRights(psid, &userRightsArray, &countOfRights);
|
||||
if (status != 0)
|
||||
return false;
|
||||
bool finded = false;
|
||||
for (ULONG i = 0; i < countOfRights; i++)
|
||||
{
|
||||
LSA_UNICODE_STRING &ur = userRightsArray[i];
|
||||
if (ur.Length != s.Length() * sizeof(WCHAR))
|
||||
continue;
|
||||
if (wcsncmp(ur.Buffer, s, s.Length()) != 0)
|
||||
continue;
|
||||
finded = true;
|
||||
res = true;
|
||||
break;
|
||||
}
|
||||
if (!finded)
|
||||
*/
|
||||
{
|
||||
/*
|
||||
LSA_ENUMERATION_INFORMATION *enums;
|
||||
ULONG countReturned;
|
||||
NTSTATUS status = policy.EnumerateAccountsWithUserRight(&userRights, &enums, &countReturned);
|
||||
if (status == 0)
|
||||
{
|
||||
for (ULONG i = 0; i < countReturned; i++)
|
||||
MyLookupSids(policy, enums[i].Sid);
|
||||
if (enums)
|
||||
::LsaFreeMemory(enums);
|
||||
res = true;
|
||||
}
|
||||
*/
|
||||
NTSTATUS status = policy.AddAccountRights(psid, &userRights);
|
||||
if (status == 0)
|
||||
res = true;
|
||||
// ULONG res = LsaNtStatusToWinError(status);
|
||||
}
|
||||
HeapFree(GetProcessHeap(), 0, psid);
|
||||
return res;
|
||||
}
|
||||
|
||||
}}
|
||||
|
||||
168
Windows/Security.h
Executable file
168
Windows/Security.h
Executable file
@@ -0,0 +1,168 @@
|
||||
// Windows/Security.h
|
||||
|
||||
#ifndef __WINDOWS_SECURITY_H
|
||||
#define __WINDOWS_SECURITY_H
|
||||
|
||||
#include "Common/String.h"
|
||||
#include "Windows/Defs.h"
|
||||
|
||||
#include <NTSecAPI.h>
|
||||
|
||||
namespace NWindows {
|
||||
namespace NSecurity {
|
||||
|
||||
class CAccessToken
|
||||
{
|
||||
HANDLE _handle;
|
||||
public:
|
||||
CAccessToken(): _handle(NULL) {};
|
||||
~CAccessToken() { Close(); }
|
||||
bool Close()
|
||||
{
|
||||
if (_handle == NULL)
|
||||
return true;
|
||||
bool res = BOOLToBool(::CloseHandle(_handle));
|
||||
if (res)
|
||||
_handle = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool OpenProcessToken(HANDLE processHandle, DWORD desiredAccess)
|
||||
{
|
||||
Close();
|
||||
return BOOLToBool(::OpenProcessToken(processHandle, desiredAccess, &_handle));
|
||||
}
|
||||
|
||||
/*
|
||||
bool OpenThreadToken(HANDLE threadHandle, DWORD desiredAccess, bool openAsSelf)
|
||||
{
|
||||
Close();
|
||||
return BOOLToBool(::OpenTreadToken(threadHandle, desiredAccess, BoolToBOOL(anOpenAsSelf), &_handle));
|
||||
}
|
||||
*/
|
||||
|
||||
bool AdjustPrivileges(bool disableAllPrivileges, PTOKEN_PRIVILEGES newState,
|
||||
DWORD bufferLength, PTOKEN_PRIVILEGES previousState, PDWORD returnLength)
|
||||
{ return BOOLToBool(::AdjustTokenPrivileges(_handle, BoolToBOOL(disableAllPrivileges),
|
||||
newState, bufferLength, previousState, returnLength)); }
|
||||
|
||||
bool AdjustPrivileges(bool disableAllPrivileges, PTOKEN_PRIVILEGES newState)
|
||||
{ return AdjustPrivileges(disableAllPrivileges, newState, 0, NULL, NULL); }
|
||||
|
||||
bool AdjustPrivileges(PTOKEN_PRIVILEGES newState)
|
||||
{ return AdjustPrivileges(false, newState); }
|
||||
|
||||
};
|
||||
|
||||
#ifndef _UNICODE
|
||||
typedef NTSTATUS (NTAPI *LsaOpenPolicyP)(PLSA_UNICODE_STRING SystemName,
|
||||
PLSA_OBJECT_ATTRIBUTES ObjectAttributes, ACCESS_MASK DesiredAccess, PLSA_HANDLE PolicyHandle);
|
||||
typedef NTSTATUS (NTAPI *LsaCloseP)(LSA_HANDLE ObjectHandle);
|
||||
typedef NTSTATUS (NTAPI *LsaAddAccountRightsP)(LSA_HANDLE PolicyHandle,
|
||||
PSID AccountSid, PLSA_UNICODE_STRING UserRights, ULONG CountOfRights );
|
||||
#define MY_STATUS_NOT_IMPLEMENTED ((NTSTATUS)0xC0000002L)
|
||||
#endif
|
||||
|
||||
struct CPolicy
|
||||
{
|
||||
protected:
|
||||
LSA_HANDLE _handle;
|
||||
#ifndef _UNICODE
|
||||
HMODULE hModule;
|
||||
#endif
|
||||
public:
|
||||
operator LSA_HANDLE() const { return _handle; }
|
||||
CPolicy(): _handle(NULL)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
hModule = GetModuleHandle(TEXT("Advapi32.dll"));
|
||||
#endif
|
||||
};
|
||||
~CPolicy() { Close(); }
|
||||
|
||||
NTSTATUS Open(PLSA_UNICODE_STRING systemName, PLSA_OBJECT_ATTRIBUTES objectAttributes,
|
||||
ACCESS_MASK desiredAccess)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (hModule == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
LsaOpenPolicyP lsaOpenPolicy = (LsaOpenPolicyP)GetProcAddress(hModule, "LsaOpenPolicy");
|
||||
if (lsaOpenPolicy == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
Close();
|
||||
return
|
||||
#ifdef _UNICODE
|
||||
::LsaOpenPolicy
|
||||
#else
|
||||
lsaOpenPolicy
|
||||
#endif
|
||||
(systemName, objectAttributes, desiredAccess, &_handle);
|
||||
}
|
||||
|
||||
NTSTATUS Close()
|
||||
{
|
||||
if (_handle == NULL)
|
||||
return 0;
|
||||
|
||||
#ifndef _UNICODE
|
||||
if (hModule == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
LsaCloseP lsaClose = (LsaCloseP)GetProcAddress(hModule, "LsaClose");
|
||||
if (lsaClose == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
NTSTATUS res =
|
||||
#ifdef _UNICODE
|
||||
::LsaClose
|
||||
#else
|
||||
lsaClose
|
||||
#endif
|
||||
(_handle);
|
||||
_handle = NULL;
|
||||
return res;
|
||||
}
|
||||
|
||||
NTSTATUS EnumerateAccountsWithUserRight(PLSA_UNICODE_STRING userRights,
|
||||
PLSA_ENUMERATION_INFORMATION *enumerationBuffer, PULONG countReturned)
|
||||
{ return LsaEnumerateAccountsWithUserRight(_handle, userRights, (void **)enumerationBuffer, countReturned); }
|
||||
|
||||
NTSTATUS EnumerateAccountRights(PSID sid, PLSA_UNICODE_STRING* userRights, PULONG countOfRights)
|
||||
{ return ::LsaEnumerateAccountRights(_handle, sid, userRights, countOfRights); }
|
||||
|
||||
NTSTATUS LookupSids(ULONG count, PSID* sids,
|
||||
PLSA_REFERENCED_DOMAIN_LIST* referencedDomains, PLSA_TRANSLATED_NAME* names)
|
||||
{ return LsaLookupSids(_handle, count, sids, referencedDomains, names); }
|
||||
|
||||
NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights, ULONG countOfRights)
|
||||
{
|
||||
#ifndef _UNICODE
|
||||
if (hModule == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
LsaAddAccountRightsP lsaAddAccountRights = (LsaAddAccountRightsP)GetProcAddress(hModule, "LsaAddAccountRights");
|
||||
if (lsaAddAccountRights == NULL)
|
||||
return MY_STATUS_NOT_IMPLEMENTED;
|
||||
#endif
|
||||
|
||||
return
|
||||
#ifdef _UNICODE
|
||||
::LsaAddAccountRights
|
||||
#else
|
||||
lsaAddAccountRights
|
||||
#endif
|
||||
(_handle, accountSid, userRights, countOfRights);
|
||||
}
|
||||
NTSTATUS AddAccountRights(PSID accountSid, PLSA_UNICODE_STRING userRights)
|
||||
{ return AddAccountRights(accountSid, userRights, 1); }
|
||||
|
||||
NTSTATUS RemoveAccountRights(PSID accountSid, bool allRights, PLSA_UNICODE_STRING userRights, ULONG countOfRights)
|
||||
{ return LsaRemoveAccountRights(_handle, accountSid, BoolToBOOL(allRights), userRights, countOfRights); }
|
||||
};
|
||||
|
||||
bool AddLockMemoryPrivilege();
|
||||
|
||||
}}
|
||||
|
||||
#endif
|
||||
@@ -2,10 +2,17 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Common/MyCom.h"
|
||||
#include "Windows/Shell.h"
|
||||
#include "Windows/COM.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
namespace NShell {
|
||||
|
||||
@@ -77,26 +84,34 @@ CDrop::~CDrop()
|
||||
Free();
|
||||
}
|
||||
|
||||
UINT CDrop::QueryFile(UINT fileIndex, LPTSTR fileName, UINT fileNameSize)
|
||||
{
|
||||
return ::DragQueryFile(m_Object, fileIndex, fileName, fileNameSize);
|
||||
}
|
||||
|
||||
UINT CDrop::QueryCountOfFiles()
|
||||
{
|
||||
return QueryFile(0xFFFFFFFF, NULL, 0);
|
||||
return QueryFile(0xFFFFFFFF, (LPTSTR)NULL, 0);
|
||||
}
|
||||
|
||||
CSysString CDrop::QueryFileName(UINT fileIndex)
|
||||
UString CDrop::QueryFileName(UINT fileIndex)
|
||||
{
|
||||
CSysString fileName;
|
||||
UINT bufferSize = QueryFile(fileIndex, NULL, 0);
|
||||
QueryFile(fileIndex, fileName.GetBuffer(bufferSize), bufferSize + 1);
|
||||
fileName.ReleaseBuffer();
|
||||
UString fileName;
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
AString fileNameA;
|
||||
UINT bufferSize = QueryFile(fileIndex, (LPTSTR)NULL, 0);
|
||||
QueryFile(fileIndex, fileNameA.GetBuffer(bufferSize + 2), bufferSize + 1);
|
||||
fileNameA.ReleaseBuffer();
|
||||
fileName = GetUnicodeString(fileNameA);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
UINT bufferSize = QueryFile(fileIndex, (LPWSTR)NULL, 0);
|
||||
QueryFile(fileIndex, fileName.GetBuffer(bufferSize + 2), bufferSize + 1);
|
||||
fileName.ReleaseBuffer();
|
||||
}
|
||||
return fileName;
|
||||
}
|
||||
|
||||
void CDrop::QueryFileNames(CSysStringVector &fileNames)
|
||||
void CDrop::QueryFileNames(UStringVector &fileNames)
|
||||
{
|
||||
fileNames.Clear();
|
||||
UINT numFiles = QueryCountOfFiles();
|
||||
@@ -111,8 +126,7 @@ void CDrop::QueryFileNames(CSysStringVector &fileNames)
|
||||
|
||||
bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path)
|
||||
{
|
||||
bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList,
|
||||
path.GetBuffer(MAX_PATH)));
|
||||
bool result = BOOLToBool(::SHGetPathFromIDList(itemIDList, path.GetBuffer(MAX_PATH * 2)));
|
||||
path.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
@@ -177,4 +191,80 @@ bool BrowseForFolder(HWND owner, LPCTSTR title,
|
||||
// BIF_STATUSTEXT; BIF_USENEWUI (Version 5.0)
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
|
||||
bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path)
|
||||
{
|
||||
bool result = BOOLToBool(::SHGetPathFromIDListW(itemIDList, path.GetBuffer(MAX_PATH * 2)));
|
||||
path.ReleaseBuffer();
|
||||
return result;
|
||||
}
|
||||
|
||||
bool BrowseForFolder(LPBROWSEINFOW browseInfo, UString &resultPath)
|
||||
{
|
||||
NWindows::NCOM::CComInitializer comInitializer;
|
||||
LPITEMIDLIST itemIDList = ::SHBrowseForFolderW(browseInfo);
|
||||
if (itemIDList == NULL)
|
||||
return false;
|
||||
CItemIDList itemIDListHolder;
|
||||
itemIDListHolder.Attach(itemIDList);
|
||||
return GetPathFromIDList(itemIDList, resultPath);
|
||||
}
|
||||
|
||||
|
||||
int CALLBACK BrowseCallbackProc2(HWND hwnd, UINT uMsg, LPARAM lp, LPARAM data)
|
||||
{
|
||||
switch(uMsg)
|
||||
{
|
||||
case BFFM_INITIALIZED:
|
||||
{
|
||||
SendMessageW(hwnd, BFFM_SETSELECTIONW, TRUE, data);
|
||||
break;
|
||||
}
|
||||
case BFFM_SELCHANGED:
|
||||
{
|
||||
wchar_t dir[MAX_PATH * 2];
|
||||
if (::SHGetPathFromIDListW((LPITEMIDLIST) lp , dir))
|
||||
SendMessageW(hwnd, BFFM_SETSTATUSTEXTW, 0, (LPARAM)dir);
|
||||
else
|
||||
SendMessageW(hwnd, BFFM_SETSTATUSTEXTW, 0, (LPARAM)L"");
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static bool BrowseForFolder(HWND owner, LPCWSTR title, UINT ulFlags,
|
||||
LPCWSTR initialFolder, UString &resultPath)
|
||||
{
|
||||
UString displayName;
|
||||
BROWSEINFOW browseInfo;
|
||||
browseInfo.hwndOwner = owner;
|
||||
browseInfo.pidlRoot = NULL;
|
||||
browseInfo.pszDisplayName = displayName.GetBuffer(MAX_PATH);
|
||||
browseInfo.lpszTitle = title;
|
||||
browseInfo.ulFlags = ulFlags;
|
||||
browseInfo.lpfn = (initialFolder != NULL) ? BrowseCallbackProc2 : NULL;
|
||||
browseInfo.lParam = (LPARAM)initialFolder;
|
||||
return BrowseForFolder(&browseInfo, resultPath);
|
||||
}
|
||||
|
||||
bool BrowseForFolder(HWND owner, LPCWSTR title, LPCWSTR initialFolder, UString &resultPath)
|
||||
{
|
||||
if (g_IsNT)
|
||||
return BrowseForFolder(owner, title,
|
||||
BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT, initialFolder, resultPath);
|
||||
// BIF_STATUSTEXT; BIF_USENEWUI (Version 5.0)
|
||||
CSysString s;
|
||||
bool res = BrowseForFolder(owner, GetSystemString(title),
|
||||
BIF_NEWDIALOGSTYLE | BIF_RETURNONLYFSDIRS | BIF_STATUSTEXT, GetSystemString(initialFolder), s);
|
||||
resultPath = GetUnicodeString(s);
|
||||
return res;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
}}
|
||||
|
||||
@@ -63,21 +63,29 @@ public:
|
||||
bool QueryPoint(LPPOINT point)
|
||||
{ return BOOLToBool(::DragQueryPoint(m_Object, point)); }
|
||||
void Finish() { ::DragFinish(m_Object); }
|
||||
UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT fileNameSize);
|
||||
UINT QueryFile(UINT fileIndex, LPTSTR fileName, UINT fileNameSize)
|
||||
{ return ::DragQueryFile(m_Object, fileIndex, fileName, fileNameSize); }
|
||||
#ifndef _UNICODE
|
||||
UINT QueryFile(UINT fileIndex, LPWSTR fileName, UINT fileNameSize)
|
||||
{ return ::DragQueryFileW(m_Object, fileIndex, fileName, fileNameSize); }
|
||||
#endif
|
||||
UINT QueryCountOfFiles();
|
||||
CSysString QueryFileName(UINT fileIndex);
|
||||
void QueryFileNames(CSysStringVector &fileNames);
|
||||
UString QueryFileName(UINT fileIndex);
|
||||
void QueryFileNames(UStringVector &fileNames);
|
||||
};
|
||||
|
||||
/////////////////////////////
|
||||
// Functions
|
||||
|
||||
bool GetPathFromIDList(LPCITEMIDLIST itemIDList, CSysString &path);
|
||||
|
||||
bool BrowseForFolder(LPBROWSEINFO lpbi, CSysString &resultPath);
|
||||
bool BrowseForFolder(HWND owner, LPCTSTR title,
|
||||
LPCTSTR initialFolder, CSysString &resultPath);
|
||||
bool BrowseForFolder(HWND owner, LPCTSTR title, LPCTSTR initialFolder, CSysString &resultPath);
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool GetPathFromIDList(LPCITEMIDLIST itemIDList, UString &path);
|
||||
bool BrowseForFolder(LPBROWSEINFO lpbi, UString &resultPath);
|
||||
bool BrowseForFolder(HWND owner, LPCWSTR title, LPCWSTR initialFolder, UString &resultPath);
|
||||
#endif
|
||||
}}
|
||||
|
||||
|
||||
|
||||
@@ -2,24 +2,115 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Windows/Window.h"
|
||||
#ifndef _UNICODE
|
||||
#include "Common/StringConvert.h"
|
||||
#endif
|
||||
#include "Windows/Window.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CWindow::SetText(LPCWSTR s)
|
||||
{
|
||||
if (::SetWindowTextW(_window, s))
|
||||
return true;
|
||||
if (::GetLastError() != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
return SetText(UnicodeStringToMultiByte(s));
|
||||
ATOM MyRegisterClass(CONST WNDCLASSW *wndClass)
|
||||
{
|
||||
if (g_IsNT)
|
||||
return RegisterClassW(wndClass);
|
||||
WNDCLASSA wndClassA;
|
||||
wndClassA.style = wndClass->style;
|
||||
wndClassA.lpfnWndProc = wndClass->lpfnWndProc;
|
||||
wndClassA.cbClsExtra = wndClass->cbClsExtra;
|
||||
wndClassA.cbWndExtra = wndClass->cbWndExtra;
|
||||
wndClassA.hInstance = wndClass->hInstance;
|
||||
wndClassA.hIcon = wndClass->hIcon;
|
||||
wndClassA.hCursor = wndClass->hCursor;
|
||||
wndClassA.hbrBackground = wndClass->hbrBackground;
|
||||
AString menuName;
|
||||
AString className;
|
||||
if (IS_INTRESOURCE(wndClass->lpszMenuName))
|
||||
wndClassA.lpszMenuName = (LPCSTR)wndClass->lpszMenuName;
|
||||
else
|
||||
{
|
||||
menuName = GetSystemString(wndClass->lpszMenuName);
|
||||
wndClassA.lpszMenuName = menuName;
|
||||
}
|
||||
if (IS_INTRESOURCE(wndClass->lpszClassName))
|
||||
wndClassA.lpszClassName = (LPCSTR)wndClass->lpszClassName;
|
||||
else
|
||||
{
|
||||
className = GetSystemString(wndClass->lpszClassName);
|
||||
wndClassA.lpszClassName = className;
|
||||
}
|
||||
return RegisterClassA(&wndClassA);
|
||||
}
|
||||
|
||||
bool CWindow::Create(LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
_window = ::CreateWindowW(className, windowName,
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, createParam);
|
||||
return (_window != NULL);
|
||||
}
|
||||
return Create(GetSystemString(className), GetSystemString(windowName),
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, createParam);
|
||||
}
|
||||
|
||||
bool CWindow::CreateEx(DWORD exStyle, LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
_window = ::CreateWindowExW(exStyle, className, windowName,
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, createParam);
|
||||
return (_window != NULL);
|
||||
}
|
||||
AString classNameA;
|
||||
LPCSTR classNameP;
|
||||
if (IS_INTRESOURCE(className))
|
||||
classNameP = (LPCSTR)className;
|
||||
else
|
||||
{
|
||||
classNameA = GetSystemString(className);
|
||||
classNameP = classNameA;
|
||||
}
|
||||
AString windowNameA;
|
||||
LPCSTR windowNameP;
|
||||
if (IS_INTRESOURCE(windowName))
|
||||
windowNameP = (LPCSTR)windowName;
|
||||
else
|
||||
{
|
||||
windowNameA = GetSystemString(windowName);
|
||||
windowNameP = windowNameA;
|
||||
}
|
||||
return CreateEx(exStyle, classNameP, windowNameP,
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, createParam);
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool MySetWindowText(HWND wnd, LPCWSTR s)
|
||||
{
|
||||
if (g_IsNT)
|
||||
return BOOLToBool(::SetWindowTextW(wnd, s));
|
||||
return BOOLToBool(::SetWindowTextA(wnd, UnicodeStringToMultiByte(s)));
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CWindow::GetText(CSysString &s)
|
||||
{
|
||||
s.Empty();
|
||||
@@ -36,28 +127,26 @@ bool CWindow::GetText(CSysString &s)
|
||||
#ifndef _UNICODE
|
||||
bool CWindow::GetText(UString &s)
|
||||
{
|
||||
s.Empty();
|
||||
int length = GetWindowTextLengthW(_window);
|
||||
if (length == 0)
|
||||
if (g_IsNT)
|
||||
{
|
||||
UINT lastError = ::GetLastError();
|
||||
if (lastError == ERROR_SUCCESS)
|
||||
return true;
|
||||
if (lastError != ERROR_CALL_NOT_IMPLEMENTED)
|
||||
return false;
|
||||
CSysString sysString;
|
||||
bool result = GetText(sysString);
|
||||
s = GetUnicodeString(sysString);
|
||||
return result;
|
||||
s.Empty();
|
||||
int length = GetWindowTextLengthW(_window);
|
||||
if (length == 0)
|
||||
return (::GetLastError() == ERROR_SUCCESS);
|
||||
length = GetWindowTextW(_window, s.GetBuffer(length), length + 1);
|
||||
s.ReleaseBuffer();
|
||||
if (length == 0)
|
||||
return (::GetLastError() == ERROR_SUCCESS);
|
||||
return true;
|
||||
}
|
||||
length = GetWindowTextW(_window, s.GetBuffer(length), length + 1);
|
||||
s.ReleaseBuffer();
|
||||
if (length == 0)
|
||||
return (::GetLastError() == ERROR_SUCCESS);
|
||||
return true;
|
||||
CSysString sysString;
|
||||
bool result = GetText(sysString);
|
||||
s = GetUnicodeString(sysString);
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
/*
|
||||
bool CWindow::ModifyStyleBase(int styleOffset,
|
||||
DWORD remove, DWORD add, UINT flags)
|
||||
|
||||
109
Windows/Window.h
109
Windows/Window.h
@@ -8,6 +8,21 @@
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
inline ATOM MyRegisterClass(CONST WNDCLASS *wndClass)
|
||||
{ return ::RegisterClass(wndClass); }
|
||||
|
||||
#ifndef _UNICODE
|
||||
ATOM MyRegisterClass(CONST WNDCLASSW *wndClass);
|
||||
#endif
|
||||
|
||||
#ifdef _UNICODE
|
||||
inline bool MySetWindowText(HWND wnd, LPCWSTR s) { return BOOLToBool(::SetWindowText(wnd, s)); }
|
||||
#else
|
||||
bool MySetWindowText(HWND wnd, LPCWSTR s);
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
class CWindow
|
||||
{
|
||||
private:
|
||||
@@ -22,8 +37,7 @@ public:
|
||||
return *this;
|
||||
}
|
||||
operator HWND() const { return _window; }
|
||||
void Attach(HWND newWindow)
|
||||
{ _window = newWindow; }
|
||||
void Attach(HWND newWindow) { _window = newWindow; }
|
||||
HWND Detach()
|
||||
{
|
||||
HWND window = _window;
|
||||
@@ -31,18 +45,11 @@ public:
|
||||
return window;
|
||||
}
|
||||
|
||||
HWND GetParent() const
|
||||
{ return ::GetParent(_window); }
|
||||
bool GetWindowRect(LPRECT rect) const
|
||||
{ return BOOLToBool(::GetWindowRect(_window,rect )); }
|
||||
bool IsZoomed() const
|
||||
{ return BOOLToBool(::IsZoomed(_window)); }
|
||||
|
||||
bool ClientToScreen(LPPOINT point) const
|
||||
{ return BOOLToBool(::ClientToScreen(_window, point)); }
|
||||
|
||||
bool ScreenToClient(LPPOINT point) const
|
||||
{ return BOOLToBool(::ScreenToClient(_window, point)); }
|
||||
HWND GetParent() const { return ::GetParent(_window); }
|
||||
bool GetWindowRect(LPRECT rect) const { return BOOLToBool(::GetWindowRect(_window,rect )); }
|
||||
bool IsZoomed() const { return BOOLToBool(::IsZoomed(_window)); }
|
||||
bool ClientToScreen(LPPOINT point) const { return BOOLToBool(::ClientToScreen(_window, point)); }
|
||||
bool ScreenToClient(LPPOINT point) const { return BOOLToBool(::ScreenToClient(_window, point)); }
|
||||
|
||||
bool CreateEx(DWORD exStyle, LPCTSTR className,
|
||||
LPCTSTR windowName, DWORD style,
|
||||
@@ -56,6 +63,32 @@ public:
|
||||
return (_window != NULL);
|
||||
}
|
||||
|
||||
bool Create(LPCTSTR className,
|
||||
LPCTSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam)
|
||||
{
|
||||
_window = ::CreateWindow(className, windowName,
|
||||
style, x, y, width, height, parentWindow,
|
||||
idOrHMenu, instance, createParam);
|
||||
return (_window != NULL);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool Create(LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam);
|
||||
bool CreateEx(DWORD exStyle, LPCWSTR className,
|
||||
LPCWSTR windowName, DWORD style,
|
||||
int x, int y, int width, int height,
|
||||
HWND parentWindow, HMENU idOrHMenu,
|
||||
HINSTANCE instance, LPVOID createParam);
|
||||
#endif
|
||||
|
||||
|
||||
bool Destroy()
|
||||
{
|
||||
if (_window == NULL)
|
||||
@@ -65,25 +98,17 @@ public:
|
||||
_window = NULL;
|
||||
return result;
|
||||
}
|
||||
bool IsWindow()
|
||||
{ return BOOLToBool(::IsWindow(_window)); }
|
||||
bool IsWindow() { return BOOLToBool(::IsWindow(_window)); }
|
||||
bool Move(int x, int y, int width, int height, bool repaint = true)
|
||||
{ return BOOLToBool(::MoveWindow(_window, x, y, width, height, BoolToBOOL(repaint))); }
|
||||
bool GetClientRect(LPRECT rect)
|
||||
{ return BOOLToBool(::GetClientRect(_window, rect)); }
|
||||
bool Show(int cmdShow)
|
||||
{ return BOOLToBool(::ShowWindow(_window, cmdShow)); }
|
||||
bool SetPlacement(CONST WINDOWPLACEMENT *placement)
|
||||
{ return BOOLToBool(::SetWindowPlacement(_window, placement)); }
|
||||
bool GetPlacement(WINDOWPLACEMENT *placement)
|
||||
{ return BOOLToBool(::GetWindowPlacement(_window, placement)); }
|
||||
|
||||
bool Update()
|
||||
{ return BOOLToBool(::UpdateWindow(_window)); }
|
||||
bool GetClientRect(LPRECT rect) { return BOOLToBool(::GetClientRect(_window, rect)); }
|
||||
bool Show(int cmdShow) { return BOOLToBool(::ShowWindow(_window, cmdShow)); }
|
||||
bool SetPlacement(CONST WINDOWPLACEMENT *placement) { return BOOLToBool(::SetWindowPlacement(_window, placement)); }
|
||||
bool GetPlacement(WINDOWPLACEMENT *placement) { return BOOLToBool(::GetWindowPlacement(_window, placement)); }
|
||||
bool Update() { return BOOLToBool(::UpdateWindow(_window)); }
|
||||
bool InvalidateRect(LPCRECT rect, bool backgroundErase = true)
|
||||
{ return BOOLToBool(::InvalidateRect(_window, rect, BoolToBOOL(backgroundErase))); }
|
||||
void SetRedraw(bool redraw = true)
|
||||
{ SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); }
|
||||
void SetRedraw(bool redraw = true) { SendMessage(WM_SETREDRAW, BoolToBOOL(redraw), 0); }
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
LONG SetStyle(LONG_PTR style)
|
||||
@@ -109,6 +134,11 @@ public:
|
||||
#ifndef _WIN32_WCE
|
||||
LONG_PTR SetLongPtr(int index, LONG_PTR newLongPtr )
|
||||
{ return ::SetWindowLongPtr(_window, index, newLongPtr); }
|
||||
#ifndef _UNICODE
|
||||
LONG_PTR SetLongPtrW(int index, LONG_PTR newLongPtr )
|
||||
{ return ::SetWindowLongPtrW(_window, index, newLongPtr); }
|
||||
#endif
|
||||
|
||||
LONG_PTR GetLongPtr(int index) const
|
||||
{ return ::GetWindowLongPtr(_window, index ); }
|
||||
LONG_PTR SetUserDataLongPtr(LONG_PTR newLongPtr )
|
||||
@@ -124,18 +154,25 @@ public:
|
||||
{ return ModifyStyleBase(GWL_EXSTYLE, remove, add, flags); }
|
||||
*/
|
||||
|
||||
HWND SetFocus()
|
||||
{ return ::SetFocus(_window); }
|
||||
HWND SetFocus() { return ::SetFocus(_window); }
|
||||
|
||||
LRESULT SendMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
|
||||
{ return ::SendMessage(_window, message, wParam, lParam) ;}
|
||||
{ return ::SendMessage(_window, message, wParam, lParam) ;}
|
||||
#ifndef _UNICODE
|
||||
LRESULT SendMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
|
||||
{ return ::SendMessageW(_window, message, wParam, lParam) ;}
|
||||
#endif
|
||||
|
||||
bool PostMessage(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
|
||||
{ return BOOLToBool(::PostMessage(_window, message, wParam, lParam)) ;}
|
||||
|
||||
bool SetText(LPCTSTR s)
|
||||
{ return BOOLToBool(::SetWindowText(_window, s)); }
|
||||
#ifndef _UNICODE
|
||||
bool CWindow::SetText(LPCWSTR s);
|
||||
LRESULT PostMessageW(UINT message, WPARAM wParam = 0, LPARAM lParam = 0)
|
||||
{ return ::PostMessageW(_window, message, wParam, lParam) ;}
|
||||
#endif
|
||||
|
||||
bool SetText(LPCTSTR s) { return BOOLToBool(::SetWindowText(_window, s)); }
|
||||
#ifndef _UNICODE
|
||||
bool CWindow::SetText(LPCWSTR s) { return MySetWindowText(_window, s); }
|
||||
#endif
|
||||
|
||||
int GetTextLength() const
|
||||
|
||||
Reference in New Issue
Block a user