IS7zDec.c 4.9 KB

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