This commit is contained in:
2025-10-28 10:46:46 +01:00
parent 8f851ef9fe
commit c27646dfa0
3 changed files with 36 additions and 18 deletions

View File

@@ -24,7 +24,7 @@ namespace Perfect11
private List<IPlugin> _tweaks = new List<IPlugin>(); private List<IPlugin> _tweaks = new List<IPlugin>();
private CancellationTokenSource _cts; private CancellationTokenSource _cts;
private bool _isDownloading = false; private bool _isDownloading = false;
string url = $"https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26200.6584.250915-1905.25h2_ge_release_svc_refresh_CLIENT_CONSUMER_x64FRE_{Utilities.GetLanguageCode()}.iso"; string url = $"https://software-static.download.prss.microsoft.com/dbazure/888969d5-f34g-4e03-ac9d-1f9786c66749/26200.6584.250915-1905.25h2_ge_release_svc_refresh_CLIENT_CONSUMER_{Utilities.GetSystemArchitecture()}FRE_{Utilities.GetLanguageCode()}.iso";
string destination = Path.Combine(@"C:\Temp", @"windows.iso"); string destination = Path.Combine(@"C:\Temp", @"windows.iso");
private static string AppEdition = "Perfect11 Community Edition"; private static string AppEdition = "Perfect11 Community Edition";
public Form1() public Form1()
@@ -464,6 +464,11 @@ namespace Perfect11
private void poisonComboBox1_SelectedIndexChanged(object sender, EventArgs e) private void poisonComboBox1_SelectedIndexChanged(object sender, EventArgs e)
{ {
if (Utilities.GetSystemArchitecture().ToLower() == "a64" && upgradeMethod.SelectedIndex != 0 && upgradeMethod.SelectedIndex != 3)
{
upgradeMethod.SelectedIndex = 0;
MessageBox.Show("You're running Windows on ARM, some options are not available.", "Perfect11", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
statusLabel.Text = "Ready."; statusLabel.Text = "Ready.";
installProgress.Value = 0; installProgress.Value = 0;
upgradeButton.Enabled = true; upgradeButton.Enabled = true;
@@ -669,21 +674,16 @@ namespace Perfect11
byte[] buffer = new byte[8192]; byte[] buffer = new byte[8192];
int bytesRead; int bytesRead;
DateTime lastUpdate = DateTime.Now; DateTime lastUpdate = DateTime.Now;
while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length, token)) > 0) while ((bytesRead = await contentStream.ReadAsync(buffer, 0, buffer.Length, token)) > 0)
{ {
await fileStream.WriteAsync(buffer, 0, bytesRead, token); await fileStream.WriteAsync(buffer, 0, bytesRead, token);
totalRead += bytesRead; totalRead += bytesRead;
if (totalBytes.HasValue) if (totalBytes.HasValue)
{ {
int progress = (int)((totalRead * 100L) / totalBytes.Value); int progress = (int)((totalRead * 100L) / totalBytes.Value);
if (progress > 100) progress = 100; if (progress > 100) progress = 100;
installProgress.Value = progress; installProgress.Value = progress;
statusLabel.Text = $"ISO Download Progress: {progress}%"; statusLabel.Text = $"ISO Download Progress: {progress}%";
// Aggiorna la UI ogni ~200ms
if ((DateTime.Now - lastUpdate).TotalMilliseconds > 200) if ((DateTime.Now - lastUpdate).TotalMilliseconds > 200)
{ {
Application.DoEvents(); Application.DoEvents();
@@ -699,7 +699,6 @@ namespace Perfect11
string sevenZipPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"Tools\7z.exe"); string sevenZipPath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), @"Tools\7z.exe");
if (!File.Exists(sevenZipPath)) if (!File.Exists(sevenZipPath))
throw new FileNotFoundException("7-Zip not found."); throw new FileNotFoundException("7-Zip not found.");
ProcessStartInfo psi = new ProcessStartInfo ProcessStartInfo psi = new ProcessStartInfo
{ {
FileName = sevenZipPath, FileName = sevenZipPath,
@@ -708,15 +707,12 @@ namespace Perfect11
UseShellExecute = false, UseShellExecute = false,
CreateNoWindow = true CreateNoWindow = true
}; };
using (Process proc = new Process { StartInfo = psi }) using (Process proc = new Process { StartInfo = psi })
{ {
proc.Start(); proc.Start();
string line; string line;
int lastPercent = 0; int lastPercent = 0;
var regex = new Regex(@"(\d+)%"); var regex = new Regex(@"(\d+)%");
Invoke(new Action(() => Invoke(new Action(() =>
{ {
installProgress.Value = 0; installProgress.Value = 0;
@@ -727,11 +723,9 @@ namespace Perfect11
while (!proc.HasExited) while (!proc.HasExited)
{ {
token.ThrowIfCancellationRequested(); token.ThrowIfCancellationRequested();
line = proc.StandardOutput.ReadLine(); line = proc.StandardOutput.ReadLine();
if (line == null) if (line == null)
continue; continue;
var match = regex.Match(line); var match = regex.Match(line);
if (match.Success) if (match.Success)
{ {
@@ -749,7 +743,6 @@ namespace Perfect11
} }
}, token); }, token);
proc.WaitForExit(); proc.WaitForExit();
if (proc.ExitCode != 0) if (proc.ExitCode != 0)
throw new Exception($"7-Zip exited with code {proc.ExitCode}"); throw new Exception($"7-Zip exited with code {proc.ExitCode}");
} }

View File

@@ -1,13 +1,14 @@
using Microsoft.Win32; using System;
using Newtonsoft.Json;
using Perfect11.TweaksInterface;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Globalization; using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
using System.Runtime.InteropServices;
using System.Security.Principal; using System.Security.Principal;
using Microsoft.Win32;
using Newtonsoft.Json;
using Perfect11.TweaksInterface;
namespace Perfect11.Library namespace Perfect11.Library
{ {
@@ -147,5 +148,18 @@ namespace Perfect11.Library
} }
} }
} }
public static string GetSystemArchitecture()
{
string arch = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITECTURE");
string archWow64 = Environment.GetEnvironmentVariable("PROCESSOR_ARCHITEW6432");
string osArch;
if (!string.IsNullOrEmpty(archWow64))
osArch = archWow64; // 64-bit OS, 32-bit process
else
osArch = arch;
if (osArch.ToLower() == "arm64")
osArch = "A64";
return osArch;
}
} }
} }

View File

@@ -24,6 +24,17 @@ namespace Perfect11
#else #else
Application.ThreadException += (s, e) => { }; Application.ThreadException += (s, e) => { };
#endif #endif
if (Utilities.GetSystemArchitecture().ToLower() == "x86")
{
MessageBox.Show("You're running on Windows 32 bits, this program requires Windows 64 bits.","Perfect11",MessageBoxButtons.OK,MessageBoxIcon.Error);
return;
}
else if (Utilities.GetSystemArchitecture().ToLower() == "a64")
{
var dialog = MessageBox.Show("You're running Windows on ARM. ARM64 support for this tool is experimental, and not everything will work fine. Are you sure to continue?","Perfect11",MessageBoxButtons.YesNo,MessageBoxIcon.Warning,MessageBoxDefaultButton.Button2);
if (dialog == DialogResult.No)
return;
}
Application.Run(new Form1()); Application.Run(new Form1());
} }
} }