Skip to content

Commit a3ce99c

Browse files
crramirezCopilot
andauthored
Pengwin: support migration from WLinux, improve WSL launch behavior, and update branding & terminal profiles (#814)
* Upgrade to Pengwin 26.2.1: enhance WSL compatibility, update executable paths, improve directory handling, introduce additional features, and refresh assets and app manifest. * Update DistroLauncher/DistroLauncher.cpp Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
1 parent fa1a583 commit a3ce99c

File tree

60 files changed

+53
-58
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+53
-58
lines changed

DistroLauncher/DistributionInfo.cpp

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,11 @@
55

66
#include "stdafx.h"
77

8-
HRESULT DistributionInfo::ChangeDefaultUserInWslConf(const std::wstring_view userName)
9-
{
10-
DWORD exitCode = 0;
11-
12-
wchar_t commandLine[255];
13-
_swprintf_p(commandLine, _countof(commandLine),
14-
L"if [ $(grep -c \"\\[user\\]\" /etc/wsl.conf) -eq \"0\" ]; then echo -e \"\\n[user]\\ndefault=%1$s\">>/etc/wsl.conf; else sed -i \"s/\\(default=\\)\\(.*\\)/\\1%1$s/\" /etc/wsl.conf ; fi",
15-
std::wstring(userName).c_str());
16-
17-
if (const auto hr = g_wslApi.WslLaunchInteractive(commandLine, true, &exitCode); FAILED(hr) || exitCode != 0)
18-
{
19-
return hr;
20-
}
21-
22-
return 0;
23-
}
24-
258
bool DistributionInfo::CreateUser(std::wstring_view userName)
269
{
2710
// Create the user account.
2811
DWORD exitCode;
29-
std::wstring commandLine = L"/usr/sbin/adduser --quiet --gecos '' ";
12+
std::wstring commandLine = L"/usr/sbin/adduser --quiet --comment '' ";
3013
commandLine += userName;
3114
auto hr = g_wslApi.WslLaunchInteractive(commandLine.c_str(), true, &exitCode);
3215
if (FAILED(hr) || exitCode != 0)

DistroLauncher/DistributionInfo.h

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ namespace DistributionInfo
1313
//
1414
// WARNING: This value must not change between versions of your app,
1515
// otherwise users upgrading from older versions will see launch failures.
16-
const std::wstring NAME = L"WLinux";
16+
const std::wstring NAME = L"Pengwin";
17+
const std::wstring NAME_OLD = L"WLinux";
1718

1819
// The title bar for the console window while the distribution is installing.
1920
const std::wstring WINDOW_TITLE = L"Pengwin";
@@ -23,7 +24,4 @@ namespace DistributionInfo
2324

2425
// Query the UID of the user account.
2526
ULONG QueryUid(std::wstring_view userName);
26-
27-
// Changes the default user in /etc/wsl.conf
28-
HRESULT ChangeDefaultUserInWslConf(std::wstring_view userName);
2927
}

DistroLauncher/DistroLauncher.cpp

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ using namespace Windows::Storage;
3030
// Helper class for calling WSL Functions:
3131
// https://msdn.microsoft.com/en-us/library/windows/desktop/mt826874(v=vs.85).aspx
3232
// ReSharper disable once CppInconsistentNaming
33-
WslApiLoader g_wslApi(DistributionInfo::NAME);
33+
WslApiLoader g_wslApi(DistributionInfo::NAME, DistributionInfo::NAME_OLD);
3434

3535
static HRESULT InstallDistribution(bool createUser);
3636
static HRESULT SetDefaultUser(std::wstring_view userName);
@@ -85,20 +85,7 @@ HRESULT SetDefaultUser(std::wstring_view userName)
8585
return E_INVALIDARG;
8686
}
8787

88-
// Set the default user as root, so ChangeDefaultUserInWslConf chan make the change
89-
HRESULT hr = g_wslApi.WslConfigureDistribution(0, WSL_DISTRIBUTION_FLAGS_DEFAULT);
90-
if (FAILED(hr))
91-
{
92-
return hr;
93-
}
94-
95-
hr = DistributionInfo::ChangeDefaultUserInWslConf(userName);
96-
if (FAILED(hr))
97-
{
98-
return hr;
99-
}
100-
101-
hr = g_wslApi.WslConfigureDistribution(uid, WSL_DISTRIBUTION_FLAGS_DEFAULT);
88+
HRESULT hr = g_wslApi.WslConfigureDistribution(uid, WSL_DISTRIBUTION_FLAGS_DEFAULT);
10289
if (FAILED(hr))
10390
{
10491
return hr;
@@ -172,6 +159,17 @@ fire_and_forget ShowPengwinUi()
172159
}
173160
}
174161

162+
static bool is_current_dir_not_system32()
163+
{
164+
wchar_t system_32dir[MAX_PATH];
165+
GetSystemDirectoryW(system_32dir, MAX_PATH);
166+
167+
wchar_t current_dir[MAX_PATH];
168+
GetCurrentDirectoryW(MAX_PATH, current_dir);
169+
170+
return _wcsicmp(system_32dir, current_dir) != 0;
171+
}
172+
175173
// ReSharper disable once IdentifierTypo
176174
int wmain(const int argc, const wchar_t* argv[])
177175
{
@@ -201,13 +199,6 @@ int wmain(const int argc, const wchar_t* argv[])
201199
// Install the distribution if it is not already.
202200
const auto installOnly = arguments.size() > 0 && arguments[0] == ARG_INSTALL;
203201
auto hr = S_OK;
204-
/*
205-
206-
if (!g_wslApi.WslIsDistributionRegistered())
207-
{
208-
g_wslApi.SetDistributionName(L"Pengwin");
209-
}
210-
*/
211202

212203
if (!g_wslApi.WslIsDistributionRegistered())
213204
{
@@ -246,7 +237,11 @@ int wmain(const int argc, const wchar_t* argv[])
246237

247238
if (arguments.empty())
248239
{
249-
hr = g_wslApi.WslLaunchInteractive(L"", false, &exitCode);
240+
/* If the current working dir is not System32 then it was called from Open with Terminal
241+
option or from command line. In this case is better to start the distro in the current directory */
242+
const bool useCurrentWorkingDirectory = is_current_dir_not_system32();
243+
244+
hr = g_wslApi.WslLaunchInteractive(L"", useCurrentWorkingDirectory, &exitCode);
250245

251246
// Check exitCode to see if wsl.exe returned that it could not start the Linux process
252247
// then prompt users for input so they can view the error message.

DistroLauncher/WslApiLoader.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@
66
#include "stdafx.h"
77
#include "WslApiLoader.h"
88

9-
WslApiLoader::WslApiLoader(const std::wstring& distributionName) :
10-
_distributionName(distributionName)
9+
WslApiLoader::WslApiLoader(const std::wstring& distributionName, const std::wstring& distributionNameOld) :
10+
_distributionName(distributionName),
11+
_distributionNameOld(distributionNameOld)
1112
{
1213
_wslApiDll = LoadLibraryEx(L"wslapi.dll", nullptr, LOAD_LIBRARY_SEARCH_SYSTEM32);
1314
if (_wslApiDll != nullptr)
@@ -40,9 +41,18 @@ BOOL WslApiLoader::WslIsOptionalComponentInstalled() const
4041
_launch != nullptr;
4142
}
4243

43-
BOOL WslApiLoader::WslIsDistributionRegistered() const
44+
BOOL WslApiLoader::WslIsDistributionRegistered()
4445
{
45-
return _isDistributionRegistered(_distributionName.c_str());
46+
if (!_isDistributionRegistered(_distributionName.c_str()))
47+
{
48+
if (!_isDistributionRegistered(_distributionNameOld.c_str()))
49+
{
50+
return FALSE;
51+
}
52+
_distributionName = _distributionNameOld;
53+
return TRUE;
54+
}
55+
return TRUE;
4656
}
4757

4858
HRESULT WslApiLoader::WslRegisterDistribution() const

DistroLauncher/WslApiLoader.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@ using WSL_LAUNCH = HRESULT(STDAPICALLTYPE*)(PCWSTR, PCWSTR, BOOL, HANDLE, HANDLE
2323
class WslApiLoader
2424
{
2525
public:
26-
WslApiLoader(const std::wstring& distributionName);
26+
WslApiLoader(const std::wstring& distributionName, const std::wstring& distributionNameOld);
2727
~WslApiLoader();
2828

2929
BOOL WslIsOptionalComponentInstalled() const;
3030

31-
BOOL WslIsDistributionRegistered() const;
31+
BOOL WslIsDistributionRegistered();
3232

3333
HRESULT WslRegisterDistribution() const;
3434

@@ -52,6 +52,7 @@ class WslApiLoader
5252

5353
private:
5454
std::wstring _distributionName;
55+
std::wstring _distributionNameOld;
5556
HMODULE _wslApiDll;
5657
WSL_IS_DISTRIBUTION_REGISTERED _isDistributionRegistered;
5758
WSL_REGISTER_DISTRIBUTION _registerDistribution;

Pengwin/Assets/background1.png

33.4 KB

Pengwin/Assets/background2.png

95.4 KB

Pengwin/Assets/pengwin.png

-1.31 KB
13.8 KB
22.7 KB

0 commit comments

Comments
 (0)