| 1 |
jcl/source/common/JclCompression.pas | 180 ++++++++++++++++++++++++++++++----- |
| 2 |
jcl/source/windows/sevenzip.pas | 10 +- |
| 3 |
2 files changed, 161 insertions(+), 29 deletions(-) |
| 4 |
|
| 5 |
diff --git a/jcl/source/common/JclCompression.pas b/jcl/source/common/JclCompression.pas |
| 6 |
index e5e6a2f..80889a3 100644 |
| 7 |
--- a/jcl/source/common/JclCompression.pas |
| 8 |
+++ b/jcl/source/common/JclCompression.pas |
| 9 |
@@ -44,8 +44,7 @@ |
| 10 |
|
| 11 |
unit JclCompression; |
| 12 |
|
| 13 |
-{$I jcl.inc} |
| 14 |
-{$I crossplatform.inc} |
| 15 |
+{$mode delphi} |
| 16 |
|
| 17 |
interface |
| 18 |
|
| 19 |
@@ -75,7 +74,10 @@ uses |
| 20 |
ZLib, |
| 21 |
{$ENDIF ZLIB_RTL} |
| 22 |
{$ENDIF ~HAS_UNITSCOPE} |
| 23 |
- zlibh, bzip2, JclWideStrings, JclBase, JclStreams; |
| 24 |
+ {$IFNDEF FPC} |
| 25 |
+ zlibh, bzip2, |
| 26 |
+ {$ENDIF FPC} |
| 27 |
+ DCJclAlternative; // Must be after Classes, SysUtils, Windows |
| 28 |
|
| 29 |
{$IFDEF RTL230_UP} |
| 30 |
{$HPPEMIT '// To avoid ambiguity with System::Zlib::z_stream_s we force using ours'} |
| 31 |
@@ -180,6 +182,9 @@ uses |
| 32 |
**************************************************************************************************} |
| 33 |
|
| 34 |
type |
| 35 |
+ |
| 36 |
+{$IFNDEF FPC} |
| 37 |
+ |
| 38 |
TJclCompressionStream = class(TJclStream) |
| 39 |
private |
| 40 |
FOnProgress: TNotifyEvent; |
| 41 |
@@ -562,8 +567,12 @@ type |
| 42 |
function Seek(const Offset: Int64; Origin: TSeekOrigin): Int64; override; |
| 43 |
end; |
| 44 |
|
| 45 |
+{$ENDIF FPC} |
| 46 |
+ |
| 47 |
EJclCompressionError = class(EJclError); |
| 48 |
|
| 49 |
+{$IFNDEF FPC} |
| 50 |
+ |
| 51 |
// callback type used in helper functions below: |
| 52 |
TJclCompressStreamProgressCallback = procedure(FileSize, Position: Int64; UserData: Pointer) of object; |
| 53 |
|
| 54 |
@@ -586,6 +595,8 @@ procedure BZip2Stream(SourceStream, DestinationStream: TStream; CompressionLevel |
| 55 |
procedure UnBZip2Stream(SourceStream, DestinationStream: TStream; |
| 56 |
ProgressCallback: TJclCompressStreamProgressCallback = nil; UserData: Pointer = nil); |
| 57 |
|
| 58 |
+{$ENDIF FPC} |
| 59 |
+ |
| 60 |
// archive ancestor classes |
| 61 |
{$IFDEF MSWINDOWS} |
| 62 |
type |
| 63 |
@@ -595,6 +606,7 @@ type |
| 64 |
var AVolumeMaxSize: Int64) of object; |
| 65 |
TJclCompressionProgressEvent = procedure(Sender: TObject; const Value, MaxValue: Int64) of object; |
| 66 |
TJclCompressionRatioEvent = procedure(Sender: TObject; const InSize, OutSize: Int64) of object; |
| 67 |
+ TJclCompressionPasswordEvent = procedure(Sender: TObject; var Password: WideString) of object; |
| 68 |
|
| 69 |
TJclCompressionItemProperty = (ipPackedName, ipPackedSize, ipPackedExtension, |
| 70 |
ipFileSize, ipFileName, ipAttributes, ipCreationTime, ipLastAccessTime, |
| 71 |
@@ -770,6 +782,7 @@ type |
| 72 |
FOnRatio: TJclCompressionRatioEvent; |
| 73 |
FOnVolume: TJclCompressionVolumeEvent; |
| 74 |
FOnVolumeMaxSize: TJclCompressionVolumeMaxSizeEvent; |
| 75 |
+ FOnPassword: TJclCompressionPasswordEvent; |
| 76 |
FPassword: WideString; |
| 77 |
FVolumeIndex: Integer; |
| 78 |
FVolumeIndexOffset: Integer; |
| 79 |
@@ -803,6 +816,9 @@ type |
| 80 |
// function QueryInterface(const IID: TGUID; out Obj): HRESULT; stdcall; |
| 81 |
function _AddRef: Integer; stdcall; |
| 82 |
function _Release: Integer; stdcall; |
| 83 |
+ public |
| 84 |
+ PropNames: array of WideString; |
| 85 |
+ PropValues: array of TPropVariant; |
| 86 |
public |
| 87 |
class function MultipleItemContainer: Boolean; virtual; |
| 88 |
class function VolumeAccess: TJclStreamAccess; virtual; |
| 89 |
@@ -855,6 +871,7 @@ type |
| 90 |
property OnVolume: TJclCompressionVolumeEvent read FOnVolume write FOnVolume; |
| 91 |
property OnVolumeMaxSize: TJclCompressionVolumeMaxSizeEvent read FOnVolumeMaxSize |
| 92 |
write FOnVolumeMaxSize; |
| 93 |
+ property OnPassword: TJclCompressionPasswordEvent read FOnPassword write FOnPassword; |
| 94 |
property Password: WideString read FPassword write FPassword; |
| 95 |
|
| 96 |
property SupportsNestedArchive: Boolean read GetSupportsNestedArchive; |
| 97 |
@@ -1193,6 +1210,7 @@ function GetArchiveFormats: TJclCompressionArchiveFormats; |
| 98 |
type |
| 99 |
TJclSevenzipCompressArchive = class(TJclCompressArchive, IInterface) |
| 100 |
private |
| 101 |
+ FSfxModule: String; |
| 102 |
FOutArchive: IOutArchive; |
| 103 |
protected |
| 104 |
function GetItemClass: TJclCompressionItemClass; override; |
| 105 |
@@ -1203,6 +1221,7 @@ type |
| 106 |
destructor Destroy; override; |
| 107 |
procedure Compress; override; |
| 108 |
property OutArchive: IOutArchive read GetOutArchive; |
| 109 |
+ property SfxModule: String read FSfxModule write FSfxModule; |
| 110 |
end; |
| 111 |
|
| 112 |
// file formats |
| 113 |
@@ -2189,6 +2208,9 @@ function Create7zFile(const SourceFile, DestinationFile: TFileName; VolumeSize: |
| 114 |
OnArchiveProgress: TJclCompressionProgressEvent = nil; |
| 115 |
OnArchiveRatio: TJclCompressionRatioEvent = nil): Boolean; overload; |
| 116 |
|
| 117 |
+var |
| 118 |
+ JclCompressSharedFiles: Boolean = False; |
| 119 |
+ |
| 120 |
{$ENDIF MSWINDOWS} |
| 121 |
|
| 122 |
{$IFDEF UNITVERSIONING} |
| 123 |
@@ -2206,8 +2228,7 @@ const |
| 124 |
implementation |
| 125 |
|
| 126 |
uses |
| 127 |
- JclUnicode, // WideSameText |
| 128 |
- JclDateTime, JclFileUtils, JclResources, JclStrings, JclSysUtils; |
| 129 |
+ DCJclResources, DCJclCompression; |
| 130 |
|
| 131 |
const |
| 132 |
JclDefaultBufferSize = 131072; // 128k |
| 133 |
@@ -2218,6 +2239,8 @@ var |
| 134 |
GlobalStreamFormats: TObject; |
| 135 |
GlobalArchiveFormats: TObject; |
| 136 |
|
| 137 |
+{$IFNDEF FPC} |
| 138 |
+ |
| 139 |
//=== { TJclCompressionStream } ============================================== |
| 140 |
|
| 141 |
constructor TJclCompressionStream.Create(AStream: TStream); |
| 142 |
@@ -3743,6 +3766,8 @@ begin |
| 143 |
end; |
| 144 |
end; |
| 145 |
|
| 146 |
+{$ENDIF FPC} |
| 147 |
+ |
| 148 |
{$IFDEF MSWINDOWS} |
| 149 |
|
| 150 |
function OpenFileStream(const FileName: TFileName; StreamAccess: TJclStreamAccess): TStream; |
| 151 |
@@ -3887,7 +3912,7 @@ end; |
| 152 |
function TJclCompressionItem.GetNestedArchiveName: WideString; |
| 153 |
var |
| 154 |
ParentArchiveExtension, ArchiveFileName, ArchiveExtension: WideString; |
| 155 |
- ExtensionMap: TJclWideStrings; |
| 156 |
+ ExtensionMap: TStrings; |
| 157 |
begin |
| 158 |
if ipPackedName in ValidProperties then |
| 159 |
Result := PackedName |
| 160 |
@@ -3914,7 +3939,7 @@ begin |
| 161 |
else |
| 162 |
if ArchiveFileName <> '' then |
| 163 |
begin |
| 164 |
- ExtensionMap := TJclWideStringList.Create; |
| 165 |
+ ExtensionMap := TStringList.Create; |
| 166 |
try |
| 167 |
ExtensionMap.Delimiter := ';'; |
| 168 |
ExtensionMap.DelimitedText := Archive.ArchiveSubExtensions; |
| 169 |
@@ -3962,9 +3987,16 @@ begin |
| 170 |
end; |
| 171 |
|
| 172 |
function TJclCompressionItem.GetStream: TStream; |
| 173 |
+var |
| 174 |
+ AItemAccess: TJclStreamAccess; |
| 175 |
begin |
| 176 |
if not Assigned(FStream) and (FileName <> '') then |
| 177 |
- FStream := OpenFileStream(FileName, Archive.ItemAccess); |
| 178 |
+ begin |
| 179 |
+ AItemAccess:= Archive.ItemAccess; |
| 180 |
+ if (AItemAccess = saReadOnly) and JclCompressSharedFiles then |
| 181 |
+ AItemAccess:= saReadOnlyDenyNone; |
| 182 |
+ FStream := OpenFileStream(FileName, AItemAccess); |
| 183 |
+ end; |
| 184 |
|
| 185 |
Result := FStream; |
| 186 |
end; |
| 187 |
@@ -5544,6 +5576,18 @@ begin |
| 188 |
end; |
| 189 |
if not AllHandled then |
| 190 |
raise EJclCompressionError.CreateRes(@RsCompressionReplaceError); |
| 191 |
+ end |
| 192 |
+ else begin |
| 193 |
+ // Remove temporary files |
| 194 |
+ for Index := 0 to FVolumes.Count - 1 do |
| 195 |
+ begin |
| 196 |
+ AVolume := TJclCompressionVolume(FVolumes.Items[Index]); |
| 197 |
+ if AVolume.OwnsTmpStream then |
| 198 |
+ begin |
| 199 |
+ FreeAndNil(AVolume.FTmpStream); |
| 200 |
+ FileDelete(AVolume.TmpFileName); |
| 201 |
+ end; |
| 202 |
+ end; |
| 203 |
end; |
| 204 |
end; |
| 205 |
|
| 206 |
@@ -5791,6 +5835,8 @@ begin |
| 207 |
FItemIndex := AItemIndex; |
| 208 |
FStream := nil; |
| 209 |
FOwnsStream := False; |
| 210 |
+ |
| 211 |
+ NeedStream; |
| 212 |
end; |
| 213 |
|
| 214 |
constructor TJclSevenzipInStream.Create(AStream: TStream; AOwnsStream: Boolean); |
| 215 |
@@ -6117,6 +6163,8 @@ end; |
| 216 |
|
| 217 |
procedure SetSevenzipArchiveCompressionProperties(AJclArchive: IInterface; ASevenzipArchive: IInterface); |
| 218 |
var |
| 219 |
+ Index: Integer; |
| 220 |
+ JclArchive: TJclCompressionArchive; |
| 221 |
PropertySetter: Sevenzip.ISetProperties; |
| 222 |
InArchive, OutArchive: Boolean; |
| 223 |
Unused: IInterface; |
| 224 |
@@ -6254,9 +6302,18 @@ begin |
| 225 |
else |
| 226 |
AddWideStringProperty('S', IntToStr(Solid.SolidBlockSize) + 'F'); |
| 227 |
end; |
| 228 |
+ |
| 229 |
+ JclArchive := AJclArchive as TJclCompressionArchive; |
| 230 |
+ for Index := Low(JclArchive.PropNames) to High(JclArchive.PropNames) do |
| 231 |
+ begin |
| 232 |
+ AddProperty(PWideChar(JclArchive.PropNames[Index]), JclArchive.PropValues[Index]); |
| 233 |
+ end; |
| 234 |
end; |
| 235 |
if Length(PropNames) > 0 then |
| 236 |
+ begin |
| 237 |
SevenZipCheck(PropertySetter.SetProperties(@PropNames[0], @PropValues[0], Length(PropNames))); |
| 238 |
+ SetLength(JclArchive.PropNames, 0); SetLength(JclArchive.PropValues, 0); |
| 239 |
+ end; |
| 240 |
end; |
| 241 |
end; |
| 242 |
|
| 243 |
@@ -6510,7 +6567,10 @@ begin |
| 244 |
// kpidCharacts: ; |
| 245 |
// kpidVa: ; |
| 246 |
// kpidId: ; |
| 247 |
- // kpidShortName: ; |
| 248 |
+ kpidShortName: |
| 249 |
+ begin |
| 250 |
+ Value.vt := VT_EMPTY; |
| 251 |
+ end; |
| 252 |
// kpidCreatorApp: ; |
| 253 |
// kpidSectorSize: ; |
| 254 |
kpidPosixAttrib: |
| 255 |
@@ -6525,6 +6585,11 @@ begin |
| 256 |
// kpidLocalName: ; |
| 257 |
// kpidProvider: ; |
| 258 |
// kpidUserDefined: ; |
| 259 |
+ kpidIsAltStream: |
| 260 |
+ begin |
| 261 |
+ Value.vt := VT_BOOL; |
| 262 |
+ Value.bool := False; |
| 263 |
+ end; |
| 264 |
else |
| 265 |
Value.vt := VT_EMPTY; |
| 266 |
Result := S_FALSE; |
| 267 |
@@ -6534,9 +6599,27 @@ end; |
| 268 |
function TJclSevenzipUpdateCallback.GetStream(Index: Cardinal; |
| 269 |
out InStream: ISequentialInStream): HRESULT; |
| 270 |
begin |
| 271 |
+ Result := E_FAIL; |
| 272 |
FLastStream := Index; |
| 273 |
- InStream := TJclSevenzipInStream.Create(FArchive, Index); |
| 274 |
- Result := S_OK; |
| 275 |
+ repeat |
| 276 |
+ try |
| 277 |
+ InStream := TJclSevenzipInStream.Create(FArchive, Index); |
| 278 |
+ Result := S_OK; |
| 279 |
+ except |
| 280 |
+ on E: Exception do |
| 281 |
+ begin |
| 282 |
+ case MessageBox(0, PAnsiChar(E.Message), nil, MB_ABORTRETRYIGNORE or MB_ICONERROR) of |
| 283 |
+ IDABORT: Exit(E_ABORT); |
| 284 |
+ IDIGNORE: |
| 285 |
+ begin |
| 286 |
+ FArchive.Items[Index].OperationSuccess := osNoOperation; |
| 287 |
+ FLastStream := MAXDWORD; |
| 288 |
+ Exit(S_FALSE); |
| 289 |
+ end; |
| 290 |
+ end; |
| 291 |
+ end; |
| 292 |
+ end; |
| 293 |
+ until Result = S_OK; |
| 294 |
end; |
| 295 |
|
| 296 |
function TJclSevenzipUpdateCallback.GetUpdateItemInfo(Index: Cardinal; NewData, |
| 297 |
@@ -6595,17 +6678,20 @@ end; |
| 298 |
function TJclSevenzipUpdateCallback.SetOperationResult( |
| 299 |
OperationResult: Integer): HRESULT; |
| 300 |
begin |
| 301 |
- case OperationResult of |
| 302 |
- kOK: |
| 303 |
- FArchive.Items[FLastStream].OperationSuccess := osOK; |
| 304 |
- kUnSupportedMethod: |
| 305 |
- FArchive.Items[FLastStream].OperationSuccess := osUnsupportedMethod; |
| 306 |
- kDataError: |
| 307 |
- FArchive.Items[FLastStream].OperationSuccess := osDataError; |
| 308 |
- kCRCError: |
| 309 |
- FArchive.Items[FLastStream].OperationSuccess := osCRCError; |
| 310 |
- else |
| 311 |
- FArchive.Items[FLastStream].OperationSuccess := osUnknownError; |
| 312 |
+ if FLastStream < MAXDWORD then |
| 313 |
+ begin |
| 314 |
+ case OperationResult of |
| 315 |
+ kOK: |
| 316 |
+ FArchive.Items[FLastStream].OperationSuccess := osOK; |
| 317 |
+ kUnSupportedMethod: |
| 318 |
+ FArchive.Items[FLastStream].OperationSuccess := osUnsupportedMethod; |
| 319 |
+ kDataError: |
| 320 |
+ FArchive.Items[FLastStream].OperationSuccess := osDataError; |
| 321 |
+ kCRCError: |
| 322 |
+ FArchive.Items[FLastStream].OperationSuccess := osCRCError; |
| 323 |
+ else |
| 324 |
+ FArchive.Items[FLastStream].OperationSuccess := osUnknownError; |
| 325 |
+ end; |
| 326 |
end; |
| 327 |
|
| 328 |
Result := S_OK; |
| 329 |
@@ -6681,7 +6767,10 @@ end; |
| 330 |
|
| 331 |
procedure TJclSevenzipCompressArchive.Compress; |
| 332 |
var |
| 333 |
+ Value: HRESULT; |
| 334 |
+ Index: Integer; |
| 335 |
OutStream: IOutStream; |
| 336 |
+ AVolume: TJclCompressionVolume; |
| 337 |
UpdateCallback: IArchiveUpdateCallback; |
| 338 |
SplitStream: TJclDynamicSplitStream; |
| 339 |
begin |
| 340 |
@@ -6692,12 +6781,32 @@ begin |
| 341 |
SplitStream := TJclDynamicSplitStream.Create(False); |
| 342 |
SplitStream.OnVolume := NeedStream; |
| 343 |
SplitStream.OnVolumeMaxSize := NeedStreamMaxSize; |
| 344 |
- OutStream := TJclSevenzipOutStream.Create(SplitStream, True, False); |
| 345 |
+ if Length(FSfxModule) > 0 then |
| 346 |
+ OutStream := TSfxSevenzipOutStream.Create(SplitStream, FSfxModule) |
| 347 |
+ else begin |
| 348 |
+ OutStream := TJclSevenzipOutStream.Create(SplitStream, True, False); |
| 349 |
+ end; |
| 350 |
UpdateCallback := TJclSevenzipUpdateCallback.Create(Self); |
| 351 |
|
| 352 |
SetSevenzipArchiveCompressionProperties(Self, OutArchive); |
| 353 |
|
| 354 |
- SevenzipCheck(OutArchive.UpdateItems(OutStream, ItemCount, UpdateCallback)); |
| 355 |
+ Value:= OutArchive.UpdateItems(OutStream, ItemCount, UpdateCallback); |
| 356 |
+ |
| 357 |
+ if Value <> S_OK then |
| 358 |
+ begin |
| 359 |
+ // Remove partial archives |
| 360 |
+ for Index := 0 to FVolumes.Count - 1 do |
| 361 |
+ begin |
| 362 |
+ AVolume := TJclCompressionVolume(FVolumes.Items[Index]); |
| 363 |
+ if AVolume.OwnsStream then |
| 364 |
+ begin |
| 365 |
+ FreeAndNil(AVolume.FStream); |
| 366 |
+ FileDelete(AVolume.FileName); |
| 367 |
+ end; |
| 368 |
+ end; |
| 369 |
+ end; |
| 370 |
+ |
| 371 |
+ SevenzipCheck(Value); |
| 372 |
finally |
| 373 |
FCompressing := False; |
| 374 |
// release volumes and other finalizations |
| 375 |
@@ -7422,7 +7531,14 @@ function TJclSevenzipOpenCallback.CryptoGetTextPassword( |
| 376 |
password: PBStr): HRESULT; |
| 377 |
begin |
| 378 |
if Assigned(password) then |
| 379 |
+ begin |
| 380 |
+ if Length(FArchive.FPassword) = 0 then |
| 381 |
+ begin |
| 382 |
+ if Assigned(FArchive.OnPassword) then |
| 383 |
+ FArchive.OnPassword(FArchive, FArchive.FPassword); |
| 384 |
+ end; |
| 385 |
password^ := SysAllocString(PWideChar(FArchive.Password)); |
| 386 |
+ end; |
| 387 |
Result := S_OK; |
| 388 |
end; |
| 389 |
|
| 390 |
@@ -7456,7 +7572,14 @@ function TJclSevenzipExtractCallback.CryptoGetTextPassword( |
| 391 |
password: PBStr): HRESULT; |
| 392 |
begin |
| 393 |
if Assigned(password) then |
| 394 |
+ begin |
| 395 |
+ if Length(FArchive.FPassword) = 0 then |
| 396 |
+ begin |
| 397 |
+ if Assigned(FArchive.OnPassword) then |
| 398 |
+ FArchive.OnPassword(FArchive, FArchive.FPassword); |
| 399 |
+ end; |
| 400 |
password^ := SysAllocString(PWideChar(FArchive.Password)); |
| 401 |
+ end; |
| 402 |
Result := S_OK; |
| 403 |
end; |
| 404 |
|
| 405 |
@@ -8807,6 +8930,7 @@ end; |
| 406 |
|
| 407 |
procedure TJclSevenzipUpdateArchive.Compress; |
| 408 |
var |
| 409 |
+ Value: HRESULT; |
| 410 |
OutStream: IOutStream; |
| 411 |
UpdateCallback: IArchiveUpdateCallback; |
| 412 |
SplitStream: TJclDynamicSplitStream; |
| 413 |
@@ -8824,7 +8948,13 @@ begin |
| 414 |
|
| 415 |
SetSevenzipArchiveCompressionProperties(Self, OutArchive); |
| 416 |
|
| 417 |
- SevenzipCheck(OutArchive.UpdateItems(OutStream, ItemCount, UpdateCallback)); |
| 418 |
+ Value:= OutArchive.UpdateItems(OutStream, ItemCount, UpdateCallback); |
| 419 |
+ |
| 420 |
+ if Value <> S_OK then |
| 421 |
+ begin |
| 422 |
+ FReplaceVolumes:= False; |
| 423 |
+ SevenzipCheck(Value); |
| 424 |
+ end; |
| 425 |
finally |
| 426 |
FCompressing := False; |
| 427 |
// release reference to volume streams |
| 428 |
diff --git a/jcl/source/windows/sevenzip.pas b/jcl/source/windows/sevenzip.pas |
| 429 |
index 06fb94f..68f4ae2 100644 |
| 430 |
--- a/jcl/source/windows/sevenzip.pas |
| 431 |
+++ b/jcl/source/windows/sevenzip.pas |
| 432 |
@@ -53,10 +53,11 @@ |
| 433 |
|
| 434 |
unit sevenzip; |
| 435 |
|
| 436 |
+{$mode delphi} |
| 437 |
+ |
| 438 |
interface |
| 439 |
|
| 440 |
-{$I jcl.inc} |
| 441 |
-{$I windowsonly.inc} |
| 442 |
+{$DEFINE 7ZIP_LINKONREQUEST} |
| 443 |
|
| 444 |
uses |
| 445 |
{$IFDEF HAS_UNITSCOPE} |
| 446 |
@@ -67,8 +68,7 @@ uses |
| 447 |
{$IFDEF UNITVERSIONING} |
| 448 |
JclUnitVersioning, |
| 449 |
{$ENDIF UNITVERSIONING} |
| 450 |
- JclBase, |
| 451 |
- JclSysUtils; |
| 452 |
+ DCJclAlternative; |
| 453 |
|
| 454 |
//DOM-IGNORE-BEGIN |
| 455 |
|
| 456 |
@@ -251,6 +251,8 @@ const |
| 457 |
kpidPosixAttrib = 53; |
| 458 |
kpidLink = 54; |
| 459 |
|
| 460 |
+ kpidIsAltStream = 63; |
| 461 |
+ |
| 462 |
kpidTotalSize = $1100; |
| 463 |
kpidFreeSpace = $1101; |
| 464 |
kpidClusterSize = $1102; |