Skip to content

Commit ad249e4

Browse files
committed
Merge branch 'sfxsetup-gfw-extra'
This are the extra features Git for Windows needs in the SFX component. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
2 parents 49b4284 + 26d9174 commit ad249e4

File tree

9 files changed

+341
-13
lines changed

9 files changed

+341
-13
lines changed

CPP/7zip/Bundles/SFXSetup/ExtractEngine.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ struct CThreadExtracting
9494
};
9595

9696
HRESULT ExtractArchive(CCodecs *codecs, const FString &fileName, const FString &destFolder,
97-
bool showProgress, bool &isCorrupt, UString &errorMessage)
97+
bool showProgress, const UString &extractDialogText, bool &isCorrupt, UString &errorMessage)
9898
{
9999
isCorrupt = false;
100100
CThreadExtracting t;
@@ -117,7 +117,10 @@ HRESULT ExtractArchive(CCodecs *codecs, const FString &fileName, const FString &
117117
return HRESULT_FROM_WIN32(wres);
118118

119119
UString title;
120-
LangString(IDS_PROGRESS_EXTRACTING, title);
120+
if (extractDialogText.IsEmpty())
121+
LangString(IDS_PROGRESS_EXTRACTING, title);
122+
else
123+
title = extractDialogText;
121124
t.ExtractCallbackSpec->StartProgressDialog(title, thread);
122125
}
123126
else

CPP/7zip/Bundles/SFXSetup/ExtractEngine.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
#include "../../UI/Common/LoadCodecs.h"
77

88
HRESULT ExtractArchive(CCodecs *codecs, const FString &fileName, const FString &destFolder,
9-
bool showProgress, bool &isCorrupt, UString &errorMessage);
9+
bool showProgress, const FString & extractDialogText, bool &isCorrupt, UString &errorMessage);
1010

1111
#endif

CPP/7zip/Bundles/SFXSetup/SFXSetup.vcxproj

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@
9393
<ObjectFileName>.\ReleaseD\</ObjectFileName>
9494
<ProgramDataBaseFileName>.\ReleaseD\</ProgramDataBaseFileName>
9595
<CallingConvention>StdCall</CallingConvention>
96+
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
97+
<OmitFramePointers>true</OmitFramePointers>
98+
<WholeProgramOptimization>true</WholeProgramOptimization>
99+
<DebugInformationFormat>None</DebugInformationFormat>
96100
</ClCompile>
97101
<Midl>
98102
<SuppressStartupBanner>true</SuppressStartupBanner>
@@ -113,6 +117,8 @@
113117
<SuppressStartupBanner>true</SuppressStartupBanner>
114118
<SubSystem>Windows</SubSystem>
115119
<AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
120+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
121+
<GenerateDebugInformation>false</GenerateDebugInformation>
116122
</Link>
117123
</ItemDefinitionGroup>
118124
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
@@ -174,6 +180,10 @@
174180
<ObjectFileName>.\Release\</ObjectFileName>
175181
<ProgramDataBaseFileName>.\Release\</ProgramDataBaseFileName>
176182
<CallingConvention>StdCall</CallingConvention>
183+
<FavorSizeOrSpeed>Size</FavorSizeOrSpeed>
184+
<OmitFramePointers>true</OmitFramePointers>
185+
<WholeProgramOptimization>true</WholeProgramOptimization>
186+
<DebugInformationFormat>None</DebugInformationFormat>
177187
</ClCompile>
178188
<Midl>
179189
<SuppressStartupBanner>true</SuppressStartupBanner>
@@ -194,9 +204,12 @@
194204
<SuppressStartupBanner>true</SuppressStartupBanner>
195205
<SubSystem>Windows</SubSystem>
196206
<AdditionalDependencies>comctl32.lib;odbc32.lib;odbccp32.lib;%(AdditionalDependencies)</AdditionalDependencies>
207+
<LinkTimeCodeGeneration>UseLinkTimeCodeGeneration</LinkTimeCodeGeneration>
208+
<GenerateDebugInformation>false</GenerateDebugInformation>
197209
</Link>
198210
</ItemDefinitionGroup>
199211
<ItemGroup>
212+
<ResourceCompile Include="..\..\UI\FileManager\ExtractPathDialog.rc" />
200213
<ResourceCompile Include="resource.rc" />
201214
</ItemGroup>
202215
<ItemGroup>
@@ -355,6 +368,7 @@
355368
<ClCompile Include="..\..\..\Windows\FileName.cpp" />
356369
<ClCompile Include="..\..\..\Windows\PropVariant.cpp" />
357370
<ClCompile Include="..\..\..\Windows\ResourceString.cpp" />
371+
<ClCompile Include="..\..\..\Windows\Shell.cpp" />
358372
<ClCompile Include="..\..\..\Windows\Synchronization.cpp" />
359373
<ClCompile Include="..\..\..\Windows\System.cpp" />
360374
<ClCompile Include="..\..\..\Windows\TimeUtils.cpp" />
@@ -398,6 +412,7 @@
398412
<ClCompile Include="..\..\UI\Common\LoadCodecs.cpp" />
399413
<ClCompile Include="..\..\UI\Common\OpenArchive.cpp" />
400414
<ClCompile Include="..\..\UI\Explorer\MyMessages.cpp" />
415+
<ClCompile Include="..\..\UI\FileManager\ExtractPathDialog.cpp" />
401416
<ClCompile Include="..\..\UI\FileManager\FormatUtils.cpp" />
402417
<ClCompile Include="..\..\UI\FileManager\ProgressDialog.cpp" />
403418
<ClCompile Include="ExtractCallbackSfx.cpp" />
@@ -448,6 +463,7 @@
448463
<ClInclude Include="..\..\..\Windows\FileName.h" />
449464
<ClInclude Include="..\..\..\Windows\PropVariant.h" />
450465
<ClInclude Include="..\..\..\Windows\ResourceString.h" />
466+
<ClInclude Include="..\..\..\Windows\Shell.h" />
451467
<ClInclude Include="..\..\..\Windows\Synchronization.h" />
452468
<ClInclude Include="..\..\..\Windows\System.h" />
453469
<ClInclude Include="..\..\..\Windows\TimeUtils.h" />
@@ -485,6 +501,8 @@
485501
<ClInclude Include="..\..\UI\Common\LoadCodecs.h" />
486502
<ClInclude Include="..\..\UI\Common\OpenArchive.h" />
487503
<ClInclude Include="..\..\UI\Explorer\MyMessages.h" />
504+
<ClInclude Include="..\..\UI\FileManager\ExtractPathDialog.h" />
505+
<ClInclude Include="..\..\UI\FileManager\ExtractPathDialogRes.h" />
488506
<ClInclude Include="..\..\UI\FileManager\FormatUtils.h" />
489507
<ClInclude Include="..\..\UI\FileManager\LangUtils.h" />
490508
<ClInclude Include="..\..\UI\FileManager\ProgressDialog.h" />

CPP/7zip/Bundles/SFXSetup/SFXSetup.vcxproj.filters

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,9 @@
4848
<ResourceCompile Include="resource.rc">
4949
<Filter>Spec</Filter>
5050
</ResourceCompile>
51+
<ResourceCompile Include="..\..\UI\FileManager\ExtractPathDialog.rc">
52+
<Filter>File Manager</Filter>
53+
</ResourceCompile>
5154
</ItemGroup>
5255
<ItemGroup>
5356
<ClCompile Include="StdAfx.cpp">
@@ -299,6 +302,9 @@
299302
<ClCompile Include="..\..\..\..\C\MtDec.c">
300303
<Filter>C</Filter>
301304
</ClCompile>
305+
<ClCompile Include="..\..\UI\FileManager\ExtractPathDialog.cpp">
306+
<Filter>File Manager</Filter>
307+
</ClCompile>
302308
</ItemGroup>
303309
<ItemGroup>
304310
<ClInclude Include="StdAfx.h">
@@ -516,6 +522,12 @@
516522
<ClInclude Include="..\..\..\..\C\MtDec.h">
517523
<Filter>C</Filter>
518524
</ClInclude>
525+
<ClInclude Include="..\..\UI\FileManager\ExtractPathDialog.h">
526+
<Filter>File Manager</Filter>
527+
</ClInclude>
528+
<ClInclude Include="..\..\UI\FileManager\ExtractPathDialogRes.h">
529+
<Filter>File Manager</Filter>
530+
</ClInclude>
519531
<ClInclude Include="..\..\Archive\IArchive.h" />
520532
<ClInclude Include="..\..\Common\Common.h" />
521533
<ClInclude Include="..\..\Common\MyCom.h" />

CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp

Lines changed: 96 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222

2323
#include "../../UI/Explorer/MyMessages.h"
2424

25+
#include "../../UI/FileManager/ExtractPathDialog.h"
26+
2527
#include "ExtractEngine.h"
2628

2729
#include "resource.h"
@@ -158,14 +160,59 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
158160
FString fullPath;
159161
NDLL::MyGetModuleFileName(fullPath);
160162

161-
switches.Trim();
162163
bool assumeYes = false;
163-
if (switches.IsPrefixedBy_Ascii_NoCase("-y"))
164+
UString installPath;
165+
for (;;)
164166
{
165-
assumeYes = true;
166-
switches = switches.Ptr(2);
167167
switches.Trim();
168-
}
168+
if (switches.IsPrefixedBy_Ascii_NoCase("-y"))
169+
{
170+
assumeYes = true;
171+
switches = switches.Ptr(2);
172+
}
173+
else if (switches.IsPrefixedBy_Ascii_NoCase("-o") || switches.IsPrefixedBy_Ascii_NoCase("\"-o") || switches.IsPrefixedBy_Ascii_NoCase("-\"o"))
174+
{
175+
bool quoted = false;
176+
177+
if (switches[0] == L'"' || switches[1] == L'"')
178+
{
179+
quoted = true;
180+
switches = switches.Ptr(3);
181+
}
182+
else
183+
{
184+
switches = switches.Ptr(2);
185+
switches.Trim();
186+
}
187+
188+
189+
unsigned pos;
190+
for (pos = 0; pos < switches.Len(); pos++)
191+
{
192+
wchar_t c = switches[pos];
193+
if (c == L'"')
194+
{
195+
if (!quoted)
196+
quoted = true;
197+
else if (pos + 1 < switches.Len() && switches[pos + 1] == L'"')
198+
{
199+
installPath += L'"';
200+
pos++;
201+
}
202+
else
203+
quoted = false;
204+
continue;
205+
}
206+
207+
if (!quoted && (c == L' ' || c == L'\t'))
208+
break;
209+
installPath += switches[pos];
210+
}
211+
switches = switches.Ptr(pos);
212+
}
213+
else
214+
break;
215+
}
169216

170217
AString config;
171218
if (!ReadDataString(fullPath, kStartID, kEndID, config))
@@ -176,7 +223,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
176223
}
177224

178225
UString dirPrefix ("." STRING_PATH_SEPARATOR);
179-
UString appLaunched;
226+
UString appLaunched, extractDialogText, extractPath;
180227
bool showProgress = true;
181228
if (!config.IsEmpty())
182229
{
@@ -190,12 +237,51 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
190237
const UString friendlyName = GetTextConfigValue(pairs, "Title");
191238
const UString installPrompt = GetTextConfigValue(pairs, "BeginPrompt");
192239
const UString progress = GetTextConfigValue(pairs, "Progress");
240+
extractDialogText = GetTextConfigValue(pairs, "ExtractDialogText");
241+
UString extractPathText = GetTextConfigValue(pairs, "ExtractPathText");
242+
UString cancelPrompt = GetTextConfigValue(pairs, "CancelPrompt");
193243
if (progress.IsEqualTo_Ascii_NoCase("no"))
194244
showProgress = false;
195245
const int index = FindTextConfigItem(pairs, "Directory");
196246
if (index >= 0)
197247
dirPrefix = pairs[index].String;
198-
if (!installPrompt.IsEmpty() && !assumeYes)
248+
if (installPath.IsEmpty())
249+
installPath = GetTextConfigValue(pairs, "InstallPath");
250+
251+
if (installPath.Find(L"%%S") >= 0)
252+
{
253+
FString s2 = fullPath;
254+
int sep = s2.ReverseFind_PathSepar();
255+
if (sep > 0) {
256+
s2.DeleteFrom(sep + 1);
257+
NName::NormalizeDirPathPrefix(s2);
258+
sep = s2.Len();
259+
if (sep > 0 && IS_PATH_SEPAR(s2[sep - 1]))
260+
s2.DeleteFrom(sep - 1);
261+
}
262+
installPath.Replace(L"%%S", fs2us(s2));
263+
}
264+
extractPath = installPath;
265+
266+
if (!extractPathText.IsEmpty() && !assumeYes)
267+
{
268+
for (;;) {
269+
CExtractPathDialog extractPathDialog;
270+
extractPathDialog.Title = friendlyName;
271+
extractPathDialog.Prompt = installPrompt;
272+
extractPathDialog.Label = extractPathText;
273+
extractPathDialog.Value = extractPath;
274+
if (extractPathDialog.Create(NULL) != IDOK) {
275+
if (!cancelPrompt.IsEmpty() &&
276+
MessageBoxW(0, cancelPrompt, friendlyName, MB_YESNO | MB_DEFBUTTON2) == IDNO)
277+
continue;
278+
return 5;
279+
}
280+
extractPath = extractPathDialog.Value;
281+
break;
282+
}
283+
}
284+
else if (!installPrompt.IsEmpty() && !assumeYes)
199285
{
200286
if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO |
201287
MB_ICONQUESTION) != IDYES)
@@ -210,7 +296,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
210296
}
211297

212298
CTempDir tempDir;
213-
if (!tempDir.Create(kTempDirPrefix))
299+
if (extractPath.IsEmpty() && !tempDir.Create(kTempDirPrefix))
214300
{
215301
if (!assumeYes)
216302
ShowErrorMessage(L"Cannot create temp folder archive");
@@ -228,13 +314,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
228314
}
229315
}
230316

231-
const FString tempDirPath = tempDir.GetPath();
317+
const FString tempDirPath = extractPath.IsEmpty() ? tempDir.GetPath() : extractPath;
232318
// tempDirPath = "M:\\1\\"; // to test low disk space
233319
{
234320
bool isCorrupt = false;
235321
UString errorMessage;
236322
HRESULT result = ExtractArchive(codecs, fullPath, tempDirPath, showProgress,
237-
isCorrupt, errorMessage);
323+
extractDialogText, isCorrupt, errorMessage);
238324

239325
if (result != S_OK)
240326
{

0 commit comments

Comments
 (0)