#include "raw.h"
#include "mszip.h"
+#if defined(WIN32)
+#define GetSizeOfFile(handle) _GetSizeOfFile(handle)
+static long _GetSizeOfFile(FILEHANDLE handle)
+{
+ unsigned long size = GetFileSize(handle, NULL);
+ if (size == INVALID_FILE_SIZE)
+ {
+ return -1;
+ }
+ return size;
+}
+#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
+static bool _ReadFileData(FILEHANDLE handle, void* buffer, unsigned long size, unsigned long* bytesread)
+{
+ return ReadFile(handle, buffer, size, bytesread, NULL);
+}
+#else
+#define GetSizeOfFile(handle) _GetSizeOfFile(handle)
+static long _GetSizeOfFile(FILEHANDLE handle)
+{
+ long size;
+ fseek(handle, 0, SEEK_END);
+ size = ftell(handle);
+ fseek(handle, 0, SEEK_SET);
+ return size;
+}
+#define ReadFileData(handle, buffer, size, bytesread) _ReadFileData(handle, buffer, size, bytesread)
+static bool _ReadFileData(FILEHANDLE handle, void* buffer, unsigned long size, unsigned long* bytesread)
+{
+ *bytesread = fread(buffer, 1, size, handle);
+ return *bytesread == size;
+}
+#endif
#ifndef CAB_READ_ONLY
while ((Search->Next) &&
(Search->Next->File.FileControlID > CAB_FILE_MAX_FOLDER) &&
(Search->Next->File.FileOffset <= LastFileOffset)) {
- DPRINT(MAX_TRACE, ("Skipping file (%s) FileOffset (0x%X) LastFileOffset (0x%X).\n",
+ DPRINT(MAX_TRACE, ("Skipping file (%s) FileOffset (0x%lX) LastFileOffset (0x%lX).\n",
Search->Next->FileName, Search->Next->File.FileOffset, LastFileOffset));
Search->Next = Search->Next->Next;
}
#if defined(WIN32)
if (!DosDateTimeToFileTime(File->File.FileDate, File->File.FileTime, &FileTime)) {
CloseFile(DestFile);
- DPRINT(MIN_TRACE, ("DosDateTimeToFileTime() failed (%d).\n", GetLastError()));
+ DPRINT(MIN_TRACE, ("DosDateTimeToFileTime() failed (%lu).\n", GetLastError()));
return CAB_STATUS_CANNOT_WRITE;
}
ReuseBlock = (CurrentDataNode == File->DataBlock);
if (Size > 0) {
do {
- DPRINT(MAX_TRACE, ("CO (0x%X) ReuseBlock (%d) Offset (0x%X) Size (%d) BytesLeftInBlock (%d)\n",
+ DPRINT(MAX_TRACE, ("CO (0x%lX) ReuseBlock (%d) Offset (0x%lX) Size (%ld) BytesLeftInBlock (%ld)\n",
File->DataBlock->UncompOffset, (unsigned int)ReuseBlock, Offset, Size,
BytesLeftInBlock));
CurrentBuffer = Buffer;
TotalBytesRead = 0;
do {
- DPRINT(MAX_TRACE, ("Size (%d bytes).\n", Size));
+ DPRINT(MAX_TRACE, ("Size (%lu bytes).\n", Size));
if (((Status = ReadBlock(&CFData, sizeof(CFDATA), &BytesRead)) !=
CAB_STATUS_SUCCESS) || (BytesRead != sizeof(CFDATA))) {
BytesToRead = CFData.CompSize;
- DPRINT(MAX_TRACE, ("Read: (0x%X,0x%X).\n",
- CurrentBuffer, Buffer));
+ DPRINT(MAX_TRACE, ("Read: (0x%lX,0x%lX).\n",
+ (DWORD)CurrentBuffer, (DWORD)Buffer));
if (((Status = ReadBlock(CurrentBuffer, BytesToRead, &BytesRead)) !=
CAB_STATUS_SUCCESS) || (BytesToRead != BytesRead)) {
}
} while (CFData.UncompSize == 0);
- DPRINT(MAX_TRACE, ("TotalBytesRead (%d).\n", TotalBytesRead));
+ DPRINT(MAX_TRACE, ("TotalBytesRead (%lu).\n", TotalBytesRead));
Status = Codec->Uncompress(OutputBuffer, Buffer, TotalBytesRead, &BytesToWrite);
if (Status != CS_SUCCESS) {
}
if (BytesToWrite != CFData.UncompSize) {
- DPRINT(MID_TRACE, ("BytesToWrite (%d) != CFData.UncompSize (%d)\n",
+ DPRINT(MID_TRACE, ("BytesToWrite (%lu) != CFData.UncompSize (%d)\n",
BytesToWrite, CFData.UncompSize));
return CAB_STATUS_INVALID_CAB;
}
BytesToWrite = BytesLeftInBlock;
- DPRINT(MAX_TRACE, ("Seeking to absolute offset 0x%X.\n",
+ DPRINT(MAX_TRACE, ("Seeking to absolute offset 0x%lX.\n",
CurrentDataNode->AbsoluteOffset + sizeof(CFDATA) +
CurrentDataNode->Data.CompSize));
if (!WriteFile(DestFile, (void*)((unsigned long)OutputBuffer + BytesSkipped),
BytesToWrite, &BytesWritten, NULL) ||
(BytesToWrite != BytesWritten)) {
- DPRINT(MIN_TRACE, ("Status 0x%X.\n", GetLastError()));
+ DPRINT(MIN_TRACE, ("Status 0x%lX.\n", GetLastError()));
#else
BytesWritten = BytesToWrite;
if (fwrite((void*)((unsigned long)OutputBuffer + BytesSkipped),
BytesToRead = TotalBytesLeft;
if (!ReadFileData(SourceFile, CurrentIBuffer, BytesToRead, &BytesRead) || (BytesToRead != BytesRead)) {
- DPRINT(MIN_TRACE, ("Cannot read from file. BytesToRead (%d) BytesRead (%d) CurrentIBufferSize (%d).\n",
+ DPRINT(MIN_TRACE, ("Cannot read from file. BytesToRead (%lu) BytesRead (%lu) CurrentIBufferSize (%lu).\n",
BytesToRead, BytesRead, CurrentIBufferSize));
return CAB_STATUS_INVALID_CAB;
}
ContinueFile = true;
CreateNewDisk = false;
- DPRINT(MAX_TRACE, ("First on new disk. CurrentIBufferSize (%d) CurrentOBufferSize (%d).\n",
+ DPRINT(MAX_TRACE, ("First on new disk. CurrentIBufferSize (%lu) CurrentOBufferSize (%lu).\n",
CurrentIBufferSize, CurrentOBufferSize));
if ((CurrentIBufferSize > 0) || (CurrentOBufferSize > 0)) {
* Status of operation
*/
{
- PCFFOLDER_NODE PrevNode;
- PCFFOLDER_NODE NextNode;
unsigned long Status;
DestroyFileNodes();
unsigned long BytesRead;
PCFFILE_NODE File;
- DPRINT(MAX_TRACE, ("Reading file table at absolute offset (0x%X).\n",
+ DPRINT(MAX_TRACE, ("Reading file table at absolute offset (0x%lX).\n",
CABHeader.FileTableOffset));
/* Seek to file table */
unsigned long Status;
unsigned long i;
- DPRINT(MAX_TRACE, ("Reading data blocks for folder (%d) at absolute offset (0x%X).\n",
+ DPRINT(MAX_TRACE, ("Reading data blocks for folder (%lu) at absolute offset (0x%lX).\n",
FolderNode->Index, FolderNode->Folder.DataOffset));
AbsoluteOffset = FolderNode->Folder.DataOffset;
* Status of operation
*/
{
- PCFFOLDER_NODE FolderNode;
- PCFFILE_NODE FileNode;
unsigned long TotalSize;
unsigned long Size;
while (FolderNode != NULL) {
if (FolderNode->Commit) {
- DPRINT(MAX_TRACE, ("Writing folder entry. CompressionType (0x%X) DataBlockCount (%d) DataOffset (0x%X).\n",
+ DPRINT(MAX_TRACE, ("Writing folder entry. CompressionType (0x%X) DataBlockCount (%d) DataOffset (0x%lX).\n",
FolderNode->Folder.CompressionType, FolderNode->Folder.DataBlockCount, FolderNode->Folder.DataOffset));
#if defined(WIN32)
SetCont = true;
}
- DPRINT(MAX_TRACE, ("Writing file entry. FileControlID (0x%X) FileOffset (0x%X) FileSize (%d) FileName (%s).\n",
+ DPRINT(MAX_TRACE, ("Writing file entry. FileControlID (0x%X) FileOffset (0x%lX) FileSize (%lu) FileName (%s).\n",
File->File.FileControlID, File->File.FileOffset, File->File.FileSize, File->FileName));
#if defined(WIN32)
Status = ScratchFile->Seek(DataNode->ScratchFilePosition);
while (DataNode != NULL) {
- DPRINT(MAX_TRACE, ("Reading block at (0x%X) CompSize (%d) UncompSize (%d).\n",
+ DPRINT(MAX_TRACE, ("Reading block at (0x%lX) CompSize (%d) UncompSize (%d).\n",
DataNode->ScratchFilePosition,
DataNode->Data.CompSize,
DataNode->Data.UncompSize));
CurrentIBufferSize,
&TotalCompSize);
- DPRINT(MAX_TRACE, ("Block compressed. CurrentIBufferSize (%d) TotalCompSize(%d).\n",
+ DPRINT(MAX_TRACE, ("Block compressed. CurrentIBufferSize (%lu) TotalCompSize(%lu).\n",
CurrentIBufferSize, TotalCompSize));
CurrentOBuffer = OutputBuffer;
*/
{
#if defined(WIN32)
- unsigned long Attributes;
+ long Attributes;
Attributes = GetFileAttributes(File->FileName);
if (Attributes == -1)