mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 05:15:01 -06:00
9.04 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
8874e4fbc9
commit
829409452d
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user