@@ -293,28 +293,8 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
293293 hr = _engine->SetVariableNumeric (L" CompileAll" , installAllUsers);
294294 ExitOnFailure (hr, L" Failed to update CompileAll" );
295295
296- hr = BalGetStringVariable (L" TargetDir" , &targetDir);
297- if (FAILED (hr) || !targetDir || !targetDir[0 ]) {
298- ReleaseStr (targetDir);
299- targetDir = nullptr ;
300-
301- hr = BalGetStringVariable (
302- installAllUsers ? L" DefaultAllUsersTargetDir" : L" DefaultJustForMeTargetDir" ,
303- &defaultDir
304- );
305- BalExitOnFailure (hr, " Failed to get the default install directory" );
306-
307- if (!defaultDir || !defaultDir[0 ]) {
308- BalLogError (E_INVALIDARG, " Default install directory is blank" );
309- }
310-
311- hr = BalFormatString (defaultDir, &targetDir);
312- BalExitOnFailure1 (hr, " Failed to format '%ls'" , defaultDir);
313-
314- hr = _engine->SetVariableString (L" TargetDir" , targetDir);
315- BalExitOnFailure (hr, " Failed to set install target directory" );
316- }
317- ReleaseStr (targetDir);
296+ hr = EnsureTargetDir ();
297+ ExitOnFailure (hr, L" Failed to set TargetDir" );
318298
319299 OnPlan (BOOTSTRAPPER_ACTION_INSTALL);
320300 break ;
@@ -2972,6 +2952,39 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
29722952 return ;
29732953 }
29742954
2955+ HRESULT EnsureTargetDir () {
2956+ LONGLONG installAllUsers;
2957+ LPWSTR targetDir = nullptr , defaultDir = nullptr ;
2958+ HRESULT hr = BalGetStringVariable (L" TargetDir" , &targetDir);
2959+ if (FAILED (hr) || !targetDir || !targetDir[0 ]) {
2960+ ReleaseStr (targetDir);
2961+ targetDir = nullptr ;
2962+
2963+ hr = BalGetNumericVariable (L" InstallAllUsers" , &installAllUsers);
2964+ ExitOnFailure (hr, L" Failed to get install scope" );
2965+
2966+ hr = BalGetStringVariable (
2967+ installAllUsers ? L" DefaultAllUsersTargetDir" : L" DefaultJustForMeTargetDir" ,
2968+ &defaultDir
2969+ );
2970+ BalExitOnFailure (hr, " Failed to get the default install directory" );
2971+
2972+ if (!defaultDir || !defaultDir[0 ]) {
2973+ BalLogError (E_INVALIDARG, " Default install directory is blank" );
2974+ }
2975+
2976+ hr = BalFormatString (defaultDir, &targetDir);
2977+ BalExitOnFailure1 (hr, " Failed to format '%ls'" , defaultDir);
2978+
2979+ hr = _engine->SetVariableString (L" TargetDir" , targetDir);
2980+ BalExitOnFailure (hr, " Failed to set install target directory" );
2981+ }
2982+ LExit:
2983+ ReleaseStr (defaultDir);
2984+ ReleaseStr (targetDir);
2985+ return hr;
2986+ }
2987+
29752988public:
29762989 //
29772990 // Constructor - initialize member variables.
@@ -3057,6 +3070,7 @@ class PythonBootstrapperApplication : public CBalBaseBootstrapperApplication {
30573070 _baFunction = nullptr ;
30583071
30593072 LoadOptionalFeatureStates (pEngine);
3073+ EnsureTargetDir ();
30603074 }
30613075
30623076
0 commit comments