This commit is contained in:
Igor Pavlov
2011-04-11 00:00:00 +00:00
committed by Kornel Lesiński
parent de4f8c22fe
commit 35596517f2
322 changed files with 9989 additions and 7759 deletions

View File

@@ -2,10 +2,10 @@
#include "StdAfx.h"
#ifndef _UNICODE
#include "Common/StringConvert.h"
#endif
#include "Windows/Control/Dialog.h"
#ifndef _UNICODE
#include "../../Common/StringConvert.h"
#endif
extern HINSTANCE g_hInstance;
#ifndef _UNICODE
@@ -17,17 +17,16 @@ namespace NControl {
static INT_PTR APIENTRY DialogProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
{
CWindow dialogTmp(dialogHWND);
CWindow tempDialog(dialogHWND);
if (message == WM_INITDIALOG)
dialogTmp.SetUserDataLongPtr(lParam);
CDialog *dialog = (CDialog *)(dialogTmp.GetUserDataLongPtr());
tempDialog.SetUserDataLongPtr(lParam);
CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr());
if (dialog == NULL)
return FALSE;
if (message == WM_INITDIALOG)
dialog->Attach(dialogHWND);
try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
catch(...) { return true; }
catch(...) { return TRUE; }
}
bool CDialog::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
@@ -68,7 +67,7 @@ bool CDialog::OnCommand(int code, int itemID, LPARAM lParam)
bool CDialog::OnButtonClicked(int buttonID, HWND /* buttonHWND */)
{
switch(buttonID)
switch (buttonID)
{
case IDOK: OnOK(); break;
case IDCANCEL: OnCancel(); break;

View File

@@ -4,6 +4,10 @@
#include "Windows/Control/ListView.h"
#ifndef _UNICODE
extern bool g_IsNT;
#endif
namespace NWindows {
namespace NControl {
@@ -93,4 +97,59 @@ int CListView::SetSubItem(int index, int subIndex, LPCWSTR text)
#endif
static LRESULT APIENTRY ListViewSubclassProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
{
CWindow window(hwnd);
CListView2 *w = (CListView2 *)(window.GetUserDataLongPtr());
if (w == NULL)
return 0;
return w->OnMessage(message, wParam, lParam);
}
LRESULT CListView2::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
#ifndef _UNICODE
if (g_IsNT)
return CallWindowProcW(_origWindowProc, *this, message, wParam, lParam);
else
#endif
return CallWindowProc(_origWindowProc, *this, message, wParam, lParam);
}
void CListView2::SetWindowProc()
{
SetUserDataLongPtr((LONG_PTR)this);
#ifndef _UNICODE
if (g_IsNT)
_origWindowProc = (WNDPROC)SetLongPtrW(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc);
else
#endif
_origWindowProc = (WNDPROC)SetLongPtr(GWLP_WNDPROC, (LONG_PTR)ListViewSubclassProc);
}
/*
LRESULT CListView3::OnMessage(UINT message, WPARAM wParam, LPARAM lParam)
{
LRESULT res = CListView2::OnMessage(message, wParam, lParam);
if (message == WM_GETDLGCODE)
{
// when user presses RETURN, windows sends default (first) button command to parent dialog.
// we disable this:
MSG *msg = (MSG *)lParam;
WPARAM key = wParam;
bool change = false;
if (msg)
{
if (msg->message == WM_KEYDOWN && msg->wParam == VK_RETURN)
change = true;
}
else if (wParam == VK_RETURN)
change = true;
if (change)
res |= DLGC_WANTALLKEYS;
}
return res;
}
*/
}}

View File

@@ -18,9 +18,12 @@ public:
HWND parentWindow, HMENU idOrHMenu,
HINSTANCE instance, LPVOID createParam);
#ifndef UNDER_CE
bool SetUnicodeFormat(bool fUnicode) { return BOOLToBool(ListView_SetUnicodeFormat(_window, BOOLToBool(fUnicode))); }
#endif
void SetUnicodeFormat()
{
#ifndef UNDER_CE
ListView_SetUnicodeFormat(_window, TRUE);
#endif
}
bool DeleteAllItems() { return BOOLToBool(ListView_DeleteAllItems(_window)); }
bool DeleteColumn(int columnIndex) { return BOOLToBool(ListView_DeleteColumn(_window, columnIndex)); }
@@ -65,8 +68,12 @@ public:
{ return BOOLToBool(ListView_SortItems(_window, compareFunction, dataParam)); }
void SetItemState(int index, UINT state, UINT mask) { ListView_SetItemState(_window, index, state, mask); }
void SetItemState_Selected(int index, bool select) { SetItemState(index, select ? LVIS_SELECTED : 0, LVIS_SELECTED); }
void SetItemState_Selected(int index) { SetItemState(index, LVIS_SELECTED, LVIS_SELECTED); }
void SelectAll() { SetItemState_Selected(-1); }
void SetItemState_FocusedSelected(int index) { SetItemState(index, LVIS_FOCUSED | LVIS_SELECTED, LVIS_FOCUSED | LVIS_SELECTED); }
UINT GetItemState(int index, UINT mask) const { return ListView_GetItemState(_window, index, mask); }
bool IsItemSelected(int index) const { return GetItemState(index, LVIS_SELECTED) == LVIS_SELECTED; }
bool GetColumn(int columnIndex, LVCOLUMN* columnInfo) const
{ return BOOLToBool(ListView_GetColumn(_window, columnIndex, columnInfo)); }
@@ -104,6 +111,22 @@ public:
bool SetColumnWidthAuto(int iCol) { return SetColumnWidth(iCol, LVSCW_AUTOSIZE); }
};
class CListView2: public CListView
{
WNDPROC _origWindowProc;
public:
void SetWindowProc();
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
};
/*
class CListView3: public CListView2
{
public:
virtual LRESULT OnMessage(UINT message, WPARAM wParam, LPARAM lParam);
};
*/
}}
#endif

View File

@@ -15,50 +15,30 @@ extern bool g_IsNT;
namespace NWindows {
namespace NControl {
INT_PTR APIENTRY ProperyPageProcedure(HWND dialogHWND, UINT message,
WPARAM wParam, LPARAM lParam)
static INT_PTR APIENTRY MyProperyPageProcedure(HWND dialogHWND, UINT message, WPARAM wParam, LPARAM lParam)
{
CDialog tempDialog(dialogHWND);
CWindow tempDialog(dialogHWND);
if (message == WM_INITDIALOG)
tempDialog.SetUserDataLongPtr(((PROPSHEETPAGE *)lParam)->lParam);
CDialog *dialog = (CDialog *)(tempDialog.GetUserDataLongPtr());
if (dialog == NULL)
return FALSE;
if (message == WM_INITDIALOG)
dialog->Attach(dialogHWND);
switch (message)
{
case WM_INITDIALOG:
return dialog->OnInit();
case WM_COMMAND:
return dialog->OnCommand(wParam, lParam);
case WM_NOTIFY:
return dialog->OnNotify((UINT)wParam, (LPNMHDR) lParam);
}
if (dialog == NULL)
return false;
return dialog->OnMessage(message, wParam, lParam);
try { return BoolToBOOL(dialog->OnMessage(message, wParam, lParam)); }
catch(...) { return TRUE; }
}
bool CPropertyPage::OnNotify(UINT /* controlID */, LPNMHDR lParam)
{
switch(lParam->code)
switch (lParam->code)
{
case PSN_APPLY:
SetMsgResult(OnApply(LPPSHNOTIFY(lParam)));
break;
case PSN_KILLACTIVE:
SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam))));
break;
case PSN_SETACTIVE:
SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam)));
break;
case PSN_RESET:
OnReset(LPPSHNOTIFY(lParam));
break;
case PSN_HELP:
OnNotifyHelp(LPPSHNOTIFY(lParam));
break;
default:
return false;
case PSN_APPLY: SetMsgResult(OnApply(LPPSHNOTIFY(lParam))); break;
case PSN_KILLACTIVE: SetMsgResult(BoolToBOOL(OnKillActive(LPPSHNOTIFY(lParam)))); break;
case PSN_SETACTIVE: SetMsgResult(OnSetActive(LPPSHNOTIFY(lParam))); break;
case PSN_RESET: OnReset(LPPSHNOTIFY(lParam)); break;
case PSN_HELP: OnNotifyHelp(LPPSHNOTIFY(lParam)); break;
default: return false;
}
return true;
}
@@ -90,7 +70,7 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare
page.hInstance = g_hInstance;
page.pszTemplate = MAKEINTRESOURCE(pageInfo.ID);
page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure;
if (titles[i].IsEmpty())
page.pszTitle = NULL;
@@ -111,7 +91,7 @@ INT_PTR MyPropertySheet(const CObjectVector<CPageInfo> &pagesInfo, HWND hwndPare
page.hInstance = g_hInstance;
page.pszTemplate = MAKEINTRESOURCEW(pageInfo.ID);
page.pszIcon = NULL;
page.pfnDlgProc = NWindows::NControl::ProperyPageProcedure;
page.pfnDlgProc = NWindows::NControl::MyProperyPageProcedure;
if (pageInfo.Title.IsEmpty())
page.pszTitle = NULL;

View File

@@ -2,16 +2,14 @@
#include "StdAfx.h"
#ifndef _UNICODE
#include "../Common/StringConvert.h"
#endif
#include "DLL.h"
#ifndef _UNICODE
extern bool g_IsNT;
#endif
extern HINSTANCE g_hInstance;
namespace NWindows {
namespace NDLL {
@@ -19,92 +17,91 @@ bool CLibrary::Free()
{
if (_module == 0)
return true;
// MessageBox(0, TEXT(""), TEXT("Free"), 0);
// Sleep(5000);
if (!::FreeLibrary(_module))
return false;
_module = 0;
return true;
}
bool CLibrary::LoadOperations(HMODULE newModule)
bool CLibrary::LoadEx(CFSTR path, DWORD flags)
{
if (newModule == NULL)
return false;
if (!Free())
return false;
_module = newModule;
return true;
}
bool CLibrary::LoadEx(LPCTSTR fileName, DWORD flags)
{
// MessageBox(0, fileName, TEXT("LoadEx"), 0);
return LoadOperations(::LoadLibraryEx(fileName, NULL, flags));
}
bool CLibrary::Load(LPCTSTR fileName)
{
// MessageBox(0, fileName, TEXT("Load"), 0);
// Sleep(5000);
// OutputDebugString(fileName);
// OutputDebugString(TEXT("\n"));
return LoadOperations(::LoadLibrary(fileName));
}
#ifndef _UNICODE
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)
{
if (g_IsNT)
return LoadOperations(::LoadLibraryExW(fileName, NULL, flags));
return LoadEx(GetSysPath(fileName), flags);
}
bool CLibrary::Load(LPCWSTR fileName)
{
if (g_IsNT)
return LoadOperations(::LoadLibraryW(fileName));
return Load(GetSysPath(fileName));
}
#endif
bool MyGetModuleFileName(HMODULE hModule, CSysString &result)
{
result.Empty();
TCHAR fullPath[MAX_PATH + 2];
DWORD size = ::GetModuleFileName(hModule, fullPath, MAX_PATH + 1);
if (size <= MAX_PATH && size != 0)
#ifndef _UNICODE
if (!g_IsNT)
{
result = fullPath;
return true;
_module = ::LoadLibraryEx(fs2fas(path), NULL, flags);
}
else
#endif
{
_module = ::LoadLibraryExW(fs2us(path), NULL, flags);
}
return (_module != NULL);
}
bool CLibrary::Load(CFSTR path)
{
if (!Free())
return false;
#ifndef _UNICODE
if (!g_IsNT)
{
_module = ::LoadLibrary(fs2fas(path));
}
else
#endif
{
_module = ::LoadLibraryW(fs2us(path));
}
return (_module != NULL);
}
bool MyGetModuleFileName(FString &path)
{
HMODULE hModule = g_hInstance;
path.Empty();
#ifndef _UNICODE
if (!g_IsNT)
{
TCHAR s[MAX_PATH + 2];
s[0] = 0;
DWORD size = ::GetModuleFileName(hModule, s, MAX_PATH + 1);
if (size <= MAX_PATH && size != 0)
{
path = fas2fs(s);
return true;
}
}
else
#endif
{
WCHAR s[MAX_PATH + 2];
s[0] = 0;
DWORD size = ::GetModuleFileNameW(hModule, s, MAX_PATH + 1);
if (size <= MAX_PATH && size != 0)
{
path = us2fs(s);
return true;
}
}
return false;
}
#ifndef _UNICODE
bool MyGetModuleFileName(HMODULE hModule, UString &result)
#ifndef _SFX
FString GetModuleDirPrefix()
{
result.Empty();
if (g_IsNT)
FString s;
if (NDLL::MyGetModuleFileName(s))
{
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;
int pos = s.ReverseFind(FCHAR_PATH_SEPARATOR);
if (pos >= 0)
return s.Left(pos + 1);
}
CSysString resultSys;
if (!MyGetModuleFileName(hModule, resultSys))
return false;
result = MultiByteToUnicodeString(resultSys, GetCurrentCodePage());
return true;
return FTEXT(".") FSTRING_PATH_SEPARATOR;
}
#endif
}}

View File

@@ -9,15 +9,13 @@ namespace NWindows {
namespace NDLL {
#ifdef UNDER_CE
#define My_GetProcAddress(module, proceName) GetProcAddressA(module, proceName)
#define My_GetProcAddress(module, procName) ::GetProcAddressA(module, procName)
#else
#define My_GetProcAddress(module, proceName) ::GetProcAddress(module, proceName)
#define My_GetProcAddress(module, procName) ::GetProcAddress(module, procName)
#endif
class CLibrary
{
bool LoadOperations(HMODULE newModule);
protected:
HMODULE _module;
public:
CLibrary(): _module(NULL) {};
@@ -40,19 +38,14 @@ public:
}
bool Free();
bool LoadEx(LPCTSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
bool Load(LPCTSTR fileName);
#ifndef _UNICODE
bool LoadEx(LPCWSTR fileName, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
bool Load(LPCWSTR fileName);
#endif
bool LoadEx(CFSTR path, DWORD flags = LOAD_LIBRARY_AS_DATAFILE);
bool Load(CFSTR path);
FARPROC GetProc(LPCSTR procName) const { return My_GetProcAddress(_module, procName); }
};
bool MyGetModuleFileName(HMODULE hModule, CSysString &result);
#ifndef _UNICODE
bool MyGetModuleFileName(HMODULE hModule, UString &result);
#endif
bool MyGetModuleFileName(FString &path);
FString GetModuleDirPrefix();
}}

View File

@@ -14,37 +14,47 @@ extern bool g_IsNT;
namespace NWindows {
namespace NError {
bool MyFormatMessage(DWORD messageID, CSysString &message)
static bool MyFormatMessage(DWORD errorCode, UString &message)
{
LPVOID msgBuf;
if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,messageID, 0, (LPTSTR) &msgBuf,0, NULL) == 0)
return false;
message = (LPCTSTR)msgBuf;
#ifndef _UNICODE
if (!g_IsNT)
{
if (::FormatMessage(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorCode, 0, (LPTSTR) &msgBuf, 0, NULL) == 0)
return false;
message = GetUnicodeString((LPCTSTR)msgBuf);
}
else
#endif
{
if (::FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorCode, 0, (LPWSTR) &msgBuf, 0, NULL) == 0)
return false;
message = (LPCWSTR)msgBuf;
}
::LocalFree(msgBuf);
return true;
}
#ifndef _UNICODE
bool MyFormatMessage(DWORD messageID, UString &message)
UString MyFormatMessageW(DWORD errorCode)
{
if (g_IsNT)
UString message;
if (!MyFormatMessage(errorCode, message))
{
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;
message = (LPCWSTR)msgBuf;
::LocalFree(msgBuf);
return true;
wchar_t s[16];
for (int i = 0; i < 8; i++)
{
int t = errorCode & 0xF;
errorCode >>= 4;
s[7 - i] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10)));
}
s[8] = '\0';
message = (UString)L"Error #" + s;
}
CSysString messageSys;
bool result = MyFormatMessage(messageID, messageSys);
message = GetUnicodeString(messageSys);
return result;
return message;
}
#endif
}}

View File

@@ -8,25 +8,7 @@
namespace NWindows {
namespace NError {
bool MyFormatMessage(DWORD messageID, CSysString &message);
inline CSysString MyFormatMessage(DWORD messageID)
{
CSysString message;
MyFormatMessage(messageID, message);
return message;
}
#ifdef _UNICODE
inline UString MyFormatMessageW(DWORD messageID)
{ return MyFormatMessage(messageID); }
#else
bool MyFormatMessage(DWORD messageID, UString &message);
inline UString MyFormatMessageW(DWORD messageID)
{
UString message;
MyFormatMessage(messageID, message);
return message;
}
#endif
UString MyFormatMessageW(DWORD errorCode);
}}

View File

File diff suppressed because it is too large Load Diff

View File

@@ -1,177 +1,72 @@
// Windows/FileDir.h
#ifndef __WINDOWS_FILEDIR_H
#define __WINDOWS_FILEDIR_H
#ifndef __WINDOWS_FILE_DIR_H
#define __WINDOWS_FILE_DIR_H
#include "../Common/MyString.h"
#include "Defs.h"
#include "FileIO.h"
namespace NWindows {
namespace NFile {
namespace NDirectory {
#ifdef WIN_LONG_PATH
bool GetLongPaths(LPCWSTR s1, LPCWSTR s2, UString &d1, UString &d2);
bool GetLongPaths(CFSTR s1, CFSTR s2, UString &d1, UString &d2);
#endif
bool MyGetWindowsDirectory(CSysString &path);
bool MyGetSystemDirectory(CSysString &path);
#ifndef _UNICODE
bool MyGetWindowsDirectory(UString &path);
bool MyGetSystemDirectory(UString &path);
#endif
bool MyGetWindowsDirectory(FString &path);
bool MyGetSystemDirectory(FString &path);
bool SetDirTime(LPCWSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
bool SetDirTime(CFSTR fileName, const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
bool MySetFileAttributes(CFSTR fileName, DWORD fileAttributes);
bool MyMoveFile(CFSTR existFileName, CFSTR newFileName);
bool MyRemoveDirectory(CFSTR path);
bool MyCreateDirectory(CFSTR path);
bool CreateComplexDirectory(CFSTR path);
bool DeleteFileAlways(CFSTR name);
bool RemoveDirectoryWithSubItems(const FString &path);
bool MySetFileAttributes(LPCTSTR fileName, DWORD fileAttributes);
bool MyMoveFile(LPCTSTR existFileName, LPCTSTR newFileName);
bool MyRemoveDirectory(LPCTSTR pathName);
bool MyCreateDirectory(LPCTSTR pathName);
bool CreateComplexDirectory(LPCTSTR pathName);
bool DeleteFileAlways(LPCTSTR name);
bool RemoveDirectoryWithSubItems(const CSysString &path);
bool MyGetFullPathName(CFSTR path, FString &resFullPath);
bool GetFullPathAndSplit(CFSTR path, FString &resDirPrefix, FString &resFileName);
bool GetOnlyDirPrefix(CFSTR path, FString &resDirPrefix);
#ifndef _UNICODE
bool MySetFileAttributes(LPCWSTR fileName, DWORD fileAttributes);
bool MyMoveFile(LPCWSTR existFileName, LPCWSTR newFileName);
bool MyRemoveDirectory(LPCWSTR pathName);
bool MyCreateDirectory(LPCWSTR pathName);
bool CreateComplexDirectory(LPCWSTR pathName);
bool DeleteFileAlways(LPCWSTR name);
bool RemoveDirectoryWithSubItems(const UString &path);
#endif
#ifndef UNDER_CE
bool GetOnlyDirPrefix(LPCTSTR fileName, CSysString &resultName);
bool GetOnlyName(LPCTSTR fileName, CSysString &resultName);
#ifdef UNDER_CE
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath, int &fileNamePartStartIndex);
#else
bool MyGetShortPathName(LPCTSTR longPath, CSysString &shortPath);
bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath, int &fileNamePartStartIndex);
bool MyGetFullPathName(LPCTSTR fileName, CSysString &resultPath);
#ifndef _UNICODE
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath,
int &fileNamePartStartIndex);
bool MyGetFullPathName(LPCWSTR fileName, UString &resultPath);
bool GetOnlyName(LPCWSTR fileName, UString &resultName);
bool GetOnlyDirPrefix(LPCWSTR fileName, UString &resultName);
#endif
inline bool MySetCurrentDirectory(LPCTSTR path)
{ return BOOLToBool(::SetCurrentDirectory(path)); }
bool MyGetCurrentDirectory(CSysString &resultPath);
#ifndef _UNICODE
bool MySetCurrentDirectory(LPCWSTR path);
bool MyGetCurrentDirectory(UString &resultPath);
#endif
bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, CSysString &resultPath, UINT32 &filePart);
#ifndef _UNICODE
bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath, UINT32 &filePart);
#endif
inline bool MySearchPath(LPCTSTR path, LPCTSTR fileName, LPCTSTR extension, CSysString &resultPath)
{
UINT32 value;
return MySearchPath(path, fileName, extension, resultPath, value);
}
#ifndef _UNICODE
inline bool MySearchPath(LPCWSTR path, LPCWSTR fileName, LPCWSTR extension, UString &resultPath)
{
UINT32 value;
return MySearchPath(path, fileName, extension, resultPath, value);
}
#endif
bool MySetCurrentDirectory(CFSTR path);
bool MyGetCurrentDirectory(FString &resultPath);
#endif
bool MyGetTempPath(CSysString &resultPath);
#ifndef _UNICODE
bool MyGetTempPath(UString &resultPath);
#endif
UINT MyGetTempFileName(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);
#ifndef _UNICODE
UINT MyGetTempFileName(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);
#endif
bool MyGetTempPath(FString &resultPath);
class CTempFile
{
bool _mustBeDeleted;
CSysString _fileName;
FString _path;
void DisableDeleting() { _mustBeDeleted = false; }
public:
CTempFile(): _mustBeDeleted(false) {}
~CTempFile() { Remove(); }
const FString &GetPath() const { return _path; }
bool Create(CFSTR pathPrefix, NIO::COutFile *outFile); // pathPrefix is not folder prefix
bool CreateRandomInTempFolder(CFSTR namePrefix, NIO::COutFile *outFile);
bool Remove();
bool MoveTo(CFSTR name, bool deleteDestBefore);
};
class CTempDir
{
bool _mustBeDeleted;
FString _path;
public:
CTempDir(): _mustBeDeleted(false) {}
~CTempDir() { Remove(); }
const FString &GetPath() const { return _path; }
void DisableDeleting() { _mustBeDeleted = false; }
UINT Create(LPCTSTR dirPath, LPCTSTR prefix, CSysString &resultPath);
bool Create(LPCTSTR prefix, CSysString &resultPath);
bool Create(CFSTR namePrefix) ;
bool Remove();
};
#ifdef _UNICODE
typedef CTempFile CTempFileW;
#else
class CTempFileW
{
bool _mustBeDeleted;
UString _fileName;
public:
CTempFileW(): _mustBeDeleted(false) {}
~CTempFileW() { Remove(); }
void DisableDeleting() { _mustBeDeleted = false; }
UINT Create(LPCWSTR dirPath, LPCWSTR prefix, UString &resultPath);
bool Create(LPCWSTR prefix, UString &resultPath);
bool Remove();
};
#endif
bool CreateTempDirectory(LPCTSTR prefixChars, CSysString &dirName);
class CTempDirectory
{
bool _mustBeDeleted;
CSysString _tempDir;
public:
const CSysString &GetPath() const { return _tempDir; }
CTempDirectory(): _mustBeDeleted(false) {}
~CTempDirectory() { Remove(); }
bool Create(LPCTSTR prefix) ;
bool Remove()
{
if (!_mustBeDeleted)
return true;
_mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);
return (!_mustBeDeleted);
}
void DisableDeleting() { _mustBeDeleted = false; }
};
#ifdef _UNICODE
typedef CTempDirectory CTempDirectoryW;
#else
class CTempDirectoryW
{
bool _mustBeDeleted;
UString _tempDir;
public:
const UString &GetPath() const { return _tempDir; }
CTempDirectoryW(): _mustBeDeleted(false) {}
~CTempDirectoryW() { Remove(); }
bool Create(LPCWSTR prefix) ;
bool Remove()
{
if (!_mustBeDeleted)
return true;
_mustBeDeleted = !RemoveDirectoryWithSubItems(_tempDir);
return (!_mustBeDeleted);
}
void DisableDeleting() { _mustBeDeleted = false; }
};
#endif
}}}
#endif

View File

@@ -16,42 +16,24 @@ namespace NWindows {
namespace NFile {
#ifdef SUPPORT_DEVICE_FILE
bool IsDeviceName(LPCTSTR n);
#ifndef _UNICODE
bool IsDeviceName(LPCWSTR n);
#endif
bool IsDeviceName(CFSTR n);
#endif
#if defined(WIN_LONG_PATH) && defined(_UNICODE)
#define WIN_LONG_PATH2
#if defined(WIN_LONG_PATH)
bool GetLongPath(CFSTR fileName, UString &res);
#endif
bool GetLongPath(LPCWSTR fileName, UString &res);
namespace NFind {
static const TCHAR kDot = TEXT('.');
bool CFileInfo::IsDots() const
{
if (!IsDir() || Name.IsEmpty())
return false;
if (Name[0] != kDot)
if (Name[0] != FTEXT('.'))
return false;
return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
return Name.Length() == 1 || (Name.Length() == 2 && Name[1] == FTEXT('.'));
}
#ifndef _UNICODE
bool CFileInfoW::IsDots() const
{
if (!IsDir() || Name.IsEmpty())
return false;
if (Name[0] != kDot)
return false;
return Name.Length() == 1 || (Name[1] == kDot && Name.Length() == 2);
}
#endif
#define WIN_FD_TO_MY_FI(fi, fd) \
fi.Attrib = fd.dwFileAttributes; \
fi.CTime = fd.ftCreationTime; \
@@ -68,26 +50,20 @@ bool CFileInfoW::IsDots() const
#endif
*/
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfo &fi)
{
WIN_FD_TO_MY_FI(fi, fd);
fi.Name = fd.cFileName;
fi.Name = us2fs(fd.cFileName);
}
#ifndef _UNICODE
static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
{
WIN_FD_TO_MY_FI(fi, fd);
fi.Name = fd.cFileName;
}
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)
{
WIN_FD_TO_MY_FI(fi, fd);
fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());
fi.Name = fas2fs(fd.cFileName);
}
#endif
@@ -104,36 +80,24 @@ bool CFindFile::Close()
return true;
}
bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fi)
bool CFindFile::FindFirst(CFSTR wildcard, CFileInfo &fi)
{
if (!Close())
return false;
WIN32_FIND_DATA fd;
_handle = ::FindFirstFile(wildcard, &fd);
#ifdef WIN_LONG_PATH2
if (_handle == INVALID_HANDLE_VALUE)
#ifndef _UNICODE
if (!g_IsNT)
{
UString longPath;
if (GetLongPath(wildcard, longPath))
_handle = ::FindFirstFileW(longPath, &fd);
WIN32_FIND_DATAA fd;
_handle = ::FindFirstFileA(fs2fas(wildcard), &fd);
if (_handle == INVALID_HANDLE_VALUE)
return false;
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
else
#endif
if (_handle == INVALID_HANDLE_VALUE)
return false;
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
return true;
}
#ifndef _UNICODE
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fi)
{
if (!Close())
return false;
if (g_IsNT)
{
WIN32_FIND_DATAW fd;
_handle = ::FindFirstFileW(wildcard, &fd);
_handle = ::FindFirstFileW(fs2us(wildcard), &fd);
#ifdef WIN_LONG_PATH
if (_handle == INVALID_HANDLE_VALUE)
{
@@ -142,50 +106,33 @@ bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fi)
_handle = ::FindFirstFileW(longPath, &fd);
}
#endif
if (_handle != INVALID_HANDLE_VALUE)
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
else
{
WIN32_FIND_DATAA fd;
_handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,
GetCurrentCodePage()), &fd);
if (_handle != INVALID_HANDLE_VALUE)
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
return (_handle != INVALID_HANDLE_VALUE);
}
#endif
bool CFindFile::FindNext(CFileInfo &fi)
{
WIN32_FIND_DATA fd;
bool result = BOOLToBool(::FindNextFile(_handle, &fd));
if (result)
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
return result;
}
#ifndef _UNICODE
bool CFindFile::FindNext(CFileInfoW &fi)
{
if (g_IsNT)
{
WIN32_FIND_DATAW fd;
if (!::FindNextFileW(_handle, &fd))
if (_handle == INVALID_HANDLE_VALUE)
return false;
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
else
return true;
}
bool CFindFile::FindNext(CFileInfo &fi)
{
#ifndef _UNICODE
if (!g_IsNT)
{
WIN32_FIND_DATAA fd;
if (!::FindNextFileA(_handle, &fd))
return false;
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
else
#endif
{
WIN32_FIND_DATAW fd;
if (!::FindNextFileW(_handle, &fd))
return false;
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
}
return true;
}
#endif
#define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0;
@@ -198,7 +145,7 @@ void CFileInfoBase::Clear()
Attrib = 0;
}
bool CFileInfo::Find(LPCTSTR wildcard)
bool CFileInfo::Find(CFSTR wildcard)
{
#ifdef SUPPORT_DEVICE_FILE
if (IsDeviceName(wildcard))
@@ -215,72 +162,66 @@ bool CFileInfo::Find(LPCTSTR wildcard)
}
#endif
CFindFile finder;
return finder.FindFirst(wildcard, *this);
}
#ifndef _UNICODE
bool CFileInfoW::Find(LPCWSTR wildcard)
{
#ifdef SUPPORT_DEVICE_FILE
if (IsDeviceName(wildcard))
{
Clear();
IsDevice = true;
NIO::CInFile inFile;
if (!inFile.Open(wildcard))
return false;
Name = wildcard + 4;
if (inFile.LengthDefined)
Size = inFile.Length;
if (finder.FindFirst(wildcard, *this))
return true;
#ifdef _WIN32
{
DWORD lastError = GetLastError();
if (lastError == ERROR_BAD_NETPATH || lastError == ERROR_FILE_NOT_FOUND)
{
int len = MyStringLen(wildcard);
if (len > 2 && wildcard[0] == '\\' && wildcard[1] == '\\')
{
int pos = FindCharPosInString(wildcard + 2, FTEXT('\\'));
if (pos >= 0)
{
pos += 2 + 1;
len -= pos;
CFSTR remString = wildcard + pos;
int pos2 = FindCharPosInString(remString, FTEXT('\\'));
FString s = wildcard;
if (pos2 < 0 || pos2 == len - 1)
{
FString s = wildcard;
if (pos2 < 0)
{
pos2 = len;
s += FTEXT('\\');
}
s += FCHAR_ANY_MASK;
if (finder.FindFirst(s, *this))
if (Name == FTEXT("."))
{
Name = s.Mid(pos, pos2);
return true;
}
::SetLastError(lastError);
}
}
}
}
}
#endif
CFindFile finder;
return finder.FindFirst(wildcard, *this);
return false;
}
#endif
bool DoesFileExist(LPCTSTR name)
bool DoesFileExist(CFSTR name)
{
CFileInfo fi;
return fi.Find(name) && !fi.IsDir();
}
bool DoesDirExist(LPCTSTR name)
bool DoesDirExist(CFSTR name)
{
CFileInfo fi;
return fi.Find(name) && fi.IsDir();
}
bool DoesFileOrDirExist(LPCTSTR name)
bool DoesFileOrDirExist(CFSTR name)
{
CFileInfo fi;
return fi.Find(name);
}
#ifndef _UNICODE
bool DoesFileExist(LPCWSTR name)
{
CFileInfoW fi;
return fi.Find(name) && !fi.IsDir();
}
bool DoesDirExist(LPCWSTR name)
{
CFileInfoW fi;
return fi.Find(name) && fi.IsDir();
}
bool DoesFileOrDirExist(LPCWSTR name)
{
CFileInfoW fi;
return fi.Find(name);
}
#endif
/////////////////////////////////////
// CEnumerator
bool CEnumerator::NextAny(CFileInfo &fi)
{
if (_findFile.IsHandleAllocated())
@@ -311,39 +252,6 @@ bool CEnumerator::Next(CFileInfo &fi, bool &found)
return (::GetLastError() == ERROR_NO_MORE_FILES);
}
#ifndef _UNICODE
bool CEnumeratorW::NextAny(CFileInfoW &fi)
{
if (_findFile.IsHandleAllocated())
return _findFile.FindNext(fi);
else
return _findFile.FindFirst(_wildcard, fi);
}
bool CEnumeratorW::Next(CFileInfoW &fi)
{
for (;;)
{
if (!NextAny(fi))
return false;
if (!fi.IsDots())
return true;
}
}
bool CEnumeratorW::Next(CFileInfoW &fi, bool &found)
{
if (Next(fi))
{
found = true;
return true;
}
found = false;
return (::GetLastError() == ERROR_NO_MORE_FILES);
}
#endif
////////////////////////////////
// CFindChangeNotification
// FindFirstChangeNotification can return 0. MSDN doesn't tell about it.
@@ -358,104 +266,82 @@ bool CFindChangeNotification::Close()
return true;
}
HANDLE CFindChangeNotification::FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter)
{
_handle = ::FindFirstChangeNotification(pathName, BoolToBOOL(watchSubtree), notifyFilter);
#ifdef WIN_LONG_PATH2
if (!IsHandleAllocated())
{
UString longPath;
if (GetLongPath(pathName, longPath))
_handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
}
#endif
return _handle;
}
#ifndef _UNICODE
HANDLE CFindChangeNotification::FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter)
HANDLE CFindChangeNotification::FindFirst(CFSTR pathName, bool watchSubtree, DWORD notifyFilter)
{
#ifndef _UNICODE
if (!g_IsNT)
return FindFirst(UnicodeStringToMultiByte(pathName, GetCurrentCodePage()), watchSubtree, notifyFilter);
_handle = ::FindFirstChangeNotificationW(pathName, BoolToBOOL(watchSubtree), notifyFilter);
#ifdef WIN_LONG_PATH
if (!IsHandleAllocated())
{
UString longPath;
if (GetLongPath(pathName, longPath))
_handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
}
_handle = ::FindFirstChangeNotification(fs2fas(pathName), BoolToBOOL(watchSubtree), notifyFilter);
else
#endif
{
_handle = ::FindFirstChangeNotificationW(fs2us(pathName), BoolToBOOL(watchSubtree), notifyFilter);
#ifdef WIN_LONG_PATH
if (!IsHandleAllocated())
{
UString longPath;
if (GetLongPath(pathName, longPath))
_handle = ::FindFirstChangeNotificationW(longPath, BoolToBOOL(watchSubtree), notifyFilter);
}
#endif
}
return _handle;
}
#endif
#ifndef UNDER_CE
bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings)
{
driveStrings.Clear();
UINT32 size = GetLogicalDriveStrings(0, NULL);
if (size == 0)
return false;
CSysString buffer;
UINT32 newSize = GetLogicalDriveStrings(size, buffer.GetBuffer(size));
if (newSize == 0)
return false;
if (newSize > size)
return false;
CSysString string;
for (UINT32 i = 0; i < newSize; i++)
{
TCHAR c = buffer[i];
if (c == TEXT('\0'))
{
driveStrings.Add(string);
string.Empty();
}
else
string += c;
}
if (!string.IsEmpty())
return false;
return true;
}
#ifndef _UNICODE
bool MyGetLogicalDriveStrings(UStringVector &driveStrings)
bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings)
{
driveStrings.Clear();
if (g_IsNT)
#ifndef _UNICODE
if (!g_IsNT)
{
driveStrings.Clear();
UINT32 size = GetLogicalDriveStrings(0, NULL);
if (size == 0)
return false;
AString buf;
UINT32 newSize = GetLogicalDriveStrings(size, buf.GetBuffer(size));
if (newSize == 0 || newSize > size)
return false;
AString s;
for (UINT32 i = 0; i < newSize; i++)
{
char c = buf[i];
if (c == '\0')
{
driveStrings.Add(fas2fs(s));
s.Empty();
}
else
s += c;
}
return s.IsEmpty();
}
else
#endif
{
UINT32 size = GetLogicalDriveStringsW(0, NULL);
if (size == 0)
return false;
UString buffer;
UINT32 newSize = GetLogicalDriveStringsW(size, buffer.GetBuffer(size));
if (newSize == 0)
UString buf;
UINT32 newSize = GetLogicalDriveStringsW(size, buf.GetBuffer(size));
if (newSize == 0 || newSize > size)
return false;
if (newSize > size)
return false;
UString string;
UString s;
for (UINT32 i = 0; i < newSize; i++)
{
WCHAR c = buffer[i];
WCHAR c = buf[i];
if (c == L'\0')
{
driveStrings.Add(string);
string.Empty();
driveStrings.Add(us2fs(s));
s.Empty();
}
else
string += c;
s += c;
}
return string.IsEmpty();
return s.IsEmpty();
}
CSysStringVector driveStringsA;
bool res = MyGetLogicalDriveStrings(driveStringsA);
for (int i = 0; i < driveStringsA.Size(); i++)
driveStrings.Add(GetUnicodeString(driveStringsA[i]));
return res;
}
#endif
#endif

View File

@@ -1,12 +1,11 @@
// Windows/FileFind.h
#ifndef __WINDOWS_FILEFIND_H
#define __WINDOWS_FILEFIND_H
#ifndef __WINDOWS_FILE_FIND_H
#define __WINDOWS_FILE_FIND_H
#include "../Common/MyString.h"
#include "../Common/Types.h"
#include "Defs.h"
#include "FileName.h"
namespace NWindows {
namespace NFile {
@@ -60,24 +59,12 @@ public:
struct CFileInfo: public CFileInfoBase
{
CSysString Name;
FString Name;
bool IsDots() const;
bool Find(LPCTSTR wildcard);
bool Find(CFSTR wildcard);
};
#ifdef _UNICODE
typedef CFileInfo CFileInfoW;
#else
struct CFileInfoW: public CFileInfoBase
{
UString Name;
bool IsDots() const;
bool Find(LPCWSTR wildcard);
};
#endif
class CFindFile
{
friend class CEnumerator;
@@ -85,53 +72,28 @@ class CFindFile
public:
bool IsHandleAllocated() const { return _handle != INVALID_HANDLE_VALUE; }
CFindFile(): _handle(INVALID_HANDLE_VALUE) {}
~CFindFile() { Close(); }
bool FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo);
~CFindFile() { Close(); }
bool FindFirst(CFSTR wildcard, CFileInfo &fileInfo);
bool FindNext(CFileInfo &fileInfo);
#ifndef _UNICODE
bool FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo);
bool FindNext(CFileInfoW &fileInfo);
#endif
bool Close();
};
bool DoesFileExist(LPCTSTR name);
bool DoesDirExist(LPCTSTR name);
bool DoesFileOrDirExist(LPCTSTR name);
#ifndef _UNICODE
bool DoesFileExist(LPCWSTR name);
bool DoesDirExist(LPCWSTR name);
bool DoesFileOrDirExist(LPCWSTR name);
#endif
bool DoesFileExist(CFSTR name);
bool DoesDirExist(CFSTR name);
bool DoesFileOrDirExist(CFSTR name);
class CEnumerator
{
CFindFile _findFile;
CSysString _wildcard;
FString _wildcard;
bool NextAny(CFileInfo &fileInfo);
public:
CEnumerator(): _wildcard(NName::kAnyStringWildcard) {}
CEnumerator(const CSysString &wildcard): _wildcard(wildcard) {}
CEnumerator(const FString &wildcard): _wildcard(wildcard) {}
bool Next(CFileInfo &fileInfo);
bool Next(CFileInfo &fileInfo, bool &found);
};
#ifdef _UNICODE
typedef CEnumerator CEnumeratorW;
#else
class CEnumeratorW
{
CFindFile _findFile;
UString _wildcard;
bool NextAny(CFileInfoW &fileInfo);
public:
CEnumeratorW(): _wildcard(NName::kAnyStringWildcard) {}
CEnumeratorW(const UString &wildcard): _wildcard(wildcard) {}
bool Next(CFileInfoW &fileInfo);
bool Next(CFileInfoW &fileInfo, bool &found);
};
#endif
class CFindChangeNotification
{
HANDLE _handle;
@@ -141,21 +103,14 @@ public:
CFindChangeNotification(): _handle(INVALID_HANDLE_VALUE) {}
~CFindChangeNotification() { Close(); }
bool Close();
HANDLE FindFirst(LPCTSTR pathName, bool watchSubtree, DWORD notifyFilter);
#ifndef _UNICODE
HANDLE FindFirst(LPCWSTR pathName, bool watchSubtree, DWORD notifyFilter);
#endif
HANDLE FindFirst(CFSTR pathName, bool watchSubtree, DWORD notifyFilter);
bool FindNext() { return BOOLToBool(::FindNextChangeNotification(_handle)); }
};
#ifndef UNDER_CE
bool MyGetLogicalDriveStrings(CSysStringVector &driveStrings);
#ifndef _UNICODE
bool MyGetLogicalDriveStrings(UStringVector &driveStrings);
#endif
bool MyGetLogicalDriveStrings(CObjectVector<FString> &driveStrings);
#endif
}}}
#endif

View File

@@ -4,13 +4,6 @@
#include "FileIO.h"
#if defined(WIN_LONG_PATH) || defined(SUPPORT_DEVICE_FILE)
#include "../Common/MyString.h"
#endif
#ifndef _UNICODE
#include "../Common/StringConvert.h"
#endif
#ifndef _UNICODE
extern bool g_IsNT;
#endif
@@ -19,11 +12,12 @@ namespace NWindows {
namespace NFile {
#ifdef SUPPORT_DEVICE_FILE
bool IsDeviceName(LPCTSTR n)
bool IsDeviceName(CFSTR n)
{
#ifdef UNDER_CE
int len = (int)MyStringLen(n);
if (len < 5 || len > 5 || memcmp(n, TEXT("DSK"), 3 * sizeof(TCHAR)) != 0)
if (len < 5 || len > 5 || memcmp(n, FTEXT("DSK"), 3 * sizeof(FCHAR)) != 0)
return false;
if (n[4] != ':')
return false;
@@ -34,7 +28,7 @@ bool IsDeviceName(LPCTSTR n)
int len = (int)MyStringLen(n);
if (len == 6 && n[5] == ':')
return true;
if (len < 18 || len > 22 || memcmp(n + 4, TEXT("PhysicalDrive"), 13 * sizeof(TCHAR)) != 0)
if (len < 18 || len > 22 || memcmp(n + 4, FTEXT("PhysicalDrive"), 13 * sizeof(FCHAR)) != 0)
return false;
for (int i = 17; i < len; i++)
if (n[i] < '0' || n[i] > '9')
@@ -43,22 +37,6 @@ bool IsDeviceName(LPCTSTR n)
return true;
}
#ifndef _UNICODE
bool IsDeviceName(LPCWSTR n)
{
if (n[0] != '\\' || n[1] != '\\' || n[2] != '.' || n[3] != '\\')
return false;
int len = (int)wcslen(n);
if (len == 6 && n[5] == ':')
return true;
if (len < 18 || len > 22 || wcsncmp(n + 4, L"PhysicalDrive", 13) != 0)
return false;
for (int i = 17; i < len; i++)
if (n[i] < '0' || n[i] > '9')
return false;
return true;
}
#endif
#endif
#if defined(WIN_LONG_PATH) && defined(_UNICODE)
@@ -66,32 +44,34 @@ bool IsDeviceName(LPCWSTR n)
#endif
#ifdef WIN_LONG_PATH
bool GetLongPathBase(LPCWSTR s, UString &res)
bool GetLongPathBase(CFSTR s, UString &res)
{
res.Empty();
int len = MyStringLen(s);
wchar_t c = s[0];
if (len < 1 || c == L'\\' || c == L'.' && (len == 1 || len == 2 && s[1] == L'.'))
FChar c = s[0];
if (len < 1 || c == '\\' || c == '.' && (len == 1 || len == 2 && s[1] == '.'))
return true;
UString curDir;
bool isAbs = false;
if (len > 3)
isAbs = (s[1] == L':' && s[2] == L'\\' && (c >= L'a' && c <= L'z' || c >= L'A' && c <= L'Z'));
isAbs = (s[1] == ':' && s[2] == '\\' && (c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z'));
if (!isAbs)
{
DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, curDir.GetBuffer(MAX_PATH + 1));
curDir.ReleaseBuffer();
if (needLength == 0 || needLength > MAX_PATH)
return false;
if (curDir[curDir.Length() - 1] != L'\\')
curDir += L'\\';
}
res = UString(L"\\\\?\\") + curDir + s;
{
WCHAR temp[MAX_PATH + 2];
temp[0] = 0;
DWORD needLength = ::GetCurrentDirectoryW(MAX_PATH + 1, temp);
if (needLength == 0 || needLength > MAX_PATH)
return false;
curDir = temp;
if (curDir.Back() != L'\\')
curDir += L'\\';
}
res = UString(L"\\\\?\\") + curDir + fs2us(s);
return true;
}
bool GetLongPath(LPCWSTR path, UString &longPath)
bool GetLongPath(CFSTR path, UString &longPath)
{
if (GetLongPathBase(path, longPath))
return !longPath.IsEmpty();
@@ -103,58 +83,39 @@ namespace NIO {
CFileBase::~CFileBase() { Close(); }
bool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,
bool CFileBase::Create(CFSTR fileName, DWORD desiredAccess,
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{
if (!Close())
return false;
_handle = ::CreateFile(fileName, desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
flagsAndAttributes, (HANDLE)NULL);
#ifdef WIN_LONG_PATH2
if (_handle == INVALID_HANDLE_VALUE)
{
UString longPath;
if (GetLongPath(fileName, longPath))
_handle = ::CreateFileW(longPath, desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
flagsAndAttributes, (HANDLE)NULL);
}
#endif
#ifdef SUPPORT_DEVICE_FILE
IsDeviceFile = false;
#endif
return (_handle != INVALID_HANDLE_VALUE);
}
#ifndef _UNICODE
bool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{
if (!g_IsNT)
return Create(UnicodeStringToMultiByte(fileName, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP),
desiredAccess, shareMode, creationDisposition, flagsAndAttributes);
if (!Close())
return false;
_handle = ::CreateFileW(fileName, desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
flagsAndAttributes, (HANDLE)NULL);
#ifdef WIN_LONG_PATH
if (_handle == INVALID_HANDLE_VALUE)
{
UString longPath;
if (GetLongPath(fileName, longPath))
_handle = ::CreateFileW(longPath, desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition,
flagsAndAttributes, (HANDLE)NULL);
}
#endif
#ifdef SUPPORT_DEVICE_FILE
IsDeviceFile = false;
#endif
#ifndef _UNICODE
if (!g_IsNT)
{
_handle = ::CreateFile(fs2fas(fileName), desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL);
}
else
#endif
{
_handle = ::CreateFileW(fs2us(fileName), desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL);
#ifdef WIN_LONG_PATH
if (_handle == INVALID_HANDLE_VALUE)
{
UString longPath;
if (GetLongPath(fileName, longPath))
_handle = ::CreateFileW(longPath, desiredAccess, shareMode,
(LPSECURITY_ATTRIBUTES)NULL, creationDisposition, flagsAndAttributes, (HANDLE)NULL);
}
#endif
}
return (_handle != INVALID_HANDLE_VALUE);
}
#endif
bool CFileBase::Close()
{
@@ -226,21 +187,23 @@ bool CFileBase::SeekToEnd(UInt64 &newPosition)
return Seek(0, FILE_END, newPosition);
}
bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const
/*
bool CFileBase::GetFileInformation(CByHandleFileInfo &fi) const
{
BY_HANDLE_FILE_INFORMATION winFileInfo;
if (!::GetFileInformationByHandle(_handle, &winFileInfo))
BY_HANDLE_FILE_INFORMATION wfi;
if (!::GetFileInformationByHandle(_handle, &wfi))
return false;
fileInfo.Attrib = winFileInfo.dwFileAttributes;
fileInfo.CTime = winFileInfo.ftCreationTime;
fileInfo.ATime = winFileInfo.ftLastAccessTime;
fileInfo.MTime = winFileInfo.ftLastWriteTime;
fileInfo.VolumeSerialNumber = winFileInfo.dwFileAttributes;
fileInfo.Size = (((UInt64)winFileInfo.nFileSizeHigh) << 32) + winFileInfo.nFileSizeLow;
fileInfo.NumberOfLinks = winFileInfo.nNumberOfLinks;
fileInfo.FileIndex = (((UInt64)winFileInfo.nFileIndexHigh) << 32) + winFileInfo.nFileIndexLow;
fi.Attrib = wfi.dwFileAttributes;
fi.CTime = wfi.ftCreationTime;
fi.ATime = wfi.ftLastAccessTime;
fi.MTime = wfi.ftLastWriteTime;
fi.Size = (((UInt64)wfi.nFileSizeHigh) << 32) + wfi.nFileSizeLow;
fi.VolumeSerialNumber = wfi.dwVolumeSerialNumber;
fi.NumLinks = wfi.nNumberOfLinks;
fi.FileIndex = (((UInt64)wfi.nFileIndexHigh) << 32) + wfi.nFileIndexLow;
return true;
}
*/
/////////////////////////
// CInFile
@@ -284,34 +247,19 @@ void CInFile::GetDeviceLength()
#define MY_DEVICE_EXTRA_CODE
#endif
bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
bool CInFile::Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{
bool res = Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes);
MY_DEVICE_EXTRA_CODE
return res;
}
bool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)
bool CInFile::OpenShared(CFSTR fileName, bool shareForWrite)
{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
bool CInFile::Open(LPCTSTR fileName)
bool CInFile::Open(CFSTR fileName)
{ return OpenShared(fileName, false); }
#ifndef _UNICODE
bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{
bool res = Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes);
MY_DEVICE_EXTRA_CODE
return res;
}
bool CInFile::OpenShared(LPCWSTR fileName, bool shareForWrite)
{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
bool CInFile::Open(LPCWSTR fileName)
{ return OpenShared(fileName, false); }
#endif
// ReadFile and WriteFile functions in Windows have BUG:
// If you Read or Write 64MB or more (probably min_failure_size = 64MB - 32KB + 1)
// from/to Network file, it returns ERROR_NO_SYSTEM_RESOURCES
@@ -360,31 +308,18 @@ 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); }
static inline DWORD GetCreationDisposition(bool createAlways)
{ return createAlways? CREATE_ALWAYS: CREATE_NEW; }
bool COutFile::Open(LPCTSTR fileName, DWORD creationDisposition)
{ return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }
bool COutFile::Create(LPCTSTR fileName, bool createAlways)
{ return Open(fileName, GetCreationDisposition(createAlways)); }
#ifndef _UNICODE
bool COutFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
bool COutFile::Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
{ return CFileBase::Create(fileName, GENERIC_WRITE, shareMode, creationDisposition, flagsAndAttributes); }
bool COutFile::Open(LPCWSTR fileName, DWORD creationDisposition)
bool COutFile::Open(CFSTR fileName, DWORD creationDisposition)
{ return Open(fileName, FILE_SHARE_READ, creationDisposition, FILE_ATTRIBUTE_NORMAL); }
bool COutFile::Create(LPCWSTR fileName, bool createAlways)
bool COutFile::Create(CFSTR fileName, bool createAlways)
{ return Open(fileName, GetCreationDisposition(createAlways)); }
#endif
bool COutFile::SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime)
{ return BOOLToBool(::SetFileTime(_handle, cTime, aTime, mTime)); }

View File

@@ -1,9 +1,10 @@
// Windows/FileIO.h
#ifndef __WINDOWS_FILEIO_H
#define __WINDOWS_FILEIO_H
#ifndef __WINDOWS_FILE_IO_H
#define __WINDOWS_FILE_IO_H
#include "../Common/Types.h"
#include "../Common/MyString.h"
#include "Defs.h"
@@ -11,29 +12,27 @@ namespace NWindows {
namespace NFile {
namespace NIO {
/*
struct CByHandleFileInfo
{
DWORD Attrib;
UInt64 Size;
FILETIME CTime;
FILETIME ATime;
FILETIME MTime;
DWORD Attrib;
DWORD VolumeSerialNumber;
UInt64 Size;
DWORD NumberOfLinks;
DWORD NumLinks;
UInt64 FileIndex;
};
*/
class CFileBase
{
protected:
HANDLE _handle;
bool Create(LPCTSTR fileName, DWORD desiredAccess,
bool Create(CFSTR fileName, DWORD desiredAccess,
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
#ifndef _UNICODE
bool Create(LPCWSTR fileName, DWORD desiredAccess,
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
#endif
public:
#ifdef SUPPORT_DEVICE_FILE
@@ -55,7 +54,7 @@ public:
bool SeekToBegin();
bool SeekToEnd(UInt64 &newPosition);
bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
// bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
};
#define IOCTL_CDROM_BASE FILE_DEVICE_CD_ROM
@@ -97,14 +96,10 @@ class CInFile: public CFileBase
#endif
public:
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool OpenShared(LPCTSTR fileName, bool shareForWrite);
bool Open(LPCTSTR fileName);
#ifndef _UNICODE
bool Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool OpenShared(LPCWSTR fileName, bool shareForWrite);
bool Open(LPCWSTR fileName);
#endif
bool Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool OpenShared(CFSTR fileName, bool shareForWrite);
bool Open(CFSTR fileName);
bool Read1(void *data, UInt32 size, UInt32 &processedSize);
bool ReadPart(void *data, UInt32 size, UInt32 &processedSize);
bool Read(void *data, UInt32 size, UInt32 &processedSize);
@@ -113,15 +108,9 @@ public:
class COutFile: public CFileBase
{
public:
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 creationDisposition);
bool Create(LPCWSTR fileName, bool createAlways);
#endif
bool Open(CFSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
bool Open(CFSTR fileName, DWORD creationDisposition);
bool Create(CFSTR fileName, bool createAlways);
bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
bool SetMTime(const FILETIME *mTime);

View File

@@ -2,49 +2,28 @@
#include "StdAfx.h"
#include "Windows/FileName.h"
#include "Common/Wildcard.h"
#include "FileName.h"
namespace NWindows {
namespace NFile {
namespace NName {
void NormalizeDirPathPrefix(CSysString &dirPath)
void NormalizeDirPathPrefix(FString &dirPath)
{
if (dirPath.IsEmpty())
return;
if (dirPath.ReverseFind(kDirDelimiter) != dirPath.Length() - 1)
dirPath += kDirDelimiter;
if (dirPath.ReverseFind(FCHAR_PATH_SEPARATOR) != dirPath.Length() - 1)
dirPath += FCHAR_PATH_SEPARATOR;
}
#ifndef _UNICODE
#ifndef USE_UNICODE_FSTRING
void NormalizeDirPathPrefix(UString &dirPath)
{
if (dirPath.IsEmpty())
return;
if (dirPath.ReverseFind(wchar_t(kDirDelimiter)) != dirPath.Length() - 1)
dirPath += wchar_t(kDirDelimiter);
if (dirPath.ReverseFind(WCHAR_PATH_SEPARATOR) != dirPath.Length() - 1)
dirPath += WCHAR_PATH_SEPARATOR;
}
#endif
const wchar_t kExtensionDelimiter = L'.';
void SplitNameToPureNameAndExtension(const UString &fullName,
UString &pureName, UString &extensionDelimiter, UString &extension)
{
int index = fullName.ReverseFind(kExtensionDelimiter);
if (index < 0)
{
pureName = fullName;
extensionDelimiter.Empty();
extension.Empty();
}
else
{
pureName = fullName.Left(index);
extensionDelimiter = kExtensionDelimiter;
extension = fullName.Mid(index + 1);
}
}
}}}

View File

@@ -1,9 +1,7 @@
// Windows/FileName.h
#ifndef __WINDOWS_FILENAME_H
#define __WINDOWS_FILENAME_H
#include "../../C/Types.h"
#ifndef __WINDOWS_FILE_NAME_H
#define __WINDOWS_FILE_NAME_H
#include "../Common/MyString.h"
@@ -11,16 +9,8 @@ namespace NWindows {
namespace NFile {
namespace NName {
const TCHAR kDirDelimiter = CHAR_PATH_SEPARATOR;
const TCHAR kAnyStringWildcard = '*';
void NormalizeDirPathPrefix(CSysString &dirPath); // ensures that it ended with '\\'
#ifndef _UNICODE
void NormalizeDirPathPrefix(UString &dirPath); // ensures that it ended with '\\'
#endif
void SplitNameToPureNameAndExtension(const UString &fullName,
UString &pureName, UString &extensionDelimiter, UString &extension);
void NormalizeDirPathPrefix(FString &dirPath); // ensures that it ended with '\\', if dirPath is not epmty
void NormalizeDirPathPrefix(UString &dirPath);
}}}

View File

@@ -2,6 +2,10 @@
#include "StdAfx.h"
#ifndef _UNICODE
#include "Common/StringConvert.h"
#endif
#include "FileSystem.h"
#include "Defs.h"
@@ -14,113 +18,94 @@ namespace NFile {
namespace NSystem {
bool MyGetVolumeInformation(
LPCTSTR rootPathName,
CSysString &volumeName,
LPDWORD volumeSerialNumber,
LPDWORD maximumComponentLength,
LPDWORD fileSystemFlags,
CSysString &fileSystemName)
{
bool result = BOOLToBool(GetVolumeInformation(
rootPathName,
volumeName.GetBuffer(MAX_PATH), MAX_PATH,
volumeSerialNumber,
maximumComponentLength,
fileSystemFlags,
fileSystemName.GetBuffer(MAX_PATH), MAX_PATH));
volumeName.ReleaseBuffer();
fileSystemName.ReleaseBuffer();
return result;
}
#ifndef _UNICODE
bool MyGetVolumeInformation(
LPCWSTR rootPathName,
CFSTR rootPath,
UString &volumeName,
LPDWORD volumeSerialNumber,
LPDWORD maximumComponentLength,
LPDWORD fileSystemFlags,
UString &fileSystemName)
{
if (g_IsNT)
BOOL res;
#ifndef _UNICODE
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;
TCHAR v[MAX_PATH + 2]; v[0] = 0;
TCHAR f[MAX_PATH + 2]; f[0] = 0;
res = GetVolumeInformation(fs2fas(rootPath),
v, MAX_PATH,
volumeSerialNumber, maximumComponentLength, fileSystemFlags,
f, MAX_PATH);
volumeName = MultiByteToUnicodeString(v);
fileSystemName = MultiByteToUnicodeString(f);
}
AString volumeNameA, fileSystemNameA;
bool result = MyGetVolumeInformation(GetSystemString(rootPathName), volumeNameA,
volumeSerialNumber, maximumComponentLength, fileSystemFlags,fileSystemNameA);
if (result)
else
#endif
{
volumeName = GetUnicodeString(volumeNameA);
fileSystemName = GetUnicodeString(fileSystemNameA);
WCHAR v[MAX_PATH + 2]; v[0] = 0;
WCHAR f[MAX_PATH + 2]; f[0] = 0;
res = GetVolumeInformationW(fs2us(rootPath),
v, MAX_PATH,
volumeSerialNumber, maximumComponentLength, fileSystemFlags,
f, MAX_PATH);
volumeName = v;
fileSystemName = f;
}
return result;
return BOOLToBool(res);
}
#endif
typedef BOOL (WINAPI * GetDiskFreeSpaceExPointer)(
LPCTSTR lpDirectoryName, // directory name
UINT MyGetDriveType(CFSTR pathName)
{
#ifndef _UNICODE
if (!g_IsNT)
{
return GetDriveType(fs2fas(pathName));
}
else
#endif
{
return GetDriveTypeW(fs2us(pathName));
}
}
typedef BOOL (WINAPI * GetDiskFreeSpaceExW_Pointer)(
LPCWSTR lpDirectoryName, // directory name
PULARGE_INTEGER lpFreeBytesAvailable, // bytes available to caller
PULARGE_INTEGER lpTotalNumberOfBytes, // bytes on disk
PULARGE_INTEGER lpTotalNumberOfFreeBytes // free bytes on disk
);
bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize)
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize)
{
GetDiskFreeSpaceExPointer pGetDiskFreeSpaceEx =
(GetDiskFreeSpaceExPointer)GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExA");
DWORD numSectorsPerCluster, bytesPerSector, numFreeClusters, numClusters;
bool sizeIsDetected = false;
if (pGetDiskFreeSpaceEx)
#ifndef _UNICODE
if (!g_IsNT)
{
ULARGE_INTEGER i64FreeBytesToCaller, totalSize2, freeSize2;
sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(rootPathName,
&i64FreeBytesToCaller,
&totalSize2,
&freeSize2));
totalSize = totalSize2.QuadPart;
freeSize = freeSize2.QuadPart;
if (!::GetDiskFreeSpace(fs2fas(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters))
return false;
}
else
#endif
{
GetDiskFreeSpaceExW_Pointer pGetDiskFreeSpaceEx = (GetDiskFreeSpaceExW_Pointer)GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")), "GetDiskFreeSpaceExW");
if (pGetDiskFreeSpaceEx)
{
ULARGE_INTEGER freeBytesToCaller2, totalSize2, freeSize2;
sizeIsDetected = BOOLToBool(pGetDiskFreeSpaceEx(fs2us(rootPath), &freeBytesToCaller2, &totalSize2, &freeSize2));
totalSize = totalSize2.QuadPart;
freeSize = freeSize2.QuadPart;
}
if (!::GetDiskFreeSpaceW(fs2us(rootPath), &numSectorsPerCluster, &bytesPerSector, &numFreeClusters, &numClusters))
return false;
}
DWORD numSectorsPerCluster;
DWORD bytesPerSector;
DWORD numberOfFreeClusters;
DWORD totalNumberOfClusters;
if (!::GetDiskFreeSpace(rootPathName,
&numSectorsPerCluster,
&bytesPerSector,
&numberOfFreeClusters,
&totalNumberOfClusters))
return false;
clusterSize = (UInt64)bytesPerSector * (UInt64)numSectorsPerCluster;
if (!sizeIsDetected)
{
totalSize = clusterSize * (UInt64)totalNumberOfClusters;
freeSize = clusterSize * (UInt64)numberOfFreeClusters;
totalSize = clusterSize * (UInt64)numClusters;
freeSize = clusterSize * (UInt64)numFreeClusters;
}
return true;
}
#ifndef _UNICODE
bool MyGetDiskFreeSpace(LPCWSTR rootPathName,
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize)
{
return MyGetDiskFreeSpace(GetSystemString(rootPathName), clusterSize, totalSize, freeSize);
}
#endif
}}}

View File

@@ -1,51 +1,27 @@
// Windows/FileSystem.h
#ifndef __WINDOWS_FILESYSTEM_H
#define __WINDOWS_FILESYSTEM_H
#ifndef __WINDOWS_FILE_SYSTEM_H
#define __WINDOWS_FILE_SYSTEM_H
#include "../Common/MyString.h"
#include "../Common/Types.h"
#ifndef _UNICODE
#include "../Common/StringConvert.h"
#endif
namespace NWindows {
namespace NFile {
namespace NSystem {
bool MyGetVolumeInformation(
LPCTSTR rootPathName,
CSysString &volumeName,
LPDWORD volumeSerialNumber,
LPDWORD maximumComponentLength,
LPDWORD fileSystemFlags,
CSysString &fileSystemName);
#ifndef _UNICODE
bool MyGetVolumeInformation(
LPCWSTR rootPathName,
CFSTR rootPath ,
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
UINT MyGetDriveType(CFSTR pathName);
bool MyGetDiskFreeSpace(LPCTSTR rootPathName,
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
#ifndef _UNICODE
bool MyGetDiskFreeSpace(LPCWSTR rootPathName,
UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
#endif
bool MyGetDiskFreeSpace(CFSTR rootPath, UInt64 &clusterSize, UInt64 &totalSize, UInt64 &freeSize);
}}}
#endif

View File

@@ -20,7 +20,7 @@ void StringToProp(const AString &s, NCOM::CPropVariant &prop)
prop = MultiByteToUnicodeString(s);
}
void PairToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 value, NCOM::CPropVariant &prop)
AString TypePairToString(const CUInt32PCharPair *pairs, unsigned num, UInt32 value)
{
AString s;
for (unsigned i = 0; i < num; i++)
@@ -31,7 +31,13 @@ void PairToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 value, NCOM:
}
if (s.IsEmpty())
s = GetHex(value);
StringToProp(s, prop);
return s;
}
void PairToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 value, NCOM::CPropVariant &prop)
{
StringToProp(TypePairToString(pairs, num, value), prop);
}
AString TypeToString(const char *table[], unsigned num, UInt32 value)
@@ -56,9 +62,12 @@ AString FlagsToString(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags)
UInt32 flag = (UInt32)1 << (unsigned)p.Value;
if ((flags & flag) != 0)
{
if (!s.IsEmpty())
s += ' ';
s += p.Name;
if (p.Name[0] != 0)
{
if (!s.IsEmpty())
s += ' ';
s += p.Name;
}
}
flags &= ~flag;
}
@@ -75,4 +84,3 @@ void FlagsToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags, NCOM
{
StringToProp(FlagsToString(pairs, num, flags), prop);
}

View File

@@ -13,6 +13,7 @@ struct CUInt32PCharPair
};
void StringToProp(const AString &s, NWindows::NCOM::CPropVariant &prop);
AString TypePairToString(const CUInt32PCharPair *pairs, unsigned num, UInt32 value);
void PairToProp(const CUInt32PCharPair *pairs, unsigned num, UInt32 value, NWindows::NCOM::CPropVariant &prop);
AString FlagsToString(const CUInt32PCharPair *pairs, unsigned num, UInt32 flags);

View File

@@ -13,8 +13,9 @@ static const UInt32 kNumTimeQuantumsInSecond = 10000000;
static const UInt32 kFileTimeStartYear = 1601;
static const UInt32 kDosTimeStartYear = 1980;
static const UInt32 kUnixTimeStartYear = 1970;
static const UInt64 kUnixTimeStartValue = ((UInt64)kNumTimeQuantumsInSecond) *
60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear));
static const UInt64 kUnixTimeOffset =
(UInt64)60 * 60 * 24 * (89 + 365 * (kUnixTimeStartYear - kFileTimeStartYear));
static const UInt64 kNumSecondsInFileTime = (UInt64)(Int64)-1 / kNumTimeQuantumsInSecond;
bool DosTimeToFileTime(UInt32 dosTime, FILETIME &ft)
{
@@ -117,20 +118,52 @@ bool FileTimeToDosTime(const FILETIME &ft, UInt32 &dosTime)
void UnixTimeToFileTime(UInt32 unixTime, FILETIME &ft)
{
UInt64 v = kUnixTimeStartValue + ((UInt64)unixTime) * kNumTimeQuantumsInSecond;
UInt64 v = (kUnixTimeOffset + (UInt64)unixTime) * kNumTimeQuantumsInSecond;
ft.dwLowDateTime = (DWORD)v;
ft.dwHighDateTime = (DWORD)(v >> 32);
}
bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &ft)
{
Int64 v = (Int64)kUnixTimeOffset + unixTime;
if (unixTime < 0)
{
if (v < 0)
{
ft.dwLowDateTime = ft.dwHighDateTime = 0;
return false;
}
}
else
{
if (v < unixTime || v > kNumSecondsInFileTime)
{
ft.dwLowDateTime = ft.dwHighDateTime = (UInt32)(Int32)-1;
return false;
}
}
UInt64 v2 = (UInt64)v * kNumTimeQuantumsInSecond;
ft.dwLowDateTime = (DWORD)v2;
ft.dwHighDateTime = (DWORD)(v2 >> 32);
return true;
}
Int64 FileTimeToUnixTime64(const FILETIME &ft)
{
UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
return (Int64)(winTime / kNumTimeQuantumsInSecond) - kUnixTimeOffset;
}
bool FileTimeToUnixTime(const FILETIME &ft, UInt32 &unixTime)
{
UInt64 winTime = (((UInt64)ft.dwHighDateTime) << 32) + ft.dwLowDateTime;
if (winTime < kUnixTimeStartValue)
winTime /= kNumTimeQuantumsInSecond;
if (winTime < kUnixTimeOffset)
{
unixTime = 0;
return false;
}
winTime = (winTime - kUnixTimeStartValue) / kNumTimeQuantumsInSecond;
winTime -= kUnixTimeOffset;
if (winTime > 0xFFFFFFFF)
{
unixTime = 0xFFFFFFFF;

View File

@@ -11,7 +11,9 @@ namespace NTime {
bool DosTimeToFileTime(UInt32 dosTime, FILETIME &fileTime);
bool FileTimeToDosTime(const FILETIME &fileTime, UInt32 &dosTime);
void UnixTimeToFileTime(UInt32 unixTime, FILETIME &fileTime);
bool UnixTime64ToFileTime(Int64 unixTime, FILETIME &fileTime);
bool FileTimeToUnixTime(const FILETIME &fileTime, UInt32 &unixTime);
Int64 FileTimeToUnixTime64(const FILETIME &ft);
bool GetSecondsSince1601(unsigned year, unsigned month, unsigned day,
unsigned hour, unsigned min, unsigned sec, UInt64 &resSeconds);
void GetCurUtcFileTime(FILETIME &ft);