mirror of
https://github.com/reactos/reactos.git
synced 2024-10-06 01:13:38 +00:00
- Fix funky ways of checking for success, when calling SetFilePointer.
The only correct and always working way is checking for INVALID_SET_FILE_POINTER. - Fix setting the file attributes. We didn't pass the destination directory before, so if the user specified another destination directory, the SetFileAttributes call failed. - Simplify GetAttributesOnFile and SetAttributesOnFile svn path=/trunk/; revision=32092
This commit is contained in:
parent
6a480b0db6
commit
3fdd323b73
|
@ -189,7 +189,7 @@ ULONG CCFDATAStorage::Truncate()
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
if (!SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN))
|
if( SetFilePointer(FileHandle, 0, NULL, FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
return CAB_STATUS_FAILURE;
|
return CAB_STATUS_FAILURE;
|
||||||
if (!SetEndOfFile(FileHandle))
|
if (!SetEndOfFile(FileHandle))
|
||||||
return CAB_STATUS_FAILURE;
|
return CAB_STATUS_FAILURE;
|
||||||
|
@ -231,10 +231,10 @@ ULONG CCFDATAStorage::Seek(LONG Position)
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
if (SetFilePointer(FileHandle,
|
if( SetFilePointer(FileHandle,
|
||||||
Position,
|
Position,
|
||||||
NULL,
|
NULL,
|
||||||
FILE_BEGIN) == 0xFFFFFFFF)
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
return CAB_STATUS_FAILURE;
|
return CAB_STATUS_FAILURE;
|
||||||
else
|
else
|
||||||
return CAB_STATUS_SUCCESS;
|
return CAB_STATUS_SUCCESS;
|
||||||
|
@ -712,10 +712,9 @@ ULONG CCabinet::Open()
|
||||||
DataReserved = (Size >> 24) & 0xFF;
|
DataReserved = (Size >> 24) & 0xFF;
|
||||||
|
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT);
|
if (SetFilePointer(FileHandle, CabinetReserved, NULL, FILE_CURRENT) == INVALID_SET_FILE_POINTER)
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_FAILURE;
|
return CAB_STATUS_FAILURE;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -823,7 +822,7 @@ void CCabinet::Close()
|
||||||
|
|
||||||
|
|
||||||
ULONG CCabinet::FindFirst(char* FileName,
|
ULONG CCabinet::FindFirst(char* FileName,
|
||||||
PCAB_SEARCH Search)
|
PCAB_SEARCH Search)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Finds the first file in the cabinet that matches a search criteria
|
* FUNCTION: Finds the first file in the cabinet that matches a search criteria
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
|
@ -1030,7 +1029,7 @@ ULONG CCabinet::ExtractFile(char* FileName)
|
||||||
#else
|
#else
|
||||||
//DPRINT(MIN_TRACE, ("FIXME: DosDateTimeToFileTime\n"));
|
//DPRINT(MIN_TRACE, ("FIXME: DosDateTimeToFileTime\n"));
|
||||||
#endif
|
#endif
|
||||||
SetAttributesOnFile(File);
|
SetAttributesOnFile(DestName, File->File.Attributes);
|
||||||
|
|
||||||
Buffer = (unsigned char*)AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough
|
Buffer = (unsigned char*)AllocateMemory(CAB_BLOCKSIZE + 12); // This should be enough
|
||||||
if (!Buffer)
|
if (!Buffer)
|
||||||
|
@ -1049,9 +1048,9 @@ ULONG CCabinet::ExtractFile(char* FileName)
|
||||||
File->DataBlock->AbsoluteOffset,
|
File->DataBlock->AbsoluteOffset,
|
||||||
NULL,
|
NULL,
|
||||||
FILE_BEGIN);
|
FILE_BEGIN);
|
||||||
if (GetLastError() != NO_ERROR)
|
if (Offset == INVALID_SET_FILE_POINTER)
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1171,13 +1170,12 @@ ULONG CCabinet::ExtractFile(char* FileName)
|
||||||
|
|
||||||
/* Search to start of file */
|
/* Search to start of file */
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetFilePointer(FileHandle,
|
if( SetFilePointer(FileHandle,
|
||||||
File->DataBlock->AbsoluteOffset,
|
File->DataBlock->AbsoluteOffset,
|
||||||
NULL,
|
NULL,
|
||||||
FILE_BEGIN);
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -1247,14 +1245,13 @@ ULONG CCabinet::ExtractFile(char* FileName)
|
||||||
|
|
||||||
/* Go to next data block */
|
/* Go to next data block */
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetFilePointer(FileHandle,
|
if( SetFilePointer(FileHandle,
|
||||||
CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) +
|
CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) +
|
||||||
CurrentDataNode->Data.CompSize,
|
CurrentDataNode->Data.CompSize,
|
||||||
NULL,
|
NULL,
|
||||||
FILE_BEGIN);
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -2231,14 +2228,12 @@ ULONG CCabinet::ReadString(char* String, ULONG MaxLength)
|
||||||
/* Back up some bytes */
|
/* Back up some bytes */
|
||||||
Size = (BytesRead - Size) - 1;
|
Size = (BytesRead - Size) - 1;
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetLastError(NO_ERROR);
|
if( SetFilePointer(FileHandle,
|
||||||
(ULONG)SetFilePointer(FileHandle,
|
-(LONG)Size,
|
||||||
-(LONG)Size,
|
NULL,
|
||||||
NULL,
|
FILE_CURRENT) == INVALID_SET_FILE_POINTER )
|
||||||
FILE_CURRENT);
|
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -2269,15 +2264,12 @@ ULONG CCabinet::ReadFileTable()
|
||||||
|
|
||||||
/* Seek to file table */
|
/* Seek to file table */
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetLastError(NO_ERROR);
|
if( SetFilePointer(FileHandle,
|
||||||
SetFilePointer(FileHandle,
|
CABHeader.FileTableOffset,
|
||||||
CABHeader.FileTableOffset,
|
NULL,
|
||||||
NULL,
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
FILE_BEGIN);
|
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
DPRINT(MIN_TRACE, ("Error: %lu\n", GetLastError()));
|
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -2360,14 +2352,12 @@ ULONG CCabinet::ReadDataBlocks(PCFFOLDER_NODE FolderNode)
|
||||||
|
|
||||||
/* Seek to data block */
|
/* Seek to data block */
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
SetLastError(NO_ERROR);
|
if( SetFilePointer(FileHandle,
|
||||||
SetFilePointer(FileHandle,
|
AbsoluteOffset,
|
||||||
AbsoluteOffset,
|
NULL,
|
||||||
NULL,
|
FILE_BEGIN) == INVALID_SET_FILE_POINTER )
|
||||||
FILE_BEGIN);
|
|
||||||
if (GetLastError() != NO_ERROR)
|
|
||||||
{
|
{
|
||||||
DPRINT(MIN_TRACE, ("SetFilePointer() failed.\n"));
|
DPRINT(MIN_TRACE, ("SetFilePointer() failed, error code is %u.\n", GetLastError()));
|
||||||
return CAB_STATUS_INVALID_CAB;
|
return CAB_STATUS_INVALID_CAB;
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
|
@ -3384,20 +3374,10 @@ ULONG CCabinet::GetAttributesOnFile(PCFFILE_NODE File)
|
||||||
if (Attributes == -1)
|
if (Attributes == -1)
|
||||||
return CAB_STATUS_CANNOT_READ;
|
return CAB_STATUS_CANNOT_READ;
|
||||||
|
|
||||||
if (Attributes & FILE_ATTRIBUTE_READONLY)
|
// 0x37 = READONLY | HIDDEN | SYSTEM | DIRECTORY | ARCHIVE
|
||||||
File->File.Attributes |= CAB_ATTRIB_READONLY;
|
// The IDs for these attributes are the same in the CAB file and under Windows
|
||||||
|
// If the file has any other attributes, strip them off by the logical AND.
|
||||||
if (Attributes & FILE_ATTRIBUTE_HIDDEN)
|
File->File.Attributes = (USHORT)(Attributes & 0x37);
|
||||||
File->File.Attributes |= CAB_ATTRIB_HIDDEN;
|
|
||||||
|
|
||||||
if (Attributes & FILE_ATTRIBUTE_SYSTEM)
|
|
||||||
File->File.Attributes |= CAB_ATTRIB_SYSTEM;
|
|
||||||
|
|
||||||
if (Attributes & FILE_ATTRIBUTE_DIRECTORY)
|
|
||||||
File->File.Attributes |= CAB_ATTRIB_DIRECTORY;
|
|
||||||
|
|
||||||
if (Attributes & FILE_ATTRIBUTE_ARCHIVE)
|
|
||||||
File->File.Attributes |= CAB_ATTRIB_ARCHIVE;
|
|
||||||
#else
|
#else
|
||||||
struct stat stbuf;
|
struct stat stbuf;
|
||||||
char buf[MAX_PATH];
|
char buf[MAX_PATH];
|
||||||
|
@ -3431,34 +3411,21 @@ ULONG CCabinet::GetAttributesOnFile(PCFFILE_NODE File)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
ULONG CCabinet::SetAttributesOnFile(PCFFILE_NODE File)
|
ULONG CCabinet::SetAttributesOnFile(char* FileName, USHORT FileAttributes)
|
||||||
/*
|
/*
|
||||||
* FUNCTION: Sets attributes on a file
|
* FUNCTION: Sets attributes on a file
|
||||||
* ARGUMENTS:
|
* ARGUMENTS:
|
||||||
* File = Pointer to CFFILE node for file
|
* FileName = File name with path
|
||||||
|
* FileAttributes = Attributes of that file
|
||||||
* RETURNS:
|
* RETURNS:
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
#if defined(WIN32)
|
#if defined(WIN32)
|
||||||
ULONG Attributes = 0;
|
// 0x37 = READONLY | HIDDEN | SYSTEM | DIRECTORY | ARCHIVE
|
||||||
|
// The IDs for these attributes are the same in the CAB file and under Windows
|
||||||
if (File->File.Attributes & CAB_ATTRIB_READONLY)
|
// If the file has any other attributes, strip them off by the logical AND.
|
||||||
Attributes |= FILE_ATTRIBUTE_READONLY;
|
SetFileAttributes(FileName, (DWORD)(FileAttributes & 0x37));
|
||||||
|
|
||||||
if (File->File.Attributes & CAB_ATTRIB_HIDDEN)
|
|
||||||
Attributes |= FILE_ATTRIBUTE_HIDDEN;
|
|
||||||
|
|
||||||
if (File->File.Attributes & CAB_ATTRIB_SYSTEM)
|
|
||||||
Attributes |= FILE_ATTRIBUTE_SYSTEM;
|
|
||||||
|
|
||||||
if (File->File.Attributes & CAB_ATTRIB_DIRECTORY)
|
|
||||||
Attributes |= FILE_ATTRIBUTE_DIRECTORY;
|
|
||||||
|
|
||||||
if (File->File.Attributes & CAB_ATTRIB_ARCHIVE)
|
|
||||||
Attributes |= FILE_ATTRIBUTE_ARCHIVE;
|
|
||||||
|
|
||||||
SetFileAttributes(File->FileName, Attributes);
|
|
||||||
|
|
||||||
return CAB_STATUS_SUCCESS;
|
return CAB_STATUS_SUCCESS;
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -416,7 +416,7 @@ private:
|
||||||
ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode);
|
ULONG CommitDataBlocks(PCFFOLDER_NODE FolderNode);
|
||||||
ULONG WriteDataBlock();
|
ULONG WriteDataBlock();
|
||||||
ULONG GetAttributesOnFile(PCFFILE_NODE File);
|
ULONG GetAttributesOnFile(PCFFILE_NODE File);
|
||||||
ULONG SetAttributesOnFile(PCFFILE_NODE File);
|
ULONG SetAttributesOnFile(char* FileName, USHORT FileAttributes);
|
||||||
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
||||||
#if !defined(WIN32)
|
#if !defined(WIN32)
|
||||||
void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);
|
void ConvertDateAndTime(time_t* Time, PUSHORT DosDate, PUSHORT DosTime);
|
||||||
|
|
Loading…
Reference in a new issue