Rev 5729 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5729 | Rev 5809 | ||
---|---|---|---|
Line 4... | Line 4... | ||
4 | #include "7zAlloc.h" |
4 | #include "7zAlloc.h" |
5 | #include "7zBuf.h" |
5 | #include "7zBuf.h" |
6 | #include "7zCrc.h" |
6 | #include "7zCrc.h" |
7 | #include "7zFile.h" |
7 | #include "7zFile.h" |
8 | #include "7zVersion.h" |
8 | #include "7zVersion.h" |
- | 9 | #include "http.h" |
|
9 | #include "package.h" |
10 | #include "package.h" |
Line 10... | Line 11... | ||
10 | 11 | ||
11 | #define PERIOD_4 (4 * 365 + 1) |
12 | #define PERIOD_4 (4 * 365 + 1) |
12 | #define PERIOD_100 (PERIOD_4 * 25 - 1) |
13 | #define PERIOD_100 (PERIOD_4 * 25 - 1) |
Line 321... | Line 322... | ||
321 | UIntToStr_2(s, min); s[2] = ':'; s += 3; |
322 | UIntToStr_2(s, min); s[2] = ':'; s += 3; |
322 | UIntToStr_2(s, sec); s[2] = 0; |
323 | UIntToStr_2(s, sec); s[2] = 0; |
323 | } |
324 | } |
Line 324... | Line -... | ||
324 | - | ||
325 | 325 | ||
326 | 326 | ||
327 | void do_install(list_t *install) |
327 | void do_7z_unpack(const char *srcpath) |
328 | { |
328 | { |
- | 329 | CFileInStream archiveStream; |
|
329 | CFileInStream archiveStream; |
330 | CLookToRead lookStream; |
330 | CLookToRead lookStream; |
331 | |
331 | CSzArEx db; |
332 | CSzArEx db; |
332 | SRes res; |
333 | SRes res; |
333 | ISzAlloc allocImp; |
334 | ISzAlloc allocImp; |
334 | ISzAlloc allocTempImp; |
335 | ISzAlloc allocTempImp; |
Line 335... | Line 336... | ||
335 | UInt16 *temp = NULL; |
336 | UInt16 *temp = NULL; |
336 | size_t tempSize = 0; |
- | |
Line 337... | Line 337... | ||
337 | 337 | size_t tempSize = 0; |
|
338 | package_t *pkg, *tmp; |
338 | |
Line 339... | Line 339... | ||
339 | char *cache_path; |
339 | memset(&lookStream,0,sizeof(lookStream)); |
340 | 340 | ||
Line 341... | Line -... | ||
341 | allocImp.Alloc = SzAlloc; |
- | |
342 | allocImp.Free = SzFree; |
- | |
343 | - | ||
344 | allocTempImp.Alloc = SzAllocTemp; |
- | |
345 | allocTempImp.Free = SzFreeTemp; |
341 | allocImp.Alloc = SzAlloc; |
346 | 342 | allocImp.Free = SzFree; |
|
Line 347... | Line 343... | ||
347 | list_for_each_entry_safe(pkg, tmp, install, list) |
343 | |
348 | { |
344 | allocTempImp.Alloc = SzAllocTemp; |
Line 349... | Line 345... | ||
349 | cache_path = make_cache_path(pkg->filename); |
345 | allocTempImp.Free = SzFreeTemp; |
350 | 346 | ||
- | 347 | if (InFile_Open(&archiveStream.file, srcpath)) |
|
- | 348 | return; |
|
Line 351... | Line 349... | ||
351 | if (InFile_Open(&archiveStream.file, cache_path)) |
349 | |
Line -... | Line 350... | ||
- | 350 | FileInStream_CreateVTable(&archiveStream); |
|
- | 351 | LookToRead_CreateVTable(&lookStream, False); |
|
- | 352 | ||
- | 353 | lookStream.realStream = &archiveStream.s; |
|
- | 354 | LookToRead_Init(&lookStream); |
|
352 | continue; |
355 | CrcGenerateTable(); |
Line 353... | Line 356... | ||
353 | 356 | SzArEx_Init(&db); |
|
354 | FileInStream_CreateVTable(&archiveStream); |
357 | |
355 | LookToRead_CreateVTable(&lookStream, False); |
- | |
356 | - | ||
357 | lookStream.realStream = &archiveStream.s; |
- | |
358 | LookToRead_Init(&lookStream); |
- | |
359 | - | ||
360 | SzArEx_Init(&db); |
- | |
361 | - | ||
362 | res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); |
358 | res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); |
363 | 359 | ||
364 | if (res == SZ_OK) |
360 | if (res == SZ_OK) |
365 | { |
361 | { |
Line 366... | Line 362... | ||
366 | UInt32 i; |
362 | UInt32 i; |
367 | UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ |
363 | UInt32 blockIndex = 0xFFFFFFFF; /* it can have any value before first call (if outBuffer = 0) */ |
Line 368... | Line 364... | ||
368 | Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ |
364 | Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ |
Line 369... | Line 365... | ||
369 | size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ |
365 | size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ |
- | 366 | ||
- | 367 | for (i = 0; i < db.NumFiles; i++) |
|
- | 368 | { |
|
- | 369 | size_t offset = 0; |
|
- | 370 | size_t outSizeProcessed = 0; |
|
370 | 371 | size_t len; |
|
371 | for (i = 0; i < db.NumFiles; i++) |
- | |
372 | { |
- | |
373 | size_t offset = 0; |
- | |
374 | size_t outSizeProcessed = 0; |
- | |
375 | size_t len; |
- | |
376 | unsigned isDir = SzArEx_IsDir(&db, i); |
372 | unsigned isDir = SzArEx_IsDir(&db, i); |
377 | 373 | ||
378 | if ( isDir ) |
- | |
379 | continue; |
374 | if ( isDir ) |
- | 375 | continue; |
|
Line 380... | Line 376... | ||
380 | 376 | ||
381 | len = SzArEx_GetFileNameUtf16(&db, i, NULL); |
377 | len = SzArEx_GetFileNameUtf16(&db, i, NULL); |
- | 378 | ||
- | 379 | if (len > tempSize) |
|
- | 380 | { |
|
- | 381 | SzFree(NULL, temp); |
|
- | 382 | tempSize = len; |
|
- | 383 | temp = (UInt16 *)SzAlloc(NULL, tempSize * sizeof(temp[0])); |
|
- | 384 | if (!temp) |
|
- | 385 | { |
|
- | 386 | res = SZ_ERROR_MEM; |
|
- | 387 | break; |
|
- | 388 | } |
|
- | 389 | } |
|
382 | 390 | ||
383 | if (len > tempSize) |
391 | SzArEx_GetFileNameUtf16(&db, i, temp); |
- | 392 | res = PrintString(temp); |
|
- | 393 | if (res != SZ_OK) |
|
- | 394 | break; |
|
- | 395 | printf("\n"); |
|
- | 396 | ||
- | 397 | if (isDir) |
|
384 | { |
398 | printf("/"); |
- | 399 | else |
|
- | 400 | { |
|
- | 401 | res = SzArEx_Extract(&db, &lookStream.s, i, |
|
- | 402 | &blockIndex, &outBuffer, &outBufferSize, |
|
- | 403 | &offset, &outSizeProcessed, |
|
- | 404 | &allocImp, &allocTempImp); |
|
- | 405 | if (res != SZ_OK) |
|
- | 406 | break; |
|
- | 407 | } |
|
- | 408 | ||
Line 385... | Line 409... | ||
385 | SzFree(NULL, temp); |
409 | if (1) |
386 | tempSize = len; |
- | |
387 | temp = (UInt16 *)SzAlloc(NULL, tempSize * sizeof(temp[0])); |
- | |
388 | if (!temp) |
410 | { |
389 | { |
411 | CSzFile outFile; |
- | 412 | size_t processedSize; |
|
390 | res = SZ_ERROR_MEM; |
413 | size_t j; |
- | 414 | UInt16 *name = (UInt16 *)temp; |
|
391 | break; |
415 | const UInt16 *destPath = (const UInt16 *)name; |
- | 416 | ||
392 | } |
417 | for (j = 0; name[j] != 0; j++) |
393 | } |
418 | if (name[j] == '/') |
394 | 419 | { |
|
395 | SzArEx_GetFileNameUtf16(&db, i, temp); |
420 | name[j] = 0; |
Line 396... | Line 421... | ||
396 | res = PrintString(temp); |
421 | MyCreateDir(name); |
- | 422 | name[j] = CHAR_PATH_SEPARATOR; |
|
- | 423 | } |
|
397 | if (res != SZ_OK) |
424 | |
398 | break; |
- | |
399 | printf("\n"); |
- | |
400 | - | ||
401 | if (isDir) |
- | |
402 | printf("/"); |
- | |
403 | else |
- | |
404 | { |
- | |
405 | res = SzArEx_Extract(&db, &lookStream.s, i, |
- | |
406 | &blockIndex, &outBuffer, &outBufferSize, |
- | |
407 | &offset, &outSizeProcessed, |
- | |
408 | &allocImp, &allocTempImp); |
- | |
409 | if (res != SZ_OK) |
- | |
410 | break; |
- | |
411 | } |
- | |
412 | - | ||
413 | if (1) |
- | |
414 | { |
- | |
415 | CSzFile outFile; |
- | |
416 | size_t processedSize; |
- | |
417 | size_t j; |
- | |
418 | UInt16 *name = (UInt16 *)temp; |
- | |
419 | const UInt16 *destPath = (const UInt16 *)name; |
- | |
420 | - | ||
421 | for (j = 0; name[j] != 0; j++) |
- | |
422 | if (name[j] == '/') |
- | |
423 | { |
- | |
424 | if (1) |
- | |
425 | { |
- | |
426 | name[j] = 0; |
- | |
427 | MyCreateDir(name); |
- | |
428 | name[j] = CHAR_PATH_SEPARATOR; |
- | |
429 | } |
- | |
430 | else |
- | |
431 | destPath = name + j + 1; |
- | |
432 | } |
- | |
433 | - | ||
434 | if (isDir) |
425 | if (isDir) |
435 | { |
426 | { |
436 | MyCreateDir(destPath); |
427 | MyCreateDir(destPath); |
437 | printf("\n"); |
428 | printf("\n"); |
438 | continue; |
429 | continue; |
439 | } |
430 | } |
440 | else if (OutFile_OpenUtf16(&outFile, destPath)) |
431 | else if (OutFile_OpenUtf16(&outFile, destPath)) |
441 | { |
432 | { |
442 | PrintError("can not open output file"); |
433 | PrintError("can not open output file"); |
443 | res = SZ_ERROR_FAIL; |
434 | res = SZ_ERROR_FAIL; |
444 | break; |
- | |
445 | } |
435 | break; |
446 | - | ||
447 | processedSize = outSizeProcessed; |
436 | } |
448 | 437 | ||
- | 438 | processedSize = outSizeProcessed; |
|
449 | if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed) |
439 | |
- | 440 | if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed) |
|
- | 441 | { |
|
- | 442 | PrintError("can not write output file\n"); |
|
- | 443 | res = SZ_ERROR_FAIL; |
|
- | 444 | break; |
|
Line -... | Line 445... | ||
- | 445 | } |
|
- | 446 | ||
- | 447 | if (File_Close(&outFile)) |
|
- | 448 | { |
|
- | 449 | PrintError("can not close output file\n"); |
|
- | 450 | res = SZ_ERROR_FAIL; |
|
- | 451 | break; |
|
- | 452 | } |
|
- | 453 | }; |
|
- | 454 | }; |
|
- | 455 | IAlloc_Free(&allocImp, outBuffer); |
|
- | 456 | }; |
|
- | 457 | SzArEx_Free(&db, &allocImp); |
|
- | 458 | SzFree(NULL, temp); |
|
- | 459 | ||
450 | { |
460 | File_Close(&archiveStream.file); |