5
5
6
6
#include " stdafx.h"
7
7
8
- // Commandline arguments:
8
+ // Commandline arguments:
9
9
#define ARG_CONFIG L" config"
10
10
#define ARG_CONFIG_DEFAULT_USER L" --default-user"
11
11
#define ARG_INSTALL L" install"
12
12
#define ARG_INSTALL_ROOT L" --root"
13
13
#define ARG_RUN L" run"
14
14
#define ARG_RUN_C L" -c"
15
15
16
+ #include < winrt/Windows.Foundation.h>
17
+ #include < winrt/Windows.Storage.h>
18
+
19
+
20
+ using namespace winrt ;
21
+ using namespace Windows ::UI::ViewManagement;
22
+ using namespace Windows ::Foundation;
23
+ using namespace Windows ::System;
24
+ using namespace Windows ::Storage;
25
+
26
+
16
27
// Helper class for calling WSL Functions:
17
28
// https://msdn.microsoft.com/en-us/library/windows/desktop/mt826874(v=vs.85).aspx
18
29
WslApiLoader g_wslApi (DistributionInfo::Name);
@@ -70,7 +81,7 @@ HRESULT SetDefaultUser(std::wstring_view userName)
70
81
return E_INVALIDARG;
71
82
}
72
83
73
- auto hr = g_wslApi.WslConfigureDistribution (uid, WSL_DISTRIBUTION_FLAGS_DEFAULT);
84
+ const auto hr = g_wslApi.WslConfigureDistribution (uid, WSL_DISTRIBUTION_FLAGS_DEFAULT);
74
85
if (FAILED (hr))
75
86
{
76
87
return hr;
@@ -81,7 +92,52 @@ HRESULT SetDefaultUser(std::wstring_view userName)
81
92
return hr;
82
93
}
83
94
84
- int wmain (int argc, wchar_t const * argv[])
95
+ int RetrieveCurrentTheme ()
96
+ {
97
+ DWORD value = 0 ;
98
+ DWORD size = sizeof (value);
99
+
100
+ // ReSharper disable once CppTooWideScope
101
+ const auto status = RegGetValueW (HKEY_CURRENT_USER,
102
+ L" SOFTWARE\\ Microsoft\\ Windows\\ CurrentVersion\\ Themes\\ Personalize" ,
103
+ L" AppsUseLightTheme" ,
104
+ RRF_RT_DWORD,
105
+ nullptr ,
106
+ &value,
107
+ &size
108
+ );
109
+
110
+ if (status == ERROR_SUCCESS)
111
+ {
112
+ return value;
113
+ }
114
+
115
+ return -1 ;
116
+ }
117
+
118
+ fire_and_forget SyncIcons ()
119
+ {
120
+ const int value = RetrieveCurrentTheme ();
121
+ const hstring nameSuffix = value == 0 ? L" " : L" " ;
122
+ const hstring iconName = L" pengwin" ;
123
+
124
+ const hstring extension = L" .png" ;
125
+ const hstring composedPath = iconName + nameSuffix + extension;
126
+ const auto path = Uri (L" ms-appx:///Assets/" + composedPath);
127
+
128
+ try
129
+ {
130
+ const auto iconFile = StorageFile::GetFileFromApplicationUriAsync (path).get ();
131
+
132
+ co_await iconFile.CopyAsync (ApplicationData::Current ().LocalFolder (), iconName + extension,
133
+ NameCollisionOption::ReplaceExisting);
134
+ }
135
+ catch (...)
136
+ {
137
+ }
138
+ }
139
+
140
+ int wmain (int argc, const wchar_t * argv[])
85
141
{
86
142
// Update the title bar of the console window.
87
143
SetConsoleTitleW (DistributionInfo::WindowTitle.c_str ());
@@ -107,12 +163,12 @@ int wmain(int argc, wchar_t const* argv[])
107
163
}
108
164
109
165
// Install the distribution if it is not already.
110
- auto installOnly = ((arguments.size () > 0 ) && (arguments[0 ] == ARG_INSTALL));
166
+ const auto installOnly = ((arguments.size () > 0 ) && (arguments[0 ] == ARG_INSTALL));
111
167
auto hr = S_OK;
112
168
if (!g_wslApi.WslIsDistributionRegistered ())
113
169
{
114
170
// If the "--root" option is specified, do not create a user account.
115
- auto useRoot = ((installOnly) && (arguments.size () > 1 ) && (arguments[1 ] == ARG_INSTALL_ROOT));
171
+ const auto useRoot = ((installOnly) && (arguments.size () > 1 ) && (arguments[1 ] == ARG_INSTALL_ROOT));
116
172
hr = InstallDistribution (!useRoot);
117
173
if (FAILED (hr))
118
174
{
@@ -132,6 +188,8 @@ int wmain(int argc, wchar_t const* argv[])
132
188
// Parse the command line arguments.
133
189
if ((SUCCEEDED (hr)) && (!installOnly))
134
190
{
191
+ SyncIcons ();
192
+
135
193
if (arguments.empty ())
136
194
{
137
195
hr = g_wslApi.WslLaunchInteractive (L" " , false , &exitCode);
0 commit comments