diff --git a/SophiApp/SophiApp/Customisations/CustomisationConstants.cs b/SophiApp/SophiApp/Customisations/CustomisationConstants.cs index 9b7db429..1fc1d7dd 100644 --- a/SophiApp/SophiApp/Customisations/CustomisationConstants.cs +++ b/SophiApp/SophiApp/Customisations/CustomisationConstants.cs @@ -608,6 +608,8 @@ public static extern bool ShowWindowAsync(IntPtr hWnd, int nCmdShow) internal const byte DIALOG_DETAILED_VALUE = 1; internal const string DISABLED = "Disabled"; internal const byte DISABLED_VALUE = 0; + internal const string DOTNET_INSTALL_ARGS = "/install /passive /norestart"; + internal const string DOTNET_LOG_PATTERN = "Microsoft_Windows_Desktop_Runtime_*.log"; internal const string ENABLED = "Enabled"; internal const byte ENABLED_VALUE = 1; internal const string ENTHUSIAST_MODE = "EnthusiastMode"; diff --git a/SophiApp/SophiApp/Customisations/CustomisationOs.cs b/SophiApp/SophiApp/Customisations/CustomisationOs.cs index ce1b33cd..acd9b300 100644 --- a/SophiApp/SophiApp/Customisations/CustomisationOs.cs +++ b/SophiApp/SophiApp/Customisations/CustomisationOs.cs @@ -940,6 +940,38 @@ public static void _352(bool _) } } + public static void _354(bool _) + { + var temp = Environment.GetEnvironmentVariable(TEMP); + var latestRelease = AppHelper.CloudNet6Version.Releases.Where(release => release.ReleaseVersion == $"{AppHelper.CloudNet6Version.LatestRelease}").First(); + var latestRuntime = latestRelease.WindowsDesktop.Files.Where(file => file.Name == "windowsdesktop-runtime-win-x86.exe").First(); + var installer = $@"{temp}\{latestRuntime.Url.Substring(latestRuntime.Url.LastIndexOf('/') + 1)}"; + WebHelper.Download(latestRuntime.Url, installer); + ProcessHelper.StartWait(installer, DOTNET_INSTALL_ARGS); + FileHelper.TryDeleteFile(installer); + Directory.EnumerateFileSystemEntries(temp, DOTNET_LOG_PATTERN) + .ToList() + .ForEach(log => FileHelper.TryDeleteFile(log)); + } + + public static void _355(bool _) => DotNetHelper.Uninstall("windowsdesktop-runtime-6.*-win-x86.exe"); + + public static void _357(bool _) + { + var temp = Environment.GetEnvironmentVariable(TEMP); + var latestRelease = AppHelper.CloudNet6Version.Releases.Where(release => release.ReleaseVersion == $"{AppHelper.CloudNet6Version.LatestRelease}").First(); + var latestRuntime = latestRelease.WindowsDesktop.Files.Where(file => file.Name == "windowsdesktop-runtime-win-x64.exe").First(); + var installer = $@"{temp}\{latestRuntime.Url.Substring(latestRuntime.Url.LastIndexOf('/') + 1)}"; + WebHelper.Download(latestRuntime.Url, installer); + ProcessHelper.StartWait(installer, DOTNET_INSTALL_ARGS); + FileHelper.TryDeleteFile(installer); + Directory.EnumerateFileSystemEntries(temp, DOTNET_LOG_PATTERN) + .ToList() + .ForEach(log => FileHelper.TryDeleteFile(log)); + } + + public static void _358(bool _) => DotNetHelper.Uninstall("windowsdesktop-runtime-6.*-win-x64.exe"); + public static void _500(bool IsChecked) { if (IsChecked) diff --git a/SophiApp/SophiApp/Customisations/CustomisationStatus.cs b/SophiApp/SophiApp/Customisations/CustomisationStatus.cs index 11eeee69..57c1c3e5 100644 --- a/SophiApp/SophiApp/Customisations/CustomisationStatus.cs +++ b/SophiApp/SophiApp/Customisations/CustomisationStatus.cs @@ -448,7 +448,7 @@ public static bool _354() if (HttpHelper.IsOnline) { var cloudNetVersion = AppHelper.CloudNet6Version.LatestRelease; - return DotNetHelper.HasInstalled(cloudNetVersion, DotNetRid.Win_x86) + return DotNetHelper.IsInstalled(cloudNetVersion, DotNetRid.Win_x86) ? throw new DotNetInstalledException(cloudNetVersion) : false; } @@ -456,12 +456,16 @@ public static bool _354() throw new NoInternetConnectionException(); } + public static bool _355() => DotNetHelper.IsInstalled("windowsdesktop-runtime-6.*-win-x86.exe", DotNetRid.Win_x86) + ? false + : throw new FileNotExistException("windowsdesktop-runtime-6.*-win-x86.exe"); + public static bool _357() { if (HttpHelper.IsOnline) { var cloudNetVersion = AppHelper.CloudNet6Version.LatestRelease; - return DotNetHelper.HasInstalled(cloudNetVersion, DotNetRid.Win_x64) + return DotNetHelper.IsInstalled(cloudNetVersion, DotNetRid.Win_x64) ? throw new DotNetInstalledException(cloudNetVersion) : false; } @@ -469,6 +473,10 @@ public static bool _357() throw new NoInternetConnectionException(); } + public static bool _358() => DotNetHelper.IsInstalled("windowsdesktop-runtime-6.*-win-x64.exe", DotNetRid.Win_x86) + ? false + : throw new FileNotExistException("windowsdesktop-runtime-6.*-win-x64.exe"); + public static bool _500() => HttpHelper.IsOnline ? UwpHelper.PackageExist(UWP_MS_WIN_PHOTOS) ? UwpHelper.PackageExist(_500_UWP_HEVC_VIDEO) diff --git a/SophiApp/SophiApp/Dto/MsNetDto.cs b/SophiApp/SophiApp/Dto/MsNetDto.cs index dda046a4..4447a52e 100644 --- a/SophiApp/SophiApp/Dto/MsNetDto.cs +++ b/SophiApp/SophiApp/Dto/MsNetDto.cs @@ -7,5 +7,47 @@ internal class MsNetDto { [JsonProperty("latest-release")] public Version LatestRelease { get; set; } + + [JsonProperty("releases")] + public MsNetRelease[] Releases { get; set; } + } + + internal class MsNetRelease + { + [JsonProperty("release-date")] + public DateTime ReleaseDate { get; set; } + + [JsonProperty("release-version")] + public string ReleaseVersion { get; set; } + + [JsonProperty("windowsdesktop")] + public MsNetWindowsDesktop WindowsDesktop { get; set; } + } + + internal class MsNetWindowsDesktop + { + [JsonProperty("files")] + public MsNetWindowsDesktopFiles[] Files { get; set; } + + [JsonProperty("version")] + public string Version { get; set; } + + [JsonProperty("version-display")] + public string VersionDisplay { get; set; } + } + + internal class MsNetWindowsDesktopFiles + { + [JsonProperty("hash")] + public string Hash { get; set; } + + [JsonProperty("name")] + public string Name { get; set; } + + [JsonProperty("rid")] + public string Rid { get; set; } + + [JsonProperty("url")] + public string Url { get; set; } } } \ No newline at end of file diff --git a/SophiApp/SophiApp/Helpers/DotNetHelper.cs b/SophiApp/SophiApp/Helpers/DotNetHelper.cs index 345edfb0..d4f372f5 100644 --- a/SophiApp/SophiApp/Helpers/DotNetHelper.cs +++ b/SophiApp/SophiApp/Helpers/DotNetHelper.cs @@ -20,11 +20,23 @@ internal class DotNetHelper {DotNetRid.Win_x86, "win-x86" }, {DotNetRid.Win_x64, "win-x64" } }; - internal static bool HasInstalled(Version version, DotNetRid rid) + internal static bool IsInstalled(Version version, DotNetRid rid) { - var runtime = $"dotnet-runtime-{version}-{Platform[rid]}.exe"; + var runtime = $"windowsdesktop-runtime-{version}-{Platform[rid]}.exe"; return Directory.GetFileSystemEntries(ENVIRONMENT_PACKAGE_CACHE, runtime, SearchOption.AllDirectories) .Count() == 1; } + + internal static bool IsInstalled(string runtime, DotNetRid rid) + { + return Directory.GetFileSystemEntries(ENVIRONMENT_PACKAGE_CACHE, runtime, SearchOption.AllDirectories) + .Count() == 1; + } + + internal static void Uninstall(string runtime) + { + var runtimeFile = Directory.GetFileSystemEntries(ENVIRONMENT_PACKAGE_CACHE, runtime, SearchOption.AllDirectories).First(); + ProcessHelper.StartWait(runtimeFile, "/uninstall /passive /norestart"); + } } } \ No newline at end of file