other-licenses/7zstub/src/7zip/Bundles/SFXSetup-moz/ExtractEngine.cpp

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/other-licenses/7zstub/src/7zip/Bundles/SFXSetup-moz/ExtractEngine.cpp	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,139 @@
     1.4 +// ExtractEngine.cpp
     1.5 +
     1.6 +#include "StdAfx.h"
     1.7 +
     1.8 +#include "ExtractEngine.h"
     1.9 +
    1.10 +#include "Common/StringConvert.h"
    1.11 +
    1.12 +#include "Windows/FileDir.h"
    1.13 +#include "Windows/FileFind.h"
    1.14 +#include "Windows/Thread.h"
    1.15 +
    1.16 +#include "../../UI/Common/OpenArchive.h"
    1.17 +
    1.18 +#include "../../UI/Explorer/MyMessages.h"
    1.19 +#include "../../FileManager/FormatUtils.h"
    1.20 +
    1.21 +#include "ExtractCallback.h"
    1.22 +
    1.23 +using namespace NWindows;
    1.24 +
    1.25 +struct CThreadExtracting
    1.26 +{
    1.27 +  CArchiveLink ArchiveLink;
    1.28 +
    1.29 +  CExtractCallbackImp *ExtractCallbackSpec;
    1.30 +  CMyComPtr<IArchiveExtractCallback> ExtractCallback;
    1.31 +
    1.32 +  #ifndef _NO_PROGRESS
    1.33 +  HRESULT Result;
    1.34 +
    1.35 +  HRESULT Extract()
    1.36 +  {
    1.37 +    return ArchiveLink.GetArchive()->Extract(0, (UInt32)-1 , BoolToInt(false), ExtractCallback);
    1.38 +  }
    1.39 +  DWORD Process()
    1.40 +  {
    1.41 +    ExtractCallbackSpec->ProgressDialog.WaitCreating();
    1.42 +    Result = Extract();
    1.43 +    ExtractCallbackSpec->ProgressDialog.MyClose();
    1.44 +    return 0;
    1.45 +  }
    1.46 +  static DWORD WINAPI MyThreadFunction(void *param)
    1.47 +  {
    1.48 +    return ((CThreadExtracting *)param)->Process();
    1.49 +  }
    1.50 +  #endif
    1.51 +};
    1.52 +
    1.53 +static const LPCWSTR kCantFindArchive = L"Can not find archive file";
    1.54 +static const LPCWSTR kCantOpenArchive = L"File is not correct archive";
    1.55 +
    1.56 +HRESULT ExtractArchive(
    1.57 +    const UString &fileName, 
    1.58 +    const UString &folderName,
    1.59 +    COpenCallbackGUI *openCallback,
    1.60 +    bool showProgress,
    1.61 +    bool &isCorrupt,
    1.62 +    UString &errorMessage)
    1.63 +{
    1.64 +  isCorrupt = false;
    1.65 +  NFile::NFind::CFileInfoW archiveFileInfo;
    1.66 +  if (!NFile::NFind::FindFile(fileName, archiveFileInfo))
    1.67 +  {
    1.68 +    errorMessage = kCantFindArchive;
    1.69 +    return E_FAIL;
    1.70 +  }
    1.71 +
    1.72 +  CThreadExtracting extracter;
    1.73 +
    1.74 +  HRESULT result = MyOpenArchive(fileName, extracter.ArchiveLink, openCallback);
    1.75 +
    1.76 +  if (result != S_OK)
    1.77 +  {
    1.78 +    errorMessage = kCantOpenArchive;
    1.79 +    return result;
    1.80 +  }
    1.81 +
    1.82 +  UString directoryPath = folderName;
    1.83 +  NFile::NName::NormalizeDirPathPrefix(directoryPath);
    1.84 +
    1.85 +  /*
    1.86 +  UString directoryPath;
    1.87 +  {
    1.88 +    UString fullPath;
    1.89 +    int fileNamePartStartIndex;
    1.90 +    if (!NWindows::NFile::NDirectory::MyGetFullPathName(fileName, fullPath, fileNamePartStartIndex))
    1.91 +    {
    1.92 +      MessageBox(NULL, "Error 1329484", "7-Zip", 0);
    1.93 +      return E_FAIL;
    1.94 +    }
    1.95 +    directoryPath = fullPath.Left(fileNamePartStartIndex);
    1.96 +  }
    1.97 +  */
    1.98 +
    1.99 +  if(!NFile::NDirectory::CreateComplexDirectory(directoryPath))
   1.100 +  {
   1.101 +    errorMessage = MyFormatNew(IDS_CANNOT_CREATE_FOLDER, 
   1.102 +        #ifdef LANG        
   1.103 +        0x02000603, 
   1.104 +        #endif 
   1.105 +        directoryPath);
   1.106 +    return E_FAIL;
   1.107 +  }
   1.108 +  
   1.109 +  extracter.ExtractCallbackSpec = new CExtractCallbackImp;
   1.110 +  extracter.ExtractCallback = extracter.ExtractCallbackSpec;
   1.111 +  
   1.112 +  extracter.ExtractCallbackSpec->Init(
   1.113 +      extracter.ArchiveLink.GetArchive(), 
   1.114 +      directoryPath, L"Default", archiveFileInfo.LastWriteTime, 0);
   1.115 +
   1.116 +  #ifndef _NO_PROGRESS
   1.117 +
   1.118 +  if (showProgress)
   1.119 +  {
   1.120 +    CThread thread;
   1.121 +    if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter))
   1.122 +      throw 271824;
   1.123 +    
   1.124 +    UString title;
   1.125 +    #ifdef LANG        
   1.126 +    title = LangLoadString(IDS_PROGRESS_EXTRACTING, 0x02000890);
   1.127 +    #else
   1.128 +    title = NWindows::MyLoadStringW(IDS_PROGRESS_EXTRACTING);
   1.129 +    #endif
   1.130 +    extracter.ExtractCallbackSpec->StartProgressDialog(title);
   1.131 +    result = extracter.Result;
   1.132 +  }
   1.133 +  else
   1.134 +
   1.135 +  #endif
   1.136 +  {
   1.137 +    result = extracter.Extract();
   1.138 +  }
   1.139 +  errorMessage = extracter.ExtractCallbackSpec->_message;
   1.140 +  isCorrupt = extracter.ExtractCallbackSpec->_isCorrupt;
   1.141 +  return result;
   1.142 +}

mercurial