Skip to content

Commit

Permalink
NET运行时安装方法返回结果
Browse files Browse the repository at this point in the history
  • Loading branch information
nnhy committed Mar 13, 2024
1 parent e99b8a5 commit 1eda410
Showing 1 changed file with 62 additions and 45 deletions.
107 changes: 62 additions & 45 deletions Stardust/Managers/NetRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ static Version GetLast(IList<VerInfo> vers, String? prefix = null, String? suffi
#if NET5_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public void InstallNet40()
public Boolean InstallNet40()
{
var vers = new List<VerInfo>();
vers.AddRange(Get1To45VersionFromRegistry());
Expand All @@ -212,7 +212,7 @@ public void InstallNet40()
if (!Force && ver >= target)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

var rs = Install("dotNetFx40_Full_x86_x64.exe", null);
Expand All @@ -234,14 +234,17 @@ public void InstallNet40()
}
#endif

rs = Install("dotNetFx40_Full_x86_x64.exe", null);
}

return rs;
}

/// <summary>安装.NET4.5</summary>
#if NET5_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public void InstallNet45()
public Boolean InstallNet45()
{
var vers = new List<VerInfo>();
vers.AddRange(Get1To45VersionFromRegistry());
Expand All @@ -253,18 +256,20 @@ public void InstallNet45()
if (!Force && ver >= target)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

Install("NDP452-KB2901907-x86-x64-AllOS-ENU.exe");
var rs = Install("NDP452-KB2901907-x86-x64-AllOS-ENU.exe");
Install("NDP452-KB2901907-x86-x64-AllOS-CHS.exe");

return rs;
}

/// <summary>安装.NET4.8</summary>
#if NET5_0_OR_GREATER
[SupportedOSPlatform("windows")]
#endif
public void InstallNet48()
public Boolean InstallNet48()
{
var vers = new List<VerInfo>();
vers.AddRange(Get1To45VersionFromRegistry());
Expand All @@ -278,7 +283,7 @@ public void InstallNet48()
if (!Force && ver >= target)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

#if NET20
Expand All @@ -302,22 +307,25 @@ public void InstallNet48()
}

// win10/win11 中安装 .NET4.8.1
var rs = false;
if (osVer.Major >= 10)
{
Install("ndp481-x86-x64-allos-enu.exe", null, "/passive /promptrestart /showfinalerror");
rs = Install("ndp481-x86-x64-allos-enu.exe", null, "/passive /promptrestart /showfinalerror");
Install("ndp481-x86-x64-allos-chs.exe", null, "/passive /promptrestart /showfinalerror");
}
else
{
Install("ndp48-x86-x64-allos-enu.exe", null, "/passive /promptrestart /showfinalerror");
rs = Install("ndp48-x86-x64-allos-enu.exe", null, "/passive /promptrestart /showfinalerror");
Install("ndp48-x86-x64-allos-chs.exe", null, "/passive /promptrestart /showfinalerror");
}

return rs;
}

/// <summary>安装.NET6.0</summary>
/// <param name="target">目标版本。包括子版本,如6.0.15</param>
/// <param name="kind">安装类型。如aspnet/desktop/host</param>
public void InstallNet6(String target, String? kind = null)
public Boolean InstallNet6(String target, String? kind = null)
{
var vers = GetNetCore();

Expand All @@ -330,7 +338,7 @@ public void InstallNet6(String target, String? kind = null)
if (!Force && ver >= targetVer)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

#if NET20
Expand All @@ -356,22 +364,23 @@ public void InstallNet6(String target, String? kind = null)
}
}

var rs = false;
if (is64)
{
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x64.exe");
Install($"aspnetcore-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x64.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x64.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x64.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
break;
}
}
Expand All @@ -380,26 +389,28 @@ public void InstallNet6(String target, String? kind = null)
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x86.exe");
Install($"aspnetcore-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x86.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x86.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x86.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
break;
}
}

return rs;
}

/// <summary>安装.NET7.0</summary>
/// <param name="target">目标版本。包括子版本,如6.0.15</param>
/// <param name="kind">安装类型。如aspnet/desktop/host</param>
public void InstallNet7(String target, String? kind = null)
public Boolean InstallNet7(String target, String? kind = null)
{
var vers = GetNetCore();

Expand All @@ -412,7 +423,7 @@ public void InstallNet7(String target, String? kind = null)
if (!Force && ver >= targetVer)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

#if NET20
Expand All @@ -438,22 +449,23 @@ public void InstallNet7(String target, String? kind = null)
}
}

var rs = false;
if (is64)
{
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x64.exe");
Install($"aspnetcore-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x64.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x64.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x64.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
break;
}
}
Expand All @@ -462,26 +474,28 @@ public void InstallNet7(String target, String? kind = null)
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x86.exe");
Install($"aspnetcore-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x86.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x86.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x86.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
break;
}
}

return rs;
}

/// <summary>安装.NET8.0</summary>
/// <param name="target">目标版本。包括子版本,如6.0.15</param>
/// <param name="kind">安装类型。如aspnet/desktop/host</param>
public void InstallNet8(String target, String? kind = null)
public Boolean InstallNet8(String target, String? kind = null)
{
var vers = GetNetCore();

Expand All @@ -494,7 +508,7 @@ public void InstallNet8(String target, String? kind = null)
if (!Force && ver >= targetVer)
{
WriteLog("已安装最新版 v{0}", ver);
return;
return false;
}

#if NET20
Expand All @@ -520,22 +534,23 @@ public void InstallNet8(String target, String? kind = null)
}
}

var rs = false;
if (is64)
{
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x64.exe");
Install($"aspnetcore-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x64.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x64.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x64.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x64.exe");
rs = Install($"dotnet-runtime-{target}-win-x64.exe");
break;
}
}
Expand All @@ -544,20 +559,22 @@ public void InstallNet8(String target, String? kind = null)
switch (kind)
{
case "aspnet":
Install($"dotnet-runtime-{target}-win-x86.exe");
Install($"aspnetcore-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"aspnetcore-runtime-{target}-win-x86.exe");
break;
case "desktop":
Install($"windowsdesktop-runtime-{target}-win-x86.exe");
rs = Install($"windowsdesktop-runtime-{target}-win-x86.exe");
break;
case "host":
Install($"dotnet-hosting-{target}-win.exe");
rs = Install($"dotnet-hosting-{target}-win.exe");
break;
default:
Install($"dotnet-runtime-{target}-win-x86.exe");
rs = Install($"dotnet-runtime-{target}-win-x86.exe");
break;
}
}

return rs;
}

/// <summary>在Linux上安装.NET运行时</summary>
Expand Down

0 comments on commit 1eda410

Please sign in to comment.