Fixed toolchain install on windows

This commit is contained in:
2025-04-15 14:18:58 +02:00
parent 849e221b32
commit dc9bfcb155
3 changed files with 64 additions and 32 deletions

View File

@@ -29,7 +29,7 @@ public class InstallerWindow : EditorWindow
private void RefreshToolStatus() private void RefreshToolStatus()
{ {
mipsToolStatus.Clear(); mipsToolStatus.Clear();
foreach (var tool in ToolchainChecker.requiredTools) foreach (var tool in ToolchainChecker.GetRequiredTools())
{ {
mipsToolStatus[tool] = ToolchainChecker.IsToolAvailable(tool); mipsToolStatus[tool] = ToolchainChecker.IsToolAvailable(tool);
} }
@@ -148,9 +148,12 @@ public class InstallerWindow : EditorWindow
isInstalling = true; isInstalling = true;
EditorUtility.DisplayProgressBar("Installing MIPS Toolchain", EditorUtility.DisplayProgressBar("Installing MIPS Toolchain",
"Please wait while the MIPS toolchain is being installed...", 0f); "Please wait while the MIPS toolchain is being installed...", 0f);
await ToolchainInstaller.InstallToolchain(); bool success = await ToolchainInstaller.InstallToolchain();
EditorUtility.ClearProgressBar(); EditorUtility.ClearProgressBar();
if (success)
{
EditorUtility.DisplayDialog("Installation Complete", "MIPS toolchain installed successfully.", "OK"); EditorUtility.DisplayDialog("Installation Complete", "MIPS toolchain installed successfully.", "OK");
}
RefreshToolStatus(); // Update cached statuses after installation RefreshToolStatus(); // Update cached statuses after installation
} }
catch (System.Exception ex) catch (System.Exception ex)

View File

@@ -1,36 +1,32 @@
using UnityEngine; using UnityEngine;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.IO;
using System;
public static class ToolchainChecker public static class ToolchainChecker
{ {
public static readonly string[] requiredTools = new[] public static readonly string[] mipsToolSuffixes = new[]
{ {
"mipsel-linux-gnu-addr2line", "addr2line", "ar", "as", "cpp", "elfedit", "g++", "gcc", "gcc-ar", "gcc-nm",
"mipsel-linux-gnu-ar", "gcc-ranlib", "gcov", "ld", "nm", "objcopy", "objdump", "ranlib", "readelf",
"mipsel-linux-gnu-as", "size", "strings", "strip"
"mipsel-linux-gnu-cpp",
"mipsel-linux-gnu-elfedit",
"mipsel-linux-gnu-g++",
"mipsel-linux-gnu-gcc",
"mipsel-linux-gnu-gcc-ar",
"mipsel-linux-gnu-gcc-nm",
"mipsel-linux-gnu-gcc-ranlib",
"mipsel-linux-gnu-gcov",
"mipsel-linux-gnu-ld",
"mipsel-linux-gnu-nm",
"mipsel-linux-gnu-objcopy",
"mipsel-linux-gnu-objdump",
"mipsel-linux-gnu-ranlib",
"mipsel-linux-gnu-readelf",
"mipsel-linux-gnu-size",
"mipsel-linux-gnu-strings",
"mipsel-linux-gnu-strip"
}; };
/// <summary> /// <summary>
/// Checks for the availability of a given tool by using a system command. /// Returns the full tool names to be checked, based on platform.
/// "where" is used on Windows and "which" on other platforms. /// </summary>
public static string[] GetRequiredTools()
{
string prefix = Application.platform == RuntimePlatform.WindowsEditor
? "mipsel-none-elf-"
: "mipsel-linux-gnu-";
return mipsToolSuffixes.Select(s => prefix + s).ToArray();
}
/// <summary>
/// Checks for availability of any tool (either full name like "make" or "mipsel-*").
/// </summary> /// </summary>
public static bool IsToolAvailable(string toolName) public static bool IsToolAvailable(string toolName)
{ {
@@ -55,7 +51,22 @@ public static class ToolchainChecker
string output = process.StandardOutput.ReadToEnd().Trim(); string output = process.StandardOutput.ReadToEnd().Trim();
process.WaitForExit(); process.WaitForExit();
return !string.IsNullOrEmpty(output); if (!string.IsNullOrEmpty(output))
return true;
// Additional fallback for MIPS tools on Windows in local MIPS path
if (Application.platform == RuntimePlatform.WindowsEditor &&
toolName.StartsWith("mipsel-none-elf-"))
{
string localMipsBin = Path.Combine(
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
"mips", "mips", "bin");
string fullPath = Path.Combine(localMipsBin, toolName + ".exe");
return File.Exists(fullPath);
}
return false;
} }
catch catch
{ {

View File

@@ -3,6 +3,7 @@ using System.Diagnostics;
using System.Threading.Tasks; using System.Threading.Tasks;
using UnityEngine; using UnityEngine;
using UnityEditor; using UnityEditor;
using System.IO;
public static class ToolchainInstaller public static class ToolchainInstaller
{ {
@@ -21,11 +22,25 @@ public static class ToolchainInstaller
{ {
var tcs = new TaskCompletionSource<int>(); var tcs = new TaskCompletionSource<int>();
if (fileName.Equals("mips", StringComparison.OrdinalIgnoreCase))
{
fileName = "powershell";
// Get the AppData\Roaming path for the user
string roamingPath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData);
string scriptPath = Path.Combine(roamingPath, "mips\\mips.ps1");
// Pass the arguments to the PowerShell script
arguments = $"-ExecutionPolicy Bypass -File \"{scriptPath}\" {arguments}";
}
Process process = new Process(); Process process = new Process();
process.StartInfo.FileName = fileName; process.StartInfo.FileName = fileName;
process.StartInfo.Arguments = arguments; process.StartInfo.Arguments = arguments;
process.StartInfo.CreateNoWindow = true; process.StartInfo.CreateNoWindow = false;
process.StartInfo.UseShellExecute = false; process.StartInfo.UseShellExecute = true;
if (!string.IsNullOrEmpty(workingDirectory)) if (!string.IsNullOrEmpty(workingDirectory))
process.StartInfo.WorkingDirectory = workingDirectory; process.StartInfo.WorkingDirectory = workingDirectory;
@@ -50,6 +65,7 @@ public static class ToolchainInstaller
throw new Exception($"Process '{fileName} {arguments}' exited with code {exitCode}"); throw new Exception($"Process '{fileName} {arguments}' exited with code {exitCode}");
} }
#region MIPS Toolchain Installation #region MIPS Toolchain Installation
/// <summary> /// <summary>
@@ -66,7 +82,7 @@ public static class ToolchainInstaller
await RunCommandAsync("powershell", await RunCommandAsync("powershell",
"-c \"& { iwr -UseBasicParsing https://raw.githubusercontent.com/grumpycoders/pcsx-redux/main/mips.ps1 | iex }\""); "-c \"& { iwr -UseBasicParsing https://raw.githubusercontent.com/grumpycoders/pcsx-redux/main/mips.ps1 | iex }\"");
EditorUtility.DisplayDialog("Reboot Required", EditorUtility.DisplayDialog("Reboot Required",
"Installing the MIPS toolchain requires a reboot. Please reboot your computer before proceeding further.", "Installing the MIPS toolchain requires a reboot. Please reboot your computer and click the button again.",
"OK"); "OK");
} }
catch (Exception ex) catch (Exception ex)
@@ -81,7 +97,7 @@ public static class ToolchainInstaller
/// Installs the MIPS toolchain based on the current platform. /// Installs the MIPS toolchain based on the current platform.
/// Uses pkexec on Linux to request graphical elevation. /// Uses pkexec on Linux to request graphical elevation.
/// </summary> /// </summary>
public static async Task InstallToolchain() public static async Task<bool> InstallToolchain()
{ {
switch (Application.platform) switch (Application.platform)
{ {
@@ -91,10 +107,11 @@ public static class ToolchainInstaller
if (!ToolchainChecker.IsToolAvailable("mips")) if (!ToolchainChecker.IsToolAvailable("mips"))
{ {
await InstallMips(); await InstallMips();
return false;
} }
else else
{ {
if (win32MipsToolsInstalling) return; if (win32MipsToolsInstalling) return false;
win32MipsToolsInstalling = true; win32MipsToolsInstalling = true;
await RunCommandAsync("mips", $"install {mipsVersion}"); await RunCommandAsync("mips", $"install {mipsVersion}");
} }
@@ -168,6 +185,7 @@ public static class ToolchainInstaller
"Your platform is not supported by this extension. Please install the MIPS toolchain manually.", "OK"); "Your platform is not supported by this extension. Please install the MIPS toolchain manually.", "OK");
throw new Exception("Unsupported platform"); throw new Exception("Unsupported platform");
} }
return true;
} }
#endregion #endregion