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