This repository has been archived by the owner on May 7, 2020. It is now read-only.
forked from mirror/rarfilesource
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Utils.cpp
178 lines (143 loc) · 3.64 KB
/
Utils.cpp
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* Copyright (C) 2008-2012, OctaneSnail <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include <windows.h>
#include <streams.h>
#include <strsafe.h>
#include "Utils.h"
#include "RFS.h"
void ErrorMsg (DWORD errorCode, wchar_t *format, ...)
{
wchar_t buffer [1024];
wchar_t *end;
size_t remaining;
va_list argptr;
// __asm int 3;
va_start (argptr, format);
StringCchVPrintfEx (buffer, 1024, &end, &remaining, 0, format, argptr);
va_end (argptr);
if (errorCode && remaining > 9)
{
wcscpy (end, L"\n\nError: ");
end += 9;
remaining -= 9;
FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS,
NULL, errorCode, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT), end, (DWORD) remaining, NULL);
}
DbgLog((LOG_ERROR, 0, L"%s", buffer));
MessageBox (NULL, buffer, RARFileSourceName, MB_OK | MB_ICONERROR);
}
#ifdef _DEBUG
static wchar_t *mhd_flags [] =
{
L"MHD_VOLUME",
L"MHD_COMMENT",
L"MHD_LOCK",
L"MHD_SOLID",
L"MHD_NEWNUMBERING",
L"MHD_AV",
L"MHD_PROTECT",
L"MHD_PASSWORD",
L"MHD_FIRSTVOLUME",
L"MHD_ENCRYPTVER"
};
static wchar_t *lhd_flags1 [] =
{
L"LHD_SPLIT_BEFORE",
L"LHD_SPLIT_AFTER",
L"LHD_PASSWORD",
L"LHD_COMMENT",
L"LHD_SOLID"
};
static wchar_t *lhd_flags2 [] =
{
L"LHD_LARGE",
L"LHD_UNICODE",
L"LHD_SALT",
L"LHD_VERSION",
L"LHD_EXTTIME",
L"LHD_EXTFLAGS"
};
static wchar_t *earc_flags [] =
{
L"EARC_NEXT_VOLUME",
L"EARC_DATACRC",
L"EARC_REVSPACE",
L"EARC_VOLNUMBER"
};
void LogHeader (rar_header_t *rh)
{
int i;
WORD flags = rh->ch.flags;
DbgLog((LOG_TRACE, 2, L"Header CRC %04hx TYPE %02x FLAGS %04hx SIZE %08lx %08lx",
rh->ch.crc, rh->ch.type, rh->ch.flags, rh->ch.size.HighPart, rh->ch.size.LowPart));
switch (rh->ch.type)
{
case HEADER_TYPE_MARKER:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_MARKER"));
break;
case HEADER_TYPE_ARCHIVE:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_ARCHIVE"));
for (i = 0; i < 10; i ++)
{
if (flags & 1)
DbgLog((LOG_TRACE, 2, L" %s", mhd_flags [i]));
flags >>= 1;
}
break;
case HEADER_TYPE_FILE:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_FILE"));
for (i = 0; i < 5; i ++)
{
if (flags & 1)
DbgLog((LOG_TRACE, 2, L" %s", lhd_flags1 [i]));
flags >>= 1;
}
flags >>= 3;
for (i = 0; i < 6; i ++)
{
if (flags & 1)
DbgLog((LOG_TRACE, 2, L" %s", lhd_flags2 [i]));
flags >>= 1;
}
break;
case HEADER_TYPE_SUBBLOCK:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_SUBBLOCK"));
break;
case HEADER_TYPE_RECOVERY:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_RECOVERY"));
break;
case HEADER_TYPE_NEWSUBLOCK:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_NEWSUBLOCK"));
break;
case HEADER_TYPE_END:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_END"));
for (i = 0; i < 4; i ++)
{
if (flags & 1)
DbgLog((LOG_TRACE, 2, L" %s", earc_flags [i]));
flags >>= 1;
}
break;
default:
DbgLog((LOG_TRACE, 2, L" HEADER_TYPE_UNKNOWN"));
}
if (rh->ch.flags & SKIP_IF_UNKNOWN)
DbgLog((LOG_TRACE, 2, L" SKIP_IF_UNKNOWN"));
if (rh->ch.flags & LONG_BLOCK)
DbgLog((LOG_TRACE, 2, L" LONG_BLOCK"));
}
#endif // _DEBUG