Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show only latest VS, VC prompts by default #11326

Merged
7 commits merged into from
Sep 29, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions src/cascadia/TerminalSettingsModel/BaseVisualStudioGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,17 @@ void BaseVisualStudioGenerator::GenerateProfiles(std::vector<winrt::com_ptr<impl
{
// There's no point in enumerating valid Visual Studio instances more than once,
// so cache them for use by both Visual Studio profile generators.
static const auto instances = VsSetupConfiguration::QueryInstances();
static auto instances = VsSetupConfiguration::QueryInstances();

for (auto const& instance : instances)
// Sort instances based on version and install date.
std::sort(instances.begin(), instances.end(), BaseVisualStudioGenerator::Compare);
heaths marked this conversation as resolved.
Show resolved Hide resolved

// Iterate through instances from newest to oldest.
bool latest = true;
for (auto it = instances.rbegin(); it != instances.rend(); it++)
{
auto const& instance = *it;

try
{
if (!IsInstanceValid(instance))
Expand All @@ -29,8 +36,24 @@ void BaseVisualStudioGenerator::GenerateProfiles(std::vector<winrt::com_ptr<impl
profile->Commandline(winrt::hstring{ GetProfileCommandLine(instance) });
profile->StartingDirectory(winrt::hstring{ instance.GetInstallationPath() });
profile->Icon(winrt::hstring{ GetProfileIconPath() });
profile->Hidden(!latest);
profiles.emplace_back(std::move(profile));

latest = false;
}
CATCH_LOG();
}
}

bool BaseVisualStudioGenerator::Compare(const VsSetupConfiguration::VsSetupInstance& a, const VsSetupConfiguration::VsSetupInstance& b)
{
auto const aVersion = a.GetComparableVersion();
auto const bVersion = b.GetComparableVersion();

if (aVersion == bVersion)
{
return a.GetComparableInstallDate() < b.GetComparableInstallDate();
}

return aVersion < bVersion;
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,8 @@ namespace winrt::Microsoft::Terminal::Settings::Model
virtual std::wstring GetProfileCommandLine(const VsSetupConfiguration::VsSetupInstance& instance) const = 0;
virtual std::wstring GetProfileGuidSeed(const VsSetupConfiguration::VsSetupInstance& instance) const = 0;
virtual std::wstring GetProfileIconPath() const = 0;

private:
static bool Compare(const VsSetupConfiguration::VsSetupInstance& a, const VsSetupConfiguration::VsSetupInstance& b);
};
};
7 changes: 7 additions & 0 deletions src/cascadia/TerminalSettingsModel/VsSetupConfiguration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,13 @@ std::wstring VsSetupConfiguration::GetInstanceId(ISetupInstance* pInst)
return bstrInstanceId.get();
}

unsigned long long VsSetupConfiguration::GetInstallDate(ISetupInstance* pInst)
{
FILETIME ftInstallDate{ 0 };
THROW_IF_FAILED(pInst->GetInstallDate(&ftInstallDate));
return wil::filetime::to_int64(ftInstallDate);
}

std::wstring VsSetupConfiguration::GetStringProperty(ISetupPropertyStore* pProps, std::wstring_view name)
{
if (pProps == nullptr)
Expand Down
48 changes: 46 additions & 2 deletions src/cascadia/TerminalSettingsModel/VsSetupConfiguration.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,15 @@ namespace winrt::Microsoft::Terminal::Settings::Model
public:
struct VsSetupInstance
{
VsSetupInstance(VsSetupInstance&& other) :
query(std::move(other.query)),
inst(std::move(other.inst)),
profileNameSuffix(std::move(other.profileNameSuffix)),
installDate(other.installDate),
version(other.version)
{
}
heaths marked this conversation as resolved.
Show resolved Hide resolved

std::wstring ResolvePath(std::wstring_view relativePath) const
{
return VsSetupConfiguration::ResolvePath(inst.get(), relativePath);
Expand Down Expand Up @@ -65,7 +74,17 @@ namespace winrt::Microsoft::Terminal::Settings::Model

std::wstring GetVersion() const
{
return GetInstallationVersion(inst.get());
return VsSetupConfiguration::GetInstallationVersion(inst.get());
}

unsigned long long GetComparableInstallDate() const
{
return installDate;
}

unsigned long long GetComparableVersion() const
{
return version;
}

std::wstring GetInstallationPath() const
Expand Down Expand Up @@ -116,13 +135,17 @@ namespace winrt::Microsoft::Terminal::Settings::Model
return profileNameSuffix;
}

VsSetupInstance& operator=(VsSetupInstance&&) = default;

private:
friend class VsSetupConfiguration;

VsSetupInstance(ComPtrSetupQuery pQuery, ComPtrSetupInstance pInstance) :
query(std::move(pQuery)),
inst(std::move(pInstance)),
profileNameSuffix(BuildProfileNameSuffix())
profileNameSuffix(BuildProfileNameSuffix()),
installDate(GetInstallDate()),
version(GetInstallationVersion())
{
}

Expand All @@ -131,6 +154,10 @@ namespace winrt::Microsoft::Terminal::Settings::Model

std::wstring profileNameSuffix;

// Cache oft-accessed properties used in sorting.
unsigned long long installDate;
unsigned long long version;

std::wstring BuildProfileNameSuffix() const
{
ComPtrCatalogPropertyStore catalogProperties = GetCatalogPropertyStore();
Expand Down Expand Up @@ -167,6 +194,22 @@ namespace winrt::Microsoft::Terminal::Settings::Model
return GetVersion();
}

unsigned long long GetInstallDate() const
{
return VsSetupConfiguration::GetInstallDate(inst.get());
}

unsigned long long GetInstallationVersion() const
heaths marked this conversation as resolved.
Show resolved Hide resolved
{
const auto helper = wil::com_query<ISetupHelper>(query);

std::wstring versionString{ GetVersion() };
unsigned long long version{ 0 };

THROW_IF_FAILED(helper->ParseVersion(versionString.data(), &version));
return version;
}

static std::wstring GetChannelNameSuffixTag(ISetupPropertyStore* instanceProperties)
{
std::wstring tag;
Expand Down Expand Up @@ -229,6 +272,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model
static std::wstring GetInstallationVersion(ISetupInstance* pInst);
static std::wstring GetInstallationPath(ISetupInstance* pInst);
static std::wstring GetInstanceId(ISetupInstance* pInst);
static unsigned long long GetInstallDate(ISetupInstance* pInst);
static std::wstring GetStringProperty(ISetupPropertyStore* pProps, std::wstring_view name);
};
};