1370b324cSopenharmony_ci// ExtractGUI.cpp
2370b324cSopenharmony_ci
3370b324cSopenharmony_ci#include "StdAfx.h"
4370b324cSopenharmony_ci
5370b324cSopenharmony_ci#include "../../../Common/IntToString.h"
6370b324cSopenharmony_ci#include "../../../Common/StringConvert.h"
7370b324cSopenharmony_ci
8370b324cSopenharmony_ci#include "../../../Windows/FileDir.h"
9370b324cSopenharmony_ci#include "../../../Windows/FileFind.h"
10370b324cSopenharmony_ci#include "../../../Windows/FileName.h"
11370b324cSopenharmony_ci#include "../../../Windows/Thread.h"
12370b324cSopenharmony_ci
13370b324cSopenharmony_ci#include "../FileManager/ExtractCallback.h"
14370b324cSopenharmony_ci#include "../FileManager/FormatUtils.h"
15370b324cSopenharmony_ci#include "../FileManager/LangUtils.h"
16370b324cSopenharmony_ci#include "../FileManager/resourceGui.h"
17370b324cSopenharmony_ci#include "../FileManager/OverwriteDialogRes.h"
18370b324cSopenharmony_ci
19370b324cSopenharmony_ci#include "../Common/ArchiveExtractCallback.h"
20370b324cSopenharmony_ci#include "../Common/PropIDUtils.h"
21370b324cSopenharmony_ci
22370b324cSopenharmony_ci#include "../Explorer/MyMessages.h"
23370b324cSopenharmony_ci
24370b324cSopenharmony_ci#include "resource2.h"
25370b324cSopenharmony_ci#include "ExtractRes.h"
26370b324cSopenharmony_ci
27370b324cSopenharmony_ci#include "ExtractDialog.h"
28370b324cSopenharmony_ci#include "ExtractGUI.h"
29370b324cSopenharmony_ci#include "HashGUI.h"
30370b324cSopenharmony_ci
31370b324cSopenharmony_ci#include "../FileManager/PropertyNameRes.h"
32370b324cSopenharmony_ci
33370b324cSopenharmony_ciusing namespace NWindows;
34370b324cSopenharmony_ciusing namespace NFile;
35370b324cSopenharmony_ciusing namespace NDir;
36370b324cSopenharmony_ci
37370b324cSopenharmony_cistatic const wchar_t * const kIncorrectOutDir = L"Incorrect output directory path";
38370b324cSopenharmony_ci
39370b324cSopenharmony_ci#ifndef Z7_SFX
40370b324cSopenharmony_ci
41370b324cSopenharmony_cistatic void AddValuePair(UString &s, UINT resourceID, UInt64 value, bool addColon = true)
42370b324cSopenharmony_ci{
43370b324cSopenharmony_ci  AddLangString(s, resourceID);
44370b324cSopenharmony_ci  if (addColon)
45370b324cSopenharmony_ci    s += ':';
46370b324cSopenharmony_ci  s.Add_Space();
47370b324cSopenharmony_ci  s.Add_UInt64(value);
48370b324cSopenharmony_ci  s.Add_LF();
49370b324cSopenharmony_ci}
50370b324cSopenharmony_ci
51370b324cSopenharmony_cistatic void AddSizePair(UString &s, UINT resourceID, UInt64 value)
52370b324cSopenharmony_ci{
53370b324cSopenharmony_ci  AddLangString(s, resourceID);
54370b324cSopenharmony_ci  s += ": ";
55370b324cSopenharmony_ci  AddSizeValue(s, value);
56370b324cSopenharmony_ci  s.Add_LF();
57370b324cSopenharmony_ci}
58370b324cSopenharmony_ci
59370b324cSopenharmony_ci#endif
60370b324cSopenharmony_ci
61370b324cSopenharmony_ciclass CThreadExtracting: public CProgressThreadVirt
62370b324cSopenharmony_ci{
63370b324cSopenharmony_ci  HRESULT ProcessVirt() Z7_override;
64370b324cSopenharmony_cipublic:
65370b324cSopenharmony_ci  /*
66370b324cSopenharmony_ci  #ifdef Z7_EXTERNAL_CODECS
67370b324cSopenharmony_ci  const CExternalCodecs *externalCodecs;
68370b324cSopenharmony_ci  #endif
69370b324cSopenharmony_ci  */
70370b324cSopenharmony_ci
71370b324cSopenharmony_ci  CCodecs *codecs;
72370b324cSopenharmony_ci  CExtractCallbackImp *ExtractCallbackSpec;
73370b324cSopenharmony_ci  const CObjectVector<COpenType> *FormatIndices;
74370b324cSopenharmony_ci  const CIntVector *ExcludedFormatIndices;
75370b324cSopenharmony_ci
76370b324cSopenharmony_ci  UStringVector *ArchivePaths;
77370b324cSopenharmony_ci  UStringVector *ArchivePathsFull;
78370b324cSopenharmony_ci  const NWildcard::CCensorNode *WildcardCensor;
79370b324cSopenharmony_ci  const CExtractOptions *Options;
80370b324cSopenharmony_ci
81370b324cSopenharmony_ci  #ifndef Z7_SFX
82370b324cSopenharmony_ci  CHashBundle *HashBundle;
83370b324cSopenharmony_ci  virtual void ProcessWasFinished_GuiVirt() Z7_override;
84370b324cSopenharmony_ci  #endif
85370b324cSopenharmony_ci
86370b324cSopenharmony_ci  CMyComPtr<IFolderArchiveExtractCallback> FolderArchiveExtractCallback;
87370b324cSopenharmony_ci  UString Title;
88370b324cSopenharmony_ci
89370b324cSopenharmony_ci  CPropNameValPairs Pairs;
90370b324cSopenharmony_ci};
91370b324cSopenharmony_ci
92370b324cSopenharmony_ci
93370b324cSopenharmony_ci#ifndef Z7_SFX
94370b324cSopenharmony_civoid CThreadExtracting::ProcessWasFinished_GuiVirt()
95370b324cSopenharmony_ci{
96370b324cSopenharmony_ci  if (HashBundle && !Pairs.IsEmpty())
97370b324cSopenharmony_ci    ShowHashResults(Pairs, *this);
98370b324cSopenharmony_ci}
99370b324cSopenharmony_ci#endif
100370b324cSopenharmony_ci
101370b324cSopenharmony_ciHRESULT CThreadExtracting::ProcessVirt()
102370b324cSopenharmony_ci{
103370b324cSopenharmony_ci  CDecompressStat Stat;
104370b324cSopenharmony_ci
105370b324cSopenharmony_ci  #ifndef Z7_SFX
106370b324cSopenharmony_ci  /*
107370b324cSopenharmony_ci  if (HashBundle)
108370b324cSopenharmony_ci    HashBundle->Init();
109370b324cSopenharmony_ci  */
110370b324cSopenharmony_ci  #endif
111370b324cSopenharmony_ci
112370b324cSopenharmony_ci  HRESULT res = Extract(
113370b324cSopenharmony_ci      /*
114370b324cSopenharmony_ci      #ifdef Z7_EXTERNAL_CODECS
115370b324cSopenharmony_ci      externalCodecs,
116370b324cSopenharmony_ci      #endif
117370b324cSopenharmony_ci      */
118370b324cSopenharmony_ci      codecs,
119370b324cSopenharmony_ci      *FormatIndices, *ExcludedFormatIndices,
120370b324cSopenharmony_ci      *ArchivePaths, *ArchivePathsFull,
121370b324cSopenharmony_ci      *WildcardCensor, *Options,
122370b324cSopenharmony_ci      ExtractCallbackSpec, ExtractCallbackSpec, FolderArchiveExtractCallback,
123370b324cSopenharmony_ci      #ifndef Z7_SFX
124370b324cSopenharmony_ci        HashBundle,
125370b324cSopenharmony_ci      #endif
126370b324cSopenharmony_ci      FinalMessage.ErrorMessage.Message, Stat);
127370b324cSopenharmony_ci
128370b324cSopenharmony_ci  #ifndef Z7_SFX
129370b324cSopenharmony_ci  if (res == S_OK && ExtractCallbackSpec->IsOK())
130370b324cSopenharmony_ci  {
131370b324cSopenharmony_ci    if (HashBundle)
132370b324cSopenharmony_ci    {
133370b324cSopenharmony_ci      AddValuePair(Pairs, IDS_ARCHIVES_COLON, Stat.NumArchives);
134370b324cSopenharmony_ci      AddSizeValuePair(Pairs, IDS_PROP_PACKED_SIZE, Stat.PackSize);
135370b324cSopenharmony_ci      AddHashBundleRes(Pairs, *HashBundle);
136370b324cSopenharmony_ci    }
137370b324cSopenharmony_ci    else if (Options->TestMode)
138370b324cSopenharmony_ci    {
139370b324cSopenharmony_ci      UString s;
140370b324cSopenharmony_ci
141370b324cSopenharmony_ci      AddValuePair(s, IDS_ARCHIVES_COLON, Stat.NumArchives, false);
142370b324cSopenharmony_ci      AddSizePair(s, IDS_PROP_PACKED_SIZE, Stat.PackSize);
143370b324cSopenharmony_ci
144370b324cSopenharmony_ci      if (Stat.NumFolders != 0)
145370b324cSopenharmony_ci        AddValuePair(s, IDS_PROP_FOLDERS, Stat.NumFolders);
146370b324cSopenharmony_ci      AddValuePair(s, IDS_PROP_FILES, Stat.NumFiles);
147370b324cSopenharmony_ci      AddSizePair(s, IDS_PROP_SIZE, Stat.UnpackSize);
148370b324cSopenharmony_ci      if (Stat.NumAltStreams != 0)
149370b324cSopenharmony_ci      {
150370b324cSopenharmony_ci        s.Add_LF();
151370b324cSopenharmony_ci        AddValuePair(s, IDS_PROP_NUM_ALT_STREAMS, Stat.NumAltStreams);
152370b324cSopenharmony_ci        AddSizePair(s, IDS_PROP_ALT_STREAMS_SIZE, Stat.AltStreams_UnpackSize);
153370b324cSopenharmony_ci      }
154370b324cSopenharmony_ci      s.Add_LF();
155370b324cSopenharmony_ci      AddLangString(s, IDS_MESSAGE_NO_ERRORS);
156370b324cSopenharmony_ci      FinalMessage.OkMessage.Title = Title;
157370b324cSopenharmony_ci      FinalMessage.OkMessage.Message = s;
158370b324cSopenharmony_ci    }
159370b324cSopenharmony_ci  }
160370b324cSopenharmony_ci  #endif
161370b324cSopenharmony_ci
162370b324cSopenharmony_ci  return res;
163370b324cSopenharmony_ci}
164370b324cSopenharmony_ci
165370b324cSopenharmony_ci
166370b324cSopenharmony_ci
167370b324cSopenharmony_ciHRESULT ExtractGUI(
168370b324cSopenharmony_ci    // DECL_EXTERNAL_CODECS_LOC_VARS
169370b324cSopenharmony_ci    CCodecs *codecs,
170370b324cSopenharmony_ci    const CObjectVector<COpenType> &formatIndices,
171370b324cSopenharmony_ci    const CIntVector &excludedFormatIndices,
172370b324cSopenharmony_ci    UStringVector &archivePaths,
173370b324cSopenharmony_ci    UStringVector &archivePathsFull,
174370b324cSopenharmony_ci    const NWildcard::CCensorNode &wildcardCensor,
175370b324cSopenharmony_ci    CExtractOptions &options,
176370b324cSopenharmony_ci    #ifndef Z7_SFX
177370b324cSopenharmony_ci    CHashBundle *hb,
178370b324cSopenharmony_ci    #endif
179370b324cSopenharmony_ci    bool showDialog,
180370b324cSopenharmony_ci    bool &messageWasDisplayed,
181370b324cSopenharmony_ci    CExtractCallbackImp *extractCallback,
182370b324cSopenharmony_ci    HWND hwndParent)
183370b324cSopenharmony_ci{
184370b324cSopenharmony_ci  messageWasDisplayed = false;
185370b324cSopenharmony_ci
186370b324cSopenharmony_ci  CThreadExtracting extracter;
187370b324cSopenharmony_ci  /*
188370b324cSopenharmony_ci  #ifdef Z7_EXTERNAL_CODECS
189370b324cSopenharmony_ci  extracter.externalCodecs = _externalCodecs;
190370b324cSopenharmony_ci  #endif
191370b324cSopenharmony_ci  */
192370b324cSopenharmony_ci  extracter.codecs = codecs;
193370b324cSopenharmony_ci  extracter.FormatIndices = &formatIndices;
194370b324cSopenharmony_ci  extracter.ExcludedFormatIndices = &excludedFormatIndices;
195370b324cSopenharmony_ci
196370b324cSopenharmony_ci  if (!options.TestMode)
197370b324cSopenharmony_ci  {
198370b324cSopenharmony_ci    FString outputDir = options.OutputDir;
199370b324cSopenharmony_ci    #ifndef UNDER_CE
200370b324cSopenharmony_ci    if (outputDir.IsEmpty())
201370b324cSopenharmony_ci      GetCurrentDir(outputDir);
202370b324cSopenharmony_ci    #endif
203370b324cSopenharmony_ci    if (showDialog)
204370b324cSopenharmony_ci    {
205370b324cSopenharmony_ci      CExtractDialog dialog;
206370b324cSopenharmony_ci      FString outputDirFull;
207370b324cSopenharmony_ci      if (!MyGetFullPathName(outputDir, outputDirFull))
208370b324cSopenharmony_ci      {
209370b324cSopenharmony_ci        ShowErrorMessage(kIncorrectOutDir);
210370b324cSopenharmony_ci        messageWasDisplayed = true;
211370b324cSopenharmony_ci        return E_FAIL;
212370b324cSopenharmony_ci      }
213370b324cSopenharmony_ci      NName::NormalizeDirPathPrefix(outputDirFull);
214370b324cSopenharmony_ci
215370b324cSopenharmony_ci      dialog.DirPath = fs2us(outputDirFull);
216370b324cSopenharmony_ci
217370b324cSopenharmony_ci      dialog.OverwriteMode = options.OverwriteMode;
218370b324cSopenharmony_ci      dialog.OverwriteMode_Force = options.OverwriteMode_Force;
219370b324cSopenharmony_ci      dialog.PathMode = options.PathMode;
220370b324cSopenharmony_ci      dialog.PathMode_Force = options.PathMode_Force;
221370b324cSopenharmony_ci      dialog.ElimDup = options.ElimDup;
222370b324cSopenharmony_ci
223370b324cSopenharmony_ci      if (archivePathsFull.Size() == 1)
224370b324cSopenharmony_ci        dialog.ArcPath = archivePathsFull[0];
225370b324cSopenharmony_ci
226370b324cSopenharmony_ci      #ifndef Z7_SFX
227370b324cSopenharmony_ci      // dialog.AltStreams = options.NtOptions.AltStreams;
228370b324cSopenharmony_ci      dialog.NtSecurity = options.NtOptions.NtSecurity;
229370b324cSopenharmony_ci      if (extractCallback->PasswordIsDefined)
230370b324cSopenharmony_ci        dialog.Password = extractCallback->Password;
231370b324cSopenharmony_ci      #endif
232370b324cSopenharmony_ci
233370b324cSopenharmony_ci      if (dialog.Create(hwndParent) != IDOK)
234370b324cSopenharmony_ci        return E_ABORT;
235370b324cSopenharmony_ci
236370b324cSopenharmony_ci      outputDir = us2fs(dialog.DirPath);
237370b324cSopenharmony_ci
238370b324cSopenharmony_ci      options.OverwriteMode = dialog.OverwriteMode;
239370b324cSopenharmony_ci      options.PathMode = dialog.PathMode;
240370b324cSopenharmony_ci      options.ElimDup = dialog.ElimDup;
241370b324cSopenharmony_ci
242370b324cSopenharmony_ci      #ifndef Z7_SFX
243370b324cSopenharmony_ci      // options.NtOptions.AltStreams = dialog.AltStreams;
244370b324cSopenharmony_ci      options.NtOptions.NtSecurity = dialog.NtSecurity;
245370b324cSopenharmony_ci      extractCallback->Password = dialog.Password;
246370b324cSopenharmony_ci      extractCallback->PasswordIsDefined = !dialog.Password.IsEmpty();
247370b324cSopenharmony_ci      #endif
248370b324cSopenharmony_ci    }
249370b324cSopenharmony_ci    if (!MyGetFullPathName(outputDir, options.OutputDir))
250370b324cSopenharmony_ci    {
251370b324cSopenharmony_ci      ShowErrorMessage(kIncorrectOutDir);
252370b324cSopenharmony_ci      messageWasDisplayed = true;
253370b324cSopenharmony_ci      return E_FAIL;
254370b324cSopenharmony_ci    }
255370b324cSopenharmony_ci    NName::NormalizeDirPathPrefix(options.OutputDir);
256370b324cSopenharmony_ci
257370b324cSopenharmony_ci    /*
258370b324cSopenharmony_ci    if (!CreateComplexDirectory(options.OutputDir))
259370b324cSopenharmony_ci    {
260370b324cSopenharmony_ci      UString s = GetUnicodeString(NError::MyFormatMessage(GetLastError()));
261370b324cSopenharmony_ci      UString s2 = MyFormatNew(IDS_CANNOT_CREATE_FOLDER,
262370b324cSopenharmony_ci      #ifdef Z7_LANG
263370b324cSopenharmony_ci      0x02000603,
264370b324cSopenharmony_ci      #endif
265370b324cSopenharmony_ci      options.OutputDir);
266370b324cSopenharmony_ci      s2.Add_LF();
267370b324cSopenharmony_ci      s2 += s;
268370b324cSopenharmony_ci      MyMessageBox(s2);
269370b324cSopenharmony_ci      return E_FAIL;
270370b324cSopenharmony_ci    }
271370b324cSopenharmony_ci    */
272370b324cSopenharmony_ci  }
273370b324cSopenharmony_ci
274370b324cSopenharmony_ci  UString title = LangString(options.TestMode ? IDS_PROGRESS_TESTING : IDS_PROGRESS_EXTRACTING);
275370b324cSopenharmony_ci
276370b324cSopenharmony_ci  extracter.Title = title;
277370b324cSopenharmony_ci  extracter.ExtractCallbackSpec = extractCallback;
278370b324cSopenharmony_ci  extracter.ExtractCallbackSpec->ProgressDialog = &extracter;
279370b324cSopenharmony_ci  extracter.FolderArchiveExtractCallback = extractCallback;
280370b324cSopenharmony_ci  extracter.ExtractCallbackSpec->Init();
281370b324cSopenharmony_ci
282370b324cSopenharmony_ci  extracter.CompressingMode = false;
283370b324cSopenharmony_ci
284370b324cSopenharmony_ci  extracter.ArchivePaths = &archivePaths;
285370b324cSopenharmony_ci  extracter.ArchivePathsFull = &archivePathsFull;
286370b324cSopenharmony_ci  extracter.WildcardCensor = &wildcardCensor;
287370b324cSopenharmony_ci  extracter.Options = &options;
288370b324cSopenharmony_ci  #ifndef Z7_SFX
289370b324cSopenharmony_ci  extracter.HashBundle = hb;
290370b324cSopenharmony_ci  #endif
291370b324cSopenharmony_ci
292370b324cSopenharmony_ci  extracter.IconID = IDI_ICON;
293370b324cSopenharmony_ci
294370b324cSopenharmony_ci  RINOK(extracter.Create(title, hwndParent))
295370b324cSopenharmony_ci  messageWasDisplayed = extracter.ThreadFinishedOK && extracter.MessagesDisplayed;
296370b324cSopenharmony_ci  return extracter.Result;
297370b324cSopenharmony_ci}
298