Skip to content

Commit

Permalink
Allows checking for the existance of the snaps
Browse files Browse the repository at this point in the history
Both ubuntu-desktop-installer and subiquity.
For now only the first is relevant.
Soon the second will be.
  • Loading branch information
CarlosNihelton committed Jul 27, 2022
1 parent 7347d7b commit 52c020e
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
33 changes: 32 additions & 1 deletion DistroLauncher/WSLInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,28 @@ namespace Oobe::internal
return ini_find_value(wslConf, L"boot", L"command", L"/usr/libexec/wsl-systemd");
}

bool hasSnap(std::wstring_view name)
{
namespace fs = std::filesystem;
const auto path = Oobe::WindowsPath(fs::path{L"/var/lib/snapd/snaps/"});
return find_file_if(path, [name](const auto& entry) {
return fs::is_regular_file(entry) && starts_with({entry.path().filename().wstring()}, name);
});
}

bool hasUdiSnap()
{
static bool hasUdi = hasSnap(L"ubuntu-desktop-installer");

return hasUdi;
}

bool hasSubiquitySnap()
{
static bool hasSubiquity = hasSnap(L"subiquity");
return hasSubiquity;
}

} // namespace Oobe::internal

// This was kept under Helpers namespace to avoid touching OOBE.cpp/h files.
Expand All @@ -145,8 +167,17 @@ namespace Helpers
{
bool WslGraphicsSupported()
{
// It's possible that we have only Subiquity instead of the Ubuntu-Desktop-Installer snap.
if (!Oobe::internal::hasUdiSnap()) {
return false;
}

if (!Oobe::internal::isWslgEnabled()) {
return false;
}

// Could WSL 3 or greater exist in the future?
return (Oobe::internal::isWslgEnabled() && Oobe::internal::WslGetDistroSubsystemVersion() > 1);
return Oobe::internal::WslGetDistroSubsystemVersion() > 1;
}

} // namespace Helpers.
Expand Down
7 changes: 7 additions & 0 deletions DistroLauncher/WSLInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,13 @@ namespace Oobe::internal
/// <https://docs.microsoft.com/en-us/windows/wsl/wsl-config#:~:text=WSL%202%20VM.-,localhostForwarding,-boolean>
bool isLocalhostForwardingEnabled(const std::filesystem::path& wslConfig);

/// Returns true if the ubuntu-desktop-installer snap is found inside the rootfs.
/// It's possible that we have only Subiquity or none instead.
bool hasUdiSnap();

/// Returns true if the subiquity snap is found inside the rootfs.
/// It's possible that we have the ubuntu-desktop-installer or none instead.
bool hasSubiquitySnap();
}

namespace Oobe
Expand Down

0 comments on commit 52c020e

Please sign in to comment.