Team Fortress 2 Source Code as on 22/4/2020
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.

88 lines
3.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. //=============================================================================//
  6. #ifndef ZIP_UTILS_H
  7. #define ZIP_UTILS_H
  8. #ifdef _WIN32
  9. #pragma once
  10. #endif
  11. #include "utlsymbol.h"
  12. class CUtlBuffer;
  13. #include "tier0/dbg.h"
  14. abstract_class IZip
  15. {
  16. public:
  17. enum eCompressionType
  18. {
  19. // Type of compression used for this file in the zip
  20. eCompressionType_Unknown = -1,
  21. eCompressionType_None = 0,
  22. eCompressionType_LZMA = 14
  23. };
  24. virtual void Reset() = 0;
  25. // Add a single file to a zip - maintains the zip's previous alignment state.
  26. virtual void AddFileToZip ( const char *relativename, const char *fullpath, eCompressionType compressionType = eCompressionType_None ) = 0;
  27. // Whether a file is contained in a zip - maintains alignment
  28. virtual bool FileExistsInZip ( const char *pRelativeName ) = 0;
  29. // Reads a file from the zip - maintains alignement.
  30. virtual bool ReadFileFromZip ( const char *pRelativeName, bool bTextMode, CUtlBuffer &buf ) = 0;
  31. virtual bool ReadFileFromZip ( HANDLE hFile, const char *pRelativeName, bool bTextMode, CUtlBuffer &buf ) = 0;
  32. // Removes a single file from the zip - maintains alignment
  33. virtual void RemoveFileFromZip ( const char *relativename ) = 0;
  34. // Gets next filename in zip, for walking the directory - maintains alignment
  35. virtual int GetNextFilename ( int id, char *pBuffer, int bufferSize, int &fileSize ) = 0;
  36. // Prints the zip's contents - maintains alignment
  37. virtual void PrintDirectory ( void ) = 0;
  38. // Estimate the size of the Zip (including header, padding, etc.)
  39. virtual unsigned int EstimateSize ( void ) = 0;
  40. // Add buffer to zip as a file with given name - uses current alignment size, default 0 (no alignment)
  41. virtual void AddBufferToZip ( const char *relativename, void *data, int length, bool bTextMode, eCompressionType compressionType = eCompressionType_None ) = 0;
  42. // Writes out zip file to a buffer - uses current alignment size
  43. // (set by file's previous alignment, or a call to ForceAlignment)
  44. virtual void SaveToBuffer ( CUtlBuffer& outbuf ) = 0;
  45. // Writes out zip file to a filestream - uses current alignment size
  46. // (set by file's previous alignment, or a call to ForceAlignment)
  47. virtual void SaveToDisk ( FILE *fout ) = 0;
  48. virtual void SaveToDisk ( HANDLE hFileOut ) = 0;
  49. // Reads a zip file from a buffer into memory - sets current alignment size to
  50. // the file's alignment size, unless overridden by a ForceAlignment call)
  51. virtual void ParseFromBuffer ( void *buffer, int bufferlength ) = 0;
  52. // Mounts a zip file from the disk
  53. // Only ReadFileFromZip() is supported because the zip file could be >2GB
  54. virtual HANDLE ParseFromDisk ( const char *pFilename ) = 0;
  55. // Forces a specific alignment size for all subsequent file operations, overriding files' previous alignment size.
  56. // Return to using files' individual alignment sizes by passing FALSE.
  57. virtual void ForceAlignment ( bool aligned, bool bCompatibleFormat, unsigned int alignmentSize=0 ) = 0;
  58. virtual unsigned int GetAlignment() = 0;
  59. // Sets the endianess of the zip
  60. virtual void SetBigEndian( bool bigEndian ) = 0;
  61. virtual void ActivateByteSwapping( bool bActivate ) = 0;
  62. // Create/Release additional instances
  63. // Disk Caching is necessary for large zips
  64. static IZip *CreateZip( const char *pDiskCacheWritePath = NULL, bool bSortByName = false );
  65. static void ReleaseZip( IZip *zip );
  66. };
  67. #endif // ZIP_UTILS_H