https://git.reactos.org/?p=reactos.git;a=commitdiff;h=991d33c5d1a9bb3b21c860...
commit 991d33c5d1a9bb3b21c860d830231886869ce09c Author: Dmitry Bagdanov dimbo_job@mail.ru AuthorDate: Fri Jan 26 22:46:35 2018 +0700 Commit: Pierre Schweitzer pierre@reactos.org CommitDate: Sat Jan 27 10:42:05 2018 +0100
[CABMAN] Move CCFDATAStorage class to a separate file --- sdk/tools/cabman/CCFDATAStorage.cxx | 198 ++++++++++++++++++++++++++++++++++++ sdk/tools/cabman/CMakeLists.txt | 3 +- sdk/tools/cabman/cabinet.cxx | 172 ------------------------------- 3 files changed, 200 insertions(+), 173 deletions(-)
diff --git a/sdk/tools/cabman/CCFDATAStorage.cxx b/sdk/tools/cabman/CCFDATAStorage.cxx new file mode 100644 index 0000000000..1d7ef5e64f --- /dev/null +++ b/sdk/tools/cabman/CCFDATAStorage.cxx @@ -0,0 +1,198 @@ +/* + * PROJECT: ReactOS cabinet manager + * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+) + * PURPOSE: CCFDATAStorage class implementation for Linux/Unix + * COPYRIGHT: Copyright 2017 Casper S. Hornstrup (chorns@users.sourceforge.net) + * Copyright 2017 Colin Finck mail@colinfinck.de + * Copyright 2018 Dmitry Bagdanov dimbo_job@mail.ru + */ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <sys/stat.h> +#include <sys/types.h> + +#if !defined(_WIN32) +#include <dirent.h> +#endif + +#include "cabinet.h" +#include "raw.h" +#include "mszip.h" + +#if !defined(CAB_READ_ONLY) + + /** + * @name CCFDATAStorage class + * @implemented + * + * Default constructor + */ +CCFDATAStorage::CCFDATAStorage() +{ + FileHandle = NULL; +} + +/** +* @name CCFDATAStorage class +* @implemented +* +* Default destructor +*/ +CCFDATAStorage::~CCFDATAStorage() +{ + ASSERT(FileHandle == NULL); +} + +/** +* @name CCFDATAStorage class +* @implemented +* +* Creates the file +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::Create() +{ + if ((FileHandle = tmpfile()) == NULL) + return CAB_STATUS_CANNOT_CREATE; + + return CAB_STATUS_SUCCESS; +} + +/** +* @name CCFDATAStorage class +* @implemented +* +* Destroys the file +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::Destroy() +{ + ASSERT(FileHandle != NULL); + + fclose(FileHandle); + + FileHandle = NULL; + + return CAB_STATUS_SUCCESS; +} + +/** +* @name CCFDATAStorage class +* @implemented +* +* Truncate the scratch file to zero bytes +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::Truncate() +{ + fclose(FileHandle); + FileHandle = tmpfile(); + if (FileHandle == NULL) + { + DPRINT(MID_TRACE, ("ERROR '%i'.\n", errno)); + return CAB_STATUS_FAILURE; + } + + return CAB_STATUS_SUCCESS; +} + +/** +* @name CCFDATAStorage class +* @implemented +* +* Returns current position in file +* +* @return +* Current position +*/ +ULONG CCFDATAStorage::Position() +{ + return (ULONG)ftell(FileHandle); +} + + +/** +* @name CCFDATAStorage class +* @implemented +* +* Seeks to an absolute position +* +* @param Position +* Absolute position to seek to +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::Seek(LONG Position) +{ + if (fseek(FileHandle, (off_t)Position, SEEK_SET) != 0) + return CAB_STATUS_FAILURE; + else + return CAB_STATUS_SUCCESS; +} + + +/** +* @name CCFDATAStorage class +* @implemented +* +* Reads a CFDATA block from the file +* +* @param Data +* Pointer to CFDATA block for the buffer +* +* @param Buffer +* Pointer to buffer to store data read +* +* @param BytesRead +* Pointer to buffer to write number of bytes read +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead) +{ + *BytesRead = fread(Buffer, 1, Data->CompSize, FileHandle); + if (*BytesRead != Data->CompSize) + return CAB_STATUS_CANNOT_READ; + + return CAB_STATUS_SUCCESS; +} + + +/** +* @name CCFDATAStorage class +* @implemented +* +* Writes a CFDATA block to the file +* +* @param Data +* Pointer to CFDATA block for the buffer +* +* @param Buffer +* Pointer to buffer with data to write +* +* @param BytesWritten +* Pointer to buffer to write number of bytes written +* +* @return +* Status of operation +*/ +ULONG CCFDATAStorage::WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten) +{ + *BytesWritten = fwrite(Buffer, 1, Data->CompSize, FileHandle); + if (*BytesWritten != Data->CompSize) + return CAB_STATUS_CANNOT_WRITE; + + return CAB_STATUS_SUCCESS; +} + + +#endif /* CAB_READ_ONLY */ diff --git a/sdk/tools/cabman/CMakeLists.txt b/sdk/tools/cabman/CMakeLists.txt index baf1066ae1..f684c73f35 100644 --- a/sdk/tools/cabman/CMakeLists.txt +++ b/sdk/tools/cabman/CMakeLists.txt @@ -4,7 +4,8 @@ list(APPEND SOURCE dfp.cxx main.cxx mszip.cxx - raw.cxx) + raw.cxx + CCFDATAStorage.cxx)
include_directories(${REACTOS_SOURCE_DIR}/sdk/include/reactos/libs/zlib) add_host_tool(cabman ${SOURCE}) diff --git a/sdk/tools/cabman/cabinet.cxx b/sdk/tools/cabman/cabinet.cxx index 6fbf84309a..5202404bd8 100644 --- a/sdk/tools/cabman/cabinet.cxx +++ b/sdk/tools/cabman/cabinet.cxx @@ -62,178 +62,6 @@ void DumpBuffer(void* Buffer, ULONG Size) #endif /* DBG */ #endif
- /** - * @name CCFDATAStorage class - * @implemented - * - * Default constructor - */ -CCFDATAStorage::CCFDATAStorage() -{ - FileHandle = NULL; -} - -/** -* @name CCFDATAStorage class -* @implemented -* -* Default destructor -*/ -CCFDATAStorage::~CCFDATAStorage() -{ - ASSERT(FileHandle == NULL); -} - -/** -* @name CCFDATAStorage class -* @implemented -* -* Creates the file -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::Create() -{ - if ((FileHandle = tmpfile()) == NULL) - return CAB_STATUS_CANNOT_CREATE; - - return CAB_STATUS_SUCCESS; -} - -/** -* @name CCFDATAStorage class -* @implemented -* -* Destroys the file -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::Destroy() -{ - ASSERT(FileHandle != NULL); - - fclose(FileHandle); - - FileHandle = NULL; - - return CAB_STATUS_SUCCESS; -} - -/** -* @name CCFDATAStorage class -* @implemented -* -* Truncate the scratch file to zero bytes -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::Truncate() -{ - fclose(FileHandle); - FileHandle = tmpfile(); - if (FileHandle == NULL) - { - DPRINT(MID_TRACE, ("ERROR '%i'.\n", errno)); - return CAB_STATUS_FAILURE; - } - - return CAB_STATUS_SUCCESS; -} - -/** -* @name CCFDATAStorage class -* @implemented -* -* Returns current position in file -* -* @return -* Current position -*/ -ULONG CCFDATAStorage::Position() -{ - return (ULONG)ftell(FileHandle); -} - - -/** -* @name CCFDATAStorage class -* @implemented -* -* Seeks to an absolute position -* -* @param Position -* Absolute position to seek to -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::Seek(LONG Position) -{ - if (fseek(FileHandle, (off_t)Position, SEEK_SET) != 0) - return CAB_STATUS_FAILURE; - else - return CAB_STATUS_SUCCESS; -} - - -/** -* @name CCFDATAStorage class -* @implemented -* -* Reads a CFDATA block from the file -* -* @param Data -* Pointer to CFDATA block for the buffer -* -* @param Buffer -* Pointer to buffer to store data read -* -* @param BytesRead -* Pointer to buffer to write number of bytes read -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::ReadBlock(PCFDATA Data, void* Buffer, PULONG BytesRead) -{ - *BytesRead = fread(Buffer, 1, Data->CompSize, FileHandle); - if (*BytesRead != Data->CompSize) - return CAB_STATUS_CANNOT_READ; - - return CAB_STATUS_SUCCESS; -} - - -/** -* @name CCFDATAStorage class -* @implemented -* -* Writes a CFDATA block to the file -* -* @param Data -* Pointer to CFDATA block for the buffer -* -* @param Buffer -* Pointer to buffer with data to write -* -* @param BytesWritten -* Pointer to buffer to write number of bytes written -* -* @return -* Status of operation -*/ -ULONG CCFDATAStorage::WriteBlock(PCFDATA Data, void* Buffer, PULONG BytesWritten) -{ - *BytesWritten = fwrite(Buffer, 1, Data->CompSize, FileHandle); - if (*BytesWritten != Data->CompSize) - return CAB_STATUS_CANNOT_WRITE; - - return CAB_STATUS_SUCCESS; -} - #endif /* CAB_READ_ONLY */