spacepaste

  1.  
  2. #include "7zip/Archive/7z/7zDecode.h"
  3. class CMyProgress :
  4. public ICompressProgressInfo,
  5. public CMyUnknownImp
  6. {
  7. public:
  8. const UInt64 *InSize;
  9. const UInt64 *OutSize;
  10. HRESULT Result;
  11. NWindows::NSynchronization::CAutoResetEvent ProgressEvent;
  12. NWindows::NSynchronization::CAutoResetEvent WaitEvent;
  13. HRes Create()
  14. {
  15. RINOK(ProgressEvent.CreateIfNotCreated());
  16. return WaitEvent.CreateIfNotCreated();
  17. }
  18. void Init()
  19. {
  20. ProgressEvent.Reset();
  21. WaitEvent.Reset();
  22. }
  23. MY_UNKNOWN_IMP
  24. STDMETHOD(SetRatioInfo)(const UInt64 *inSize, const UInt64 *outSize)
  25. {
  26. /*
  27. InSize = inSize;
  28. OutSize = outSize;
  29. ProgressEvent.Set();
  30. WaitEvent.Lock();
  31. return Result;
  32. */
  33. printf("in:%I64d, out:%I64d\n", *inSize, *outSize);
  34. return 0;
  35. }
  36. };
  37. class CMyCryptoGetTextPassword :
  38. public ICryptoGetTextPassword,
  39. public CMyUnknownImp
  40. {
  41. public:
  42. UString Password;
  43. MY_UNKNOWN_IMP
  44. STDMETHOD(CryptoGetTextPassword)(BSTR *password)
  45. {
  46. return StringToBstr(Password, password);
  47. }
  48. };
  49. int main(int argc, char **argv)
  50. {
  51. NArchive::N7z::CDecoder decoder(false);
  52. CInFileStream instream;
  53. instream.Open("E:/projects/lzma920/test.7z");
  54. UInt64 packSizes = 0;
  55. instream.GetSize(&packSizes);
  56. NArchive::N7z::CFolder folder;
  57. folder.
  58. CStdOutFileStream outstream;
  59. CMyProgress progress;
  60. CMyCryptoGetTextPassword password;
  61. bool ispassword = true;
  62. HRESULT ret = decoder.Decode(&instream, 0, &packSizes, folder, &outstream, &progress, &password, ispassword, false, 0);
  63. if (ret)
  64. {
  65. printf("error\n");
  66. }
  67. return 0;
  68. }
  69.