~ubuntu-branches/ubuntu/precise/p7zip/precise-updates

« back to all changes in this revision

Viewing changes to CPP/7zip/Archive/Nsis/NsisHandler.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Mohammed Adnène Trojette
  • Date: 2009-02-14 20:12:27 UTC
  • mfrom: (1.1.11 upstream) (2.1.3 sid)
  • Revision ID: james.westby@ubuntu.com-20090214201227-go63qxm9ozfdma60
Tags: 4.65~dfsg.1-1
* New upstream release.
* Remove wx2.8 Build-Depends added by mistakes (7zG is not yet
  intended to be built).
* Use dh_clean without -k.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2
2
 
3
3
#include "StdAfx.h"
4
4
 
5
 
#include "NsisHandler.h"
 
5
#include "../../../../C/CpuArch.h"
6
6
 
7
 
#include "Common/StringConvert.h"
 
7
#include "Common/ComTry.h"
8
8
#include "Common/IntToString.h"
9
9
#include "Common/NewHandler.h"
10
 
#include "Common/ComTry.h"
11
10
 
12
11
#include "Windows/PropVariant.h"
13
12
 
 
13
#include "../../Common/StreamUtils.h"
 
14
 
14
15
#include "../Common/ItemNameUtils.h"
15
 
#include "../../Common/StreamUtils.h"
 
16
 
 
17
#include "NsisHandler.h"
 
18
 
 
19
#define Get32(p) GetUi32(p)
16
20
 
17
21
using namespace NWindows;
18
22
 
22
26
static const wchar_t *kBcjMethod = L"BCJ";
23
27
static const wchar_t *kUnknownMethod = L"Unknown";
24
28
 
25
 
static const wchar_t *kMethods[] = 
 
29
static const wchar_t *kMethods[] =
26
30
{
27
31
  L"Copy",
28
32
  L"Deflate",
32
36
 
33
37
static const int kNumMethods = sizeof(kMethods) / sizeof(kMethods[0]);
34
38
 
35
 
STATPROPSTG kProps[] = 
 
39
STATPROPSTG kProps[] =
36
40
{
37
41
  { NULL, kpidPath, VT_BSTR},
38
 
  { NULL, kpidIsFolder, VT_BOOL},
39
42
  { NULL, kpidSize, VT_UI8},
40
 
  { NULL, kpidPackedSize, VT_UI8},
41
 
  { NULL, kpidLastWriteTime, VT_FILETIME},
 
43
  { NULL, kpidPackSize, VT_UI8},
 
44
  { NULL, kpidMTime, VT_FILETIME},
42
45
  { NULL, kpidMethod, VT_BSTR},
43
46
  { NULL, kpidSolid, VT_BOOL}
44
47
};
45
48
 
46
 
STATPROPSTG kArcProps[] = 
 
49
STATPROPSTG kArcProps[] =
47
50
{
48
51
  { NULL, kpidMethod, VT_BSTR},
49
52
  { NULL, kpidSolid, VT_BOOL}
69
72
        if (item.DictionarySize > dict)
70
73
          dict = item.DictionarySize;
71
74
      }
72
 
      prop = GetMethod(filter, dict); 
 
75
      prop = GetMethod(filter, dict);
73
76
      break;
74
77
    }
75
78
    case kpidSolid: prop = _archive.IsSolid; break;
211
214
  {
212
215
    switch(propID)
213
216
    {
214
 
      case kpidPath:
215
 
        prop = L"[NSIS].nsi";
216
 
        break;
217
 
      case kpidIsFolder:
218
 
        prop = false;
219
 
        break;
 
217
      case kpidPath:  prop = L"[NSIS].nsi"; break;
220
218
      case kpidSize:
221
 
      case kpidPackedSize:
222
 
        prop = (UInt64)_archive.Script.Length();
223
 
        break;
224
 
      case kpidSolid:
225
 
        prop = false;
226
 
        break;
 
219
      case kpidPackSize:  prop = (UInt64)_archive.Script.Length(); break;
 
220
      case kpidSolid:  prop = false; break;
227
221
    }
228
222
  }
229
223
  else
234
228
    {
235
229
      case kpidPath:
236
230
      {
237
 
        UString s;
238
 
        if (_archive.IsUnicode)
239
 
          s = item.GetReducedNameU();
240
 
        else
241
 
          s = MultiByteToUnicodeString(item.GetReducedNameA(), CP_ACP);
242
 
        s = NItemName::WinNameToOSName(s);
 
231
        UString s = NItemName::WinNameToOSName(item.GetReducedName(_archive.IsUnicode));
243
232
        if (!s.IsEmpty())
244
233
          prop = (const wchar_t *)s;
245
234
        break;
246
235
      }
247
 
      case kpidIsFolder:
248
 
        prop = false;
249
 
        break;
250
236
      case kpidSize:
251
237
      {
252
238
        UInt32 size;
254
240
          prop = (UInt64)size;
255
241
        break;
256
242
      }
257
 
      case kpidPackedSize:
 
243
      case kpidPackSize:
258
244
      {
259
245
        UInt32 size;
260
246
        if (GetCompressedSize(index, size))
261
247
          prop = (UInt64)size;
262
248
        break;
263
249
      }
264
 
      case kpidLastWriteTime:
265
 
      {
266
 
        if (item.DateTime.dwHighDateTime > 0x01000000 && 
267
 
            item.DateTime.dwHighDateTime < 0xFF000000)
268
 
          prop = item.DateTime;
269
 
        break;
270
 
      }
271
 
      case kpidMethod:
272
 
      {
273
 
        prop = GetMethod(item.UseFilter, item.DictionarySize);
274
 
        break;
275
 
      }
276
 
      case kpidSolid:
277
 
        prop = _archive.IsSolid;
278
 
        break;
 
250
      case kpidMTime:
 
251
      {
 
252
        if (item.MTime.dwHighDateTime > 0x01000000 &&
 
253
            item.MTime.dwHighDateTime < 0xFF000000)
 
254
          prop = item.MTime;
 
255
        break;
 
256
      }
 
257
      case kpidMethod:  prop = GetMethod(item.UseFilter, item.DictionarySize); break;
 
258
      case kpidSolid:  prop = _archive.IsSolid; break;
279
259
    }
280
260
  }
281
261
  prop.Detach(value);
335
315
        _inStream, _archive.Method, _archive.FilterFlag, useFilter));
336
316
  }
337
317
 
 
318
  CByteBuffer byteBuf;
 
319
  const UInt32 kBufferLength = 1 << 16;
 
320
  byteBuf.SetCapacity(kBufferLength);
 
321
  Byte *buffer = byteBuf;
 
322
 
338
323
  bool dataError = false;
339
324
  for (i = 0; i < numItems; i++, currentTotalSize += currentItemSize)
340
325
  {
378
363
        bool sizeIsKnown = false;
379
364
        UInt32 fullSize = 0;
380
365
 
381
 
        const UInt32 kBufferLength = 1 << 11;
382
 
        Byte buffer[kBufferLength];
383
 
        
384
366
        if (_archive.IsSolid)
385
367
        {
386
368
          UInt64 pos = _archive.GetPosOfSolidItem(index);
404
386
          }
405
387
          if (streamPos == pos)
406
388
          {
 
389
            Byte buffer2[4];
407
390
            size_t processedSize = 4;
408
 
            RINOK(_archive.Decoder.Read(buffer, &processedSize));
 
391
            RINOK(_archive.Decoder.Read(buffer2, &processedSize));
409
392
            if (processedSize != 4)
410
393
              return E_FAIL;
411
394
            streamPos += processedSize;
412
 
            fullSize = GetUInt32FromMemLE(buffer);
 
395
            fullSize = Get32(buffer2);
413
396
            sizeIsKnown = true;
414
397
            needDecompress = true;
415
398
          }
424
407
            RINOK(_archive.Decoder.Init(
425
408
                EXTERNAL_CODECS_VARS
426
409
                _inStream, _archive.Method, _archive.FilterFlag, useFilter));
427
 
            fullSize = GetUInt32FromMemLE(buffer);
 
410
            // fullSize = Get32(buffer); // It's bug !!!
 
411
            // Test it: what is exact fullSize?
 
412
            fullSize =  0xFFFFFFFF;
428
413
          }
429
414
          else
430
415
            fullSize = item.Size;
461
446
              
462
447
              UInt64 completed;
463
448
              if (_archive.IsSolid)
 
449
                completed = currentTotalSize + offset;
 
450
              else
464
451
                completed = streamPos;
465
 
              else
466
 
                completed = currentTotalSize + offset;
467
452
              RINOK(extractCallback->SetCompleted(&completed));
468
453
              if (!testMode)
469
454
                RINOK(WriteStream(realOutStream, buffer, processedSize));
491
476
      }
492
477
    }
493
478
    realOutStream.Release();
494
 
    RINOK(extractCallback->SetOperationResult(dataError ? 
 
479
    RINOK(extractCallback->SetOperationResult(dataError ?
495
480
        NArchive::NExtract::NOperationResult::kDataError :
496
481
        NArchive::NExtract::NOperationResult::kOK));
497
482
  }