55#include " packages.h"
66#include " install.h"
77#include " MachineTypeAttributes.h"
8+ #include < fcntl.h>
9+ #include < io.h>
10+ #include < mutex>
811
912EXTERN_C IMAGE_DOS_HEADER __ImageBase;
1013
@@ -18,11 +21,45 @@ using namespace WindowsAppRuntimeInstaller::Console;
1821
1922namespace WindowsAppRuntimeInstaller
2023{
24+ static void RenderProgress (uint32_t percent)
25+ {
26+ constexpr size_t barWidth{ 50 };
27+
28+ double percentAsDouble{ static_cast <double >(percent) / 100.0 };
29+ int filled{ static_cast <int >(std::floor (barWidth * percentAsDouble)) };
30+ if ((filled == 0 ) && (percentAsDouble > 0.0 ))
31+ {
32+ // Progress is more than 0% so show at least 1 bar
33+ filled = 1 ;
34+ }
35+
36+ std::wstring bar;
37+ bar.reserve (barWidth);
38+ bar.append (static_cast <size_t >(filled), L' \u2588 ' );
39+ bar.append (static_cast <size_t >(barWidth - filled), L' ' );
40+
41+ wprintf (L" \r [%s] %0.2lf" , bar.c_str (), percentAsDouble * 100.0 );
42+ fflush (stdout);
43+ }
2144
2245 HRESULT GetAndLogDeploymentOperationResult (
2346 WindowsAppRuntimeInstaller::InstallActivity::Context& installActivityContext,
2447 const winrt::Windows::Foundation::IAsyncOperationWithProgress<winrt::Windows::Management::Deployment::DeploymentResult, winrt::Windows::Management::Deployment::DeploymentProgress> deploymentOperation)
2548 {
49+ if (_isatty (_fileno (stdout)))
50+ {
51+ static std::once_flag s_setConsoleUtf16Once;
52+ std::call_once (s_setConsoleUtf16Once, []()
53+ {
54+ _setmode (_fileno (stdout), _O_U16TEXT);
55+ });
56+
57+ deploymentOperation.Progress ([&](auto const &, winrt::Windows::Management::Deployment::DeploymentProgress const & progress)
58+ {
59+ RenderProgress (progress.percentage );
60+ });
61+ }
62+
2663 deploymentOperation.get ();
2764 if (deploymentOperation.Status () != AsyncStatus::Completed)
2865 {
@@ -335,6 +372,7 @@ namespace WindowsAppRuntimeInstaller
335372
336373 if (!quiet)
337374 {
375+ std::wcout << std::endl;
338376 std::wcout << L" Deploying package: " << packageProperties->fullName .get () << std::endl;
339377 }
340378
@@ -379,6 +417,7 @@ namespace WindowsAppRuntimeInstaller
379417 }
380418 if (!quiet)
381419 {
420+ std::wcout << std::endl;
382421 std::wcout << " Package deployment result : 0x" << std::hex << hrDeploymentResult << " " ;
383422 DisplayError (hrDeploymentResult);
384423 }
0 commit comments