使用soui开发的mbc,只支持windows版本
w1146869587
2022-01-24 4905e2e7537d507f218e8e9595485e09d9f3a2b4
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
////////////////////////////////////////////////////////////////////////////////
// This source file is part of the ZipArchive library source distribution and
// is Copyrighted 2000 - 2011 by Artpol Software - Tadeusz Dracz
//
// 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.
// 
// For the licensing details refer to the License.txt file.
//
// Web Site: http://www.artpol-software.com
////////////////////////////////////////////////////////////////////////////////
 
/**
* \file ZipFileHeader.h
* Includes the CZipFileHeader class.
*
*/
#if !defined(ZIPARCHIVE_ZIPFILEHEADER_DOT_H)
#define ZIPARCHIVE_ZIPFILEHEADER_DOT_H
 
#if _MSC_VER > 1000
#pragma once
#endif
 
#include "ZipExport.h"
#include "ZipStorage.h"
#include "ZipAutoBuffer.h"
#include "sys/types.h"
#include "ZipCompatibility.h"
#include "ZipCollections.h"
#include "ZipExtraField.h"
#include "ZipStringStoreSettings.h"
#include "ZipCryptograph.h"
#include "BitFlag.h"
 
 
class CZipCentralDir;
 
/**
    Represents a single file stored in a zip archive.
*/
class ZIP_API CZipFileHeader  
{
    friend class CZipCentralDir;
    friend class CZipArchive;
protected:
    CZipFileHeader(CZipCentralDir* pCentralDir);
public:    
    /**
        File header state flags.
 
        \see
            CZipArchive::UnicodeMode
    */
    enum StateFlags
    {
        sfNone                = 0x00,        ///< No special flags set.
#ifdef _ZIP_UNICODE_CUSTOM    
        sfCustomUnicode        = 0x10,        ///< The header uses custom Unicode functionality.
#endif
        sfModified            = 0x20        ///< The file has been modified.
    };
 
    CZipFileHeader();
    CZipFileHeader(const CZipFileHeader& header)
    {
        *this = header;
    }
    CZipFileHeader& operator=(const CZipFileHeader& header);
    virtual ~CZipFileHeader();
 
    /**
        Predicts the filename size after conversion using the current filename code page.
 
        \return 
            The number of characters not including a terminating \c NULL character.
    */
    int PredictFileNameSize() const 
    {
        if (m_fileName.HasBuffer())
        {
            return m_fileName.GetBufferSize();
        }
        CZipAutoBuffer buffer;
        ConvertFileName(buffer);
        return buffer.GetSize();
    }
    
    /**
        Predicts a file comment size.
 
        \return
            The number of characters in the comment not including a terminating \c NULL character.
    */
    int    PredictCommentSize() const 
    {
        if (m_comment.HasBuffer())
        {
            return m_comment.GetBufferSize();
        }
        CZipAutoBuffer buffer;
        ConvertComment(buffer);
        return buffer.GetSize();
    }
 
 
    /**
        Returns the filename. If necessary, performs the conversion using the current filename code page.
        Caches the result of conversion for faster access the next time.
 
        \param bClearBuffer
            If \c true, releases the internal buffer after performing the filename conversion.
            If \c false, the internal buffer is not released and both representations of the 
            filename are kept in memory (converted and not converted). This takes more memory, but the 
            conversion does not take place again when the central directory is written back to the archive.
 
        \return
            The converted filename.
 
        \see
            <a href="kb">0610051525</a>
        \see
            SetFileName
        \see 
            GetStringStoreSettings
        \see
            CZipStringStoreSettings::m_uNameCodePage
    */
    const CZipString& GetFileName(bool bClearBuffer = true);
 
    /**
        Sets the filename.
 
        The actual renaming of the file inside of the archive depends on the current commit mode.
 
        \param    lpszFileName
            The filename to set.
 
        \return 
            \c true, if the method succeeded; \c false, if the current state of the archive is invalid for this method to be called.
 
        \note
            Leading path separators are removed from the filename unless the header is a directory and the filename contains of only one path separator (indicating a root path).
 
        \see
            <a href="kb">0610231944|rename</a>
        \see
            GetFileName
        \see 
            CZipArchive::CommitChanges
    */
    bool SetFileName(LPCTSTR lpszFileName);
 
    /**
        Returns the file comment.
        
        \param bClearBuffer
            If \c true, releases the internal buffer after performing the comment conversion.
            If \c false, the internal buffer is not released and both representations of the 
            comment are kept in memory (converted and not converted). This takes more memory, but the 
            conversion does not take place again when the central directory is written back to the archive.
 
        \return
            The file comment.
 
        \see
            <a href="kb">0610231944|comment</a>
        \see
            SetComment
    */
    const CZipString& GetComment(bool bClearBuffer = false);
 
    /**
        Sets the file comment.
 
        \param lpszComment
            The file comment.
 
        \return 
            \c true, if the method succeeded; \c false, if the current state of the archive is invalid for this method to be called.
 
        \see
            <a href="kb">0610231944|comment</a>
        \see
            GetComment
    */
    bool SetComment(LPCTSTR lpszComment);
 
    /**
        Returns the value indicating whether the data descriptor is present.
 
        \return
            \c true, if the data descriptor is present; \c false otherwise.
    */
    bool IsDataDescriptor()const {    return (m_uFlag & (WORD) 8) != 0;}
 
    /**
        Returns the data descriptor size as it is required for the current file.
        Takes into account various factors, such as the archive segmentation type,
        encryption and the need for the Zip64 format.
 
        \param pStorage
            The storage to test for the segmentation type.
 
        \return 
            The required data descriptor size in bytes.
    */
    WORD GetDataDescriptorSize(const CZipStorage* pStorage) const
    {
        return GetDataDescriptorSize(NeedsSignatureInDataDescriptor(pStorage));
    }
 
    /**
        Returns the data descriptor size as it is required for the current file.
        Takes into account various factors, such as the need for the data descriptor signature
        or for the Zip64 format.
 
        \param bConsiderSignature
            \c true, if the data descriptor signature is needed; \c false otherwise.
 
        \return 
            The required data descriptor size in bytes.
    */
    WORD GetDataDescriptorSize(bool bConsiderSignature = false) const;    
 
    /**
        Returns the size of the compressed data.
    
        \param bReal
            Set to \c true when calling for a file already in an archive.
            Set to \c false when the header is not a part of the archive.
    
        \return
            The compressed data size in bytes.
 
        \see
            GetEncryptedInfoSize
     */
    ZIP_SIZE_TYPE GetDataSize(bool bReal) const
    {
        DWORD uEncrSize = GetEncryptedInfoSize();
        return bReal ? (m_uComprSize - uEncrSize) : (m_uComprSize + uEncrSize);
    }
 
    /**
        Returns the encrypted information size. The returned value depends on the used encryption method.
 
        \return
            The  encrypted information size in bytes.
    */
    DWORD GetEncryptedInfoSize() const
    {
        return CZipCryptograph::GetEncryptedInfoSize(m_uEncryptionMethod);
    }
 
    /**
        Returns the total size of this structure in the central directory.
 
        \return
            The total size in bytes.
    */
    DWORD GetSize() const;
 
    /**
        Returns the local header size. Before calling this method, the local information must be up-to-date
        (see <a href="kb">0610242128|local</a> for more information).
 
        \param bReal
            If \c true, uses the real local filename size.
            If \c false, predicts the filename size.             
 
        \return
            The local header size in bytes.
    */
    DWORD GetLocalSize(bool bReal) const;    
 
    /**
        Returns the value indicating whether the compression is efficient.
 
        \return 
            \c true if the compression is efficient; \c false if the file should be 
            stored without the compression instead.
    */
    bool CompressionEfficient()
    {
        ZIP_SIZE_TYPE uBefore = m_uUncomprSize;
        // ignore the length of encryption info 
        ZIP_SIZE_TYPE uAfter = GetDataSize(true);
        return  uAfter <= uBefore;
    }
 
    /**
        Returns the compression ratio.
 
        \return
            The compression ratio of the file.
    */
    float GetCompressionRatio()
    {
#if _MSC_VER >= 1300 || !defined(_ZIP_ZIP64)
        return m_uUncomprSize ? ((float)m_uComprSize * 100 ) / m_uUncomprSize: 0;
#else
        return m_uUncomprSize ? ((float)(__int64)(m_uComprSize) / (float)(__int64)m_uUncomprSize) * 100: 0;
#endif
    }
 
    /**
        Sets the file modification date.
 
        \param ttime
            The date to set. If this value is incorrect, the date defaults to January 1, 1980.
 
        \see
            GetTime
    */
    void SetTime(const time_t& ttime);
 
    /**
        Returns the file modification time.
 
        \return
            The modification time.
 
        \see
            SetTime
    */
    time_t GetTime()const;
 
    /**
        Returns the file system compatibility.
        External software can use this information e.g. to determine end-of-line 
        format for text files etc.
        The ZipArchive Library uses it to perform a proper file attributes conversion.
 
        \return
            The file system compatibility. It can be one of the ZipCompatibility::ZipPlatforms values.
        \see
            CZipArchive::GetSystemComatibility
        \see
            ZipPlatform::GetSystemID
    */
    int GetSystemCompatibility()const
    {
        int nRet = (int)m_iSystemCompatibility;
        return nRet;
    }
 
    /**
        Returns the file attributes.
 
        \return
            The file attributes, converted if necessary to be compatible with the current system.
 
        \note 
            Throws an exception, if the archive system or the current system 
            is not supported by the ZipArchive Library.            
 
        \see
            GetOriginalAttributes
    */
    DWORD GetSystemAttr();
 
    
    /**
        Sets the file attributes.
 
        \param    uAttr
            The attributes to set.
 
        \note
            Throws an exception, if the archive system or the current system is not supported by the ZipArchive Library.
 
        \see    
            GetSystemAttr
    */
    bool SetSystemAttr(DWORD uAttr);
 
    /**
        Returns the file attributes exactly as they are stored in the archive.
 
        \return 
            The file attributes as they are stored in the archive.
            No conversion is performed.
 
        \note
            The attributes for Linux are stored shifted left by 16 bits in this field.
        \see 
            GetSystemAttr
    */
    DWORD GetOriginalAttributes() const {return m_uExternalAttr;}
 
    /**
        Returns the value indicating whether the file represents a directory.
        This method checks the file attributes. If the attributes value is zero, 
        the method checks for the presence of a path 
        separator at the end of the filename. If the path separator is present, 
        the file is assumed to be a directory.
 
        \return
            \c true, if the file represents a directory; \c false otherwise.        
    */
    bool IsDirectory();
 
#ifdef _ZIP_UNICODE_CUSTOM    
    /**
        Returns the current string store settings.
    
        \return
            The string store settings.
 
        \see
            <a href="kb">0610051525|custom</a>
        \see
            CZipArchive::GetStringStoreSettings
     */
    CZipStringStoreSettings GetStringStoreSettings()
    {
        return m_stringSettings;
    }
#endif
 
    /**
        Returns the value indicating whether the file is encrypted.
        If the file is encrypted, you need to set the password with the 
        CZipArchive::SetPassword method before decompressing the file.
 
        \return
            \c true if the file is encrypted; \c false otherwise.
 
        \see
            CZipArchive::SetPassword
    */
    bool IsEncrypted()const {    return m_uEncryptionMethod != CZipCryptograph::encNone;}
 
    /**
        Returns the encryption method of the file.
 
        \return
            The file encryption method. It can be one of the CZipCryptograph::EncryptionMethod values.
    */
    int GetEncryptionMethod() const {return m_uEncryptionMethod;}
 
    /**
        Returns the value indicating whether the file is encrypted using WinZip AES encryption method.
 
        \return
            \c true, if the file is encrypted using WinZip AES encryption method; \c false otherwise.
    */
    bool IsWinZipAesEncryption() const
    {
        return CZipCryptograph::IsWinZipAesEncryption(m_uEncryptionMethod);
    }
 
    /**
        Returns an approximate file compression level.
 
        \return 
            The compression level. May not be the real value used when compressing the file.
    */
    int GetCompressionLevel() const;
 
    /**
        Returns the value indicating whether the current CZipFileHeader object has the time set.
 
        \return
            \c true, if the time is set; \c false otherwise.
    */
    bool HasTime() const
    {
        return m_uModTime != 0 || m_uModDate != 0;
    }
 
    /**
        Returns the value indicating whether the file was modified.
 
        \return
            \c true, if the file was modified; \c false otherwise.
 
        \see
            CZipArchive::CommitChanges
    */
    bool IsModified() const
    {
        return m_state.IsSetAny(sfModified);
    }
 
 
    /**
        Returns the state flags.
 
        \return
            State flags. It can be one or more of #StateFlags values.        
    */
    const ZipArchiveLib::CBitFlag& GetState() const
    {
        return m_state;
    }
 
    static char m_gszSignature[];        ///< The central file header signature.
    static char m_gszLocalSignature[];    ///< The local file header signature.
    unsigned char m_uVersionMadeBy;        ///< The version of the software that created the archive.
    WORD m_uVersionNeeded;                ///< The version needed to extract the file.
    WORD m_uFlag;                        ///< A general purpose bit flag.
    WORD m_uMethod;                        ///< The compression method. It can be one of the CZipCompressor::CompressionMethod values.
    WORD m_uModTime;                    ///< The file last modification time.
    WORD m_uModDate;                    ///< The file last modification date.
    DWORD m_uCrc32;                        ///< The crc-32 value.
    ZIP_SIZE_TYPE m_uComprSize;            ///< The compressed size.
    ZIP_SIZE_TYPE m_uUncomprSize;        ///< The uncompressed size.
    ZIP_VOLUME_TYPE m_uVolumeStart;        ///< The volume number at which the compressed file starts.
    WORD m_uInternalAttr;                ///< Internal file attributes.
    ZIP_SIZE_TYPE m_uLocalComprSize;    ///< The compressed size written in the local header.
    ZIP_SIZE_TYPE m_uLocalUncomprSize;    ///< The uncompressed size written in the local header.
    ZIP_SIZE_TYPE m_uOffset;            ///< Relative offset of the local header with respect to CZipFileHeader::m_uVolumeStart.
    CZipExtraField m_aLocalExtraData;    ///< The local extra field. Do not modify it after you started compressing the file.
    CZipExtraField m_aCentralExtraData; ///< The central extra field.
protected:
    DWORD m_uExternalAttr;                ///< External file attributes.
     WORD m_uLocalFileNameSize;            ///< The local filename length.
    BYTE m_uEncryptionMethod;            ///< The file encryption method. It can be one of the CZipCryptograph::EncryptionMethod values.
    bool m_bIgnoreCrc32;                ///< The value indicating whether to ignore Crc32 checking.
    DWORD m_uLocalHeaderSize;
    
    CZipCentralDir* m_pCentralDir;        ///< The parent central directory. It can be \c NULL when the header is not a part of central directory.
 
    
 
    /**
        Sets the file system compatibility.
 
        \param    iSystemID
            The file system compatibility. It can be one of the ZipCompatibility::ZipPlatforms values.
 
        \param bUpdateAttr
            If \c true, the attributes will be converted to the new system; \c false otherwise.
 
        \see
            GetSystemCompatibility
    */
    void SetSystemCompatibility(int iSystemID, bool bUpdateAttr = false)
    {
        if (bUpdateAttr)
        {
            if ((int)m_iSystemCompatibility != iSystemID)
            {
                DWORD uAttr = GetSystemAttr();
                m_iSystemCompatibility = (char)(iSystemID & 0xFF);
                SetSystemAttr(uAttr & 0xFFFF);                
            }
            return;
        }
        m_iSystemCompatibility = (char)(iSystemID & 0xFF);
    }
    
    /**
        Prepares the filename for writing to the archive.
    */
    void PrepareStringBuffers()
    {
        if (!m_fileName.HasBuffer())
        {
            ConvertFileName(m_fileName.m_buffer);
        }
        if (!m_comment.HasBuffer())
        {
            ConvertComment(m_comment.m_buffer);
        }
    }
 
    /**
        Validates an existing data descriptor after file decompression.
 
        \param pStorage
            The storage to read the data descriptor from.
 
        \return
            \c true, if the data descriptor is valid; \c false otherwise.
    */
    bool CheckDataDescriptor(CZipStorage* pStorage) const;
 
 
    /**
        Prepares the data for writing when adding a new file. When Zip64 extensions are required for this file, 
        this method adds Zip64 extra data to #m_aLocalExtraData.
 
        \param    iLevel
            The compression level.
 
        \param bSegm
            Set to \c true, if the archive is segmented; \c false otherwise.
    */
    void PrepareData(int iLevel, bool bSegm);
 
    /**    
        Writes the local file header to the \a pStorage. 
        The filename and extra field are the same as those that will be stored in the central directory.
 
        \param    pStorage
            The storage to write the local file header to.
 
    */
    void WriteLocal(CZipStorage *pStorage);
 
    /**
        Reads the local file header from the archive and validates the read data.
 
        \param pCentralDir
            Used when the archive was opened with CZipArchive::OpenFrom method. Points to the original central directory.
 
        \return
            \c true, if the data read is consistent; \c false otherwise.
 
        
        \see 
            CZipArchive::SetIgnoredConsistencyChecks
    */
    bool ReadLocal(CZipCentralDir* pCentralDir);
 
    /**
        Writes the central file header to \a pStorage.
 
        \param    pStorage
            The storage to write the central file header to.
 
        \return
            The size of the file header.
 
    */
    DWORD Write(CZipStorage *pStorage);
 
    /**
        Reads the central file header from \a pStorage and validates the read data.
 
        \param bReadSignature
            \c true, if the the central header signature should be read; \c false otherwise.
 
 
        \return
            \c true, if the read data is consistent; \c false otherwise.
 
    */
    bool Read(bool bReadSignature);
 
 
    /**
        Validates the member fields lengths. 
        The tested fields are: filename, extra fields and comment.
 
        \return
            \c false, if any of the lengths exceeds the allowed value.
    */
    bool CheckLengths(bool local) const
    {
        if (m_comment.GetBufferSize() > (int)USHRT_MAX || m_fileName.GetBufferSize() > (int)USHRT_MAX)
            return false;
        else if (local)
            return m_aLocalExtraData.Validate();
        else
            return m_aCentralExtraData.Validate();
    }
 
    /**
        Writes the Crc32 to \a pBuf.
 
        \param pBuf
            The buffer to write the Crc32 to. Must have be of at least 4 bytes size.
    */
    void WriteCrc32(char* pBuf) const;
    
    
    /**
        Returns the value indicating whether the file needs the data descriptor.
        The data descriptor is needed when a file is encrypted or the Zip64 format needs to be used.
 
        \return 
            \c true, if the data descriptor is needed; \c false otherwise.
    */
    bool NeedsDataDescriptor() const;
    
 
    /**
        Writes the data descriptor.
 
        \param pDest
            The buffer to receive the data.
 
        \param bLocal
            Set to \c true, if the local sizes are used; \c false otherwise.
    */
    void WriteSmallDataDescriptor(char* pDest, bool bLocal = true);
 
    /**
        Writes the data descriptor taking into account the Zip64 format.
 
        \param pStorage
            The storage to write the data descriptor to.
    */
    void WriteDataDescriptor(CZipStorage* pStorage);
 
    /**
        Returns the value indicating whether the signature in the data descriptor is needed.
 
        \param pStorage
            The current storage.
 
        \return
            \c true, if the signature is needed; \c false otherwise.
    */
    bool NeedsSignatureInDataDescriptor(const CZipStorage* pStorage) const
    {
        return pStorage->IsSegmented() || IsEncrypted();
    }
 
    /**
        Updates the local header in the archive after is has already been written.
 
        \param pStorage
            The storage to update the data descriptor in.
    */
    void UpdateLocalHeader(CZipStorage* pStorage);
 
    /**
        Adjusts the local compressed size.
    */
    void AdjustLocalComprSize()
    {
        AdjustLocalComprSize(m_uLocalComprSize);
    }
 
    /**
        Adjusts the local compressed size.
 
        \param uLocalComprSize
            The value to adjust.
    */
    void AdjustLocalComprSize(ZIP_SIZE_TYPE& uLocalComprSize)
    {
        uLocalComprSize += GetEncryptedInfoSize();
    }
 
    /**
        Verifies the central header signature.
 
        \param buf
            The buffer that contains the signature to verify.
 
        \return 
            \c true, if the signature is valid; \c false otherwise.
    */
    static bool VerifySignature(CZipAutoBuffer& buf)
    {
        return memcmp(buf, m_gszSignature, 4) == 0;
    }
 
    /**
        Updates the general purpose bit flag. 
 
        \param bSegm
            \c true, if the current archive is a segmented archive; \c false otherwise.
    */
    void UpdateFlag(bool bSegm)
    {
        if (bSegm || m_uEncryptionMethod == CZipCryptograph::encStandard)
            m_uFlag  |= 8; // data descriptor present
 
        if (IsEncrypted())
            m_uFlag  |= 1;        // encrypted file        
    }
 
    
private:    
 
    struct StringWithBuffer
    {
        StringWithBuffer()
        {
            m_pString = NULL;
        }
        CZipAutoBuffer m_buffer;
        StringWithBuffer& operator = (const StringWithBuffer& original)
        {            
            if (original.HasString())
            {
                SetString(original.GetString());
            }
            else
            {
                ClearString();
            }
            m_buffer = original.m_buffer;
            return *this;
        }
        void AllocateString()
        {
            ClearString();
            m_pString = new CZipString(_T(""));
        }
        bool HasString() const
        {
            return m_pString != NULL;
        }
        bool HasBuffer() const 
        {
            return m_buffer.IsAllocated() && m_buffer.GetSize() > 0;
        }
        void ClearString()
        {
            if (HasString())
            {
                delete m_pString;
                m_pString = NULL;
            }
        }
        void ClearBuffer()
        {
            m_buffer.Release();
        }
 
        const CZipString& GetString() const
        {
            ASSERT(HasString());
            return *m_pString;
        }
 
        CZipString& GetString()
        {
            ASSERT(HasString());
            return *m_pString;
        }
 
        void SetString(LPCTSTR value)
        {
            if (!HasString())
                AllocateString();
            *m_pString = value;
        }
        
        int GetBufferSize() const
        {
            return m_buffer.GetSize();
        }
        ~StringWithBuffer()
        {
            ClearString();
        }
    protected:
        CZipString* m_pString;
    };
 
    ZipArchiveLib::CBitFlag m_state;
        
    void Initialize(CZipCentralDir* pCentralDir);
 
    void SetModified(bool bModified = true)
    {
        m_state.Change(sfModified, bModified);
    }
 
    void ConvertFileName(CZipAutoBuffer& buffer) const;
    void ConvertFileName(CZipString& szFileName) const;
    void ConvertComment(CZipAutoBuffer& buffer) const;
    void ConvertComment(CZipString& szComment) const;
 
    bool UpdateFileNameFlags(const CZipString* szNewFileName, bool bAllowRemoveCDir);
    bool UpdateCommentFlags(const CZipString* szNewComment);
    bool UpdateStringsFlags(bool bAllowRemoveCDir)
    {
        return UpdateFileNameFlags(NULL, bAllowRemoveCDir) | UpdateCommentFlags(NULL);
    }
 
    UINT GetDefaultFileNameCodePage() const
    {
        return ZipCompatibility::GetDefaultNameCodePage(GetSystemCompatibility());
    }
 
    UINT GetDefaultCommentCodePage() const
    {
        return ZipCompatibility::GetDefaultCommentCodePage(GetSystemCompatibility());
    }
 
    void ClearFileName();
 
    void GetCrcAndSizes(char* pBuffer)const;
 
    bool NeedsZip64() const
    {
        return m_uComprSize >= UINT_MAX || m_uUncomprSize >= UINT_MAX || m_uVolumeStart >= USHRT_MAX || m_uOffset >= UINT_MAX;
    }
 
 
    void OnNewFileClose(CZipStorage* pStorage)
    {
        UpdateLocalHeader(pStorage);
        WriteDataDescriptor(pStorage);
        pStorage->Flush();
    }
 
#ifdef _ZIP_UNICODE_CUSTOM
    CZipStringStoreSettings m_stringSettings;
#endif
    StringWithBuffer m_fileName;
    StringWithBuffer m_comment;
    char m_iSystemCompatibility;
};
 
#endif // !defined(ZIPARCHIVE_ZIPFILEHEADER_DOT_H)