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