@@ -2308,6 +2308,7 @@ private static void InstallPythonPackage(BenchConfiguration config, IProcessExec
23082308 }
23092309 var argList = new List < string > ( ) ;
23102310 argList . Add ( "install" ) ;
2311+ argList . Add ( "--no-warn-script-location" ) ;
23112312 if ( app . IsInstalled ) argList . Add ( "--upgrade" ) ;
23122313 //argList.Add("--quiet");
23132314 if ( ! app . IsManagedPackageFromRemoteRepo ) // python wheel file
@@ -3008,7 +3009,7 @@ private static void ExportBenchEnvironment(IBenchManager man,
30083009 }
30093010 var sfxArchive = extension == ".exe" ;
30103011 if ( sfxArchive )
3011- ExportBenchEnvironmentSfx ( man , notify , targetFile , paths ) ;
3012+ ExportBenchEnvironmentSetupProgram ( man , notify , targetFile , paths ) ;
30123013 else
30133014 ExportBenchEnvironmentArchive ( man , notify , targetFile , paths ) ;
30143015 }
@@ -3031,58 +3032,113 @@ private static void CopyFileToStream(string file, Stream trg, int bufferSize = 6
30313032 }
30323033 }
30333034
3034- private static TextWriter WriteSfxConfig ( BenchConfiguration cfg , Stream trg , bool withInfoText , bool userProfileChangeWarning )
3035+ private static void WriteSetupText ( string targetDir , string title , bool preConfigured , bool userProfileChangeWarning )
30353036 {
30363037 var enc = new UTF8Encoding ( false ) ;
3037- var w = new StreamWriter ( trg , enc , 1024 ) ;
3038- w . WriteLine ( ";!@Install@!UTF-8!" ) ;
3039- if ( withInfoText )
3038+ File . WriteAllText ( Path . Combine ( targetDir , "Title.txt" ) , title , enc ) ;
3039+ using ( var w = new StreamWriter ( Path . Combine ( targetDir , "Info.txt" ) , append : false , encoding : enc ) )
30403040 {
3041- w . WriteLine ( "Title=\" Bench Transfer Package\" " ) ;
3042- w . Write ( "BeginPrompt=\" This is a pre - configured Bench environment. If you proceed, you will be asked for a target directory to extract and setup the Bench environment.\n \n " ) ;
3043- if ( userProfileChangeWarning )
3041+ if ( preConfigured )
30443042 {
3045- w . Write ( "Warning: Because this bench environment is configured to register in the user profile, the environment variables and possibly some registry keys of your user profile will be modified during setup.\n \n " ) ;
3043+ w . WriteLine ( "This is a pre-configured Bench environment." ) ;
3044+ w . WriteLine ( ) ;
3045+ if ( userProfileChangeWarning )
3046+ {
3047+ w . WriteLine ( "Warning: Because this bench environment is configured to register in the user profile, the environment variables and possibly some registry keys of your user profile will be modified during setup." ) ;
3048+ w . WriteLine ( ) ;
3049+ }
3050+ w . WriteLine ( "See https://winbench.org/ for more info." ) ;
3051+ }
3052+ else
3053+ {
3054+ w . WriteLine ( "This is the standard Bench setup package with the default environment." ) ;
30463055 }
3047- w . WriteLine ( "See https://winbench.org/ for more info.\n \n Are you sure you want to extract and setup this Bench environment?\" " ) ;
30483056 }
3049- w . WriteLine ( @"RunProgram="".\\auto\\bin\\bench.exe --verbose transfer install""" ) ;
3050- w . Write ( ";!@InstallEnd@!" ) ;
3051- w . Flush ( ) ;
3052- return w ;
30533057 }
30543058
3055- private static bool ExportBenchEnvironmentSfx ( IBenchManager man , Action < TaskInfo > notify , string targetFile , string [ ] paths )
3059+ private static bool ExportBenchEnvironmentSetupProgram ( IBenchManager man , Action < TaskInfo > notify , string targetFile , string [ ] paths )
30563060 {
3057- var tmpArchive = Path . Combine (
3061+ var msbuild = Environment . ExpandEnvironmentVariables ( "%SystemRoot%\\ Microsoft.NET\\ Framework64\\ v4.0.30319\\ msbuild.exe" ) ;
3062+ if ( ! File . Exists ( msbuild ) )
3063+ {
3064+ msbuild = Environment . ExpandEnvironmentVariables ( "%SystemRoot%\\ Microsoft.NET\\ Framework\\ v4.0.30319\\ msbuild.exe" ) ;
3065+ }
3066+ if ( ! File . Exists ( msbuild ) )
3067+ {
3068+ notify ( new TaskError ( "Can not find the MSBuild CLI as part of the .NET Framework 4" ) ) ;
3069+ return false ;
3070+ }
3071+
3072+ var tmpDir = Path . Combine (
30583073 man . Config . GetStringValue ( ConfigPropertyKeys . TempDir ) ,
3059- "bench_export_ " + Path . ChangeExtension ( Path . GetRandomFileName ( ) , ".7z " ) ) ;
3074+ "bench_setup_ " + Path . GetRandomFileName ( ) . Replace ( "." , "" ) ) ;
30603075
3061- if ( ! ExportBenchEnvironmentArchive ( man , notify , tmpArchive , paths ) ) return false ;
3076+ Directory . CreateDirectory ( tmpDir ) ;
3077+ var cleanup = true ;
30623078
3063- var sfxPath = Path . Combine ( Path . Combine ( man . Config . BenchRootDir , "res" ) , "bench.sfx" ) ;
30643079 try
30653080 {
3066- using ( var s = File . Open ( targetFile , FileMode . Create , FileAccess . Write ) )
3081+ var setupProjectDir = Path . Combine ( Path . Combine ( man . Config . BenchRootDir , "res" ) , "setup" ) ;
3082+ var fileList = File . ReadAllLines ( Path . Combine ( setupProjectDir , "files.txt" ) ) ;
3083+ foreach ( var file in fileList )
30673084 {
3068- CopyFileToStream ( sfxPath , s ) ;
3069- var userConfigDir = man . Config . GetStringValue ( ConfigPropertyKeys . UserConfigDir ) ;
3070- var includeUserConfig = Seq ( paths ) . Any ( p => string . Equals ( userConfigDir ,
3071- Path . Combine ( man . Config . BenchRootDir , p ) , StringComparison . InvariantCultureIgnoreCase ) ) ;
3072- WriteSfxConfig ( man . Config , s ,
3073- withInfoText : includeUserConfig ,
3074- userProfileChangeWarning : man . Config . GetBooleanValue ( ConfigPropertyKeys . RegisterInUserProfile ) ) ;
3075- CopyFileToStream ( tmpArchive , s ) ;
3085+ if ( string . IsNullOrWhiteSpace ( file ) ) continue ;
3086+ File . Copy ( Path . Combine ( setupProjectDir , file ) , Path . Combine ( tmpDir , file ) ) ;
30763087 }
3077- File . Delete ( tmpArchive ) ;
3088+
3089+ var userConfigDir = man . Config . GetStringValue ( ConfigPropertyKeys . UserConfigDir ) ;
3090+ var includeUserConfig = Seq ( paths ) . Any ( p => string . Equals ( userConfigDir ,
3091+ Path . Combine ( man . Config . BenchRootDir , p ) , StringComparison . InvariantCultureIgnoreCase ) ) ;
3092+
3093+ WriteSetupText ( tmpDir , "Bench Setup" ,
3094+ preConfigured : includeUserConfig ,
3095+ userProfileChangeWarning : man . Config . GetBooleanValue ( ConfigPropertyKeys . RegisterInUserProfile ) ) ;
3096+ var tmpArchive = Path . Combine ( tmpDir , "Bench.zip" ) ;
3097+
3098+ if ( ! ExportBenchEnvironmentArchive ( man , notify , tmpArchive , paths ) ) return false ;
3099+
3100+ if ( File . Exists ( targetFile ) ) File . Delete ( targetFile ) ;
3101+
3102+ var execHost = man . ProcessExecutionHost ;
3103+ var result = execHost . RunProcess ( man . Env , tmpDir , msbuild ,
3104+ string . Join ( " " ,
3105+ "-nologo" ,
3106+ "-verbosity:normal" ,
3107+ "-t:Clean;PrepareResources;Compile" ,
3108+ "-p:Configuration=Release" ,
3109+ "-fileLogger" ,
3110+ "-fileLoggerParameters:logfile=build.log;verbosity=detailed" ,
3111+ "BenchSetup.csproj" ) ,
3112+ ProcessMonitoring . ExitCode ) ;
3113+ if ( result . ExitCode != 0 )
3114+ {
3115+ notify ( new TaskError ( "MSBuild exited with error. Exit status: " + result . ExitCode ) ) ;
3116+ return false ;
3117+ }
3118+
3119+ var setupExe = Path . Combine ( tmpDir , "obj" , "Release" , "BenchSetup.exe" ) ;
3120+ if ( ! File . Exists ( setupExe ) )
3121+ {
3122+ cleanup = false ;
3123+ notify ( new TaskError ( "Compiling the transfer package failed." ) ) ;
3124+ return false ;
3125+ }
3126+ File . Move ( setupExe , targetFile ) ;
30783127 }
30793128 catch ( Exception e )
30803129 {
3081- notify ( new TaskError (
3082- "Failed to export the Bench environment." ,
3130+ notify ( new TaskError ( "Failed to export the Bench environment." ,
30833131 exception : e ) ) ;
30843132 return false ;
30853133 }
3134+ finally
3135+ {
3136+ if ( cleanup )
3137+ {
3138+ Directory . Delete ( tmpDir , true ) ;
3139+ }
3140+ }
3141+
30863142 return true ;
30873143 }
30883144
@@ -3109,7 +3165,6 @@ private static bool ExportBenchEnvironmentArchive(IBenchManager man, Action<Task
31093165 ProcessMonitoring . ExitCode ) ;
31103166 if ( result . ExitCode != 0 )
31113167 {
3112-
31133168 notify ( new TaskError ( $ "Creating export archive with 7zip failed with exit code { result . ExitCode } .") ) ;
31143169 return false ;
31153170 }
0 commit comments