mirror of
https://github.com/velopack/velopack.git
synced 2025-10-25 15:19:22 +00:00
Check for .net 5 during setup
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "stdafx.h"
|
||||
#include "FxHelper.h"
|
||||
#include "resource.h"
|
||||
#include <string>
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/hh925568(v=vs.110).aspx#net_b
|
||||
static const wchar_t* ndpPath = L"SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full";
|
||||
@@ -17,7 +18,7 @@ static const int fx48ReleaseVersion = 528040; // Minimum version for .NET 4.8
|
||||
|
||||
// According to https://msdn.microsoft.com/en-us/library/8z6watww%28v=vs.110%29.aspx,
|
||||
// to install .NET 4.5 we must be Vista SP2+, Windows 7 SP1+, or later.
|
||||
// However Ana<6E>s thinks this is just for customer support, anything >= Vista will generally work.
|
||||
// However Ana<6E>s thinks this is just for customer support, anything >= Vista will generally work.
|
||||
bool CFxHelper::CanInstallDotNet4_5()
|
||||
{
|
||||
return IsWindowsVistaOrGreater();
|
||||
@@ -58,6 +59,33 @@ bool CFxHelper::IsDotNetInstalled(NetVersion required)
|
||||
return true;
|
||||
}
|
||||
|
||||
std::string exec(const char* cmd) {
|
||||
char buffer[128];
|
||||
std::string result = "";
|
||||
FILE* pipe = _popen(cmd, "r");
|
||||
if (!pipe)
|
||||
return "";
|
||||
try {
|
||||
while (fgets(buffer, sizeof buffer, pipe) != NULL) {
|
||||
result += buffer;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
_pclose(pipe);
|
||||
return "";
|
||||
}
|
||||
_pclose(pipe);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CFxHelper::IsNet50Installed()
|
||||
{
|
||||
// it might be better to parse this registry entry, but this entry only shows a single version
|
||||
// static const wchar_t* dncPath = L"SOFTWARE\\dotnet\\Setup\\InstalledVersions";
|
||||
auto runtimes = exec("dotnet --list-runtimes");
|
||||
return runtimes.find("Desktop.App 5.0") != std::string::npos;
|
||||
}
|
||||
|
||||
UINT CFxHelper::GetDotNetVersionReleaseNumber(NetVersion version)
|
||||
{
|
||||
switch (version) {
|
||||
|
||||
@@ -5,11 +5,15 @@ enum class NetVersion {net45=0, net451=1, net452=2, net46=3, net461=4, net462=5,
|
||||
class CFxHelper
|
||||
{
|
||||
public:
|
||||
static bool IsNet50Installed();
|
||||
private:
|
||||
// CS - these are public methods i've relocated,
|
||||
// since I need net5.0 and can't be bothered to implement support for it properly
|
||||
static NetVersion GetRequiredDotNetVersion();
|
||||
static bool CanInstallDotNet4_5();
|
||||
static bool IsDotNetInstalled(NetVersion requiredVersion);
|
||||
static HRESULT InstallDotNetFramework(NetVersion version, bool isQuiet);
|
||||
private:
|
||||
// these are real private methods
|
||||
static HRESULT HandleRebootRequirement(bool isQuiet);
|
||||
static bool WriteRunOnceEntry();
|
||||
static bool RebootSystem();
|
||||
|
||||
@@ -80,29 +80,37 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance,
|
||||
goto out;
|
||||
}
|
||||
|
||||
if (!CFxHelper::CanInstallDotNet4_5()) {
|
||||
// Explain this as nicely as possible and give up.
|
||||
MessageBox(0L, L"This program cannot run on Windows XP or before; it requires a later version of Windows.", L"Incompatible Operating System", 0);
|
||||
if (!CFxHelper::IsNet50Installed())
|
||||
{
|
||||
// we should probably try to install this at some point instead of giving up
|
||||
CUpdateRunner::DisplayErrorMessage(CString(L"dotnet 5.0 desktop runtime must be installed to run this application."), NULL);
|
||||
exitCode = E_FAIL;
|
||||
goto out;
|
||||
}
|
||||
|
||||
NetVersion requiredVersion = CFxHelper::GetRequiredDotNetVersion();
|
||||
//if (!CFxHelper::CanInstallDotNet4_5()) {
|
||||
// // Explain this as nicely as possible and give up.
|
||||
// MessageBox(0L, L"This program cannot run on Windows XP or before; it requires a later version of Windows.", L"Incompatible Operating System", 0);
|
||||
// exitCode = E_FAIL;
|
||||
// goto out;
|
||||
//}
|
||||
|
||||
if (!CFxHelper::IsDotNetInstalled(requiredVersion)) {
|
||||
hr = CFxHelper::InstallDotNetFramework(requiredVersion, isQuiet);
|
||||
if (FAILED(hr)) {
|
||||
exitCode = hr; // #yolo
|
||||
CUpdateRunner::DisplayErrorMessage(CString(L"Failed to install the .NET Framework, try installing the latest version manually"), NULL);
|
||||
goto out;
|
||||
}
|
||||
|
||||
// S_FALSE isn't failure, but we still shouldn't try to install
|
||||
if (hr != S_OK) {
|
||||
exitCode = 0;
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
//NetVersion requiredVersion = CFxHelper::GetRequiredDotNetVersion();
|
||||
|
||||
//if (!CFxHelper::IsDotNetInstalled(requiredVersion)) {
|
||||
// hr = CFxHelper::InstallDotNetFramework(requiredVersion, isQuiet);
|
||||
// if (FAILED(hr)) {
|
||||
// exitCode = hr; // #yolo
|
||||
// CUpdateRunner::DisplayErrorMessage(CString(L"Failed to install the .NET Framework, try installing the latest version manually"), NULL);
|
||||
// goto out;
|
||||
// }
|
||||
//
|
||||
// // S_FALSE isn't failure, but we still shouldn't try to install
|
||||
// if (hr != S_OK) {
|
||||
// exitCode = 0;
|
||||
// goto out;
|
||||
// }
|
||||
//}
|
||||
|
||||
// If we're UAC-elevated, we shouldn't be because it will give us permissions
|
||||
// problems later. Just silently rerun ourselves.
|
||||
|
||||
Reference in New Issue
Block a user