Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

146 lines
3.8 KiB

  1. //=======================================================================
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation. All Rights Reserved.
  4. //
  5. // File: diamond.h
  6. //
  7. // Owner: YanL
  8. //
  9. // Description:
  10. //
  11. // Diamond decompressor
  12. //
  13. //=======================================================================
  14. #ifndef _DIAMOND_H
  15. #ifndef INCLUDED_TYPES_FCI_FDI
  16. extern "C"
  17. {
  18. #include <fdi.h>
  19. };
  20. #endif
  21. /*
  22. * This is from the FDI.H file and gives a good high level overview of the
  23. * method used for reading and decompressing files that are already in
  24. * memory as opposed to on disk.
  25. *
  26. * Notes for Memory Mapped File fans:
  27. * You can write wrapper routines to allow FDI to work on memory
  28. * mapped files. You'll have to create your own "handle" type so that
  29. * you can store the base memory address of the file and the current
  30. * seek position, and then you'll allocate and fill in one of these
  31. * structures and return a pointer to it in response to the PFNOPEN
  32. * call and the fdintCOPY_FILE call. Your PFNREAD and PFNWRITE
  33. * functions will do memcopy(), and update the seek position in your
  34. * "handle" structure. PFNSEEK will just change the seek position
  35. * in your "handle" structure.
  36. */
  37. struct HANDLEINFO
  38. {
  39. HANDLE handle; //If this is a file IO then this is the file
  40. //handle to pass to ReadFile or WriteFile. If
  41. //this is an in memory operation then this field
  42. //is INVALID_HANDLE_VALUE.
  43. ULONG offset; //current memory file offset
  44. };
  45. typedef frozen_array<HANDLEINFO> CHInfoArray;
  46. class CDiamond
  47. {
  48. public:
  49. CDiamond(void);
  50. ~CDiamond(void);
  51. bool valid() const
  52. {
  53. return FALSE == m_erf.fError;
  54. }
  55. bool IsValidCAB(
  56. IN LPCTSTR szCabPath
  57. );
  58. bool IsValidCAB(
  59. IN byte_buffer& bufIn // Mem buffer in
  60. );
  61. //Decompresses a cab either into memory or disk.
  62. bool Decompress(
  63. IN LPCTSTR szFileIn, // Full path to input cab file.
  64. IN LPCTSTR szFileOut
  65. );
  66. bool Decompress(
  67. IN LPCTSTR szFileIn, // Full path to input cab file.
  68. IN byte_buffer& bufOut // Mem buffer out
  69. );
  70. bool Decompress(
  71. IN byte_buffer& bufIn, // Mem buffer in
  72. IN LPCTSTR szFileOut
  73. );
  74. bool Decompress(
  75. IN byte_buffer& bufIn, // Mem buffer in
  76. IN byte_buffer& bufOut // Mem buffer out
  77. );
  78. int GetLastError()
  79. {
  80. return m_erf.fError ? m_erf.erfOper : FDIERROR_NONE;
  81. }
  82. protected:
  83. void SetInput(
  84. IN LPCTSTR szFileIn
  85. ) {
  86. m_szFileIn = szFileIn;
  87. s_pbufIn = NULL;
  88. }
  89. void SetInput(
  90. IN byte_buffer& bufIn
  91. ) {
  92. m_szFileIn = NULL;
  93. s_pbufIn = &bufIn;
  94. }
  95. void SetOutput(
  96. IN LPCTSTR szFileOut
  97. ) {
  98. m_szFileOut = szFileOut;
  99. s_pbufOut = NULL;
  100. }
  101. void SetOutput(
  102. IN byte_buffer& bufOut // Mem buffer out
  103. ) {
  104. m_szFileOut = NULL;
  105. s_pbufOut = &bufOut;
  106. }
  107. bool DoDecompress();
  108. private:
  109. static void * __cdecl DEXMemAlloc(ULONG cb);
  110. static void __cdecl DEXMemFree(void HUGE *pv);
  111. static INT_PTR __cdecl DEXFileOpen(char *pszFile, int oflag, int pmode);
  112. static UINT __cdecl DEXFileRead(INT_PTR hf, void *pv, UINT cb);
  113. static UINT __cdecl DEXFileWrite(INT_PTR hf, void *pv, UINT cb);
  114. static int __cdecl DEXFileClose(INT_PTR hf);
  115. static long __cdecl DEXFileSeek(INT_PTR hf, long dist, int seektype);
  116. private:
  117. ERF m_erf; //diamond compression Error structure
  118. HFDI m_hfdi; //Handle to FDI context
  119. LPCTSTR m_szFileOut; //pointer to output file or "?" for in memory operation.
  120. LPCTSTR m_szFileIn; //pointer to input file used when outfile is set to *.
  121. static byte_buffer* s_pbufIn;
  122. static byte_buffer* s_pbufOut;
  123. static CHInfoArray s_handles; //Memory decompression handle information arrays
  124. //increases and allocates the handle.
  125. static INT_PTR __cdecl Notification(FDINOTIFICATIONTYPE fdiNotifType, PFDINOTIFICATION pfdin);
  126. };
  127. #define _DIAMOND_H
  128. #endif