mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 23:14:54 -06:00
9.04 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
8874e4fbc9
commit
829409452d
@@ -1,49 +0,0 @@
|
||||
// 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;
|
||||
}
|
||||
|
||||
}}}
|
||||
@@ -1,123 +0,0 @@
|
||||
// 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 = (BOOLEAN)(lock ? TRUE : FALSE);
|
||||
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;
|
||||
// Check params, Probabably error
|
||||
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
|
||||
@@ -2,14 +2,14 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FileDir.h"
|
||||
#include "FileName.h"
|
||||
#include "FileFind.h"
|
||||
#include "Defs.h"
|
||||
#ifndef _UNICODE
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
|
||||
#include "FileDir.h"
|
||||
#include "FileFind.h"
|
||||
#include "FileName.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif
|
||||
@@ -291,7 +291,7 @@ bool CreateComplexDirectory(LPCTSTR _aPathName)
|
||||
if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
NFind::CFileInfo fileInfo;
|
||||
if (!NFind::FindFile(pathName, fileInfo)) // For network folders
|
||||
if (!fileInfo.Find(pathName)) // For network folders
|
||||
return true;
|
||||
if (!fileInfo.IsDir())
|
||||
return false;
|
||||
@@ -337,7 +337,7 @@ bool CreateComplexDirectory(LPCWSTR _aPathName)
|
||||
if (::GetLastError() == ERROR_ALREADY_EXISTS)
|
||||
{
|
||||
NFind::CFileInfoW fileInfo;
|
||||
if (!NFind::FindFile(pathName, fileInfo)) // For network folders
|
||||
if (!fileInfo.Find(pathName)) // For network folders
|
||||
return true;
|
||||
if (!fileInfo.IsDir())
|
||||
return false;
|
||||
@@ -773,18 +773,20 @@ bool CreateTempDirectory(LPCTSTR prefix, CSysString &dirName)
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
CTempFile tempFile;
|
||||
if (!tempFile.Create(prefix, dirName))
|
||||
return false;
|
||||
if (!::DeleteFile(dirName))
|
||||
return false;
|
||||
{
|
||||
CTempFile tempFile;
|
||||
if (!tempFile.Create(prefix, dirName))
|
||||
return false;
|
||||
if (!tempFile.Remove())
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
UINT32 randomNumber = random.Generate();
|
||||
TCHAR randomNumberString[32];
|
||||
_stprintf(randomNumberString, _T("%04X"), randomNumber);
|
||||
dirName = prefix + randomNumberString;
|
||||
*/
|
||||
if (NFind::DoesFileExist(dirName))
|
||||
if (NFind::DoesFileOrDirExist(dirName))
|
||||
continue;
|
||||
if (MyCreateDirectory(dirName))
|
||||
return true;
|
||||
@@ -810,18 +812,20 @@ bool CreateTempDirectory(LPCWSTR prefix, UString &dirName)
|
||||
*/
|
||||
for (;;)
|
||||
{
|
||||
CTempFileW tempFile;
|
||||
if (!tempFile.Create(prefix, dirName))
|
||||
return false;
|
||||
if (!DeleteFileAlways(dirName))
|
||||
return false;
|
||||
{
|
||||
CTempFileW tempFile;
|
||||
if (!tempFile.Create(prefix, dirName))
|
||||
return false;
|
||||
if (!tempFile.Remove())
|
||||
return false;
|
||||
}
|
||||
/*
|
||||
UINT32 randomNumber = random.Generate();
|
||||
TCHAR randomNumberString[32];
|
||||
_stprintf(randomNumberString, _T("%04X"), randomNumber);
|
||||
dirName = prefix + randomNumberString;
|
||||
*/
|
||||
if (NFind::DoesFileExist(dirName))
|
||||
if (NFind::DoesFileOrDirExist(dirName))
|
||||
continue;
|
||||
if (MyCreateDirectory(dirName))
|
||||
return true;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FileFind.h"
|
||||
#include "FileIO.h"
|
||||
#ifndef _UNICODE
|
||||
#include "../Common/StringConvert.h"
|
||||
#endif
|
||||
@@ -14,6 +15,13 @@ extern bool g_IsNT;
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
bool IsDeviceName(LPCTSTR n);
|
||||
#ifndef _UNICODE
|
||||
bool IsDeviceName(LPCWSTR n);
|
||||
#endif
|
||||
#endif
|
||||
|
||||
#if defined(WIN_LONG_PATH) && defined(_UNICODE)
|
||||
#define WIN_LONG_PATH2
|
||||
#endif
|
||||
@@ -44,19 +52,26 @@ bool CFileInfoW::IsDots() const
|
||||
}
|
||||
#endif
|
||||
|
||||
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfo &fi)
|
||||
{
|
||||
fi.Attrib = fd.dwFileAttributes;
|
||||
fi.CTime = fd.ftCreationTime;
|
||||
fi.ATime = fd.ftLastAccessTime;
|
||||
fi.MTime = fd.ftLastWriteTime;
|
||||
fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
|
||||
fi.Name = fd.cFileName;
|
||||
#define WIN_FD_TO_MY_FI(fi, fd) \
|
||||
fi.Attrib = fd.dwFileAttributes; \
|
||||
fi.CTime = fd.ftCreationTime; \
|
||||
fi.ATime = fd.ftLastAccessTime; \
|
||||
fi.MTime = fd.ftLastWriteTime; \
|
||||
fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow; \
|
||||
fi.IsDevice = false;
|
||||
|
||||
/*
|
||||
#ifndef _WIN32_WCE
|
||||
fi.ReparseTag = fd.dwReserved0;
|
||||
#else
|
||||
fi.ObjectID = fd.dwOID;
|
||||
#endif
|
||||
*/
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
@@ -65,32 +80,14 @@ static inline UINT GetCurrentCodePage() { return ::AreFileApisANSI() ? CP_ACP :
|
||||
|
||||
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATAW &fd, CFileInfoW &fi)
|
||||
{
|
||||
fi.Attrib = fd.dwFileAttributes;
|
||||
fi.CTime = fd.ftCreationTime;
|
||||
fi.ATime = fd.ftLastAccessTime;
|
||||
fi.MTime = fd.ftLastWriteTime;
|
||||
fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
|
||||
WIN_FD_TO_MY_FI(fi, fd);
|
||||
fi.Name = fd.cFileName;
|
||||
#ifndef _WIN32_WCE
|
||||
fi.ReparseTag = fd.dwReserved0;
|
||||
#else
|
||||
fi.ObjectID = fd.dwOID;
|
||||
#endif
|
||||
}
|
||||
|
||||
static void ConvertWIN32_FIND_DATA_To_FileInfo(const WIN32_FIND_DATA &fd, CFileInfoW &fi)
|
||||
{
|
||||
fi.Attrib = fd.dwFileAttributes;
|
||||
fi.CTime = fd.ftCreationTime;
|
||||
fi.ATime = fd.ftLastAccessTime;
|
||||
fi.MTime = fd.ftLastWriteTime;
|
||||
fi.Size = (((UInt64)fd.nFileSizeHigh) << 32) + fd.nFileSizeLow;
|
||||
WIN_FD_TO_MY_FI(fi, fd);
|
||||
fi.Name = GetUnicodeString(fd.cFileName, GetCurrentCodePage());
|
||||
#ifndef _WIN32_WCE
|
||||
fi.ReparseTag = fd.dwReserved0;
|
||||
#else
|
||||
fi.ObjectID = fd.dwOID;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -108,7 +105,7 @@ bool CFindFile::Close()
|
||||
}
|
||||
|
||||
|
||||
bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
|
||||
bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fi)
|
||||
{
|
||||
if (!Close())
|
||||
return false;
|
||||
@@ -124,12 +121,12 @@ bool CFindFile::FindFirst(LPCTSTR wildcard, CFileInfo &fileInfo)
|
||||
#endif
|
||||
if (_handle == INVALID_HANDLE_VALUE)
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
|
||||
bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fi)
|
||||
{
|
||||
if (!Close())
|
||||
return false;
|
||||
@@ -146,7 +143,7 @@ bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
|
||||
}
|
||||
#endif
|
||||
if (_handle != INVALID_HANDLE_VALUE)
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -154,95 +151,158 @@ bool CFindFile::FindFirst(LPCWSTR wildcard, CFileInfoW &fileInfo)
|
||||
_handle = ::FindFirstFileA(UnicodeStringToMultiByte(wildcard,
|
||||
GetCurrentCodePage()), &fd);
|
||||
if (_handle != INVALID_HANDLE_VALUE)
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
}
|
||||
return (_handle != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool CFindFile::FindNext(CFileInfo &fileInfo)
|
||||
bool CFindFile::FindNext(CFileInfo &fi)
|
||||
{
|
||||
WIN32_FIND_DATA fd;
|
||||
bool result = BOOLToBool(::FindNextFile(_handle, &fd));
|
||||
if (result)
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
return result;
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CFindFile::FindNext(CFileInfoW &fileInfo)
|
||||
bool CFindFile::FindNext(CFileInfoW &fi)
|
||||
{
|
||||
if (g_IsNT)
|
||||
{
|
||||
WIN32_FIND_DATAW fd;
|
||||
if (!::FindNextFileW(_handle, &fd))
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
}
|
||||
else
|
||||
{
|
||||
WIN32_FIND_DATAA fd;
|
||||
if (!::FindNextFileA(_handle, &fd))
|
||||
return false;
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fileInfo);
|
||||
ConvertWIN32_FIND_DATA_To_FileInfo(fd, fi);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo)
|
||||
#define MY_CLEAR_FILETIME(ft) ft.dwLowDateTime = ft.dwHighDateTime = 0;
|
||||
|
||||
void CFileInfoBase::Clear()
|
||||
{
|
||||
Size = 0;
|
||||
MY_CLEAR_FILETIME(CTime);
|
||||
MY_CLEAR_FILETIME(ATime);
|
||||
MY_CLEAR_FILETIME(MTime);
|
||||
Attrib = 0;
|
||||
}
|
||||
|
||||
bool CFileInfo::Find(LPCTSTR 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;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
CFindFile finder;
|
||||
return finder.FindFirst(wildcard, fileInfo);
|
||||
return finder.FindFirst(wildcard, *this);
|
||||
}
|
||||
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo)
|
||||
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;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
CFindFile finder;
|
||||
return finder.FindFirst(wildcard, fileInfo);
|
||||
return finder.FindFirst(wildcard, *this);
|
||||
}
|
||||
#endif
|
||||
|
||||
bool DoesFileExist(LPCTSTR name)
|
||||
{
|
||||
CFileInfo fileInfo;
|
||||
return FindFile(name, fileInfo);
|
||||
CFileInfo fi;
|
||||
return fi.Find(name) && !fi.IsDir();
|
||||
}
|
||||
|
||||
bool DoesDirExist(LPCTSTR name)
|
||||
{
|
||||
CFileInfo fi;
|
||||
return fi.Find(name) && fi.IsDir();
|
||||
}
|
||||
|
||||
bool DoesFileOrDirExist(LPCTSTR name)
|
||||
{
|
||||
CFileInfo fi;
|
||||
return fi.Find(name);
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool DoesFileExist(LPCWSTR name)
|
||||
{
|
||||
CFileInfoW fileInfo;
|
||||
return FindFile(name, fileInfo);
|
||||
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 &fileInfo)
|
||||
bool CEnumerator::NextAny(CFileInfo &fi)
|
||||
{
|
||||
if (_findFile.IsHandleAllocated())
|
||||
return _findFile.FindNext(fileInfo);
|
||||
return _findFile.FindNext(fi);
|
||||
else
|
||||
return _findFile.FindFirst(_wildcard, fileInfo);
|
||||
return _findFile.FindFirst(_wildcard, fi);
|
||||
}
|
||||
|
||||
bool CEnumerator::Next(CFileInfo &fileInfo)
|
||||
bool CEnumerator::Next(CFileInfo &fi)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (!NextAny(fileInfo))
|
||||
if (!NextAny(fi))
|
||||
return false;
|
||||
if (!fileInfo.IsDots())
|
||||
if (!fi.IsDots())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CEnumerator::Next(CFileInfo &fileInfo, bool &found)
|
||||
bool CEnumerator::Next(CFileInfo &fi, bool &found)
|
||||
{
|
||||
if (Next(fileInfo))
|
||||
if (Next(fi))
|
||||
{
|
||||
found = true;
|
||||
return true;
|
||||
@@ -252,28 +312,28 @@ bool CEnumerator::Next(CFileInfo &fileInfo, bool &found)
|
||||
}
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CEnumeratorW::NextAny(CFileInfoW &fileInfo)
|
||||
bool CEnumeratorW::NextAny(CFileInfoW &fi)
|
||||
{
|
||||
if (_findFile.IsHandleAllocated())
|
||||
return _findFile.FindNext(fileInfo);
|
||||
return _findFile.FindNext(fi);
|
||||
else
|
||||
return _findFile.FindFirst(_wildcard, fileInfo);
|
||||
return _findFile.FindFirst(_wildcard, fi);
|
||||
}
|
||||
|
||||
bool CEnumeratorW::Next(CFileInfoW &fileInfo)
|
||||
bool CEnumeratorW::Next(CFileInfoW &fi)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
if (!NextAny(fileInfo))
|
||||
if (!NextAny(fi))
|
||||
return false;
|
||||
if (!fileInfo.IsDots())
|
||||
if (!fi.IsDots())
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool CEnumeratorW::Next(CFileInfoW &fileInfo, bool &found)
|
||||
bool CEnumeratorW::Next(CFileInfoW &fi, bool &found)
|
||||
{
|
||||
if (Next(fileInfo))
|
||||
if (Next(fi))
|
||||
{
|
||||
found = true;
|
||||
return true;
|
||||
|
||||
@@ -5,8 +5,8 @@
|
||||
|
||||
#include "../Common/MyString.h"
|
||||
#include "../Common/Types.h"
|
||||
#include "FileName.h"
|
||||
#include "Defs.h"
|
||||
#include "FileName.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
@@ -26,18 +26,23 @@ namespace NAttributes
|
||||
class CFileInfoBase
|
||||
{
|
||||
bool MatchesMask(UINT32 mask) const { return ((Attrib & mask) != 0); }
|
||||
protected:
|
||||
void Clear();
|
||||
public:
|
||||
UInt64 Size;
|
||||
FILETIME CTime;
|
||||
FILETIME ATime;
|
||||
FILETIME MTime;
|
||||
DWORD Attrib;
|
||||
|
||||
bool IsDevice;
|
||||
|
||||
/*
|
||||
#ifndef _WIN32_WCE
|
||||
UINT32 ReparseTag;
|
||||
#else
|
||||
DWORD ObjectID;
|
||||
#endif
|
||||
*/
|
||||
|
||||
bool IsArchived() const { return MatchesMask(FILE_ATTRIBUTE_ARCHIVE); }
|
||||
bool IsCompressed() const { return MatchesMask(FILE_ATTRIBUTE_COMPRESSED); }
|
||||
@@ -53,21 +58,23 @@ public:
|
||||
bool IsTemporary() const { return MatchesMask(FILE_ATTRIBUTE_TEMPORARY); }
|
||||
};
|
||||
|
||||
class CFileInfo: public CFileInfoBase
|
||||
struct CFileInfo: public CFileInfoBase
|
||||
{
|
||||
public:
|
||||
CSysString Name;
|
||||
|
||||
bool IsDots() const;
|
||||
bool Find(LPCTSTR wildcard);
|
||||
};
|
||||
|
||||
#ifdef _UNICODE
|
||||
typedef CFileInfo CFileInfoW;
|
||||
#else
|
||||
class CFileInfoW: public CFileInfoBase
|
||||
struct CFileInfoW: public CFileInfoBase
|
||||
{
|
||||
public:
|
||||
UString Name;
|
||||
|
||||
bool IsDots() const;
|
||||
bool Find(LPCWSTR wildcard);
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -88,12 +95,13 @@ public:
|
||||
bool Close();
|
||||
};
|
||||
|
||||
bool FindFile(LPCTSTR wildcard, CFileInfo &fileInfo);
|
||||
|
||||
bool DoesFileExist(LPCTSTR name);
|
||||
bool DoesDirExist(LPCTSTR name);
|
||||
bool DoesFileOrDirExist(LPCTSTR name);
|
||||
#ifndef _UNICODE
|
||||
bool FindFile(LPCWSTR wildcard, CFileInfoW &fileInfo);
|
||||
bool DoesFileExist(LPCWSTR name);
|
||||
bool DoesDirExist(LPCWSTR name);
|
||||
bool DoesFileOrDirExist(LPCWSTR name);
|
||||
#endif
|
||||
|
||||
class CEnumerator
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "FileIO.h"
|
||||
#include "Defs.h"
|
||||
#ifdef WIN_LONG_PATH
|
||||
|
||||
#if defined(WIN_LONG_PATH) || defined(SUPPORT_DEVICE_FILE)
|
||||
#include "../Common/MyString.h"
|
||||
#endif
|
||||
#ifndef _UNICODE
|
||||
@@ -18,6 +18,40 @@ extern bool g_IsNT;
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
bool IsDeviceName(LPCTSTR n)
|
||||
{
|
||||
if (n[0] != '\\' || n[1] != '\\' || n[2] != '.' || n[3] != '\\')
|
||||
return false;
|
||||
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)
|
||||
return false;
|
||||
for (int i = 17; i < len; i++)
|
||||
if (n[i] < '0' || n[i] > '9')
|
||||
return false;
|
||||
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)
|
||||
#define WIN_LONG_PATH2
|
||||
#endif
|
||||
@@ -78,6 +112,9 @@ bool CFileBase::Create(LPCTSTR fileName, DWORD desiredAccess,
|
||||
flagsAndAttributes, (HANDLE)NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
IsDeviceFile = false;
|
||||
#endif
|
||||
return (_handle != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
|
||||
@@ -103,6 +140,9 @@ bool CFileBase::Create(LPCWSTR fileName, DWORD desiredAccess,
|
||||
flagsAndAttributes, (HANDLE)NULL);
|
||||
}
|
||||
#endif
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
IsDeviceFile = false;
|
||||
#endif
|
||||
return (_handle != INVALID_HANDLE_VALUE);
|
||||
}
|
||||
#endif
|
||||
@@ -124,6 +164,14 @@ bool CFileBase::GetPosition(UInt64 &position) const
|
||||
|
||||
bool CFileBase::GetLength(UInt64 &length) const
|
||||
{
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
if (IsDeviceFile && LengthDefined)
|
||||
{
|
||||
length = Length;
|
||||
return true;
|
||||
}
|
||||
#endif
|
||||
|
||||
DWORD sizeHigh;
|
||||
DWORD sizeLow = ::GetFileSize(_handle, &sizeHigh);
|
||||
if (sizeLow == 0xFFFFFFFF)
|
||||
@@ -135,6 +183,14 @@ bool CFileBase::GetLength(UInt64 &length) const
|
||||
|
||||
bool CFileBase::Seek(Int64 distanceToMove, DWORD moveMethod, UInt64 &newPosition) const
|
||||
{
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
if (IsDeviceFile && LengthDefined && moveMethod == FILE_END)
|
||||
{
|
||||
distanceToMove += Length;
|
||||
moveMethod = FILE_BEGIN;
|
||||
}
|
||||
#endif
|
||||
|
||||
LARGE_INTEGER value;
|
||||
value.QuadPart = distanceToMove;
|
||||
value.LowPart = ::SetFilePointer(_handle, value.LowPart, &value.HighPart, moveMethod);
|
||||
@@ -166,7 +222,7 @@ bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const
|
||||
BY_HANDLE_FILE_INFORMATION winFileInfo;
|
||||
if (!::GetFileInformationByHandle(_handle, &winFileInfo))
|
||||
return false;
|
||||
fileInfo.Attributes = winFileInfo.dwFileAttributes;
|
||||
fileInfo.Attrib = winFileInfo.dwFileAttributes;
|
||||
fileInfo.CTime = winFileInfo.ftCreationTime;
|
||||
fileInfo.ATime = winFileInfo.ftLastAccessTime;
|
||||
fileInfo.MTime = winFileInfo.ftLastWriteTime;
|
||||
@@ -180,8 +236,45 @@ bool CFileBase::GetFileInformation(CByHandleFileInfo &fileInfo) const
|
||||
/////////////////////////
|
||||
// CInFile
|
||||
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
void CInFile::GetDeviceLength()
|
||||
{
|
||||
if (_handle != INVALID_HANDLE_VALUE && IsDeviceFile)
|
||||
{
|
||||
PARTITION_INFORMATION partInfo;
|
||||
LengthDefined = true;
|
||||
Length = 0;
|
||||
|
||||
if (GetPartitionInfo(&partInfo))
|
||||
Length = partInfo.PartitionLength.QuadPart;
|
||||
else
|
||||
{
|
||||
DISK_GEOMETRY geom;
|
||||
if (!GetGeometry(&geom))
|
||||
if (!GetCdRomGeometry(&geom))
|
||||
LengthDefined = false;
|
||||
if (LengthDefined)
|
||||
Length = geom.Cylinders.QuadPart * geom.TracksPerCylinder * geom.SectorsPerTrack * geom.BytesPerSector;
|
||||
}
|
||||
// SeekToBegin();
|
||||
}
|
||||
}
|
||||
|
||||
// ((desiredAccess & (FILE_WRITE_DATA | FILE_APPEND_DATA | GENERIC_WRITE)) == 0 &&
|
||||
|
||||
#define MY_DEVICE_EXTRA_CODE \
|
||||
IsDeviceFile = IsDeviceName(fileName); \
|
||||
GetDeviceLength();
|
||||
#else
|
||||
#define MY_DEVICE_EXTRA_CODE
|
||||
#endif
|
||||
|
||||
bool CInFile::Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes); }
|
||||
{
|
||||
bool res = Create(fileName, GENERIC_READ, shareMode, creationDisposition, flagsAndAttributes);
|
||||
MY_DEVICE_EXTRA_CODE
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CInFile::OpenShared(LPCTSTR fileName, bool shareForWrite)
|
||||
{ return Open(fileName, FILE_SHARE_READ | (shareForWrite ? FILE_SHARE_WRITE : 0), OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL); }
|
||||
@@ -191,7 +284,11 @@ bool CInFile::Open(LPCTSTR fileName)
|
||||
|
||||
#ifndef _UNICODE
|
||||
bool CInFile::Open(LPCWSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes)
|
||||
{ return Create(fileName, GENERIC_READ, shareMode, creationDisposition, 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); }
|
||||
@@ -211,16 +308,21 @@ bool CInFile::Open(LPCWSTR fileName)
|
||||
|
||||
static UInt32 kChunkSizeMax = (1 << 22);
|
||||
|
||||
bool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)
|
||||
bool CInFile::Read1(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;
|
||||
return res;
|
||||
}
|
||||
|
||||
bool CInFile::ReadPart(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
if (size > kChunkSizeMax)
|
||||
size = kChunkSizeMax;
|
||||
return Read1(data, size, processedSize);
|
||||
}
|
||||
|
||||
bool CInFile::Read(void *data, UInt32 size, UInt32 &processedSize)
|
||||
{
|
||||
processedSize = 0;
|
||||
|
||||
@@ -5,26 +5,29 @@
|
||||
|
||||
#include "../Common/Types.h"
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
namespace NWindows {
|
||||
namespace NFile {
|
||||
namespace NIO {
|
||||
|
||||
struct CByHandleFileInfo
|
||||
{
|
||||
DWORD Attributes;
|
||||
DWORD Attrib;
|
||||
FILETIME CTime;
|
||||
FILETIME ATime;
|
||||
FILETIME MTime;
|
||||
DWORD VolumeSerialNumber;
|
||||
UInt64 Size;
|
||||
DWORD NumberOfLinks;
|
||||
UInt64 FileIndex;
|
||||
DWORD VolumeSerialNumber;
|
||||
UInt64 Size;
|
||||
DWORD NumberOfLinks;
|
||||
UInt64 FileIndex;
|
||||
};
|
||||
|
||||
class CFileBase
|
||||
{
|
||||
protected:
|
||||
HANDLE _handle;
|
||||
|
||||
bool Create(LPCTSTR fileName, DWORD desiredAccess,
|
||||
DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
#ifndef _UNICODE
|
||||
@@ -33,7 +36,13 @@ protected:
|
||||
#endif
|
||||
|
||||
public:
|
||||
CFileBase(): _handle(INVALID_HANDLE_VALUE){};
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
bool IsDeviceFile;
|
||||
bool LengthDefined;
|
||||
UInt64 Length;
|
||||
#endif
|
||||
|
||||
CFileBase(): _handle(INVALID_HANDLE_VALUE) {};
|
||||
~CFileBase();
|
||||
|
||||
bool Close();
|
||||
@@ -49,8 +58,42 @@ public:
|
||||
bool GetFileInformation(CByHandleFileInfo &fileInfo) const;
|
||||
};
|
||||
|
||||
#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 CInFile: public CFileBase
|
||||
{
|
||||
#ifdef SUPPORT_DEVICE_FILE
|
||||
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 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 GetPartitionInfo(PARTITION_INFORMATION *res)
|
||||
{ return DeviceIoControlOut(IOCTL_DISK_GET_PARTITION_INFO, LPVOID(res), sizeof(*res)); }
|
||||
|
||||
void GetDeviceLength();
|
||||
#endif
|
||||
|
||||
public:
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool OpenShared(LPCTSTR fileName, bool shareForWrite);
|
||||
@@ -60,15 +103,14 @@ public:
|
||||
bool OpenShared(LPCWSTR fileName, bool shareForWrite);
|
||||
bool Open(LPCWSTR fileName);
|
||||
#endif
|
||||
bool Read1(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
|
||||
{
|
||||
// DWORD m_CreationDisposition;
|
||||
public:
|
||||
// COutFile(): m_CreationDisposition(CREATE_NEW){};
|
||||
bool Open(LPCTSTR fileName, DWORD shareMode, DWORD creationDisposition, DWORD flagsAndAttributes);
|
||||
bool Open(LPCTSTR fileName, DWORD creationDisposition);
|
||||
bool Create(LPCTSTR fileName, bool createAlways);
|
||||
@@ -79,13 +121,6 @@ public:
|
||||
bool Create(LPCWSTR fileName, bool createAlways);
|
||||
#endif
|
||||
|
||||
/*
|
||||
void SetOpenCreationDisposition(DWORD creationDisposition)
|
||||
{ m_CreationDisposition = creationDisposition; }
|
||||
void SetOpenCreationDispositionCreateAlways()
|
||||
{ m_CreationDisposition = CREATE_ALWAYS; }
|
||||
*/
|
||||
|
||||
bool SetTime(const FILETIME *cTime, const FILETIME *aTime, const FILETIME *mTime);
|
||||
bool SetMTime(const FILETIME *mTime);
|
||||
bool WritePart(const void *data, UInt32 size, UInt32 &processedSize);
|
||||
|
||||
@@ -65,6 +65,26 @@ CPropVariant& CPropVariant::operator=(LPCOLESTR lpszSrc)
|
||||
}
|
||||
|
||||
|
||||
CPropVariant& CPropVariant::operator=(const char *s)
|
||||
{
|
||||
InternalClear();
|
||||
vt = VT_BSTR;
|
||||
wReserved1 = 0;
|
||||
UINT len = (UINT)strlen(s);
|
||||
bstrVal = ::SysAllocStringByteLen(0, (UINT)len * sizeof(OLECHAR));
|
||||
if (bstrVal == NULL)
|
||||
{
|
||||
vt = VT_ERROR;
|
||||
scode = E_OUTOFMEMORY;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (UINT i = 0; i <= len; i++)
|
||||
bstrVal[i] = s[i];
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
|
||||
CPropVariant& CPropVariant::operator=(bool bSrc)
|
||||
{
|
||||
if (vt != VT_BOOL)
|
||||
|
||||
@@ -31,6 +31,7 @@ public:
|
||||
CPropVariant& operator=(const PROPVARIANT& varSrc);
|
||||
CPropVariant& operator=(BSTR bstrSrc);
|
||||
CPropVariant& operator=(LPCOLESTR lpszSrc);
|
||||
CPropVariant& operator=(const char *s);
|
||||
CPropVariant& operator=(bool bSrc);
|
||||
CPropVariant& operator=(UInt32 value);
|
||||
CPropVariant& operator=(UInt64 value);
|
||||
|
||||
@@ -121,8 +121,7 @@ bool AddLockMemoryPrivilege()
|
||||
!= 0)
|
||||
return false;
|
||||
LSA_UNICODE_STRING userRights;
|
||||
wchar_t s[128];
|
||||
wcscpy(s, MY__SE_LOCK_MEMORY_NAME);
|
||||
wchar_t s[128] = MY__SE_LOCK_MEMORY_NAME;
|
||||
SetLsaString(s, &userRights);
|
||||
WCHAR userName[256 + 2];
|
||||
DWORD size = 256;
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
#ifndef __WINDOWS_SYNCHRONIZATION_H
|
||||
#define __WINDOWS_SYNCHRONIZATION_H
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../C/Threads.h"
|
||||
}
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#include "Handle.h"
|
||||
@@ -23,7 +20,7 @@ protected:
|
||||
::CEvent _object;
|
||||
public:
|
||||
bool IsCreated() { return Event_IsCreated(&_object) != 0; }
|
||||
operator HANDLE() { return _object.handle; }
|
||||
operator HANDLE() { return _object; }
|
||||
CBaseEvent() { Event_Construct(&_object); }
|
||||
~CBaseEvent() { Close(); }
|
||||
WRes Close() { return Event_Close(&_object); }
|
||||
@@ -31,16 +28,16 @@ public:
|
||||
WRes Create(bool manualReset, bool initiallyOwn, LPCTSTR name = NULL,
|
||||
LPSECURITY_ATTRIBUTES securityAttributes = NULL)
|
||||
{
|
||||
_object.handle = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),
|
||||
_object = ::CreateEvent(securityAttributes, BoolToBOOL(manualReset),
|
||||
BoolToBOOL(initiallyOwn), name);
|
||||
if (_object.handle != 0)
|
||||
if (_object != 0)
|
||||
return 0;
|
||||
return ::GetLastError();
|
||||
}
|
||||
WRes Open(DWORD desiredAccess, bool inheritHandle, LPCTSTR name)
|
||||
{
|
||||
_object.handle = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);
|
||||
if (_object.handle != 0)
|
||||
_object = ::OpenEvent(desiredAccess, BoolToBOOL(inheritHandle), name);
|
||||
if (_object != 0)
|
||||
return 0;
|
||||
return ::GetLastError();
|
||||
}
|
||||
@@ -134,7 +131,7 @@ public:
|
||||
CSemaphore() { Semaphore_Construct(&_object); }
|
||||
~CSemaphore() { Close(); }
|
||||
WRes Close() { return Semaphore_Close(&_object); }
|
||||
operator HANDLE() { return _object.handle; }
|
||||
operator HANDLE() { return _object; }
|
||||
WRes Create(UInt32 initiallyCount, UInt32 maxCount)
|
||||
{
|
||||
return Semaphore_Create(&_object, initiallyCount, maxCount);
|
||||
|
||||
@@ -3,12 +3,9 @@
|
||||
#ifndef __WINDOWS_THREAD_H
|
||||
#define __WINDOWS_THREAD_H
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "../../C/Threads.h"
|
||||
}
|
||||
|
||||
#include "Defs.h"
|
||||
|
||||
namespace NWindows {
|
||||
|
||||
@@ -25,14 +22,14 @@ public:
|
||||
WRes Wait() { return Thread_Wait(&thread); }
|
||||
|
||||
#ifdef _WIN32
|
||||
operator HANDLE() { return thread.handle; }
|
||||
void Attach(HANDLE handle) { thread.handle = handle; }
|
||||
HANDLE Detach() { HANDLE h = thread.handle; thread.handle = NULL; return h; }
|
||||
DWORD Resume() { return ::ResumeThread(thread.handle); }
|
||||
DWORD Suspend() { return ::SuspendThread(thread.handle); }
|
||||
bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread.handle, exitCode)); }
|
||||
int GetPriority() { return ::GetThreadPriority(thread.handle); }
|
||||
bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread.handle, priority)); }
|
||||
operator HANDLE() { return thread; }
|
||||
void Attach(HANDLE handle) { thread = handle; }
|
||||
HANDLE Detach() { HANDLE h = thread; thread = NULL; return h; }
|
||||
DWORD Resume() { return ::ResumeThread(thread); }
|
||||
DWORD Suspend() { return ::SuspendThread(thread); }
|
||||
bool Terminate(DWORD exitCode) { return BOOLToBool(::TerminateThread(thread, exitCode)); }
|
||||
int GetPriority() { return ::GetThreadPriority(thread); }
|
||||
bool SetPriority(int priority) { return BOOLToBool(::SetThreadPriority(thread, priority)); }
|
||||
#endif
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user