[CABMAN] Move CCFDATAStorage class to a separate file
authorDmitry Bagdanov <dimbo_job@mail.ru>
Fri, 26 Jan 2018 15:46:35 +0000 (22:46 +0700)
committerPierre Schweitzer <pierre@reactos.org>
Sat, 27 Jan 2018 09:42:05 +0000 (10:42 +0100)
sdk/tools/cabman/CCFDATAStorage.cxx [new file with mode: 0644]
sdk/tools/cabman/CMakeLists.txt
sdk/tools/cabman/cabinet.cxx

diff --git a/sdk/tools/cabman/CCFDATAStorage.cxx b/sdk/tools/cabman/CCFDATAStorage.cxx
new file mode 100644 (file)
index 0000000..1d7ef5e
--- /dev/null
@@ -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 */
index baf1066..f684c73 100644 (file)
@@ -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})
index 6fbf843..5202404 100644 (file)
@@ -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 */