ExtractGUI.cpp (7560B)
1 // ExtractGUI.cpp 2 3 #include "StdAfx.h" 4 5 #include "../../../Common/IntToString.h" 6 #include "../../../Common/StringConvert.h" 7 8 #include "../../../Windows/FileDir.h" 9 #include "../../../Windows/FileFind.h" 10 #include "../../../Windows/FileName.h" 11 #include "../../../Windows/Thread.h" 12 13 #include "../FileManager/ExtractCallback.h" 14 #include "../FileManager/FormatUtils.h" 15 #include "../FileManager/LangUtils.h" 16 #include "../FileManager/resourceGui.h" 17 #include "../FileManager/OverwriteDialogRes.h" 18 19 #include "../Common/ArchiveExtractCallback.h" 20 #include "../Common/PropIDUtils.h" 21 22 #include "../Explorer/MyMessages.h" 23 24 #include "resource2.h" 25 #include "ExtractRes.h" 26 27 #include "ExtractDialog.h" 28 #include "ExtractGUI.h" 29 #include "HashGUI.h" 30 31 #include "../FileManager/PropertyNameRes.h" 32 33 using namespace NWindows; 34 using namespace NFile; 35 using namespace NDir; 36 37 static const wchar_t * const kIncorrectOutDir = L"Incorrect output directory path"; 38 39 #ifndef _SFX 40 41 static void AddValuePair(UString &s, UINT resourceID, UInt64 value, bool addColon = true) 42 { 43 AddLangString(s, resourceID); 44 if (addColon) 45 s += ':'; 46 s.Add_Space(); 47 char sz[32]; 48 ConvertUInt64ToString(value, sz); 49 s += sz; 50 s.Add_LF(); 51 } 52 53 static void AddSizePair(UString &s, UINT resourceID, UInt64 value) 54 { 55 AddLangString(s, resourceID); 56 s += ": "; 57 AddSizeValue(s, value); 58 s.Add_LF(); 59 } 60 61 #endif 62 63 class CThreadExtracting: public CProgressThreadVirt 64 { 65 HRESULT ProcessVirt(); 66 public: 67 CCodecs *codecs; 68 CExtractCallbackImp *ExtractCallbackSpec; 69 const CObjectVector<COpenType> *FormatIndices; 70 const CIntVector *ExcludedFormatIndices; 71 72 UStringVector *ArchivePaths; 73 UStringVector *ArchivePathsFull; 74 const NWildcard::CCensorNode *WildcardCensor; 75 const CExtractOptions *Options; 76 77 #ifndef _SFX 78 CHashBundle *HashBundle; 79 virtual void ProcessWasFinished_GuiVirt(); 80 #endif 81 82 CMyComPtr<IExtractCallbackUI> ExtractCallback; 83 UString Title; 84 85 CPropNameValPairs Pairs; 86 }; 87 88 89 #ifndef _SFX 90 void CThreadExtracting::ProcessWasFinished_GuiVirt() 91 { 92 if (HashBundle && !Pairs.IsEmpty()) 93 ShowHashResults(Pairs, *this); 94 } 95 #endif 96 97 HRESULT CThreadExtracting::ProcessVirt() 98 { 99 CDecompressStat Stat; 100 101 #ifndef _SFX 102 if (HashBundle) 103 HashBundle->Init(); 104 #endif 105 106 HRESULT res = Extract(codecs, 107 *FormatIndices, *ExcludedFormatIndices, 108 *ArchivePaths, *ArchivePathsFull, 109 *WildcardCensor, *Options, ExtractCallbackSpec, ExtractCallback, 110 #ifndef _SFX 111 HashBundle, 112 #endif 113 FinalMessage.ErrorMessage.Message, Stat); 114 115 #ifndef _SFX 116 if (res == S_OK && ExtractCallbackSpec->IsOK()) 117 { 118 if (HashBundle) 119 { 120 AddValuePair(Pairs, IDS_ARCHIVES_COLON, Stat.NumArchives); 121 AddSizeValuePair(Pairs, IDS_PROP_PACKED_SIZE, Stat.PackSize); 122 AddHashBundleRes(Pairs, *HashBundle, UString()); 123 } 124 else if (Options->TestMode) 125 { 126 UString s; 127 128 AddValuePair(s, IDS_ARCHIVES_COLON, Stat.NumArchives, false); 129 AddSizePair(s, IDS_PROP_PACKED_SIZE, Stat.PackSize); 130 131 if (Stat.NumFolders != 0) 132 AddValuePair(s, IDS_PROP_FOLDERS, Stat.NumFolders); 133 AddValuePair(s, IDS_PROP_FILES, Stat.NumFiles); 134 AddSizePair(s, IDS_PROP_SIZE, Stat.UnpackSize); 135 if (Stat.NumAltStreams != 0) 136 { 137 s.Add_LF(); 138 AddValuePair(s, IDS_PROP_NUM_ALT_STREAMS, Stat.NumAltStreams); 139 AddSizePair(s, IDS_PROP_ALT_STREAMS_SIZE, Stat.AltStreams_UnpackSize); 140 } 141 s.Add_LF(); 142 AddLangString(s, IDS_MESSAGE_NO_ERRORS); 143 FinalMessage.OkMessage.Title = Title; 144 FinalMessage.OkMessage.Message = s; 145 } 146 } 147 #endif 148 149 return res; 150 } 151 152 153 154 HRESULT ExtractGUI( 155 CCodecs *codecs, 156 const CObjectVector<COpenType> &formatIndices, 157 const CIntVector &excludedFormatIndices, 158 UStringVector &archivePaths, 159 UStringVector &archivePathsFull, 160 const NWildcard::CCensorNode &wildcardCensor, 161 CExtractOptions &options, 162 #ifndef _SFX 163 CHashBundle *hb, 164 #endif 165 bool showDialog, 166 bool &messageWasDisplayed, 167 CExtractCallbackImp *extractCallback, 168 HWND hwndParent) 169 { 170 messageWasDisplayed = false; 171 172 CThreadExtracting extracter; 173 extracter.codecs = codecs; 174 extracter.FormatIndices = &formatIndices; 175 extracter.ExcludedFormatIndices = &excludedFormatIndices; 176 177 if (!options.TestMode) 178 { 179 FString outputDir = options.OutputDir; 180 #ifndef UNDER_CE 181 if (outputDir.IsEmpty()) 182 GetCurrentDir(outputDir); 183 #endif 184 if (showDialog) 185 { 186 CExtractDialog dialog; 187 FString outputDirFull; 188 if (!MyGetFullPathName(outputDir, outputDirFull)) 189 { 190 ShowErrorMessage(kIncorrectOutDir); 191 messageWasDisplayed = true; 192 return E_FAIL; 193 } 194 NName::NormalizeDirPathPrefix(outputDirFull); 195 196 dialog.DirPath = fs2us(outputDirFull); 197 198 dialog.OverwriteMode = options.OverwriteMode; 199 dialog.OverwriteMode_Force = options.OverwriteMode_Force; 200 dialog.PathMode = options.PathMode; 201 dialog.PathMode_Force = options.PathMode_Force; 202 dialog.ElimDup = options.ElimDup; 203 204 if (archivePathsFull.Size() == 1) 205 dialog.ArcPath = archivePathsFull[0]; 206 207 #ifndef _SFX 208 // dialog.AltStreams = options.NtOptions.AltStreams; 209 dialog.NtSecurity = options.NtOptions.NtSecurity; 210 if (extractCallback->PasswordIsDefined) 211 dialog.Password = extractCallback->Password; 212 #endif 213 214 if (dialog.Create(hwndParent) != IDOK) 215 return E_ABORT; 216 217 outputDir = us2fs(dialog.DirPath); 218 219 options.OverwriteMode = dialog.OverwriteMode; 220 options.PathMode = dialog.PathMode; 221 options.ElimDup = dialog.ElimDup; 222 223 #ifndef _SFX 224 // options.NtOptions.AltStreams = dialog.AltStreams; 225 options.NtOptions.NtSecurity = dialog.NtSecurity; 226 extractCallback->Password = dialog.Password; 227 extractCallback->PasswordIsDefined = !dialog.Password.IsEmpty(); 228 #endif 229 } 230 if (!MyGetFullPathName(outputDir, options.OutputDir)) 231 { 232 ShowErrorMessage(kIncorrectOutDir); 233 messageWasDisplayed = true; 234 return E_FAIL; 235 } 236 NName::NormalizeDirPathPrefix(options.OutputDir); 237 238 /* 239 if (!CreateComplexDirectory(options.OutputDir)) 240 { 241 UString s = GetUnicodeString(NError::MyFormatMessage(GetLastError())); 242 UString s2 = MyFormatNew(IDS_CANNOT_CREATE_FOLDER, 243 #ifdef LANG 244 0x02000603, 245 #endif 246 options.OutputDir); 247 s2.Add_LF(); 248 s2 += s; 249 MyMessageBox(s2); 250 return E_FAIL; 251 } 252 */ 253 } 254 255 UString title = LangString(options.TestMode ? IDS_PROGRESS_TESTING : IDS_PROGRESS_EXTRACTING); 256 257 extracter.Title = title; 258 extracter.ExtractCallbackSpec = extractCallback; 259 extracter.ExtractCallbackSpec->ProgressDialog = &extracter; 260 extracter.ExtractCallback = extractCallback; 261 extracter.ExtractCallbackSpec->Init(); 262 263 extracter.CompressingMode = false; 264 265 extracter.ArchivePaths = &archivePaths; 266 extracter.ArchivePathsFull = &archivePathsFull; 267 extracter.WildcardCensor = &wildcardCensor; 268 extracter.Options = &options; 269 #ifndef _SFX 270 extracter.HashBundle = hb; 271 #endif 272 273 extracter.IconID = IDI_ICON; 274 275 RINOK(extracter.Create(title, hwndParent)); 276 messageWasDisplayed = extracter.ThreadFinishedOK && extracter.MessagesDisplayed; 277 return extracter.Result; 278 }