mirror of
https://github.com/reactos/reactos.git
synced 2025-05-25 20:18:22 +00:00
[CABMAN] Remove _WIN32 ifdef's
This commit is contained in:
parent
5b8975211d
commit
ae391dd609
5 changed files with 244 additions and 709 deletions
File diff suppressed because it is too large
Load diff
|
@ -8,16 +8,17 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#if defined(_WIN32)
|
#if defined(_WIN32)
|
||||||
#define WIN32_LEAN_AND_MEAN
|
#define WIN32_LEAN_AND_MEAN
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#else
|
#else
|
||||||
|
#include <typedefs.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
#include <typedefs.h>
|
|
||||||
#include <unistd.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
@ -34,20 +35,23 @@
|
||||||
|
|
||||||
#define strcasecmp _stricmp
|
#define strcasecmp _stricmp
|
||||||
#define strdup _strdup
|
#define strdup _strdup
|
||||||
|
|
||||||
#define AllocateMemory(size) HeapAlloc(GetProcessHeap(), 0, size)
|
|
||||||
#define FreeMemory(buffer) HeapFree(GetProcessHeap(), 0, buffer)
|
|
||||||
#define FILEHANDLE HANDLE
|
|
||||||
#define CloseFile(handle) CloseHandle(handle)
|
|
||||||
#else
|
#else
|
||||||
#define DIR_SEPARATOR_CHAR '/'
|
#define DIR_SEPARATOR_CHAR '/'
|
||||||
#define DIR_SEPARATOR_STRING "/"
|
#define DIR_SEPARATOR_STRING "/"
|
||||||
|
#endif // _WIN32
|
||||||
|
|
||||||
#define AllocateMemory(size) malloc(size)
|
inline LONG GetSizeOfFile(FILE* handle)
|
||||||
#define FreeMemory(buffer) free(buffer)
|
{
|
||||||
#define CloseFile(handle) fclose(handle)
|
LONG size;
|
||||||
#define FILEHANDLE FILE*
|
LONG currentPos = ftell(handle);
|
||||||
#endif
|
|
||||||
|
if (fseek(handle, 0, SEEK_END) != 0)
|
||||||
|
return (LONG)-1;
|
||||||
|
|
||||||
|
size = ftell(handle);
|
||||||
|
fseek(handle, 0, SEEK_SET);
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
/* Debugging */
|
/* Debugging */
|
||||||
|
|
||||||
|
@ -309,8 +313,7 @@ public:
|
||||||
ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten);
|
ULONG WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten);
|
||||||
private:
|
private:
|
||||||
char FullName[PATH_MAX];
|
char FullName[PATH_MAX];
|
||||||
bool FileCreated;
|
FILE* FileHandle;
|
||||||
FILEHANDLE FileHandle;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif /* CAB_READ_ONLY */
|
#endif /* CAB_READ_ONLY */
|
||||||
|
@ -437,7 +440,7 @@ private:
|
||||||
ULONG WriteDataBlock();
|
ULONG WriteDataBlock();
|
||||||
ULONG GetAttributesOnFile(PCFFILE_NODE File);
|
ULONG GetAttributesOnFile(PCFFILE_NODE File);
|
||||||
ULONG SetAttributesOnFile(char* FileName, USHORT FileAttributes);
|
ULONG SetAttributesOnFile(char* FileName, USHORT FileAttributes);
|
||||||
ULONG GetFileTimes(FILEHANDLE FileHandle, PCFFILE_NODE File);
|
ULONG GetFileTimes(FILE* 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);
|
||||||
#endif
|
#endif
|
||||||
|
@ -459,7 +462,7 @@ private:
|
||||||
char CabinetReservedFile[PATH_MAX];
|
char CabinetReservedFile[PATH_MAX];
|
||||||
void* CabinetReservedFileBuffer;
|
void* CabinetReservedFileBuffer;
|
||||||
ULONG CabinetReservedFileSize;
|
ULONG CabinetReservedFileSize;
|
||||||
FILEHANDLE FileHandle;
|
FILE* FileHandle;
|
||||||
bool FileOpen;
|
bool FileOpen;
|
||||||
CFHEADER CABHeader;
|
CFHEADER CABHeader;
|
||||||
ULONG CabinetReserved;
|
ULONG CabinetReserved;
|
||||||
|
@ -495,7 +498,7 @@ private:
|
||||||
bool CreateNewFolder;
|
bool CreateNewFolder;
|
||||||
|
|
||||||
CCFDATAStorage *ScratchFile;
|
CCFDATAStorage *ScratchFile;
|
||||||
FILEHANDLE SourceFile;
|
FILE* SourceFile;
|
||||||
bool ContinueFile;
|
bool ContinueFile;
|
||||||
ULONG TotalBytesLeft;
|
ULONG TotalBytesLeft;
|
||||||
bool BlockIsSplit; // true if current data block is split
|
bool BlockIsSplit; // true if current data block is split
|
||||||
|
|
|
@ -17,40 +17,6 @@
|
||||||
#include "cabman.h"
|
#include "cabman.h"
|
||||||
#include "dfp.h"
|
#include "dfp.h"
|
||||||
|
|
||||||
|
|
||||||
#if defined(_WIN32)
|
|
||||||
#define GetSizeOfFile(handle) _GetSizeOfFile(handle)
|
|
||||||
static LONG _GetSizeOfFile(FILEHANDLE handle)
|
|
||||||
{
|
|
||||||
ULONG 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, ULONG size, PULONG bytesread)
|
|
||||||
{
|
|
||||||
return ReadFile(handle, buffer, size, (LPDWORD)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, ULONG size, PULONG bytesread)
|
|
||||||
{
|
|
||||||
*bytesread = fread(buffer, 1, size, handle);
|
|
||||||
return *bytesread == size;
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/* CDFParser */
|
/* CDFParser */
|
||||||
|
|
||||||
CDFParser::CDFParser()
|
CDFParser::CDFParser()
|
||||||
|
@ -94,31 +60,31 @@ CDFParser::~CDFParser()
|
||||||
PDISK_NUMBER DNNext;
|
PDISK_NUMBER DNNext;
|
||||||
|
|
||||||
if (FileBuffer)
|
if (FileBuffer)
|
||||||
FreeMemory(FileBuffer);
|
free(FileBuffer);
|
||||||
CNNext = CabinetName;
|
CNNext = CabinetName;
|
||||||
while (CNNext != NULL)
|
while (CNNext != NULL)
|
||||||
{
|
{
|
||||||
CNPrev = CNNext->Next;
|
CNPrev = CNNext->Next;
|
||||||
FreeMemory(CNNext);
|
free(CNNext);
|
||||||
CNNext = CNPrev;
|
CNNext = CNPrev;
|
||||||
}
|
}
|
||||||
CNNext = DiskLabel;
|
CNNext = DiskLabel;
|
||||||
while (CNNext != NULL)
|
while (CNNext != NULL)
|
||||||
{
|
{
|
||||||
CNPrev = CNNext->Next;
|
CNPrev = CNNext->Next;
|
||||||
FreeMemory(CNNext);
|
free(CNNext);
|
||||||
CNNext = CNPrev;
|
CNNext = CNPrev;
|
||||||
}
|
}
|
||||||
DNNext = MaxDiskSize;
|
DNNext = MaxDiskSize;
|
||||||
while (DNNext != NULL)
|
while (DNNext != NULL)
|
||||||
{
|
{
|
||||||
DNPrev = DNNext->Next;
|
DNPrev = DNNext->Next;
|
||||||
FreeMemory(DNNext);
|
free(DNNext);
|
||||||
DNNext = DNPrev;
|
DNNext = DNPrev;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (InfFileHandle != NULL)
|
if (InfFileHandle != NULL)
|
||||||
CloseFile(InfFileHandle);
|
fclose(InfFileHandle);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CDFParser::WriteInfLine(char* InfLine)
|
void CDFParser::WriteInfLine(char* InfLine)
|
||||||
|
@ -126,9 +92,6 @@ void CDFParser::WriteInfLine(char* InfLine)
|
||||||
char buf[PATH_MAX];
|
char buf[PATH_MAX];
|
||||||
char eolbuf[2];
|
char eolbuf[2];
|
||||||
char* destpath;
|
char* destpath;
|
||||||
#if defined(_WIN32)
|
|
||||||
ULONG BytesWritten;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
if (DontGenerateInf)
|
if (DontGenerateInf)
|
||||||
return;
|
return;
|
||||||
|
@ -149,53 +112,28 @@ void CDFParser::WriteInfLine(char* InfLine)
|
||||||
strcpy(buf, InfFileName);
|
strcpy(buf, InfFileName);
|
||||||
|
|
||||||
/* Create .inf file, overwrite if it already exists */
|
/* Create .inf file, overwrite if it already exists */
|
||||||
#if defined(_WIN32)
|
|
||||||
InfFileHandle = CreateFile(buf, // Create this file
|
|
||||||
GENERIC_WRITE, // Open for writing
|
|
||||||
0, // No sharing
|
|
||||||
NULL, // No security
|
|
||||||
CREATE_ALWAYS, // Create or overwrite
|
|
||||||
FILE_ATTRIBUTE_NORMAL, // Normal file
|
|
||||||
NULL); // No attribute template
|
|
||||||
if (InfFileHandle == INVALID_HANDLE_VALUE)
|
|
||||||
{
|
|
||||||
DPRINT(MID_TRACE, ("Error creating '%u'.\n", (UINT)GetLastError()));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
#else /* !_WIN32 */
|
|
||||||
InfFileHandle = fopen(buf, "wb");
|
InfFileHandle = fopen(buf, "wb");
|
||||||
if (InfFileHandle == NULL)
|
if (InfFileHandle == NULL)
|
||||||
{
|
{
|
||||||
DPRINT(MID_TRACE, ("Error creating '%i'.\n", errno));
|
DPRINT(MID_TRACE, ("Error creating INF file.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if defined(_WIN32)
|
if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1)
|
||||||
if (!WriteFile(InfFileHandle, InfLine, (DWORD)strlen(InfLine), (LPDWORD)&BytesWritten, NULL))
|
|
||||||
{
|
{
|
||||||
DPRINT(MID_TRACE, ("ERROR WRITING '%u'.\n", (UINT)GetLastError()));
|
DPRINT(MID_TRACE, ("Error writing INF file.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (fwrite(InfLine, strlen(InfLine), 1, InfFileHandle) < 1)
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
eolbuf[0] = 0x0d;
|
eolbuf[0] = 0x0d;
|
||||||
eolbuf[1] = 0x0a;
|
eolbuf[1] = 0x0a;
|
||||||
|
|
||||||
#if defined(_WIN32)
|
if (fwrite(eolbuf, sizeof(eolbuf), 1, InfFileHandle) < 1)
|
||||||
if (!WriteFile(InfFileHandle, eolbuf, sizeof(eolbuf), (LPDWORD)&BytesWritten, NULL))
|
|
||||||
{
|
{
|
||||||
DPRINT(MID_TRACE, ("ERROR WRITING '%u'.\n", (UINT)GetLastError()));
|
DPRINT(MID_TRACE, ("Error writing INF file.\n"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#else
|
|
||||||
if (fwrite(eolbuf, 1, sizeof(eolbuf), InfFileHandle) < 1)
|
|
||||||
return;
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -208,54 +146,43 @@ ULONG CDFParser::Load(char* FileName)
|
||||||
* Status of operation
|
* Status of operation
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
ULONG BytesRead;
|
|
||||||
LONG FileSize;
|
LONG FileSize;
|
||||||
|
|
||||||
if (FileLoaded)
|
if (FileLoaded)
|
||||||
return CAB_STATUS_SUCCESS;
|
return CAB_STATUS_SUCCESS;
|
||||||
|
|
||||||
/* Create cabinet file, overwrite if it already exists */
|
/* Open the directive file */
|
||||||
#if defined(_WIN32)
|
|
||||||
FileHandle = CreateFile(FileName, // Create this file
|
|
||||||
GENERIC_READ, // Open for reading
|
|
||||||
0, // No sharing
|
|
||||||
NULL, // No security
|
|
||||||
OPEN_EXISTING, // Open the file
|
|
||||||
FILE_ATTRIBUTE_NORMAL, // Normal file
|
|
||||||
NULL); // No attribute template
|
|
||||||
if (FileHandle == INVALID_HANDLE_VALUE)
|
|
||||||
return CAB_STATUS_CANNOT_OPEN;
|
|
||||||
#else /* !_WIN32 */
|
|
||||||
FileHandle = fopen(FileName, "rb");
|
FileHandle = fopen(FileName, "rb");
|
||||||
if (FileHandle == NULL)
|
if (FileHandle == NULL)
|
||||||
|
{
|
||||||
return CAB_STATUS_CANNOT_OPEN;
|
return CAB_STATUS_CANNOT_OPEN;
|
||||||
#endif
|
}
|
||||||
|
|
||||||
FileSize = GetSizeOfFile(FileHandle);
|
FileSize = GetSizeOfFile(FileHandle);
|
||||||
if (FileSize == -1)
|
if (FileSize == -1)
|
||||||
{
|
{
|
||||||
CloseFile(FileHandle);
|
fclose(FileHandle);
|
||||||
return CAB_STATUS_CANNOT_OPEN;
|
return CAB_STATUS_CANNOT_OPEN;
|
||||||
}
|
}
|
||||||
|
|
||||||
FileBufferSize = (ULONG)FileSize;
|
FileBufferSize = (ULONG)FileSize;
|
||||||
|
|
||||||
FileBuffer = (char*)AllocateMemory(FileBufferSize);
|
FileBuffer = (char*)malloc(FileBufferSize);
|
||||||
if (!FileBuffer)
|
if (!FileBuffer)
|
||||||
{
|
{
|
||||||
CloseFile(FileHandle);
|
fclose(FileHandle);
|
||||||
return CAB_STATUS_NOMEMORY;
|
return CAB_STATUS_NOMEMORY;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!ReadFileData(FileHandle, FileBuffer, FileBufferSize, &BytesRead))
|
if ( fread(FileBuffer, FileBufferSize, 1, FileHandle) < 1 )
|
||||||
{
|
{
|
||||||
CloseFile(FileHandle);
|
fclose(FileHandle);
|
||||||
FreeMemory(FileBuffer);
|
free(FileBuffer);
|
||||||
FileBuffer = NULL;
|
FileBuffer = NULL;
|
||||||
return CAB_STATUS_CANNOT_READ;
|
return CAB_STATUS_CANNOT_READ;
|
||||||
}
|
}
|
||||||
|
|
||||||
CloseFile(FileHandle);
|
fclose(FileHandle);
|
||||||
|
|
||||||
FileLoaded = true;
|
FileLoaded = true;
|
||||||
|
|
||||||
|
@ -571,7 +498,7 @@ bool CDFParser::SetDiskName(PCABINET_NAME *List, ULONG Number, char* String)
|
||||||
CN = CN->Next;
|
CN = CN->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
CN = (PCABINET_NAME)AllocateMemory(sizeof(CABINET_NAME));
|
CN = (PCABINET_NAME)malloc(sizeof(CABINET_NAME));
|
||||||
if (!CN)
|
if (!CN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
@ -637,7 +564,7 @@ bool CDFParser::SetDiskNumber(PDISK_NUMBER *List, ULONG Number, ULONG Value)
|
||||||
DN = DN->Next;
|
DN = DN->Next;
|
||||||
}
|
}
|
||||||
|
|
||||||
DN = (PDISK_NUMBER)AllocateMemory(sizeof(DISK_NUMBER));
|
DN = (PDISK_NUMBER)malloc(sizeof(DISK_NUMBER));
|
||||||
if (!DN)
|
if (!DN)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
|
|
|
@ -99,7 +99,7 @@ private:
|
||||||
void NextToken();
|
void NextToken();
|
||||||
/* Parsing */
|
/* Parsing */
|
||||||
bool FileLoaded;
|
bool FileLoaded;
|
||||||
FILEHANDLE FileHandle;
|
FILE* FileHandle;
|
||||||
char* FileBuffer;
|
char* FileBuffer;
|
||||||
ULONG FileBufferSize;
|
ULONG FileBufferSize;
|
||||||
ULONG CurrentOffset;
|
ULONG CurrentOffset;
|
||||||
|
@ -140,7 +140,7 @@ private:
|
||||||
ULONG ReservePerDataBlockSize;
|
ULONG ReservePerDataBlockSize;
|
||||||
ULONG ReservePerFolderSize;
|
ULONG ReservePerFolderSize;
|
||||||
char SourceDir[256];
|
char SourceDir[256];
|
||||||
FILEHANDLE InfFileHandle;
|
FILE* InfFileHandle;
|
||||||
bool InfModeEnabled;
|
bool InfModeEnabled;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -21,13 +21,13 @@
|
||||||
voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size)
|
voidpf MSZipAlloc(voidpf opaque, uInt items, uInt size)
|
||||||
{
|
{
|
||||||
DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size));
|
DPRINT(DEBUG_MEMORY, ("items = (%d) size = (%d)\n", items, size));
|
||||||
return AllocateMemory(items * size);
|
return malloc(items * size);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MSZipFree (voidpf opaque, voidpf address)
|
void MSZipFree (voidpf opaque, voidpf address)
|
||||||
{
|
{
|
||||||
DPRINT(DEBUG_MEMORY, ("\n"));
|
DPRINT(DEBUG_MEMORY, ("\n"));
|
||||||
FreeMemory(address);
|
free(address);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue