IS7zDec.c 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. /*
  2. IS7zDec.c, by Martijn Laan for Inno Setup
  3. This file is public domain (like the LZMA SDK)
  4. 7zMain.c + its dependencies + additional helper function used by Compression.SevenZipDecoder.pas
  5. */
  6. #include "../../../../Components/Lzma2/Util/7z/Precomp.h" /* Says it must be included first */
  7. /* Stop 7-Zip from directly opening files and directories. This will enable us to perform
  8. extra checks from a cdecl implementation in Delphi. */
  9. #include "../../../../Components/Lzma2/7zWindows.h"
  10. BOOL _CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
  11. #define CreateDirectoryW _CreateDirectoryW
  12. HANDLE _CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
  13. #define CreateFileA _CreateFileA
  14. HANDLE _CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile);
  15. #define CreateFileW _CreateFileW
  16. DWORD _GetFileAttributesW(LPCWSTR lpFileName);
  17. #define GetFileAttributesW _GetFileAttributesW
  18. BOOL _SetFileAttributesW(LPCWSTR lpFileName, DWORD dwFileAttributes);
  19. #define SetFileAttributesW _SetFileAttributesW
  20. #ifdef _MSC_VER
  21. /* MSVC only:
  22. Stop 7-Zip from using stdcall functions which will get unavoidable decorated names from
  23. MSVC's cl.exe which Delphi can't handle: first include windows.h and then hide the
  24. functions 7-Zip wants to use with macros pointing to cdecl prototypes. This will enable
  25. us to call the stdcall function from a cdecl implementation in Delphi and keeps the
  26. rest of windows.h available to 7-Zip. */
  27. BOOL _FileTimeToLocalFileTime(FILETIME* lpFileTime, LPFILETIME lpLocalFileTime);
  28. #define FileTimeToLocalFileTime _FileTimeToLocalFileTime
  29. DWORD _GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh);
  30. #define GetFileSize _GetFileSize
  31. BOOL _ReadFile(HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped);
  32. #define ReadFile _ReadFile
  33. DWORD _SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod);
  34. #define SetFilePointer _SetFilePointer
  35. BOOL _SetFileTime(HANDLE hFile, FILETIME* lpCreationTime, FILETIME* lpLastAccessTime, FILETIME* lpLastWriteTime);
  36. #define SetFileTime _SetFileTime
  37. BOOL _WriteFile(HANDLE hFile, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite, LPDWORD lpNumberOfBytesWritten, LPOVERLAPPED lpOverlapped);
  38. #define WriteFile _WriteFile
  39. BOOL _CloseHandle(HANDLE hObject);
  40. #define CloseHandle _CloseHandle
  41. DWORD _GetLastError(VOID);
  42. #define GetLastError _GetLastError
  43. HLOCAL _LocalFree(HLOCAL hMem);
  44. #define LocalFree _LocalFree
  45. DWORD _FormatMessageA(DWORD dwFlags, LPCVOID lpSource, DWORD dwMessageId, DWORD dwLanguageId, LPSTR lpBuffer, DWORD nSize, va_list *Arguments);
  46. #define FormatMessageA _FormatMessageA
  47. int _WideCharToMultiByte(UINT CodePage, DWORD dwFlags, LPCWCH lpWideCharStr, int cchWideChar, LPSTR lpMultiByteStr, int cbMultiByte, LPCCH lpDefaultChar, LPBOOL lpUsedDefaultChar);
  48. #define WideCharToMultiByte _WideCharToMultiByte
  49. #endif
  50. /* Stop 7-Zip from using fputs from stdio.h: first include stdio.h and then hide the
  51. real fputs 7-Zip wants to use with a macro pointing to a renamed prototype. This will
  52. enable us to log 7-Zip output from a cdecl implementation in Delphi and keeps the
  53. rest of stdio.h available to 7-Zip.*/
  54. #include <stdio.h>
  55. int _fputs(char const* str, FILE* stream);
  56. #define fputs _fputs
  57. /* Stop 7-Zip from requiring stdout ("__acrt_iob_func"). Undef first to avoid warning. */
  58. #undef stdout
  59. #define stdout NULL
  60. /* Include all needed SDK code. None of these require changes for the helper function to
  61. work but 7zMain.c was changed for better Unicode support */
  62. #define REPORT_OUTBUFFERSIZE
  63. #define REPORT_PROGRESS
  64. #include "../../../../Components/Lzma2/Util/7z/7zMain.c"
  65. #ifndef USE_WINDOWS_FILE
  66. #error USE_WINDOWS_FILE is required by Compression.SevenZipDecoder.pas
  67. #endif
  68. #include "../../../../Components/Lzma2/7zAlloc.c"
  69. #include "../../../../Components/Lzma2/7zArcIn.c"
  70. #include "../../../../Components/Lzma2/7zBuf.c"
  71. #include "../../../../Components/Lzma2/7zCrc.c"
  72. #include "../../../../Components/Lzma2/7zCrcOpt.c"
  73. #include "../../../../Components/Lzma2/7zDec.c"
  74. #include "../../../../Components/Lzma2/7zFile.c"
  75. #include "../../../../Components/Lzma2/7zStream.c"
  76. #include "../../../../Components/Lzma2/Bcj2.c"
  77. #include "../../../../Components/Lzma2/Bra.c"
  78. #include "../../../../Components/Lzma2/Bra86.c"
  79. #include "../../../../Components/Lzma2/Delta.c"
  80. #include "../../../../Components/Lzma2/LzmaDec.c"
  81. #include "../../../../Components/Lzma2/Lzma2Dec.c"
  82. /* Finally the helper function */
  83. int IS_7zDec(WCHAR *fileName, BOOL fullPaths)
  84. {
  85. WCHAR* args[3];
  86. args[0] = L"";
  87. args[1] = fullPaths?L"x":L"e";
  88. args[2] = fileName;
  89. return mainW(3, args);
  90. }