ArchiveOpenCallback.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. // ArchiveOpenCallback.h
  2. #ifndef __ARCHIVE_OPEN_CALLBACK_H
  3. #define __ARCHIVE_OPEN_CALLBACK_H
  4. #include "Common/MyString.h"
  5. #include "Common/MyCom.h"
  6. #include "Windows/FileFind.h"
  7. #ifndef _NO_CRYPTO
  8. #include "../../IPassword.h"
  9. #endif
  10. #include "../../Archive/IArchive.h"
  11. struct IOpenCallbackUI
  12. {
  13. virtual HRESULT CheckBreak() = 0;
  14. virtual HRESULT SetTotal(const UInt64 *files, const UInt64 *bytes) = 0;
  15. virtual HRESULT SetCompleted(const UInt64 *files, const UInt64 *bytes) = 0;
  16. #ifndef _NO_CRYPTO
  17. virtual HRESULT CryptoGetTextPassword(BSTR *password) = 0;
  18. virtual HRESULT GetPasswordIfAny(UString &password) = 0;
  19. virtual bool WasPasswordAsked() = 0;
  20. virtual void ClearPasswordWasAskedFlag() = 0;
  21. #endif
  22. };
  23. class COpenCallbackImp:
  24. public IArchiveOpenCallback,
  25. public IArchiveOpenVolumeCallback,
  26. public IArchiveOpenSetSubArchiveName,
  27. #ifndef _NO_CRYPTO
  28. public ICryptoGetTextPassword,
  29. #endif
  30. public CMyUnknownImp
  31. {
  32. public:
  33. #ifndef _NO_CRYPTO
  34. MY_UNKNOWN_IMP3(
  35. IArchiveOpenVolumeCallback,
  36. ICryptoGetTextPassword,
  37. IArchiveOpenSetSubArchiveName
  38. )
  39. #else
  40. MY_UNKNOWN_IMP2(
  41. IArchiveOpenVolumeCallback,
  42. IArchiveOpenSetSubArchiveName
  43. )
  44. #endif
  45. STDMETHOD(SetTotal)(const UInt64 *files, const UInt64 *bytes);
  46. STDMETHOD(SetCompleted)(const UInt64 *files, const UInt64 *bytes);
  47. // IArchiveOpenVolumeCallback
  48. STDMETHOD(GetProperty)(PROPID propID, PROPVARIANT *value);
  49. STDMETHOD(GetStream)(const wchar_t *name, IInStream **inStream);
  50. #ifndef _NO_CRYPTO
  51. // ICryptoGetTextPassword
  52. STDMETHOD(CryptoGetTextPassword)(BSTR *password);
  53. #endif
  54. STDMETHOD(SetSubArchiveName(const wchar_t *name))
  55. {
  56. _subArchiveMode = true;
  57. _subArchiveName = name;
  58. return S_OK;
  59. }
  60. private:
  61. UString _folderPrefix;
  62. NWindows::NFile::NFind::CFileInfoW _fileInfo;
  63. bool _subArchiveMode;
  64. UString _subArchiveName;
  65. public:
  66. UStringVector FileNames;
  67. IOpenCallbackUI *Callback;
  68. UInt64 TotalSize;
  69. COpenCallbackImp(): Callback(NULL) {}
  70. void Init(const UString &folderPrefix, const UString &fileName)
  71. {
  72. _folderPrefix = folderPrefix;
  73. if (!NWindows::NFile::NFind::FindFile(_folderPrefix + fileName, _fileInfo))
  74. throw 1;
  75. FileNames.Clear();
  76. _subArchiveMode = false;
  77. TotalSize = 0;
  78. }
  79. int FindName(const UString &name);
  80. };
  81. #endif