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