Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 // ExtractEngine.cpp
3 #include "StdAfx.h"
5 #include "ExtractEngine.h"
7 #include "Common/StringConvert.h"
9 #include "Windows/FileDir.h"
10 #include "Windows/FileFind.h"
11 #include "Windows/Thread.h"
13 #include "../../UI/Common/OpenArchive.h"
15 #include "../../UI/Explorer/MyMessages.h"
16 #include "../../FileManager/FormatUtils.h"
18 #include "ExtractCallback.h"
20 using namespace NWindows;
22 struct CThreadExtracting
23 {
24 CArchiveLink ArchiveLink;
26 CExtractCallbackImp *ExtractCallbackSpec;
27 CMyComPtr<IArchiveExtractCallback> ExtractCallback;
29 #ifndef _NO_PROGRESS
30 HRESULT Result;
32 HRESULT Extract()
33 {
34 return ArchiveLink.GetArchive()->Extract(0, (UInt32)-1 , BoolToInt(false), ExtractCallback);
35 }
36 DWORD Process()
37 {
38 ExtractCallbackSpec->ProgressDialog.WaitCreating();
39 Result = Extract();
40 ExtractCallbackSpec->ProgressDialog.MyClose();
41 return 0;
42 }
43 static DWORD WINAPI MyThreadFunction(void *param)
44 {
45 return ((CThreadExtracting *)param)->Process();
46 }
47 #endif
48 };
50 static const LPCWSTR kCantFindArchive = L"Can not find archive file";
51 static const LPCWSTR kCantOpenArchive = L"File is not correct archive";
53 HRESULT ExtractArchive(
54 const UString &fileName,
55 const UString &folderName,
56 COpenCallbackGUI *openCallback,
57 bool showProgress,
58 bool &isCorrupt,
59 UString &errorMessage)
60 {
61 isCorrupt = false;
62 NFile::NFind::CFileInfoW archiveFileInfo;
63 if (!NFile::NFind::FindFile(fileName, archiveFileInfo))
64 {
65 errorMessage = kCantFindArchive;
66 return E_FAIL;
67 }
69 CThreadExtracting extracter;
71 HRESULT result = MyOpenArchive(fileName, extracter.ArchiveLink, openCallback);
73 if (result != S_OK)
74 {
75 errorMessage = kCantOpenArchive;
76 return result;
77 }
79 UString directoryPath = folderName;
80 NFile::NName::NormalizeDirPathPrefix(directoryPath);
82 /*
83 UString directoryPath;
84 {
85 UString fullPath;
86 int fileNamePartStartIndex;
87 if (!NWindows::NFile::NDirectory::MyGetFullPathName(fileName, fullPath, fileNamePartStartIndex))
88 {
89 MessageBox(NULL, "Error 1329484", "7-Zip", 0);
90 return E_FAIL;
91 }
92 directoryPath = fullPath.Left(fileNamePartStartIndex);
93 }
94 */
96 if(!NFile::NDirectory::CreateComplexDirectory(directoryPath))
97 {
98 errorMessage = MyFormatNew(IDS_CANNOT_CREATE_FOLDER,
99 #ifdef LANG
100 0x02000603,
101 #endif
102 directoryPath);
103 return E_FAIL;
104 }
106 extracter.ExtractCallbackSpec = new CExtractCallbackImp;
107 extracter.ExtractCallback = extracter.ExtractCallbackSpec;
109 extracter.ExtractCallbackSpec->Init(
110 extracter.ArchiveLink.GetArchive(),
111 directoryPath, L"Default", archiveFileInfo.LastWriteTime, 0);
113 #ifndef _NO_PROGRESS
115 if (showProgress)
116 {
117 CThread thread;
118 if (!thread.Create(CThreadExtracting::MyThreadFunction, &extracter))
119 throw 271824;
121 UString title;
122 #ifdef LANG
123 title = LangLoadString(IDS_PROGRESS_EXTRACTING, 0x02000890);
124 #else
125 title = NWindows::MyLoadStringW(IDS_PROGRESS_EXTRACTING);
126 #endif
127 extracter.ExtractCallbackSpec->StartProgressDialog(title);
128 result = extracter.Result;
129 }
130 else
132 #endif
133 {
134 result = extracter.Extract();
135 }
136 errorMessage = extracter.ExtractCallbackSpec->_message;
137 isCorrupt = extracter.ExtractCallbackSpec->_isCorrupt;
138 return result;
139 }